forked from vitrine/wmaker
Compare commits
2 Commits
malloc-rs
...
refactor/r
| Author | SHA1 | Date | |
|---|---|---|---|
| 02d638d1c6 | |||
| 54bd69680a |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -142,4 +142,4 @@ WPrefs.app/WPrefs.desktop
|
|||||||
.pc
|
.pc
|
||||||
|
|
||||||
# Rust stuff.
|
# Rust stuff.
|
||||||
/*/target/**
|
/wmakerlib/target/**
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ ACLOCAL_AMFLAGS = -I m4
|
|||||||
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-silent-rules LINGUAS='*'
|
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-silent-rules LINGUAS='*'
|
||||||
|
|
||||||
|
|
||||||
SUBDIRS = wrlib WINGs wmaker-rs src util po WindowMaker wmlib WPrefs.app doc
|
SUBDIRS = wrlib WINGs src util po WindowMaker wmlib WPrefs.app doc
|
||||||
DIST_SUBDIRS = $(SUBDIRS) test
|
DIST_SUBDIRS = $(SUBDIRS) test
|
||||||
|
|
||||||
EXTRA_DIST = TODO BUGS BUGFORM FAQ INSTALL \
|
EXTRA_DIST = TODO BUGS BUGFORM FAQ INSTALL \
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ int wcopy_file(const char *dest_dir, const char *src_file, const char *dest_file
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = wmalloc(buffer_size);
|
buffer = malloc(buffer_size); /* Don't use wmalloc to avoid the memset(0) we don't need */
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
werror(_("could not allocate memory for the copy buffer"));
|
werror(_("could not allocate memory for the copy buffer"));
|
||||||
close(fd_dst);
|
close(fd_dst);
|
||||||
@@ -508,14 +508,14 @@ int wcopy_file(const char *dest_dir, const char *src_file, const char *dest_file
|
|||||||
if (close(fd_dst) != 0) {
|
if (close(fd_dst) != 0) {
|
||||||
werror(_("could not close the file \"%s\": %s"), path_dst, strerror(errno));
|
werror(_("could not close the file \"%s\": %s"), path_dst, strerror(errno));
|
||||||
cleanup_and_return_failure:
|
cleanup_and_return_failure:
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
close(fd_src);
|
close(fd_src);
|
||||||
unlink(path_dst);
|
unlink(path_dst);
|
||||||
wfree(path_dst);
|
wfree(path_dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
wfree(path_dst);
|
wfree(path_dst);
|
||||||
close(fd_src);
|
close(fd_src);
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback * callback, void *cda
|
|||||||
{
|
{
|
||||||
TimerHandler *handler;
|
TimerHandler *handler;
|
||||||
|
|
||||||
handler = wmalloc(sizeof(TimerHandler));
|
handler = malloc(sizeof(TimerHandler));
|
||||||
if (!handler)
|
if (!handler)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ WMHandlerID WMAddIdleHandler(WMCallback * callback, void *cdata)
|
|||||||
{
|
{
|
||||||
IdleHandler *handler;
|
IdleHandler *handler;
|
||||||
|
|
||||||
handler = wmalloc(sizeof(IdleHandler));
|
handler = malloc(sizeof(IdleHandler));
|
||||||
if (!handler)
|
if (!handler)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|||||||
176
WINGs/memory.c
176
WINGs/memory.c
@@ -19,15 +19,34 @@
|
|||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include "wconfig.h"
|
||||||
|
|
||||||
#include "WUtil.h"
|
#include "WUtil.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
#ifdef HAVE_STDNORETURN
|
||||||
#include <stdnoreturn.h>
|
#include <stdnoreturn.h>
|
||||||
#include <unistd.h>
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_BOEHM_GC
|
||||||
|
#ifndef GC_DEBUG
|
||||||
|
#define GC_DEBUG
|
||||||
|
#endif /* !GC_DEBUG */
|
||||||
|
#include <gc/gc.h>
|
||||||
|
#endif /* USE_BOEHM_GC */
|
||||||
|
|
||||||
|
#ifndef False
|
||||||
|
# define False 0
|
||||||
|
#endif
|
||||||
|
#ifndef True
|
||||||
|
# define True 1
|
||||||
|
#endif
|
||||||
|
|
||||||
static void defaultHandler(int bla)
|
static void defaultHandler(int bla)
|
||||||
{
|
{
|
||||||
@@ -53,3 +72,152 @@ waborthandler *wsetabort(waborthandler * handler)
|
|||||||
|
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int Aborting = 0; /* if we're in the middle of an emergency exit */
|
||||||
|
|
||||||
|
static WMHashTable *table = NULL;
|
||||||
|
|
||||||
|
void *wmalloc(size_t size)
|
||||||
|
{
|
||||||
|
void *tmp;
|
||||||
|
|
||||||
|
assert(size > 0);
|
||||||
|
|
||||||
|
#ifdef USE_BOEHM_GC
|
||||||
|
tmp = GC_MALLOC(size);
|
||||||
|
#else
|
||||||
|
tmp = malloc(size);
|
||||||
|
#endif
|
||||||
|
if (tmp == NULL) {
|
||||||
|
wwarning("malloc() failed. Retrying after 2s.");
|
||||||
|
sleep(2);
|
||||||
|
#ifdef USE_BOEHM_GC
|
||||||
|
tmp = GC_MALLOC(size);
|
||||||
|
#else
|
||||||
|
tmp = malloc(size);
|
||||||
|
#endif
|
||||||
|
if (tmp == NULL) {
|
||||||
|
if (Aborting) {
|
||||||
|
fputs("Really Bad Error: recursive malloc() failure.", stderr);
|
||||||
|
exit(-1);
|
||||||
|
} else {
|
||||||
|
wfatal("virtual memory exhausted");
|
||||||
|
Aborting = 1;
|
||||||
|
wAbort(False);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tmp != NULL)
|
||||||
|
memset(tmp, 0, size);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *wrealloc(void *ptr, size_t newsize)
|
||||||
|
{
|
||||||
|
void *nptr;
|
||||||
|
|
||||||
|
if (!ptr) {
|
||||||
|
nptr = wmalloc(newsize);
|
||||||
|
} else if (newsize == 0) {
|
||||||
|
wfree(ptr);
|
||||||
|
nptr = NULL;
|
||||||
|
} else {
|
||||||
|
#ifdef USE_BOEHM_GC
|
||||||
|
nptr = GC_REALLOC(ptr, newsize);
|
||||||
|
#else
|
||||||
|
nptr = realloc(ptr, newsize);
|
||||||
|
#endif
|
||||||
|
if (nptr == NULL) {
|
||||||
|
wwarning("realloc() failed. Retrying after 2s.");
|
||||||
|
sleep(2);
|
||||||
|
#ifdef USE_BOEHM_GC
|
||||||
|
nptr = GC_REALLOC(ptr, newsize);
|
||||||
|
#else
|
||||||
|
nptr = realloc(ptr, newsize);
|
||||||
|
#endif
|
||||||
|
if (nptr == NULL) {
|
||||||
|
if (Aborting) {
|
||||||
|
fputs("Really Bad Error: recursive realloc() failure.", stderr);
|
||||||
|
exit(-1);
|
||||||
|
} else {
|
||||||
|
wfatal("virtual memory exhausted");
|
||||||
|
Aborting = 1;
|
||||||
|
wAbort(False);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *wretain(void *ptr)
|
||||||
|
{
|
||||||
|
int *refcount;
|
||||||
|
|
||||||
|
if (!table) {
|
||||||
|
table = WMCreateHashTable(WMIntHashCallbacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
refcount = WMHashGet(table, ptr);
|
||||||
|
if (!refcount) {
|
||||||
|
refcount = wmalloc(sizeof(int));
|
||||||
|
*refcount = 1;
|
||||||
|
WMHashInsert(table, ptr, refcount);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("== %i (%p)\n", *refcount, ptr);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
(*refcount)++;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("+ %i (%p)\n", *refcount, ptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wfree(void *ptr)
|
||||||
|
{
|
||||||
|
if (ptr)
|
||||||
|
#ifdef USE_BOEHM_GC
|
||||||
|
/* This should eventually be removed, once the criss-cross
|
||||||
|
* of wmalloc()d memory being free()d, malloc()d memory being
|
||||||
|
* wfree()d, various misuses of calling wfree() on objects
|
||||||
|
* allocated by libc malloc() and calling libc free() on
|
||||||
|
* objects allocated by Boehm GC (think external libraries)
|
||||||
|
* is cleaned up.
|
||||||
|
*/
|
||||||
|
if (GC_base(ptr) != 0)
|
||||||
|
GC_FREE(ptr);
|
||||||
|
else
|
||||||
|
free(ptr);
|
||||||
|
#else
|
||||||
|
free(ptr);
|
||||||
|
#endif
|
||||||
|
ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wrelease(void *ptr)
|
||||||
|
{
|
||||||
|
int *refcount;
|
||||||
|
|
||||||
|
refcount = WMHashGet(table, ptr);
|
||||||
|
if (!refcount) {
|
||||||
|
wwarning("trying to release unexisting data %p", ptr);
|
||||||
|
} else {
|
||||||
|
(*refcount)--;
|
||||||
|
if (*refcount < 1) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("RELEASING %p\n", ptr);
|
||||||
|
#endif
|
||||||
|
WMHashRemove(table, ptr);
|
||||||
|
wfree(refcount);
|
||||||
|
wfree(ptr);
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
else {
|
||||||
|
printf("- %i (%p)\n", *refcount, ptr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -610,9 +610,10 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
|
|||||||
assert(W_ApplicationInitialized());
|
assert(W_ApplicationInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
scrPtr = wmalloc(sizeof(W_Screen));
|
scrPtr = malloc(sizeof(W_Screen));
|
||||||
if (!scrPtr)
|
if (!scrPtr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
memset(scrPtr, 0, sizeof(W_Screen));
|
||||||
|
|
||||||
scrPtr->aflags.hasAppIcon = 1;
|
scrPtr->aflags.hasAppIcon = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ static void autoDelayChanged(void *observerData, WMNotification *notification)
|
|||||||
}
|
}
|
||||||
char *value = WMGetTextFieldText(anAutoDelayT);
|
char *value = WMGetTextFieldText(anAutoDelayT);
|
||||||
adjustButtonSelectionBasedOnValue(panel, row, value);
|
adjustButtonSelectionBasedOnValue(panel, row, value);
|
||||||
wfree(value);
|
free(value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ static void storeData(_Panel * panel)
|
|||||||
if (sscanf(str, "%i", &i) != 1)
|
if (sscanf(str, "%i", &i) != 1)
|
||||||
i = 0;
|
i = 0;
|
||||||
SetIntegerForKey(i, "RaiseDelay");
|
SetIntegerForKey(i, "RaiseDelay");
|
||||||
wfree(str);
|
free(str);
|
||||||
|
|
||||||
SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
|
SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
|
||||||
SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
|
SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ static void storeData(_Panel * panel)
|
|||||||
if (sscanf(str, "%i", &i) != 1)
|
if (sscanf(str, "%i", &i) != 1)
|
||||||
i = 0;
|
i = 0;
|
||||||
SetIntegerForKey(i, "HotCornerDelay");
|
SetIntegerForKey(i, "HotCornerDelay");
|
||||||
wfree(str);
|
free(str);
|
||||||
|
|
||||||
SetIntegerForKey(WMGetSliderValue(panel->hceS), "HotCornerEdge");
|
SetIntegerForKey(WMGetSliderValue(panel->hceS), "HotCornerEdge");
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ WPrefs_DEPENDENCIES = $(top_builddir)/WINGs/libWINGs.la
|
|||||||
WPrefs_LDADD = \
|
WPrefs_LDADD = \
|
||||||
$(top_builddir)/WINGs/libWINGs.la\
|
$(top_builddir)/WINGs/libWINGs.la\
|
||||||
$(top_builddir)/WINGs/libWUtil.la\
|
$(top_builddir)/WINGs/libWUtil.la\
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(top_builddir)/wrlib/libwraster.la \
|
$(top_builddir)/wrlib/libwraster.la \
|
||||||
@XLFLAGS@ @XLIBS@ \
|
@XLFLAGS@ @XLIBS@ \
|
||||||
@LIBM@ \
|
@LIBM@ \
|
||||||
|
|||||||
12
configure.ac
12
configure.ac
@@ -49,15 +49,6 @@ AC_CONFIG_SRCDIR([src/WindowMaker.h])
|
|||||||
dnl Include at the end of 'config.h', this file is generated by top-level Makefile
|
dnl Include at the end of 'config.h', this file is generated by top-level Makefile
|
||||||
AH_BOTTOM([@%:@include "config-paths.h"])
|
AH_BOTTOM([@%:@include "config-paths.h"])
|
||||||
|
|
||||||
dnl Rust support
|
|
||||||
AC_CHECK_PROG(CARGO, [cargo], [yes], [no])
|
|
||||||
AS_IF(test x$CARGO = xno,
|
|
||||||
AC_MSG_ERROR([cargo is required. Please set the CARGO environment variable or install the Rust toolchain from https://www.rust-lang.org/])
|
|
||||||
)
|
|
||||||
AC_CHECK_PROG(RUSTC, [rustc], [yes], [no])
|
|
||||||
AS_IF(test x$RUSTC = xno,
|
|
||||||
AC_MSG_ERROR([rustc is required. Please set the RUSTC environment variable or install the Rust toolchain from https://www.rust-lang.org/])
|
|
||||||
)
|
|
||||||
|
|
||||||
dnl libtool library versioning
|
dnl libtool library versioning
|
||||||
dnl ==========================
|
dnl ==========================
|
||||||
@@ -978,9 +969,6 @@ AC_CONFIG_FILES(
|
|||||||
WINGs/Documentation/Makefile WINGs/Resources/Makefile WINGs/Extras/Makefile
|
WINGs/Documentation/Makefile WINGs/Resources/Makefile WINGs/Extras/Makefile
|
||||||
WINGs/Examples/Makefile WINGs/Tests/Makefile
|
WINGs/Examples/Makefile WINGs/Tests/Makefile
|
||||||
|
|
||||||
dnl Rust implementation of Window Maker core
|
|
||||||
wmaker-rs/Makefile
|
|
||||||
|
|
||||||
dnl Window Maker's core
|
dnl Window Maker's core
|
||||||
src/Makefile src/wconfig.h po/Makefile
|
src/Makefile src/wconfig.h po/Makefile
|
||||||
doc/Makefile doc/build/Makefile
|
doc/Makefile doc/build/Makefile
|
||||||
|
|||||||
@@ -6,7 +6,13 @@ bin_PROGRAMS = wmaker
|
|||||||
|
|
||||||
EXTRA_DIST =
|
EXTRA_DIST =
|
||||||
|
|
||||||
|
wmakerlib = $(top_builddir)/wmakerlib/target/debug/libwmakerlib.a
|
||||||
|
|
||||||
|
$(wmakerlib):
|
||||||
|
@(cd $(top_builddir)/wmakerlib && cargo build)
|
||||||
|
|
||||||
wmaker_SOURCES = \
|
wmaker_SOURCES = \
|
||||||
|
$(wmakerlib) \
|
||||||
GNUstep.h \
|
GNUstep.h \
|
||||||
WindowMaker.h \
|
WindowMaker.h \
|
||||||
actions.c \
|
actions.c \
|
||||||
@@ -134,7 +140,7 @@ else
|
|||||||
nodist_wmaker_SOURCES = misc.hack_nf.c \
|
nodist_wmaker_SOURCES = misc.hack_nf.c \
|
||||||
xmodifier.hack_nf.c
|
xmodifier.hack_nf.c
|
||||||
|
|
||||||
CLEANFILES = $(nodist_wmaker_SOURCES) ../wmaker-rs/target
|
CLEANFILES = $(nodist_wmaker_SOURCES) ../wmakerlib/target
|
||||||
|
|
||||||
misc.hack_nf.c: misc.c $(top_srcdir)/script/nested-func-to-macro.sh
|
misc.hack_nf.c: misc.c $(top_srcdir)/script/nested-func-to-macro.sh
|
||||||
$(AM_V_GEN)$(top_srcdir)/script/nested-func-to-macro.sh \
|
$(AM_V_GEN)$(top_srcdir)/script/nested-func-to-macro.sh \
|
||||||
@@ -160,7 +166,7 @@ wmaker_LDADD = \
|
|||||||
$(top_builddir)/WINGs/libWINGs.la\
|
$(top_builddir)/WINGs/libWINGs.la\
|
||||||
$(top_builddir)/WINGs/libWUtil.la\
|
$(top_builddir)/WINGs/libWUtil.la\
|
||||||
$(top_builddir)/wrlib/libwraster.la\
|
$(top_builddir)/wrlib/libwraster.la\
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
$(wmakerlib)\
|
||||||
@XLFLAGS@ \
|
@XLFLAGS@ \
|
||||||
@LIBXRANDR@ \
|
@LIBXRANDR@ \
|
||||||
@LIBXINERAMA@ \
|
@LIBXINERAMA@ \
|
||||||
|
|||||||
@@ -75,24 +75,24 @@ struct WAppIcon {
|
|||||||
Window main_window;
|
Window main_window;
|
||||||
struct WDock *dock; /* In which dock is docked. */
|
struct WDock *dock; /* In which dock is docked. */
|
||||||
struct _AppSettingsPanel *panel; /* Settings Panel */
|
struct _AppSettingsPanel *panel; /* Settings Panel */
|
||||||
unsigned int docked:1;
|
unsigned int docked;
|
||||||
unsigned int omnipresent:1; /* If omnipresent when
|
unsigned int omnipresent; /* If omnipresent when
|
||||||
* docked in clip */
|
* docked in clip */
|
||||||
unsigned int attracted:1; /* If it was attracted by the clip */
|
unsigned int attracted; /* If it was attracted by the clip */
|
||||||
unsigned int launching:1;
|
unsigned int launching;
|
||||||
unsigned int running:1; /* application is already running */
|
unsigned int running; /* application is already running */
|
||||||
unsigned int relaunching:1; /* launching 2nd instance */
|
unsigned int relaunching; /* launching 2nd instance */
|
||||||
unsigned int forced_dock:1;
|
unsigned int forced_dock;
|
||||||
unsigned int auto_launch:1; /* launch app on startup */
|
unsigned int auto_launch; /* launch app on startup */
|
||||||
unsigned int remote_start:1;
|
unsigned int remote_start;
|
||||||
unsigned int updated:1;
|
unsigned int updated;
|
||||||
unsigned int editing:1; /* editing docked icon */
|
unsigned int editing; /* editing docked icon */
|
||||||
unsigned int drop_launch:1; /* launching from drop action */
|
unsigned int drop_launch; /* launching from drop action */
|
||||||
unsigned int paste_launch:1; /* launching from paste action */
|
unsigned int paste_launch; /* launching from paste action */
|
||||||
unsigned int destroyed:1; /* appicon was destroyed */
|
unsigned int destroyed; /* appicon was destroyed */
|
||||||
unsigned int buggy_app:1; /* do not make dock rely on hints
|
unsigned int buggy_app; /* do not make dock rely on hints
|
||||||
* set by app */
|
* set by app */
|
||||||
unsigned int lock:1; /* do not allow to be destroyed */
|
unsigned int lock; /* do not allow to be destroyed */
|
||||||
};
|
};
|
||||||
|
|
||||||
/******** Accessors/mutators ********/
|
/******** Accessors/mutators ********/
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
|
|||||||
}
|
}
|
||||||
wstrlcpy(title, &slist[*index][pos], sizeof(title));
|
wstrlcpy(title, &slist[*index][pos], sizeof(title));
|
||||||
}
|
}
|
||||||
data = wmalloc(sizeof(WAppMenuData));
|
data = malloc(sizeof(WAppMenuData));
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
wwarning(_("appmenu: out of memory creating menu for window %lx"), win);
|
wwarning(_("appmenu: out of memory creating menu for window %lx"), win);
|
||||||
wMenuDestroy(menu, True);
|
wMenuDestroy(menu, True);
|
||||||
@@ -152,7 +152,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
|
|||||||
if (!entry) {
|
if (!entry) {
|
||||||
wMenuDestroy(menu, True);
|
wMenuDestroy(menu, True);
|
||||||
wwarning(_("appmenu: out of memory creating menu for window %lx"), win);
|
wwarning(_("appmenu: out of memory creating menu for window %lx"), win);
|
||||||
wfree(data);
|
free(data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (rtext[0] != 0)
|
if (rtext[0] != 0)
|
||||||
|
|||||||
31
src/dialog.c
31
src/dialog.c
@@ -39,6 +39,10 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_MALLOC_H
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#include <sys/signal.h>
|
#include <sys/signal.h>
|
||||||
@@ -1357,7 +1361,7 @@ void wShowInfoPanel(WScreen *scr)
|
|||||||
char *posn = getPrettyOSName();
|
char *posn = getPrettyOSName();
|
||||||
if (posn) {
|
if (posn) {
|
||||||
snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), posn, uts.machine);
|
snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), posn, uts.machine);
|
||||||
wfree(posn);
|
free(posn);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), uts.sysname, uts.machine);
|
snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), uts.sysname, uts.machine);
|
||||||
@@ -1389,6 +1393,31 @@ void wShowInfoPanel(WScreen *scr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO2)
|
||||||
|
{
|
||||||
|
struct mallinfo2 ma = mallinfo2();
|
||||||
|
snprintf(buffer, sizeof(buffer),
|
||||||
|
#ifdef DEBUG
|
||||||
|
_("Total memory allocated: %lu kB (in use: %lu kB, %lu free chunks)\n"),
|
||||||
|
#else
|
||||||
|
_("Total memory allocated: %lu kB (in use: %lu kB)\n"),
|
||||||
|
#endif
|
||||||
|
(ma.arena + ma.hblkhd) / 1024,
|
||||||
|
(ma.uordblks + ma.hblkhd) / 1024
|
||||||
|
#ifdef DEBUG
|
||||||
|
/*
|
||||||
|
* This information is representative of the memory
|
||||||
|
* fragmentation. In ideal case it should be 1, but
|
||||||
|
* that is never possible
|
||||||
|
*/
|
||||||
|
, ma.ordblks
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
strbuf = wstrappend(strbuf, buffer);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
strbuf = wstrappend(strbuf, _("Image formats: "));
|
strbuf = wstrappend(strbuf, _("Image formats: "));
|
||||||
strl = RSupportedFileFormats();
|
strl = RSupportedFileFormats();
|
||||||
separator = NULL;
|
separator = NULL;
|
||||||
|
|||||||
12
src/dock.c
12
src/dock.c
@@ -3194,7 +3194,7 @@ static pid_t execCommand(WAppIcon *btn, const char *command, WSavedState *state)
|
|||||||
setsid();
|
setsid();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
args = wmalloc(sizeof(char *) * (argc + 1));
|
args = malloc(sizeof(char *) * (argc + 1));
|
||||||
if (!args)
|
if (!args)
|
||||||
exit(111);
|
exit(111);
|
||||||
|
|
||||||
@@ -3338,8 +3338,8 @@ void wDockTrackWindowLaunch(WDock *dock, Window window)
|
|||||||
char *command = NULL;
|
char *command = NULL;
|
||||||
|
|
||||||
if (!PropGetWMClass(window, &wm_class, &wm_instance)) {
|
if (!PropGetWMClass(window, &wm_class, &wm_instance)) {
|
||||||
wfree(wm_class);
|
free(wm_class);
|
||||||
wfree(wm_instance);
|
free(wm_instance);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3419,8 +3419,10 @@ void wDockTrackWindowLaunch(WDock *dock, Window window)
|
|||||||
if (command)
|
if (command)
|
||||||
wfree(command);
|
wfree(command);
|
||||||
|
|
||||||
wfree(wm_class);
|
if (wm_class)
|
||||||
wfree(wm_instance);
|
free(wm_class);
|
||||||
|
if (wm_instance)
|
||||||
|
free(wm_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wClipUpdateForWorkspaceChange(WScreen *scr, int workspace)
|
void wClipUpdateForWorkspaceChange(WScreen *scr, int workspace)
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
|
|||||||
{
|
{
|
||||||
DeathHandler *handler;
|
DeathHandler *handler;
|
||||||
|
|
||||||
handler = wmalloc(sizeof(DeathHandler));
|
handler = malloc(sizeof(DeathHandler));
|
||||||
if (!handler)
|
if (!handler)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
|
|||||||
handler->client_data = cdata;
|
handler->client_data = cdata;
|
||||||
|
|
||||||
if (!deathHandlers)
|
if (!deathHandlers)
|
||||||
deathHandlers = WMCreateArrayWithDestructor(8, wfree);
|
deathHandlers = WMCreateArrayWithDestructor(8, free);
|
||||||
|
|
||||||
WMAddToArray(deathHandlers, handler);
|
WMAddToArray(deathHandlers, handler);
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ static void wdelete_death_handler(WMagicNumber id)
|
|||||||
if (!handler || !deathHandlers)
|
if (!handler || !deathHandlers)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* array destructor will call wfree(handler) */
|
/* array destructor will call free(handler) */
|
||||||
WMRemoveFromArray(deathHandlers, handler);
|
WMRemoveFromArray(deathHandlers, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ WGeometryView *WCreateGeometryView(WMScreen * scr)
|
|||||||
widgetClass = W_RegisterUserWidget();
|
widgetClass = W_RegisterUserWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
gview = wmalloc(sizeof(WGeometryView));
|
gview = malloc(sizeof(WGeometryView));
|
||||||
if (!gview) {
|
if (!gview) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ static void setWVisualID(int screen, int val)
|
|||||||
/* no array at all, alloc space for screen + 1 entries
|
/* no array at all, alloc space for screen + 1 entries
|
||||||
* and init with default value */
|
* and init with default value */
|
||||||
wVisualID_len = screen + 1;
|
wVisualID_len = screen + 1;
|
||||||
wVisualID = (int *)wmalloc(wVisualID_len * sizeof(int));
|
wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
|
||||||
for (i = 0; i < wVisualID_len; i++) {
|
for (i = 0; i < wVisualID_len; i++) {
|
||||||
wVisualID[i] = -1;
|
wVisualID[i] = -1;
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ static void setWVisualID(int screen, int val)
|
|||||||
*/
|
*/
|
||||||
static int initWVisualID(const char *user_str)
|
static int initWVisualID(const char *user_str)
|
||||||
{
|
{
|
||||||
char *mystr = wstrdup(user_str);
|
char *mystr = strdup(user_str);
|
||||||
int cur_in_pos = 0;
|
int cur_in_pos = 0;
|
||||||
int cur_out_pos = 0;
|
int cur_out_pos = 0;
|
||||||
int cur_screen = 0;
|
int cur_screen = 0;
|
||||||
@@ -191,7 +191,7 @@ static int initWVisualID(const char *user_str)
|
|||||||
cur_in_pos++;
|
cur_in_pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
wfree(mystr);
|
free(mystr);
|
||||||
|
|
||||||
if (cur_screen == 0||error_found != 0)
|
if (cur_screen == 0||error_found != 0)
|
||||||
return 1;
|
return 1;
|
||||||
@@ -383,7 +383,7 @@ Bool RelaunchWindow(WWindow *wwin)
|
|||||||
setsid();
|
setsid();
|
||||||
#endif
|
#endif
|
||||||
/* argv is not null-terminated */
|
/* argv is not null-terminated */
|
||||||
char **a = (char **) wmalloc(argc + 1);
|
char **a = (char **) malloc(argc + 1);
|
||||||
if (! a) {
|
if (! a) {
|
||||||
werror("out of memory trying to relaunch the application");
|
werror("out of memory trying to relaunch the application");
|
||||||
Exit(-1);
|
Exit(-1);
|
||||||
|
|||||||
12
src/misc.c
12
src/misc.c
@@ -520,7 +520,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
|
|||||||
|
|
||||||
len = strlen(cmdline);
|
len = strlen(cmdline);
|
||||||
olen = len + 1;
|
olen = len + 1;
|
||||||
out = wmalloc(olen);
|
out = malloc(olen);
|
||||||
if (!out) {
|
if (!out) {
|
||||||
wwarning(_("out of memory during expansion of \"%s\""), cmdline);
|
wwarning(_("out of memory during expansion of \"%s\""), cmdline);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -573,7 +573,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
|
|||||||
(unsigned int)scr->focused_window->client_win);
|
(unsigned int)scr->focused_window->client_win);
|
||||||
slen = strlen(tmpbuf);
|
slen = strlen(tmpbuf);
|
||||||
olen += slen;
|
olen += slen;
|
||||||
nout = wrealloc(out, olen);
|
nout = realloc(out, olen);
|
||||||
if (!nout) {
|
if (!nout) {
|
||||||
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%w", cmdline);
|
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%w", cmdline);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -590,7 +590,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
|
|||||||
snprintf(tmpbuf, sizeof(tmpbuf), "0x%x", (unsigned int)scr->current_workspace + 1);
|
snprintf(tmpbuf, sizeof(tmpbuf), "0x%x", (unsigned int)scr->current_workspace + 1);
|
||||||
slen = strlen(tmpbuf);
|
slen = strlen(tmpbuf);
|
||||||
olen += slen;
|
olen += slen;
|
||||||
nout = wrealloc(out, olen);
|
nout = realloc(out, olen);
|
||||||
if (!nout) {
|
if (!nout) {
|
||||||
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%W", cmdline);
|
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%W", cmdline);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -607,7 +607,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
|
|||||||
if (user_input) {
|
if (user_input) {
|
||||||
slen = strlen(user_input);
|
slen = strlen(user_input);
|
||||||
olen += slen;
|
olen += slen;
|
||||||
nout = wrealloc(out, olen);
|
nout = realloc(out, olen);
|
||||||
if (!nout) {
|
if (!nout) {
|
||||||
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%a", cmdline);
|
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%a", cmdline);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -630,7 +630,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
|
|||||||
}
|
}
|
||||||
slen = strlen(scr->xdestring);
|
slen = strlen(scr->xdestring);
|
||||||
olen += slen;
|
olen += slen;
|
||||||
nout = wrealloc(out, olen);
|
nout = realloc(out, olen);
|
||||||
if (!nout) {
|
if (!nout) {
|
||||||
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%d", cmdline);
|
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%d", cmdline);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -651,7 +651,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
|
|||||||
}
|
}
|
||||||
slen = strlen(selection);
|
slen = strlen(selection);
|
||||||
olen += slen;
|
olen += slen;
|
||||||
nout = wrealloc(out, olen);
|
nout = realloc(out, olen);
|
||||||
if (!nout) {
|
if (!nout) {
|
||||||
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%s", cmdline);
|
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%s", cmdline);
|
||||||
goto error;
|
goto error;
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ int PropGetWMClass(Window window, char **wm_class, char **wm_instance)
|
|||||||
|
|
||||||
class_hint = XAllocClassHint();
|
class_hint = XAllocClassHint();
|
||||||
if (XGetClassHint(dpy, window, class_hint) == 0) {
|
if (XGetClassHint(dpy, window, class_hint) == 0) {
|
||||||
*wm_class = wstrdup("default");
|
*wm_class = strdup("default");
|
||||||
*wm_instance = wstrdup("default");
|
*wm_instance = strdup("default");
|
||||||
XFree(class_hint);
|
XFree(class_hint);
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
*wm_instance = wstrdup(class_hint->res_name);
|
*wm_instance = strdup(class_hint->res_name);
|
||||||
*wm_class = wstrdup(class_hint->res_class);
|
*wm_class = strdup(class_hint->res_class);
|
||||||
|
|
||||||
XFree(class_hint->res_name);
|
XFree(class_hint->res_name);
|
||||||
XFree(class_hint->res_class);
|
XFree(class_hint->res_class);
|
||||||
@@ -133,7 +133,7 @@ int PropGetGNUstepWMAttr(Window window, GNUstepWMAttributes ** attr)
|
|||||||
if (!data)
|
if (!data)
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
*attr = wmalloc(sizeof(GNUstepWMAttributes));
|
*attr = malloc(sizeof(GNUstepWMAttributes));
|
||||||
if (!*attr) {
|
if (!*attr) {
|
||||||
XFree(data);
|
XFree(data);
|
||||||
return False;
|
return False;
|
||||||
@@ -183,7 +183,7 @@ void PropSetIconTileHint(WScreen * scr, RImage * image)
|
|||||||
imageAtom = XInternAtom(dpy, "_RGBA_IMAGE", False);
|
imageAtom = XInternAtom(dpy, "_RGBA_IMAGE", False);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = wmalloc(image->width * image->height * 4 + 4);
|
tmp = malloc(image->width * image->height * 4 + 4);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint");
|
wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1243,7 +1243,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
|
|||||||
if (dentry->d_name[0] == '.')
|
if (dentry->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buffer = wmalloc(strlen(path[i]) + strlen(dentry->d_name) + 4);
|
buffer = malloc(strlen(path[i]) + strlen(dentry->d_name) + 4);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
werror(_("out of memory while constructing directory menu %s"), path[i]);
|
werror(_("out of memory while constructing directory menu %s"), path[i]);
|
||||||
break;
|
break;
|
||||||
@@ -1288,7 +1288,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@@ -1315,7 +1315,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
|
|||||||
length += 7;
|
length += 7;
|
||||||
if (command)
|
if (command)
|
||||||
length += strlen(command) + 6;
|
length += strlen(command) + 6;
|
||||||
buffer = wmalloc(length);
|
buffer = malloc(length);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
werror(_("out of memory while constructing directory menu %s"), path[data->index]);
|
werror(_("out of memory while constructing directory menu %s"), path[data->index]);
|
||||||
break;
|
break;
|
||||||
@@ -1353,7 +1353,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
|
|||||||
if (command)
|
if (command)
|
||||||
length += strlen(command);
|
length += strlen(command);
|
||||||
|
|
||||||
buffer = wmalloc(length);
|
buffer = malloc(length);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
werror(_("out of memory while constructing directory menu %s"), path[data->index]);
|
werror(_("out of memory while constructing directory menu %s"), path[data->index]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -289,9 +289,9 @@ static WMPropList *makeWindowState(WWindow * wwin, WApplication * wapp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (instance)
|
if (instance)
|
||||||
wfree(instance);
|
free(instance);
|
||||||
if (class)
|
if (class)
|
||||||
wfree(class);
|
free(class);
|
||||||
if (command)
|
if (command)
|
||||||
wfree(command);
|
wfree(command);
|
||||||
|
|
||||||
@@ -382,7 +382,7 @@ static pid_t execCommand(WScreen *scr, char *command)
|
|||||||
|
|
||||||
SetupEnvironment(scr);
|
SetupEnvironment(scr);
|
||||||
|
|
||||||
args = wmalloc(sizeof(char *) * (argc + 1));
|
args = malloc(sizeof(char *) * (argc + 1));
|
||||||
if (!args)
|
if (!args)
|
||||||
exit(111);
|
exit(111);
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ reinit:
|
|||||||
wApplicationSetBouncing(data->wapp, 0);
|
wApplicationSetBouncing(data->wapp, 0);
|
||||||
WMDeleteTimerHandler(data->timer);
|
WMDeleteTimerHandler(data->timer);
|
||||||
wApplicationDestroy(data->wapp);
|
wApplicationDestroy(data->wapp);
|
||||||
wfree(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bounceDirection(WAppIcon *aicon)
|
static int bounceDirection(WAppIcon *aicon)
|
||||||
@@ -324,7 +324,7 @@ void wAppBounce(WApplication *wapp)
|
|||||||
wApplicationIncrementRefcount(wapp);
|
wApplicationIncrementRefcount(wapp);
|
||||||
wApplicationSetBouncing(wapp, 1);
|
wApplicationSetBouncing(wapp, 1);
|
||||||
|
|
||||||
AppBouncerData *data = (AppBouncerData *)wmalloc(sizeof(AppBouncerData));
|
AppBouncerData *data = (AppBouncerData *)malloc(sizeof(AppBouncerData));
|
||||||
data->wapp = wapp;
|
data->wapp = wapp;
|
||||||
data->count = data->pow = 0;
|
data->count = data->pow = 0;
|
||||||
data->dir = bounceDirection(wApplicationGetAppIcon(wapp));
|
data->dir = bounceDirection(wApplicationGetAppIcon(wapp));
|
||||||
|
|||||||
@@ -357,7 +357,8 @@ static void drawTitle(WSwitchPanel *panel, int idecks, const char *title)
|
|||||||
WMSetLabelText(panel->label, ntitle);
|
WMSetLabelText(panel->label, ntitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
wfree(ntitle);
|
if (ntitle)
|
||||||
|
free(ntitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WMArray *makeWindowListArray(WScreen *scr, int include_unmapped, Bool class_only)
|
static WMArray *makeWindowListArray(WScreen *scr, int include_unmapped, Bool class_only)
|
||||||
|
|||||||
12
src/window.c
12
src/window.c
@@ -950,10 +950,10 @@ WWindow *wManageWindow(WScreen *scr, Window window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (instance)
|
if (instance)
|
||||||
wfree(instance);
|
free(instance);
|
||||||
|
|
||||||
if (class)
|
if (class)
|
||||||
wfree(class);
|
free(class);
|
||||||
#undef ADEQUATE
|
#undef ADEQUATE
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2602,7 +2602,7 @@ void wWindowSetShape(WWindow * wwin)
|
|||||||
if (!rects)
|
if (!rects)
|
||||||
goto alt_code;
|
goto alt_code;
|
||||||
|
|
||||||
urec = wmalloc(sizeof(XRectangle) * (count + 2));
|
urec = malloc(sizeof(XRectangle) * (count + 2));
|
||||||
if (!urec) {
|
if (!urec) {
|
||||||
XFree(rects);
|
XFree(rects);
|
||||||
goto alt_code;
|
goto alt_code;
|
||||||
@@ -2779,7 +2779,7 @@ WMagicNumber wWindowAddSavedState(const char *instance, const char *class,
|
|||||||
{
|
{
|
||||||
WWindowState *wstate;
|
WWindowState *wstate;
|
||||||
|
|
||||||
wstate = wmalloc(sizeof(WWindowState));
|
wstate = malloc(sizeof(WWindowState));
|
||||||
if (!wstate)
|
if (!wstate)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -2841,9 +2841,9 @@ WMagicNumber wWindowGetSavedState(Window win)
|
|||||||
if (command)
|
if (command)
|
||||||
wfree(command);
|
wfree(command);
|
||||||
if (instance)
|
if (instance)
|
||||||
wfree(instance);
|
free(instance);
|
||||||
if (class)
|
if (class)
|
||||||
wfree(class);
|
free(class);
|
||||||
|
|
||||||
return wstate;
|
return wstate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ static void wXDNDGetTypeList(Display *dpy, Window window)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
typelist = wmalloc((count + 1) * sizeof(Atom));
|
typelist = malloc((count + 1) * sizeof(Atom));
|
||||||
a = (Atom *) data;
|
a = (Atom *) data;
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
typelist[i] = a[i];
|
typelist[i] = a[i];
|
||||||
@@ -267,7 +267,7 @@ static void wXDNDGetTypeList(Display *dpy, Window window)
|
|||||||
}
|
}
|
||||||
typelist[count] = 0;
|
typelist[count] = 0;
|
||||||
XFree(data);
|
XFree(data);
|
||||||
wfree(typelist);
|
free(typelist);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool wXDNDProcessClientMessage(XClientMessageEvent *event)
|
Bool wXDNDProcessClientMessage(XClientMessageEvent *event)
|
||||||
|
|||||||
@@ -18,70 +18,52 @@ AM_CPPFLAGS = \
|
|||||||
|
|
||||||
liblist= @LIBRARY_SEARCH_PATH@ @INTLIBS@
|
liblist= @LIBRARY_SEARCH_PATH@ @INTLIBS@
|
||||||
|
|
||||||
wdwrite_LDADD = $(top_builddir)/WINGs/libWUtil.la \
|
wdwrite_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(liblist)
|
|
||||||
|
|
||||||
wdread_LDADD = $(top_builddir)/WINGs/libWUtil.la \
|
wdread_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(liblist)
|
|
||||||
|
|
||||||
wxcopy_LDADD = @XLFLAGS@ @XLIBS@ \
|
wxcopy_LDADD = @XLFLAGS@ @XLIBS@
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a
|
|
||||||
|
|
||||||
wxpaste_LDADD = @XLFLAGS@ @XLIBS@
|
wxpaste_LDADD = @XLFLAGS@ @XLIBS@
|
||||||
|
|
||||||
getstyle_LDADD = $(top_builddir)/WINGs/libWUtil.la\
|
getstyle_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(liblist)
|
|
||||||
|
|
||||||
getstyle_SOURCES = getstyle.c fontconv.c common.h
|
getstyle_SOURCES = getstyle.c fontconv.c common.h
|
||||||
|
|
||||||
setstyle_LDADD = \
|
setstyle_LDADD = \
|
||||||
$(top_builddir)/WINGs/libWUtil.la \
|
$(top_builddir)/WINGs/libWUtil.la \
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
@XLFLAGS@ @XLIBS@ $(liblist)
|
@XLFLAGS@ @XLIBS@ $(liblist)
|
||||||
|
|
||||||
setstyle_SOURCES = setstyle.c fontconv.c common.h
|
setstyle_SOURCES = setstyle.c fontconv.c common.h
|
||||||
|
|
||||||
convertfonts_LDADD = $(top_builddir)/WINGs/libWUtil.la \
|
convertfonts_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(liblist)
|
|
||||||
|
|
||||||
convertfonts_SOURCES = convertfonts.c fontconv.c common.h
|
convertfonts_SOURCES = convertfonts.c fontconv.c common.h
|
||||||
|
|
||||||
seticons_LDADD= $(top_builddir)/WINGs/libWUtil.la\
|
seticons_LDADD= $(top_builddir)/WINGs/libWUtil.la $(liblist)
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(liblist)
|
|
||||||
|
|
||||||
geticonset_LDADD= $(top_builddir)/WINGs/libWUtil.la\
|
geticonset_LDADD= $(top_builddir)/WINGs/libWUtil.la $(liblist)
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(liblist)
|
|
||||||
|
|
||||||
wmagnify_LDADD = \
|
wmagnify_LDADD = \
|
||||||
$(top_builddir)/WINGs/libWINGs.la \
|
$(top_builddir)/WINGs/libWINGs.la \
|
||||||
$(top_builddir)/WINGs/libWUtil.la \
|
$(top_builddir)/WINGs/libWUtil.la \
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(top_builddir)/wrlib/libwraster.la \
|
$(top_builddir)/wrlib/libwraster.la \
|
||||||
@XLFLAGS@ @XLIBS@ @INTLIBS@
|
@XLFLAGS@ @XLIBS@ @INTLIBS@
|
||||||
|
|
||||||
wmsetbg_LDADD = \
|
wmsetbg_LDADD = \
|
||||||
$(top_builddir)/WINGs/libWINGs.la \
|
$(top_builddir)/WINGs/libWINGs.la \
|
||||||
$(top_builddir)/WINGs/libWUtil.la \
|
$(top_builddir)/WINGs/libWUtil.la \
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
$(top_builddir)/wrlib/libwraster.la \
|
$(top_builddir)/wrlib/libwraster.la \
|
||||||
@XLFLAGS@ @LIBXINERAMA@ @XLIBS@ @INTLIBS@
|
@XLFLAGS@ @LIBXINERAMA@ @XLIBS@ @INTLIBS@
|
||||||
|
|
||||||
wmgenmenu_LDADD = \
|
wmgenmenu_LDADD = \
|
||||||
$(top_builddir)/WINGs/libWUtil.la \
|
$(top_builddir)/WINGs/libWUtil.la \
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
@INTLIBS@
|
@INTLIBS@
|
||||||
|
|
||||||
wmgenmenu_SOURCES = wmgenmenu.c wmgenmenu.h
|
wmgenmenu_SOURCES = wmgenmenu.c wmgenmenu.h
|
||||||
|
|
||||||
wmmenugen_LDADD = \
|
wmmenugen_LDADD = \
|
||||||
$(top_builddir)/WINGs/libWUtil.la \
|
$(top_builddir)/WINGs/libWUtil.la \
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
@INTLIBS@
|
@INTLIBS@
|
||||||
|
|
||||||
wmmenugen_SOURCES = wmmenugen.c wmmenugen.h wmmenugen_misc.c \
|
wmmenugen_SOURCES = wmmenugen.c wmmenugen.h wmmenugen_misc.c \
|
||||||
@@ -93,7 +75,6 @@ wmiv_CFLAGS = @PANGO_CFLAGS@ @PTHREAD_CFLAGS@
|
|||||||
wmiv_LDADD = \
|
wmiv_LDADD = \
|
||||||
$(top_builddir)/wrlib/libwraster.la \
|
$(top_builddir)/wrlib/libwraster.la \
|
||||||
$(top_builddir)/WINGs/libWINGs.la \
|
$(top_builddir)/WINGs/libWINGs.la \
|
||||||
$(top_builddir)/wmaker-rs/target/debug/libwmaker_rs.a\
|
|
||||||
@XLFLAGS@ @XLIBS@ @GFXLIBS@ \
|
@XLFLAGS@ @XLIBS@ @GFXLIBS@ \
|
||||||
@PANGO_LIBS@ @PTHREAD_LIBS@ @LIBEXIF@
|
@PANGO_LIBS@ @PTHREAD_LIBS@ @LIBEXIF@
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ static void makeThemePack(WMPropList * style, const char *themeName)
|
|||||||
|
|
||||||
WMDeleteFromPLArray(value, 1);
|
WMDeleteFromPLArray(value, 1);
|
||||||
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
|
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
|
||||||
wfree(newPath);
|
free(newPath);
|
||||||
} else {
|
} else {
|
||||||
findCopyFile(themeDir, WMGetFromPLString(file));
|
findCopyFile(themeDir, WMGetFromPLString(file));
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ static void makeThemePack(WMPropList * style, const char *themeName)
|
|||||||
|
|
||||||
WMDeleteFromPLArray(value, 1);
|
WMDeleteFromPLArray(value, 1);
|
||||||
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
|
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
|
||||||
wfree(newPath);
|
free(newPath);
|
||||||
} else {
|
} else {
|
||||||
findCopyFile(themeDir, WMGetFromPLString(file));
|
findCopyFile(themeDir, WMGetFromPLString(file));
|
||||||
}
|
}
|
||||||
@@ -277,7 +277,7 @@ static void makeThemePack(WMPropList * style, const char *themeName)
|
|||||||
|
|
||||||
WMDeleteFromPLArray(value, 2);
|
WMDeleteFromPLArray(value, 2);
|
||||||
WMInsertInPLArray(value, 2, WMCreatePLString(newPath));
|
WMInsertInPLArray(value, 2, WMCreatePLString(newPath));
|
||||||
wfree(newPath);
|
free(newPath);
|
||||||
} else {
|
} else {
|
||||||
findCopyFile(themeDir, WMGetFromPLString(file));
|
findCopyFile(themeDir, WMGetFromPLString(file));
|
||||||
}
|
}
|
||||||
|
|||||||
18
util/wmiv.c
18
util/wmiv.c
@@ -202,7 +202,7 @@ int change_title(XTextProperty *prop, char *filename)
|
|||||||
XSetWMName(dpy, win, prop);
|
XSetWMName(dpy, win, prop);
|
||||||
if (prop->value)
|
if (prop->value)
|
||||||
XFree(prop->value);
|
XFree(prop->value);
|
||||||
wfree(combined_title);
|
free(combined_title);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,8 +596,8 @@ int linked_list_add(linked_list_t *list, const void *data)
|
|||||||
{
|
{
|
||||||
link_t *link;
|
link_t *link;
|
||||||
|
|
||||||
/* wmalloc zeros the buffer it returns, so the "next" is zero. */
|
/* calloc sets the "next" field to zero. */
|
||||||
link = wmalloc(sizeof(link_t));
|
link = calloc(1, sizeof(link_t));
|
||||||
if (!link) {
|
if (!link) {
|
||||||
fprintf(stderr, "Error: memory allocation failed\n");
|
fprintf(stderr, "Error: memory allocation failed\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -627,8 +627,8 @@ void linked_list_free(linked_list_t *list)
|
|||||||
/* Store the next value so that we don't access freed memory. */
|
/* Store the next value so that we don't access freed memory. */
|
||||||
next = link->next;
|
next = link->next;
|
||||||
if (link->data)
|
if (link->data)
|
||||||
wfree((char *)link->data);
|
free((char *)link->data);
|
||||||
wfree(link);
|
free(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,7 +651,7 @@ link_t *connect_dir(char *dirpath, linked_list_t *li)
|
|||||||
/* maybe it's a file */
|
/* maybe it's a file */
|
||||||
struct stat stDirInfo;
|
struct stat stDirInfo;
|
||||||
if (lstat(dirpath, &stDirInfo) == 0) {
|
if (lstat(dirpath, &stDirInfo) == 0) {
|
||||||
linked_list_add(li, wstrdup(dirpath));
|
linked_list_add(li, strdup(dirpath));
|
||||||
return li->first;
|
return li->first;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -664,11 +664,11 @@ link_t *connect_dir(char *dirpath, linked_list_t *li)
|
|||||||
else
|
else
|
||||||
snprintf(path, PATH_MAX, "%s%c%s", dirpath, FILE_SEPARATOR, dir[idx]->d_name);
|
snprintf(path, PATH_MAX, "%s%c%s", dirpath, FILE_SEPARATOR, dir[idx]->d_name);
|
||||||
|
|
||||||
wfree(dir[idx]);
|
free(dir[idx]);
|
||||||
if ((lstat(path, &stDirInfo) == 0) && !S_ISDIR(stDirInfo.st_mode))
|
if ((lstat(path, &stDirInfo) == 0) && !S_ISDIR(stDirInfo.st_mode))
|
||||||
linked_list_add(li, wstrdup(path));
|
linked_list_add(li, strdup(path));
|
||||||
}
|
}
|
||||||
wfree(dir);
|
free(dir);
|
||||||
return li->first;
|
return li->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ void parse_locale(const char *what, char **language, char **country, char **enco
|
|||||||
*language = wstrdup(e);
|
*language = wstrdup(e);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
wfree(e);
|
free(e);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text)
|
|||||||
RGradientStyle gtype;
|
RGradientStyle gtype;
|
||||||
int iwidth, iheight;
|
int iwidth, iheight;
|
||||||
|
|
||||||
colors = wmalloc(sizeof(RColor *) * (count - 1));
|
colors = malloc(sizeof(RColor *) * (count - 1));
|
||||||
if (!colors) {
|
if (!colors) {
|
||||||
wwarning("out of memory while parsing texture");
|
wwarning("out of memory while parsing texture");
|
||||||
goto error;
|
goto error;
|
||||||
@@ -425,7 +425,7 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text)
|
|||||||
wfree(colors);
|
wfree(colors);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!(colors[i - 2] = wmalloc(sizeof(RColor)))) {
|
if (!(colors[i - 2] = malloc(sizeof(RColor)))) {
|
||||||
wwarning("out of memory while parsing texture");
|
wwarning("out of memory while parsing texture");
|
||||||
|
|
||||||
for (j = 0; colors[j] != NULL; j++)
|
for (j = 0; colors[j] != NULL; j++)
|
||||||
|
|||||||
@@ -26,8 +26,6 @@
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "../src/wconfig.h"
|
#include "../src/wconfig.h"
|
||||||
|
|
||||||
#define LINESIZE (4*1024)
|
#define LINESIZE (4*1024)
|
||||||
@@ -199,7 +197,7 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (buf_len == 0) {
|
if (buf_len == 0) {
|
||||||
nbuf = wmalloc(buf_len = l + nl + 1);
|
nbuf = malloc(buf_len = l + nl + 1);
|
||||||
} else if (buf_len < l + nl + 1) {
|
} else if (buf_len < l + nl + 1) {
|
||||||
/*
|
/*
|
||||||
* To avoid terrible performance on big input buffers,
|
* To avoid terrible performance on big input buffers,
|
||||||
@@ -207,7 +205,12 @@ int main(int argc, char **argv)
|
|||||||
* current line.
|
* current line.
|
||||||
*/
|
*/
|
||||||
buf_len = 2 * buf_len + nl + 1;
|
buf_len = 2 * buf_len + nl + 1;
|
||||||
nbuf = wrealloc(buf, buf_len);
|
/* some realloc implementations don't do malloc if buf==NULL */
|
||||||
|
if (buf == NULL) {
|
||||||
|
nbuf = malloc(buf_len);
|
||||||
|
} else {
|
||||||
|
nbuf = realloc(buf, buf_len);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
nbuf = buf;
|
nbuf = buf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
# automake input file for wmaker-rs
|
|
||||||
|
|
||||||
AUTOMAKE_OPTIONS =
|
|
||||||
|
|
||||||
RUST_SOURCES = \
|
|
||||||
src/app_icon.rs \
|
|
||||||
src/application.rs \
|
|
||||||
src/app_menu.rs \
|
|
||||||
src/defaults.rs \
|
|
||||||
src/dock.rs \
|
|
||||||
src/global.rs \
|
|
||||||
src/icon.rs \
|
|
||||||
src/lib.rs \
|
|
||||||
src/menu.rs \
|
|
||||||
src/properties.rs \
|
|
||||||
src/screen.rs \
|
|
||||||
src/window.rs \
|
|
||||||
src/wings.rs \
|
|
||||||
src/wrlib.rs
|
|
||||||
|
|
||||||
RUST_EXTRA = \
|
|
||||||
Cargo.lock
|
|
||||||
|
|
||||||
target/debug/libwmaker_rs.a: $(RUST_SOURCES) $(RUST_EXTRA)
|
|
||||||
$(CARGO) build
|
|
||||||
|
|
||||||
check-local:
|
|
||||||
$(CARGO) test
|
|
||||||
|
|
||||||
clean-local:
|
|
||||||
$(CARGO) clean
|
|
||||||
|
|
||||||
all: target/debug/libwmaker_rs.a
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
use std::ffi::c_void;
|
|
||||||
|
|
||||||
pub type AppIcon = c_void;
|
|
||||||
|
|
||||||
pub mod ffi {
|
|
||||||
use super::AppIcon;
|
|
||||||
use std::ffi::c_int;
|
|
||||||
|
|
||||||
unsafe extern "C" {
|
|
||||||
pub fn wAppIconIsDocked(app_icon: *mut AppIcon) -> c_int;
|
|
||||||
|
|
||||||
pub fn wAppIconIsRelaunching(app_icon: *mut AppIcon) -> c_int;
|
|
||||||
|
|
||||||
pub fn wAppIconGetIcon(app_icon: *mut AppIcon) -> *mut crate::icon::Icon;
|
|
||||||
|
|
||||||
pub fn wAppIconPaint(app_icon: *mut AppIcon);
|
|
||||||
|
|
||||||
pub fn create_appicon_for_application(
|
|
||||||
app: *mut crate::application::Application,
|
|
||||||
wwin: *mut crate::window::Window,
|
|
||||||
);
|
|
||||||
|
|
||||||
pub fn removeAppIconFor(app: *mut crate::application::Application);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
//! Provides an FFI-compatible allocator for C.
|
|
||||||
//!
|
|
||||||
//! This replaces the bulk of the code form WINGs/memory.c, but
|
|
||||||
//! it should go away once we're in a place that we don't need
|
|
||||||
//! to rely on `malloc` anymore in C code.
|
|
||||||
|
|
||||||
use std::alloc::{Layout, alloc_zeroed, dealloc, realloc};
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::ffi::c_void;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
struct Allocation {
|
|
||||||
layout: Layout,
|
|
||||||
rc: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
type WMallocMap = BTreeMap<usize, Allocation>;
|
|
||||||
|
|
||||||
static ALLOCS: Mutex<WMallocMap> = Mutex::new(WMallocMap::new());
|
|
||||||
const ALIGN: usize = 64;
|
|
||||||
|
|
||||||
/// A wrapper around the Rust allocator API's `alloc_zeroed`
|
|
||||||
/// function for FFI.
|
|
||||||
///
|
|
||||||
/// Note: This will always return nil on a zero-sized
|
|
||||||
/// allocation. Don't try to use this to allocate Rust ZSTs;
|
|
||||||
/// it is only suitable for FFI.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
/// This will return a 64-byte aligned pointer of the specified
|
|
||||||
/// length, or nil if the allocation cannot be satisfied. It is
|
|
||||||
/// the caller's responsibility to ensure that the result is not
|
|
||||||
/// null, to avoid violating memory safety, and to make sure
|
|
||||||
/// that any alignment for any value the pointer is used to
|
|
||||||
/// refer to is suitably aligned.
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub unsafe extern "C" fn wmalloc(size: usize) -> *mut c_void {
|
|
||||||
if size == 0 {
|
|
||||||
return std::ptr::null_mut();
|
|
||||||
}
|
|
||||||
let layout = Layout::from_size_align(size, ALIGN).expect("layout makes sense");
|
|
||||||
let ptr = unsafe { alloc_zeroed(layout) };
|
|
||||||
if ptr.is_null() {
|
|
||||||
return std::ptr::null_mut();
|
|
||||||
}
|
|
||||||
let rc = 1;
|
|
||||||
let alloc = Allocation { layout, rc };
|
|
||||||
let mut allocs = ALLOCS.lock().expect("lock not poisoned");
|
|
||||||
allocs.insert(ptr.addr(), alloc);
|
|
||||||
ptr.cast()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A wrapper around the Rust allocator API's `dealloc` function
|
|
||||||
/// for FFI.
|
|
||||||
///
|
|
||||||
/// If the pointer argument is nil, this is a nop. Otherwise,
|
|
||||||
/// it must have been allocated by `wmalloc` or `wrealloc`.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
/// The caller must ensure that the pointer that is passed to
|
|
||||||
/// this function was allocated by `wmalloc`. Note that this
|
|
||||||
/// will not free unless this was the allocation's last
|
|
||||||
/// reference.
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub unsafe extern "C" fn wfree(ptr: *mut c_void) {
|
|
||||||
if ptr.is_null() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let alloc = {
|
|
||||||
let mut allocs = ALLOCS.lock().expect("wfree: allocs is unpoisoned");
|
|
||||||
let addr = ptr.addr();
|
|
||||||
let alloc = allocs.get_mut(&addr).expect("wfree: allocs records ptr");
|
|
||||||
alloc.rc -= 1;
|
|
||||||
let alloc = alloc.clone();
|
|
||||||
if alloc.rc == 0 {
|
|
||||||
allocs.remove(&addr).expect("wfree: allocs unaltered");
|
|
||||||
}
|
|
||||||
alloc
|
|
||||||
};
|
|
||||||
// We can call `dealloc` without holding the ALLOCS lock.
|
|
||||||
if alloc.rc == 0 {
|
|
||||||
unsafe {
|
|
||||||
dealloc(ptr.cast(), alloc.layout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A wrapper around the Rust allocator API's `realloc` function
|
|
||||||
/// for FFI calls.
|
|
||||||
///
|
|
||||||
/// Note that this attempts will always free and return NULL on
|
|
||||||
/// a reallocation of size 0, so do not try to use this to
|
|
||||||
/// allocate Rust ZSTs: it is purely for FFI. If the source
|
|
||||||
/// pointer is nil and size is positive, then the behavior is
|
|
||||||
/// that of `wmalloc`.
|
|
||||||
///
|
|
||||||
/// The pointer argument just have been allocated previously
|
|
||||||
/// with `wmalloc` or `wrealloc`.
|
|
||||||
///
|
|
||||||
/// If successful, returns a non-nil pointer, and the old
|
|
||||||
/// pointer should be considered invalid, and must not be
|
|
||||||
/// dereferenced. If the old size was smaller than the new
|
|
||||||
/// size, elements, elements after the old size are zeroed.
|
|
||||||
/// Elements between the start of the array and the minimum of
|
|
||||||
/// the old and new sizes are unchanged.
|
|
||||||
///
|
|
||||||
/// On failure, returns nil, and does not free the source
|
|
||||||
/// pointer or otherwise alter its contents.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
/// This will return a 64-byte aligned pointer of the specified
|
|
||||||
/// length, or nil if the allocation cannot be satisfied. It is
|
|
||||||
/// the caller's responsibility to ensure that the result is not
|
|
||||||
/// null, to avoid violating memory safety, and to make sure
|
|
||||||
/// that any alignment for any value the pointer is used to
|
|
||||||
/// refer to is suitably aligned.
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub unsafe extern "C" fn wrealloc(ptr: *mut c_void, size: usize) -> *mut c_void {
|
|
||||||
if size == 0 {
|
|
||||||
unsafe {
|
|
||||||
wfree(ptr);
|
|
||||||
}
|
|
||||||
return std::ptr::null_mut();
|
|
||||||
}
|
|
||||||
if ptr.is_null() {
|
|
||||||
return unsafe { wmalloc(size) };
|
|
||||||
}
|
|
||||||
let new_layout = Layout::from_size_align(size, ALIGN).expect("layout ok");
|
|
||||||
let addr = ptr.addr();
|
|
||||||
let old_layout = {
|
|
||||||
let allocs = ALLOCS.lock().expect("wrealloc: allocs is unpoisoned");
|
|
||||||
let alloc = allocs.get(&addr).expect("wrealloc: allocs records ptr");
|
|
||||||
alloc.layout
|
|
||||||
};
|
|
||||||
let old_size = old_layout.size();
|
|
||||||
let ptr = unsafe { realloc(ptr.cast(), old_layout, size) };
|
|
||||||
if ptr.is_null() {
|
|
||||||
return std::ptr::null_mut();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let mut allocs = ALLOCS.lock().expect("wrealloc: allocs still unpoisoned");
|
|
||||||
let alloc = allocs.get_mut(&addr).expect("wmrealloc: allocs knows ptr");
|
|
||||||
alloc.layout = new_layout;
|
|
||||||
}
|
|
||||||
if old_size < size {
|
|
||||||
let zlen = size - old_size;
|
|
||||||
let zptr = ptr.wrapping_add(old_size);
|
|
||||||
unsafe {
|
|
||||||
std::ptr::write_bytes(zptr, 0, zlen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ptr.cast()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Increments the reference count on `ptr`.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
/// The caller must insure that `ptr` refers to a valid, active
|
|
||||||
/// allocation that was made with `wmalloc` or `wrealloc`.
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub unsafe extern "C" fn wretain(ptr: *mut c_void) -> *mut c_void {
|
|
||||||
let addr = ptr.addr();
|
|
||||||
let mut allocs = ALLOCS.lock().expect("wretain: allocs is unpoisoned");
|
|
||||||
let alloc = allocs.get_mut(&addr).expect("wretain: allocs records ptr");
|
|
||||||
alloc.rc += 1;
|
|
||||||
ptr
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decrements the reference count on `ptr`, and frees if it
|
|
||||||
/// reaches 0, but wrapping `wfree`.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
/// `ptr` must be valid as an argument to `wfree`.
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub unsafe extern "C" fn wrelease(ptr: *mut c_void) {
|
|
||||||
unsafe {
|
|
||||||
wfree(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wmaker-rs"
|
name = "wmakerlib"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
@@ -7,4 +7,5 @@ edition = "2024"
|
|||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
libc = "0.2"
|
||||||
x11 = "2.21.0"
|
x11 = "2.21.0"
|
||||||
59
wmakerlib/src/app_icon.rs
Normal file
59
wmakerlib/src/app_icon.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use std::ffi::{c_char, c_int, c_short};
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct AppIcon {
|
||||||
|
xindex: c_short,
|
||||||
|
yindex: c_short,
|
||||||
|
next: *mut AppIcon,
|
||||||
|
prev: *mut AppIcon,
|
||||||
|
icon: *mut crate::icon::Icon,
|
||||||
|
x_pos: c_int,
|
||||||
|
y_pos: c_int,
|
||||||
|
command: *mut c_char,
|
||||||
|
dnd_command: *mut c_char,
|
||||||
|
paste_command: *mut c_char,
|
||||||
|
wm_class: *mut c_char,
|
||||||
|
wm_instance: *mut c_char,
|
||||||
|
pid: libc::pid_t,
|
||||||
|
main_window: x11::xlib::Window,
|
||||||
|
dock: *mut crate::dock::Dock,
|
||||||
|
panel: *mut crate::app_settings_panel::AppSettingsPanel,
|
||||||
|
docked: c_int,
|
||||||
|
omnipresent: c_int,
|
||||||
|
attracted: c_int,
|
||||||
|
launched: c_int,
|
||||||
|
running: c_int,
|
||||||
|
relaunching: c_int,
|
||||||
|
forced_dock: c_int,
|
||||||
|
auto_launch: c_int,
|
||||||
|
remote_start: c_int,
|
||||||
|
updated: c_int,
|
||||||
|
editing: c_int,
|
||||||
|
drop_launch: c_int,
|
||||||
|
paste_launch: c_int,
|
||||||
|
destroyed: c_int,
|
||||||
|
buggy_app: c_int,
|
||||||
|
lock: c_int,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod ffi {
|
||||||
|
use super::AppIcon;
|
||||||
|
use std::ffi::c_int;
|
||||||
|
|
||||||
|
unsafe extern "C" {
|
||||||
|
pub fn wAppIconIsDocked(app_icon: *mut AppIcon) -> c_int;
|
||||||
|
|
||||||
|
pub fn wAppIconIsRelaunching(app_icon: *mut AppIcon) -> c_int;
|
||||||
|
|
||||||
|
pub fn wAppIconGetIcon(app_icon: *mut AppIcon) -> *mut crate::icon::Icon;
|
||||||
|
|
||||||
|
pub fn wAppIconPaint(app_icon: *mut AppIcon);
|
||||||
|
|
||||||
|
pub fn create_appicon_for_application(
|
||||||
|
app: *mut crate::application::Application,
|
||||||
|
wwin: *mut crate::window::Window,
|
||||||
|
);
|
||||||
|
|
||||||
|
pub fn removeAppIconFor(app: *mut crate::application::Application);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
wmakerlib/src/app_settings_panel.rs
Normal file
3
wmakerlib/src/app_settings_panel.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
use std::ffi::c_void;
|
||||||
|
|
||||||
|
pub type AppSettingsPanel = c_void;
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
use std::ffi::c_void;
|
||||||
|
|
||||||
|
pub type Dock = c_void;
|
||||||
|
|
||||||
pub mod ffi {
|
pub mod ffi {
|
||||||
unsafe extern "C" {
|
unsafe extern "C" {
|
||||||
pub fn wDockFinishLaunch(app_icon: *mut crate::app_icon::AppIcon);
|
pub fn wDockFinishLaunch(app_icon: *mut crate::app_icon::AppIcon);
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
|
pub mod application;
|
||||||
pub mod app_icon;
|
pub mod app_icon;
|
||||||
pub mod app_menu;
|
pub mod app_menu;
|
||||||
pub mod application;
|
pub mod app_settings_panel;
|
||||||
pub mod defaults;
|
pub mod defaults;
|
||||||
pub mod dock;
|
pub mod dock;
|
||||||
pub mod global;
|
pub mod global;
|
||||||
pub mod icon;
|
pub mod icon;
|
||||||
pub mod memory;
|
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
pub mod properties;
|
pub mod properties;
|
||||||
pub mod screen;
|
pub mod screen;
|
||||||
@@ -6,8 +6,7 @@ lib_LTLIBRARIES = libWMaker.la
|
|||||||
|
|
||||||
include_HEADERS = WMaker.h
|
include_HEADERS = WMaker.h
|
||||||
|
|
||||||
AM_CPPFLAGS = $(DFLAGS) @XCFLAGS@ \
|
AM_CPPFLAGS = $(DFLAGS) @XCFLAGS@
|
||||||
-I$(top_srcdir)/WINGs -I$(top_builddir)/WINGs
|
|
||||||
|
|
||||||
libWMaker_la_LIBADD = @XLFLAGS@ @XLIBS@
|
libWMaker_la_LIBADD = @XLFLAGS@ @XLIBS@
|
||||||
|
|
||||||
|
|||||||
12
wmlib/app.c
12
wmlib/app.c
@@ -24,8 +24,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "WMaker.h"
|
#include "WMaker.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
@@ -33,7 +31,7 @@ WMAppContext *WMAppCreateWithMain(Display * display, int screen_number, Window m
|
|||||||
{
|
{
|
||||||
wmAppContext *ctx;
|
wmAppContext *ctx;
|
||||||
|
|
||||||
ctx = wmalloc(sizeof(wmAppContext));
|
ctx = malloc(sizeof(wmAppContext));
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -41,9 +39,9 @@ WMAppContext *WMAppCreateWithMain(Display * display, int screen_number, Window m
|
|||||||
ctx->screen_number = screen_number;
|
ctx->screen_number = screen_number;
|
||||||
ctx->our_leader_hint = False;
|
ctx->our_leader_hint = False;
|
||||||
ctx->main_window = main_window;
|
ctx->main_window = main_window;
|
||||||
ctx->windows = wmalloc(sizeof(Window));
|
ctx->windows = malloc(sizeof(Window));
|
||||||
if (!ctx->windows) {
|
if (!ctx->windows) {
|
||||||
wfree(ctx);
|
free(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ctx->win_count = 1;
|
ctx->win_count = 1;
|
||||||
@@ -60,13 +58,13 @@ int WMAppAddWindow(WMAppContext * app, Window window)
|
|||||||
{
|
{
|
||||||
Window *win;
|
Window *win;
|
||||||
|
|
||||||
win = wmalloc(sizeof(Window) * (app->win_count + 1));
|
win = malloc(sizeof(Window) * (app->win_count + 1));
|
||||||
if (!win)
|
if (!win)
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
memcpy(win, app->windows, sizeof(Window) * app->win_count);
|
memcpy(win, app->windows, sizeof(Window) * app->win_count);
|
||||||
|
|
||||||
wfree(app->windows);
|
free(app->windows);
|
||||||
|
|
||||||
win[app->win_count] = window;
|
win[app->win_count] = window;
|
||||||
app->windows = win;
|
app->windows = win;
|
||||||
|
|||||||
30
wmlib/menu.c
30
wmlib/menu.c
@@ -26,8 +26,6 @@
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "WMaker.h"
|
#include "WMaker.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
@@ -39,7 +37,7 @@ WMMenu *WMMenuCreate(WMAppContext * app, char *title)
|
|||||||
if (strlen(title) > 255)
|
if (strlen(title) > 255)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
menu = wmalloc(sizeof(wmMenu));
|
menu = malloc(sizeof(wmMenu));
|
||||||
if (!menu)
|
if (!menu)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -52,12 +50,12 @@ WMMenu *WMMenuCreate(WMAppContext * app, char *title)
|
|||||||
menu->realized = False;
|
menu->realized = False;
|
||||||
menu->code = app->last_menu_tag++;
|
menu->code = app->last_menu_tag++;
|
||||||
|
|
||||||
menu->entryline = wmalloc(strlen(title) + 32);
|
menu->entryline = malloc(strlen(title) + 32);
|
||||||
menu->entryline2 = wmalloc(32);
|
menu->entryline2 = malloc(32);
|
||||||
if (!menu->entryline || !menu->entryline2) {
|
if (!menu->entryline || !menu->entryline2) {
|
||||||
if (menu->entryline)
|
if (menu->entryline)
|
||||||
wfree(menu->entryline);
|
free(menu->entryline);
|
||||||
wfree(menu);
|
free(menu);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
sprintf(menu->entryline, "%i %i %s", wmBeginMenu, menu->code, title);
|
sprintf(menu->entryline, "%i %i %s", wmBeginMenu, menu->code, title);
|
||||||
@@ -79,13 +77,13 @@ WMMenuAddItem(WMMenu * menu, char *text, WMMenuAction action,
|
|||||||
if (strlen(text) > 255)
|
if (strlen(text) > 255)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
entry = wmalloc(sizeof(wmMenuEntry));
|
entry = malloc(sizeof(wmMenuEntry));
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
entry->entryline = wmalloc(strlen(text) + 100);
|
entry->entryline = malloc(strlen(text) + 100);
|
||||||
if (!entry->entryline) {
|
if (!entry->entryline) {
|
||||||
wfree(entry);
|
free(entry);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,13 +125,13 @@ int WMMenuAddSubmenu(WMMenu * menu, char *text, WMMenu * submenu)
|
|||||||
if (strlen(text) > 255)
|
if (strlen(text) > 255)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
entry = wmalloc(sizeof(wmMenuEntry));
|
entry = malloc(sizeof(wmMenuEntry));
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
entry->entryline = wmalloc(strlen(text) + 100);
|
entry->entryline = malloc(strlen(text) + 100);
|
||||||
if (!entry->entryline) {
|
if (!entry->entryline) {
|
||||||
wfree(entry);
|
free(entry);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +217,7 @@ int WMRealizeMenus(WMAppContext * app)
|
|||||||
return True;
|
return True;
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
slist = wmalloc(count * sizeof(char *));
|
slist = malloc(count * sizeof(char *));
|
||||||
if (!slist) {
|
if (!slist) {
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
@@ -229,10 +227,10 @@ int WMRealizeMenus(WMAppContext * app)
|
|||||||
addItems(slist, &i, app->main_menu);
|
addItems(slist, &i, app->main_menu);
|
||||||
|
|
||||||
if (!XStringListToTextProperty(slist, i, &text_prop)) {
|
if (!XStringListToTextProperty(slist, i, &text_prop)) {
|
||||||
wfree(slist);
|
free(slist);
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
wfree(slist);
|
free(slist);
|
||||||
XSetTextProperty(app->dpy, app->main_window, &text_prop, getatom(app->dpy));
|
XSetTextProperty(app->dpy, app->main_window, &text_prop, getatom(app->dpy));
|
||||||
|
|
||||||
XFree(text_prop.value);
|
XFree(text_prop.value);
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ libwraster_la_SOURCES += load_magick.c
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
AM_CFLAGS = @MAGICKFLAGS@
|
AM_CFLAGS = @MAGICKFLAGS@
|
||||||
AM_CPPFLAGS = $(DFLAGS) @HEADER_SEARCH_PATH@ \
|
AM_CPPFLAGS = $(DFLAGS) @HEADER_SEARCH_PATH@
|
||||||
-I$(top_srcdir)/WINGs -I$(top_builddir)/WINGs
|
|
||||||
|
|
||||||
libwraster_la_LIBADD = @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @MAGICKLIBS@ @XLIBS@ @LIBXMU@ -lm
|
libwraster_la_LIBADD = @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @MAGICKLIBS@ @XLIBS@ @LIBXMU@ -lm
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,6 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "scale.h"
|
#include "scale.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -106,17 +104,17 @@ static Bool allocateStandardPseudoColor(RContext * ctx, XStandardColormap * stdc
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->colors = wmalloc(sizeof(XColor) * ctx->ncolors);
|
ctx->colors = malloc(sizeof(XColor) * ctx->ncolors);
|
||||||
if (!ctx->colors) {
|
if (!ctx->colors) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
|
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->pixels = wmalloc(sizeof(unsigned long) * ctx->ncolors);
|
ctx->pixels = malloc(sizeof(unsigned long) * ctx->ncolors);
|
||||||
if (!ctx->pixels) {
|
if (!ctx->pixels) {
|
||||||
|
|
||||||
wfree(ctx->colors);
|
free(ctx->colors);
|
||||||
ctx->colors = NULL;
|
ctx->colors = NULL;
|
||||||
|
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
@@ -248,15 +246,15 @@ static Bool allocatePseudoColor(RContext *ctx)
|
|||||||
|
|
||||||
assert(cpc >= 2 && ncolors <= (1 << ctx->depth));
|
assert(cpc >= 2 && ncolors <= (1 << ctx->depth));
|
||||||
|
|
||||||
colors = wmalloc(sizeof(XColor) * ncolors);
|
colors = malloc(sizeof(XColor) * ncolors);
|
||||||
if (!colors) {
|
if (!colors) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->pixels = wmalloc(sizeof(unsigned long) * ncolors);
|
ctx->pixels = malloc(sizeof(unsigned long) * ncolors);
|
||||||
if (!ctx->pixels) {
|
if (!ctx->pixels) {
|
||||||
wfree(colors);
|
free(colors);
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
@@ -345,7 +343,7 @@ static XColor *allocateGrayScale(RContext * ctx)
|
|||||||
ctx->attribs->render_mode = RBestMatchRendering;
|
ctx->attribs->render_mode = RBestMatchRendering;
|
||||||
}
|
}
|
||||||
|
|
||||||
colors = wmalloc(sizeof(XColor) * ncolors);
|
colors = malloc(sizeof(XColor) * ncolors);
|
||||||
if (!colors) {
|
if (!colors) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return False;
|
return False;
|
||||||
@@ -528,7 +526,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
|||||||
RContext *context;
|
RContext *context;
|
||||||
XGCValues gcv;
|
XGCValues gcv;
|
||||||
|
|
||||||
context = wmalloc(sizeof(RContext));
|
context = malloc(sizeof(RContext));
|
||||||
if (!context) {
|
if (!context) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -539,9 +537,9 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
|||||||
|
|
||||||
context->screen_number = screen_number;
|
context->screen_number = screen_number;
|
||||||
|
|
||||||
context->attribs = wmalloc(sizeof(RContextAttributes));
|
context->attribs = malloc(sizeof(RContextAttributes));
|
||||||
if (!context->attribs) {
|
if (!context->attribs) {
|
||||||
wfree(context);
|
free(context);
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -570,7 +568,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
|||||||
templ.visualid = context->attribs->visualid;
|
templ.visualid = context->attribs->visualid;
|
||||||
vinfo = XGetVisualInfo(context->dpy, VisualIDMask | VisualScreenMask, &templ, &nret);
|
vinfo = XGetVisualInfo(context->dpy, VisualIDMask | VisualScreenMask, &templ, &nret);
|
||||||
if (!vinfo || nret == 0) {
|
if (!vinfo || nret == 0) {
|
||||||
wfree(context);
|
free(context);
|
||||||
RErrorCode = RERR_BADVISUALID;
|
RErrorCode = RERR_BADVISUALID;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -617,13 +615,13 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
|||||||
|
|
||||||
if (context->vclass == PseudoColor || context->vclass == StaticColor) {
|
if (context->vclass == PseudoColor || context->vclass == StaticColor) {
|
||||||
if (!setupPseudoColorColormap(context)) {
|
if (!setupPseudoColorColormap(context)) {
|
||||||
wfree(context);
|
free(context);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (context->vclass == GrayScale || context->vclass == StaticGray) {
|
} else if (context->vclass == GrayScale || context->vclass == StaticGray) {
|
||||||
context->colors = allocateGrayScale(context);
|
context->colors = allocateGrayScale(context);
|
||||||
if (!context->colors) {
|
if (!context->colors) {
|
||||||
wfree(context);
|
free(context);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (context->vclass == TrueColor) {
|
} else if (context->vclass == TrueColor) {
|
||||||
@@ -670,9 +668,9 @@ void RDestroyContext(RContext *context)
|
|||||||
if ((context->attribs->flags & RC_VisualID) &&
|
if ((context->attribs->flags & RC_VisualID) &&
|
||||||
!(context->attribs->flags & RC_DefaultVisual))
|
!(context->attribs->flags & RC_DefaultVisual))
|
||||||
XDestroyWindow(context->dpy, context->drawable);
|
XDestroyWindow(context->dpy, context->drawable);
|
||||||
wfree(context->attribs);
|
free(context->attribs);
|
||||||
}
|
}
|
||||||
wfree(context);
|
free(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,15 +33,13 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "convert.h"
|
#include "convert.h"
|
||||||
#include "xutil.h"
|
#include "xutil.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
|
|
||||||
|
|
||||||
#define NFREE(n) wfree(n)
|
#define NFREE(n) if (n) free(n)
|
||||||
|
|
||||||
#define HAS_ALPHA(I) ((I)->format == RRGBAFormat)
|
#define HAS_ALPHA(I) ((I)->format == RRGBAFormat)
|
||||||
|
|
||||||
@@ -72,7 +70,7 @@ static void release_conversion_table(void)
|
|||||||
RConversionTable *tmp_to_delete = tmp;
|
RConversionTable *tmp_to_delete = tmp;
|
||||||
|
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
wfree(tmp_to_delete);
|
free(tmp_to_delete);
|
||||||
}
|
}
|
||||||
conversionTable = NULL;
|
conversionTable = NULL;
|
||||||
}
|
}
|
||||||
@@ -85,7 +83,7 @@ static void release_std_conversion_table(void)
|
|||||||
RStdConversionTable *tmp_to_delete = tmp;
|
RStdConversionTable *tmp_to_delete = tmp;
|
||||||
|
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
wfree(tmp_to_delete);
|
free(tmp_to_delete);
|
||||||
}
|
}
|
||||||
stdConversionTable = NULL;
|
stdConversionTable = NULL;
|
||||||
}
|
}
|
||||||
@@ -110,7 +108,7 @@ static unsigned short *computeTable(unsigned short mask)
|
|||||||
if (tmp)
|
if (tmp)
|
||||||
return tmp->table;
|
return tmp->table;
|
||||||
|
|
||||||
tmp = (RConversionTable *) wmalloc(sizeof(RConversionTable));
|
tmp = (RConversionTable *) malloc(sizeof(RConversionTable));
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -137,7 +135,7 @@ static unsigned int *computeStdTable(unsigned int mult, unsigned int max)
|
|||||||
if (tmp)
|
if (tmp)
|
||||||
return tmp->table;
|
return tmp->table;
|
||||||
|
|
||||||
tmp = (RStdConversionTable *) wmalloc(sizeof(RStdConversionTable));
|
tmp = (RStdConversionTable *) malloc(sizeof(RStdConversionTable));
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -374,8 +372,8 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
|
|||||||
signed char *nerr;
|
signed char *nerr;
|
||||||
int ch = (HAS_ALPHA(image) ? 4 : 3);
|
int ch = (HAS_ALPHA(image) ? 4 : 3);
|
||||||
|
|
||||||
err = wmalloc(ch * (image->width + 2));
|
err = malloc(ch * (image->width + 2));
|
||||||
nerr = wmalloc(ch * (image->width + 2));
|
nerr = malloc(ch * (image->width + 2));
|
||||||
if (!err || !nerr) {
|
if (!err || !nerr) {
|
||||||
NFREE(err);
|
NFREE(err);
|
||||||
NFREE(nerr);
|
NFREE(nerr);
|
||||||
@@ -389,8 +387,8 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
|
|||||||
|
|
||||||
convertTrueColor_generic(ximg, image, err, nerr,
|
convertTrueColor_generic(ximg, image, err, nerr,
|
||||||
rtable, gtable, btable, dr, dg, db, roffs, goffs, boffs);
|
rtable, gtable, btable, dr, dg, db, roffs, goffs, boffs);
|
||||||
wfree(err);
|
free(err);
|
||||||
wfree(nerr);
|
free(nerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -542,8 +540,8 @@ static RXImage *image2PseudoColor(RContext * ctx, RImage * image)
|
|||||||
#ifdef WRLIB_DEBUG
|
#ifdef WRLIB_DEBUG
|
||||||
fprintf(stderr, "pseudo color dithering with %d colors per channel\n", cpc);
|
fprintf(stderr, "pseudo color dithering with %d colors per channel\n", cpc);
|
||||||
#endif
|
#endif
|
||||||
err = wmalloc(4 * (image->width + 3));
|
err = malloc(4 * (image->width + 3));
|
||||||
nerr = wmalloc(4 * (image->width + 3));
|
nerr = malloc(4 * (image->width + 3));
|
||||||
if (!err || !nerr) {
|
if (!err || !nerr) {
|
||||||
NFREE(err);
|
NFREE(err);
|
||||||
NFREE(nerr);
|
NFREE(nerr);
|
||||||
@@ -557,8 +555,8 @@ static RXImage *image2PseudoColor(RContext * ctx, RImage * image)
|
|||||||
convertPseudoColor_to_8(ximg, image, err + 4, nerr + 4,
|
convertPseudoColor_to_8(ximg, image, err + 4, nerr + 4,
|
||||||
rtable, gtable, btable, dr, dg, db, ctx->pixels, cpc);
|
rtable, gtable, btable, dr, dg, db, ctx->pixels, cpc);
|
||||||
|
|
||||||
wfree(err);
|
free(err);
|
||||||
wfree(nerr);
|
free(nerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ximg;
|
return ximg;
|
||||||
@@ -620,8 +618,8 @@ static RXImage *image2StandardPseudoColor(RContext * ctx, RImage * image)
|
|||||||
fprintf(stderr, "pseudo color dithering with %d colors per channel\n",
|
fprintf(stderr, "pseudo color dithering with %d colors per channel\n",
|
||||||
ctx->attribs->colors_per_channel);
|
ctx->attribs->colors_per_channel);
|
||||||
#endif
|
#endif
|
||||||
err = (short *)wmalloc(3 * (image->width + 2) * sizeof(short));
|
err = (short *)malloc(3 * (image->width + 2) * sizeof(short));
|
||||||
nerr = (short *)wmalloc(3 * (image->width + 2) * sizeof(short));
|
nerr = (short *)malloc(3 * (image->width + 2) * sizeof(short));
|
||||||
if (!err || !nerr) {
|
if (!err || !nerr) {
|
||||||
NFREE(err);
|
NFREE(err);
|
||||||
NFREE(nerr);
|
NFREE(nerr);
|
||||||
@@ -709,8 +707,8 @@ static RXImage *image2StandardPseudoColor(RContext * ctx, RImage * image)
|
|||||||
|
|
||||||
ofs += ximg->image->bytes_per_line - image->width;
|
ofs += ximg->image->bytes_per_line - image->width;
|
||||||
}
|
}
|
||||||
wfree(err);
|
free(err);
|
||||||
wfree(nerr);
|
free(nerr);
|
||||||
}
|
}
|
||||||
ximg->image->data = (char *)data;
|
ximg->image->data = (char *)data;
|
||||||
|
|
||||||
@@ -775,8 +773,8 @@ static RXImage *image2GrayScale(RContext * ctx, RImage * image)
|
|||||||
#ifdef WRLIB_DEBUG
|
#ifdef WRLIB_DEBUG
|
||||||
fprintf(stderr, "grayscale dither with %d colors per channel\n", cpc);
|
fprintf(stderr, "grayscale dither with %d colors per channel\n", cpc);
|
||||||
#endif
|
#endif
|
||||||
gerr = (short *)wmalloc((image->width + 2) * sizeof(short));
|
gerr = (short *)malloc((image->width + 2) * sizeof(short));
|
||||||
ngerr = (short *)wmalloc((image->width + 2) * sizeof(short));
|
ngerr = (short *)malloc((image->width + 2) * sizeof(short));
|
||||||
if (!gerr || !ngerr) {
|
if (!gerr || !ngerr) {
|
||||||
NFREE(gerr);
|
NFREE(gerr);
|
||||||
NFREE(ngerr);
|
NFREE(ngerr);
|
||||||
@@ -832,8 +830,8 @@ static RXImage *image2GrayScale(RContext * ctx, RImage * image)
|
|||||||
gerr = ngerr;
|
gerr = ngerr;
|
||||||
ngerr = terr;
|
ngerr = terr;
|
||||||
}
|
}
|
||||||
wfree(gerr);
|
free(gerr);
|
||||||
wfree(ngerr);
|
free(ngerr);
|
||||||
}
|
}
|
||||||
ximg->image->data = (char *)data;
|
ximg->image->data = (char *)data;
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
|
|
||||||
@@ -48,7 +46,7 @@ int RBlurImage(RImage * image)
|
|||||||
unsigned char *pptr = NULL, *tmpp;
|
unsigned char *pptr = NULL, *tmpp;
|
||||||
int ch = image->format == RRGBAFormat ? 4 : 3;
|
int ch = image->format == RRGBAFormat ? 4 : 3;
|
||||||
|
|
||||||
pptr = wmalloc(image->width * ch);
|
pptr = malloc(image->width * ch);
|
||||||
if (!pptr) {
|
if (!pptr) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return False;
|
return False;
|
||||||
@@ -140,7 +138,7 @@ int RBlurImage(RImage * image)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wfree(tmpp);
|
free(tmpp);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|||||||
18
wrlib/load.c
18
wrlib/load.c
@@ -34,8 +34,6 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -127,7 +125,7 @@ static void init_cache(void)
|
|||||||
RImageCacheMaxImage = IMAGE_CACHE_MAXIMUM_MAXPIXELS;
|
RImageCacheMaxImage = IMAGE_CACHE_MAXIMUM_MAXPIXELS;
|
||||||
|
|
||||||
if (RImageCacheSize > 0) {
|
if (RImageCacheSize > 0) {
|
||||||
RImageCache = wmalloc(sizeof(RCachedImage) * RImageCacheSize);
|
RImageCache = malloc(sizeof(RCachedImage) * RImageCacheSize);
|
||||||
if (RImageCache == NULL) {
|
if (RImageCache == NULL) {
|
||||||
fprintf(stderr, _("wrlib: out of memory for image cache\n"));
|
fprintf(stderr, _("wrlib: out of memory for image cache\n"));
|
||||||
return;
|
return;
|
||||||
@@ -144,10 +142,10 @@ void RReleaseCache(void)
|
|||||||
for (i = 0; i < RImageCacheSize; i++) {
|
for (i = 0; i < RImageCacheSize; i++) {
|
||||||
if (RImageCache[i].file) {
|
if (RImageCache[i].file) {
|
||||||
RReleaseImage(RImageCache[i].image);
|
RReleaseImage(RImageCache[i].image);
|
||||||
wfree(RImageCache[i].file);
|
free(RImageCache[i].file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wfree(RImageCache);
|
free(RImageCache);
|
||||||
RImageCache = NULL;
|
RImageCache = NULL;
|
||||||
RImageCacheSize = -1;
|
RImageCacheSize = -1;
|
||||||
}
|
}
|
||||||
@@ -175,7 +173,7 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
|
|||||||
return RCloneImage(RImageCache[i].image);
|
return RCloneImage(RImageCache[i].image);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
wfree(RImageCache[i].file);
|
free(RImageCache[i].file);
|
||||||
RImageCache[i].file = NULL;
|
RImageCache[i].file = NULL;
|
||||||
RReleaseImage(RImageCache[i].image);
|
RReleaseImage(RImageCache[i].image);
|
||||||
}
|
}
|
||||||
@@ -256,7 +254,8 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
|
|||||||
|
|
||||||
for (i = 0; i < RImageCacheSize; i++) {
|
for (i = 0; i < RImageCacheSize; i++) {
|
||||||
if (!RImageCache[i].file) {
|
if (!RImageCache[i].file) {
|
||||||
RImageCache[i].file = wstrdup(file);
|
RImageCache[i].file = malloc(strlen(file) + 1);
|
||||||
|
strcpy(RImageCache[i].file, file);
|
||||||
RImageCache[i].image = RCloneImage(image);
|
RImageCache[i].image = RCloneImage(image);
|
||||||
RImageCache[i].last_modif = st.st_mtime;
|
RImageCache[i].last_modif = st.st_mtime;
|
||||||
RImageCache[i].last_use = time(NULL);
|
RImageCache[i].last_use = time(NULL);
|
||||||
@@ -272,9 +271,10 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
|
|||||||
|
|
||||||
/* if no slot available, dump least recently used one */
|
/* if no slot available, dump least recently used one */
|
||||||
if (!done) {
|
if (!done) {
|
||||||
wfree(RImageCache[oldest_idx].file);
|
free(RImageCache[oldest_idx].file);
|
||||||
RReleaseImage(RImageCache[oldest_idx].image);
|
RReleaseImage(RImageCache[oldest_idx].image);
|
||||||
RImageCache[oldest_idx].file = wstrdup(file);
|
RImageCache[oldest_idx].file = malloc(strlen(file) + 1);
|
||||||
|
strcpy(RImageCache[oldest_idx].file, file);
|
||||||
RImageCache[oldest_idx].image = RCloneImage(image);
|
RImageCache[oldest_idx].image = RCloneImage(image);
|
||||||
RImageCache[oldest_idx].last_modif = st.st_mtime;
|
RImageCache[oldest_idx].last_modif = st.st_mtime;
|
||||||
RImageCache[oldest_idx].last_use = time(NULL);
|
RImageCache[oldest_idx].last_use = time(NULL);
|
||||||
|
|||||||
@@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
#include <gif_lib.h>
|
#include <gif_lib.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -129,7 +127,7 @@ RImage *RLoadGIF(const char *file, int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = wmalloc(width * sizeof(GifPixelType));
|
buffer = malloc(width * sizeof(GifPixelType));
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
goto bye;
|
goto bye;
|
||||||
@@ -221,7 +219,7 @@ RImage *RLoadGIF(const char *file, int index)
|
|||||||
did_not_get_any_errors:
|
did_not_get_any_errors:
|
||||||
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
|
|
||||||
if (gif)
|
if (gif)
|
||||||
#if (USE_GIF == 5) && (GIFLIB_MINOR >= 1)
|
#if (USE_GIF == 5) && (GIFLIB_MINOR >= 1)
|
||||||
|
|||||||
@@ -35,8 +35,6 @@
|
|||||||
#include <stdnoreturn.h>
|
#include <stdnoreturn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -121,7 +119,7 @@ static RImage *do_read_jpeg_file(struct jpeg_decompress_struct *cinfo, const cha
|
|||||||
goto abort_and_release_resources;
|
goto abort_and_release_resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[0] = (JSAMPROW) wmalloc(cinfo->image_width * cinfo->num_components);
|
buffer[0] = (JSAMPROW) malloc(cinfo->image_width * cinfo->num_components);
|
||||||
if (!buffer[0]) {
|
if (!buffer[0]) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
goto abort_and_release_resources;
|
goto abort_and_release_resources;
|
||||||
@@ -169,7 +167,7 @@ static RImage *do_read_jpeg_file(struct jpeg_decompress_struct *cinfo, const cha
|
|||||||
jpeg_destroy_decompress(cinfo);
|
jpeg_destroy_decompress(cinfo);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
if (buffer[0])
|
if (buffer[0])
|
||||||
wfree(buffer[0]);
|
free(buffer[0]);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -167,7 +165,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
|||||||
image->background.blue = bkcolor->blue >> 8;
|
image->background.blue = bkcolor->blue >> 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_rows = wmalloc(height * sizeof(png_bytep));
|
png_rows = calloc(height, sizeof(png_bytep));
|
||||||
if (!png_rows) {
|
if (!png_rows) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -176,7 +174,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (y = 0; y < height; y++) {
|
for (y = 0; y < height; y++) {
|
||||||
png_rows[y] = wmalloc(png_get_rowbytes(png, pinfo));
|
png_rows[y] = malloc(png_get_rowbytes(png, pinfo));
|
||||||
if (!png_rows[y]) {
|
if (!png_rows[y]) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -184,8 +182,8 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
|||||||
png_destroy_read_struct(&png, &pinfo, &einfo);
|
png_destroy_read_struct(&png, &pinfo, &einfo);
|
||||||
while (y-- > 0)
|
while (y-- > 0)
|
||||||
if (png_rows[y])
|
if (png_rows[y])
|
||||||
wfree(png_rows[y]);
|
free(png_rows[y]);
|
||||||
wfree(png_rows);
|
free(png_rows);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,7 +214,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
|||||||
}
|
}
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
if (png_rows[y])
|
if (png_rows[y])
|
||||||
wfree(png_rows[y]);
|
free(png_rows[y]);
|
||||||
wfree(png_rows);
|
free(png_rows);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -163,7 +161,7 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
|
|||||||
if (raw == '5') {
|
if (raw == '5') {
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
buf = wmalloc(w + 1);
|
buf = malloc(w + 1);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
RReleaseImage(image);
|
RReleaseImage(image);
|
||||||
@@ -171,7 +169,7 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
|
|||||||
}
|
}
|
||||||
for (y = 0; y < h; y++) {
|
for (y = 0; y < h; y++) {
|
||||||
if (!fread(buf, w, 1, file)) {
|
if (!fread(buf, w, 1, file)) {
|
||||||
wfree(buf);
|
free(buf);
|
||||||
RErrorCode = RERR_BADIMAGEFILE;
|
RErrorCode = RERR_BADIMAGEFILE;
|
||||||
RReleaseImage(image);
|
RReleaseImage(image);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -183,7 +181,7 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
|
|||||||
*(ptr++) = buf[x];
|
*(ptr++) = buf[x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wfree(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
|
|
||||||
#include <webp/decode.h>
|
#include <webp/decode.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -112,7 +110,7 @@ RImage *RLoadWEBP(const char *file_name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_data = (uint8_t *) wmalloc(raw_data_size);
|
raw_data = (uint8_t *) malloc(raw_data_size);
|
||||||
|
|
||||||
if (!raw_data) {
|
if (!raw_data) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
@@ -126,7 +124,7 @@ RImage *RLoadWEBP(const char *file_name)
|
|||||||
|
|
||||||
if (r != raw_data_size) {
|
if (r != raw_data_size) {
|
||||||
RErrorCode = RERR_READ;
|
RErrorCode = RERR_READ;
|
||||||
wfree(raw_data);
|
free(raw_data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +133,7 @@ RImage *RLoadWEBP(const char *file_name)
|
|||||||
fprintf(stderr, _("wrlib: could not get features from WebP file \"%s\", %s\n"),
|
fprintf(stderr, _("wrlib: could not get features from WebP file \"%s\", %s\n"),
|
||||||
file_name, webp_message_from_status(status));
|
file_name, webp_message_from_status(status));
|
||||||
RErrorCode = RERR_BADIMAGEFILE;
|
RErrorCode = RERR_BADIMAGEFILE;
|
||||||
wfree(raw_data);
|
free(raw_data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +141,7 @@ RImage *RLoadWEBP(const char *file_name)
|
|||||||
image = RCreateImage(features.width, features.height, True);
|
image = RCreateImage(features.width, features.height, True);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
wfree(raw_data);
|
free(raw_data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret = WebPDecodeRGBAInto(raw_data, raw_data_size, image->data,
|
ret = WebPDecodeRGBAInto(raw_data, raw_data_size, image->data,
|
||||||
@@ -153,7 +151,7 @@ RImage *RLoadWEBP(const char *file_name)
|
|||||||
image = RCreateImage(features.width, features.height, False);
|
image = RCreateImage(features.width, features.height, False);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
wfree(raw_data);
|
free(raw_data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret = WebPDecodeRGBInto(raw_data, raw_data_size, image->data,
|
ret = WebPDecodeRGBInto(raw_data, raw_data_size, image->data,
|
||||||
@@ -161,7 +159,7 @@ RImage *RLoadWEBP(const char *file_name)
|
|||||||
features.width * 3);
|
features.width * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
wfree(raw_data);
|
free(raw_data);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
fprintf(stderr, _("wrlib: failed to decode WebP from file \"%s\"\n"), file_name);
|
fprintf(stderr, _("wrlib: failed to decode WebP from file \"%s\"\n"), file_name);
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <X11/xpm.h>
|
#include <X11/xpm.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -61,11 +59,11 @@ static RImage *create_rimage_from_xpm(RContext *context, XpmImage xpm)
|
|||||||
|
|
||||||
/* make color table */
|
/* make color table */
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
color_table[i] = wmalloc(xpm.ncolors * sizeof(unsigned char));
|
color_table[i] = malloc(xpm.ncolors * sizeof(unsigned char));
|
||||||
if (!color_table[i]) {
|
if (!color_table[i]) {
|
||||||
for (i = i - 1; i >= 0; i--) {
|
for (i = i - 1; i >= 0; i--) {
|
||||||
if (color_table[i])
|
if (color_table[i])
|
||||||
wfree(color_table[i]);
|
free(color_table[i]);
|
||||||
}
|
}
|
||||||
RReleaseImage(image);
|
RReleaseImage(image);
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
@@ -125,7 +123,7 @@ static RImage *create_rimage_from_xpm(RContext *context, XpmImage xpm)
|
|||||||
*(data++) = color_table[3][*p];
|
*(data++) = color_table[3][*p];
|
||||||
}
|
}
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
wfree(color_table[i]);
|
free(color_table[i]);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,15 +59,15 @@ static void free_color_symbol_table(unsigned char *color_table[],
|
|||||||
unsigned short *symbol_table)
|
unsigned short *symbol_table)
|
||||||
{
|
{
|
||||||
if (color_table[0])
|
if (color_table[0])
|
||||||
wfree(color_table[0]);
|
free(color_table[0]);
|
||||||
if (color_table[1])
|
if (color_table[1])
|
||||||
wfree(color_table[1]);
|
free(color_table[1]);
|
||||||
if (color_table[2])
|
if (color_table[2])
|
||||||
wfree(color_table[2]);
|
free(color_table[2]);
|
||||||
if (color_table[3])
|
if (color_table[3])
|
||||||
wfree(color_table[3]);
|
free(color_table[3]);
|
||||||
if (symbol_table)
|
if (symbol_table)
|
||||||
wfree(symbol_table);
|
free(symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
RImage *RGetImageFromXPMData(RContext * context, char **data)
|
RImage *RGetImageFromXPMData(RContext * context, char **data)
|
||||||
@@ -95,11 +95,11 @@ RImage *RGetImageFromXPMData(RContext * context, char **data)
|
|||||||
if (csize != 1 && csize != 2)
|
if (csize != 1 && csize != 2)
|
||||||
goto bad_format;
|
goto bad_format;
|
||||||
|
|
||||||
color_table[0] = wmalloc(ccount);
|
color_table[0] = malloc(ccount);
|
||||||
color_table[1] = wmalloc(ccount);
|
color_table[1] = malloc(ccount);
|
||||||
color_table[2] = wmalloc(ccount);
|
color_table[2] = malloc(ccount);
|
||||||
color_table[3] = wmalloc(ccount);
|
color_table[3] = malloc(ccount);
|
||||||
symbol_table = wmalloc(ccount * sizeof(unsigned short));
|
symbol_table = malloc(ccount * sizeof(unsigned short));
|
||||||
|
|
||||||
bsize = csize * w + 16;
|
bsize = csize * w + 16;
|
||||||
|
|
||||||
@@ -283,14 +283,14 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
|||||||
if (csize != 1 && csize != 2)
|
if (csize != 1 && csize != 2)
|
||||||
goto bad_format;
|
goto bad_format;
|
||||||
|
|
||||||
color_table[0] = wmalloc(ccount);
|
color_table[0] = malloc(ccount);
|
||||||
color_table[1] = wmalloc(ccount);
|
color_table[1] = malloc(ccount);
|
||||||
color_table[2] = wmalloc(ccount);
|
color_table[2] = malloc(ccount);
|
||||||
color_table[3] = wmalloc(ccount);
|
color_table[3] = malloc(ccount);
|
||||||
symbol_table = wmalloc(ccount * sizeof(unsigned short));
|
symbol_table = malloc(ccount * sizeof(unsigned short));
|
||||||
|
|
||||||
bsize = csize * w + 16;
|
bsize = csize * w + 16;
|
||||||
buffer = wmalloc(bsize);
|
buffer = malloc(bsize);
|
||||||
|
|
||||||
if (!color_table[0] || !color_table[1] || !color_table[2] ||
|
if (!color_table[0] || !color_table[1] || !color_table[2] ||
|
||||||
!color_table[3] || !symbol_table || !bsize || !buffer) {
|
!color_table[3] || !symbol_table || !bsize || !buffer) {
|
||||||
@@ -298,7 +298,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
free_color_symbol_table(color_table, symbol_table);
|
free_color_symbol_table(color_table, symbol_table);
|
||||||
if (buffer)
|
if (buffer)
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,7 +355,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
free_color_symbol_table(color_table, symbol_table);
|
free_color_symbol_table(color_table, symbol_table);
|
||||||
if (buffer)
|
if (buffer)
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +434,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
free_color_symbol_table(color_table, symbol_table);
|
free_color_symbol_table(color_table, symbol_table);
|
||||||
if (buffer)
|
if (buffer)
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
return image;
|
return image;
|
||||||
|
|
||||||
bad_format:
|
bad_format:
|
||||||
@@ -442,7 +442,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
free_color_symbol_table(color_table, symbol_table);
|
free_color_symbol_table(color_table, symbol_table);
|
||||||
if (buffer)
|
if (buffer)
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
if (image)
|
if (image)
|
||||||
RReleaseImage(image);
|
RReleaseImage(image);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -452,7 +452,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
free_color_symbol_table(color_table, symbol_table);
|
free_color_symbol_table(color_table, symbol_table);
|
||||||
if (buffer)
|
if (buffer)
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
if (image)
|
if (image)
|
||||||
RReleaseImage(image);
|
RReleaseImage(image);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -27,8 +27,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
|
|
||||||
@@ -55,7 +53,7 @@ RImage *RCreateImage(unsigned width, unsigned height, int alpha)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
image = wmalloc(sizeof(RImage));
|
image = malloc(sizeof(RImage));
|
||||||
if (!image) {
|
if (!image) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -70,10 +68,10 @@ RImage *RCreateImage(unsigned width, unsigned height, int alpha)
|
|||||||
/* the +4 is to give extra bytes at the end of the buffer,
|
/* the +4 is to give extra bytes at the end of the buffer,
|
||||||
* so that we can optimize image conversion for MMX(tm).. see convert.c
|
* so that we can optimize image conversion for MMX(tm).. see convert.c
|
||||||
*/
|
*/
|
||||||
image->data = wmalloc(width * height * (alpha ? 4 : 3) + 4);
|
image->data = malloc(width * height * (alpha ? 4 : 3) + 4);
|
||||||
if (!image->data) {
|
if (!image->data) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
wfree(image);
|
free(image);
|
||||||
image = NULL;
|
image = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +94,8 @@ void RReleaseImage(RImage * image)
|
|||||||
image->refCount--;
|
image->refCount--;
|
||||||
|
|
||||||
if (image->refCount < 1) {
|
if (image->refCount < 1) {
|
||||||
wfree(image->data);
|
free(image->data);
|
||||||
wfree(image);
|
free(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <jpeglib.h>
|
#include <jpeglib.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -61,7 +59,7 @@ Bool RSaveJPEG(RImage *img, const char *filename, char *title)
|
|||||||
img_depth = 3;
|
img_depth = 3;
|
||||||
|
|
||||||
/* collect separate RGB values to a buffer */
|
/* collect separate RGB values to a buffer */
|
||||||
buffer = wmalloc(sizeof(char) * 3 * img->width * img->height);
|
buffer = malloc(sizeof(char) * 3 * img->width * img->height);
|
||||||
for (y = 0; y < img->height; y++) {
|
for (y = 0; y < img->height; y++) {
|
||||||
for (x = 0; x < img->width; x++) {
|
for (x = 0; x < img->width; x++) {
|
||||||
RGetPixel(img, x, y, &pixel);
|
RGetPixel(img, x, y, &pixel);
|
||||||
@@ -99,7 +97,7 @@ Bool RSaveJPEG(RImage *img, const char *filename, char *title)
|
|||||||
jpeg_finish_compress(&cinfo);
|
jpeg_finish_compress(&cinfo);
|
||||||
|
|
||||||
/* Clean */
|
/* Clean */
|
||||||
wfree(buffer);
|
free(buffer);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -97,7 +95,7 @@ Bool RSavePNG(RImage *img, const char *filename, char *title)
|
|||||||
png_write_info(png_ptr, png_info_ptr);
|
png_write_info(png_ptr, png_info_ptr);
|
||||||
|
|
||||||
/* Allocate memory for one row (3 bytes per pixel - RGB) */
|
/* Allocate memory for one row (3 bytes per pixel - RGB) */
|
||||||
png_row = (png_bytep) wmalloc(3 * width * sizeof(png_byte));
|
png_row = (png_bytep) malloc(3 * width * sizeof(png_byte));
|
||||||
|
|
||||||
/* Write image data */
|
/* Write image data */
|
||||||
for (y = 0; y < height; y++) {
|
for (y = 0; y < height; y++) {
|
||||||
@@ -123,7 +121,7 @@ Bool RSavePNG(RImage *img, const char *filename, char *title)
|
|||||||
if (png_ptr != NULL)
|
if (png_ptr != NULL)
|
||||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||||
if (png_row != NULL)
|
if (png_row != NULL)
|
||||||
wfree(png_row);
|
free(png_row);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "imgformat.h"
|
#include "imgformat.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -97,7 +95,7 @@ static Bool addcolor(XPMColor ** list, unsigned r, unsigned g, unsigned b, int *
|
|||||||
if (tmpc)
|
if (tmpc)
|
||||||
return True;
|
return True;
|
||||||
|
|
||||||
newc = wmalloc(sizeof(XPMColor));
|
newc = malloc(sizeof(XPMColor));
|
||||||
|
|
||||||
if (!newc) {
|
if (!newc) {
|
||||||
|
|
||||||
@@ -151,7 +149,7 @@ static void freecolormap(XPMColor * colormap)
|
|||||||
|
|
||||||
while (colormap) {
|
while (colormap) {
|
||||||
tmp = colormap->next;
|
tmp = colormap->next;
|
||||||
wfree(colormap);
|
free(colormap);
|
||||||
colormap = tmp;
|
colormap = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
#include "scale.h"
|
#include "scale.h"
|
||||||
#include "wr_i18n.h"
|
#include "wr_i18n.h"
|
||||||
@@ -297,7 +295,7 @@ typedef struct {
|
|||||||
/* clamp the input to the specified range */
|
/* clamp the input to the specified range */
|
||||||
#define CLAMP(v,l,h) ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
|
#define CLAMP(v,l,h) ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
|
||||||
|
|
||||||
/* return of wmalloc is not checked if NULL in the function below! */
|
/* return of calloc is not checked if NULL in the function below! */
|
||||||
RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
||||||
{
|
{
|
||||||
CLIST *contrib; /* array of contribution lists */
|
CLIST *contrib; /* array of contribution lists */
|
||||||
@@ -321,13 +319,13 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
|||||||
yscale = (double)new_height / (double)src->height;
|
yscale = (double)new_height / (double)src->height;
|
||||||
|
|
||||||
/* pre-calculate filter contributions for a row */
|
/* pre-calculate filter contributions for a row */
|
||||||
contrib = (CLIST *) wmalloc(new_width * sizeof(CLIST));
|
contrib = (CLIST *) calloc(new_width, sizeof(CLIST));
|
||||||
if (xscale < 1.0) {
|
if (xscale < 1.0) {
|
||||||
width = fwidth / xscale;
|
width = fwidth / xscale;
|
||||||
fscale = 1.0 / xscale;
|
fscale = 1.0 / xscale;
|
||||||
for (i = 0; i < new_width; ++i) {
|
for (i = 0; i < new_width; ++i) {
|
||||||
contrib[i].n = 0;
|
contrib[i].n = 0;
|
||||||
contrib[i].p = (CONTRIB *) wmalloc(ceil(width * 2 + 1) * sizeof(CONTRIB));
|
contrib[i].p = (CONTRIB *) calloc((int) ceil(width * 2 + 1), sizeof(CONTRIB));
|
||||||
center = (double)i / xscale;
|
center = (double)i / xscale;
|
||||||
left = ceil(center - width);
|
left = ceil(center - width);
|
||||||
right = floor(center + width);
|
right = floor(center + width);
|
||||||
@@ -350,7 +348,7 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
|||||||
|
|
||||||
for (i = 0; i < new_width; ++i) {
|
for (i = 0; i < new_width; ++i) {
|
||||||
contrib[i].n = 0;
|
contrib[i].n = 0;
|
||||||
contrib[i].p = (CONTRIB *) wmalloc(ceil(fwidth * 2 + 1) * sizeof(CONTRIB));
|
contrib[i].p = (CONTRIB *) calloc((int) ceil(fwidth * 2 + 1), sizeof(CONTRIB));
|
||||||
center = (double)i / xscale;
|
center = (double)i / xscale;
|
||||||
left = ceil(center - fwidth);
|
left = ceil(center - fwidth);
|
||||||
right = floor(center + fwidth);
|
right = floor(center + fwidth);
|
||||||
@@ -397,18 +395,18 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
|||||||
|
|
||||||
/* free the memory allocated for horizontal filter weights */
|
/* free the memory allocated for horizontal filter weights */
|
||||||
for (i = 0; i < new_width; ++i) {
|
for (i = 0; i < new_width; ++i) {
|
||||||
wfree(contrib[i].p);
|
free(contrib[i].p);
|
||||||
}
|
}
|
||||||
wfree(contrib);
|
free(contrib);
|
||||||
|
|
||||||
/* pre-calculate filter contributions for a column */
|
/* pre-calculate filter contributions for a column */
|
||||||
contrib = (CLIST *) wmalloc(dst->height * sizeof(CLIST));
|
contrib = (CLIST *) calloc(dst->height, sizeof(CLIST));
|
||||||
if (yscale < 1.0) {
|
if (yscale < 1.0) {
|
||||||
width = fwidth / yscale;
|
width = fwidth / yscale;
|
||||||
fscale = 1.0 / yscale;
|
fscale = 1.0 / yscale;
|
||||||
for (i = 0; i < dst->height; ++i) {
|
for (i = 0; i < dst->height; ++i) {
|
||||||
contrib[i].n = 0;
|
contrib[i].n = 0;
|
||||||
contrib[i].p = (CONTRIB *) wmalloc(ceil(width * 2 + 1) * sizeof(CONTRIB));
|
contrib[i].p = (CONTRIB *) calloc((int) ceil(width * 2 + 1), sizeof(CONTRIB));
|
||||||
center = (double)i / yscale;
|
center = (double)i / yscale;
|
||||||
left = ceil(center - width);
|
left = ceil(center - width);
|
||||||
right = floor(center + width);
|
right = floor(center + width);
|
||||||
@@ -430,7 +428,7 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
|||||||
} else {
|
} else {
|
||||||
for (i = 0; i < dst->height; ++i) {
|
for (i = 0; i < dst->height; ++i) {
|
||||||
contrib[i].n = 0;
|
contrib[i].n = 0;
|
||||||
contrib[i].p = (CONTRIB *) wmalloc(ceil(fwidth * 2 + 1) * sizeof(CONTRIB));
|
contrib[i].p = (CONTRIB *) calloc((int) ceil(fwidth * 2 + 1), sizeof(CONTRIB));
|
||||||
center = (double)i / yscale;
|
center = (double)i / yscale;
|
||||||
left = ceil(center - fwidth);
|
left = ceil(center - fwidth);
|
||||||
right = floor(center + fwidth);
|
right = floor(center + fwidth);
|
||||||
@@ -452,7 +450,7 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* apply filter to zoom vertically from tmp to dst */
|
/* apply filter to zoom vertically from tmp to dst */
|
||||||
sp = wmalloc(tmp->height * 3);
|
sp = malloc(tmp->height * 3);
|
||||||
|
|
||||||
for (k = 0; k < new_width; ++k) {
|
for (k = 0; k < new_width; ++k) {
|
||||||
CONTRIB *pp;
|
CONTRIB *pp;
|
||||||
@@ -487,13 +485,13 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
|
|||||||
p += new_width * 3;
|
p += new_width * 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wfree(sp);
|
free(sp);
|
||||||
|
|
||||||
/* free the memory allocated for vertical filter weights */
|
/* free the memory allocated for vertical filter weights */
|
||||||
for (i = 0; i < dst->height; ++i) {
|
for (i = 0; i < dst->height; ++i) {
|
||||||
wfree(contrib[i].p);
|
free(contrib[i].p);
|
||||||
}
|
}
|
||||||
wfree(contrib);
|
free(contrib);
|
||||||
|
|
||||||
RReleaseImage(tmp);
|
RReleaseImage(tmp);
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ int main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
ProgName++;
|
ProgName++;
|
||||||
|
|
||||||
color_name = (char **)wmalloc(sizeof(char *) * argc);
|
color_name = (char **)malloc(sizeof(char *) * argc);
|
||||||
if (color_name == NULL) {
|
if (color_name == NULL) {
|
||||||
fprintf(stderr, "Cannot allocate memory!\n");
|
fprintf(stderr, "Cannot allocate memory!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -106,13 +106,13 @@ int main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
colors = wmalloc(sizeof(RColor *) * (ncolors + 1));
|
colors = malloc(sizeof(RColor *) * (ncolors + 1));
|
||||||
for (i = 0; i < ncolors; i++) {
|
for (i = 0; i < ncolors; i++) {
|
||||||
if (!XParseColor(dpy, ctx->cmap, color_name[i], &color)) {
|
if (!XParseColor(dpy, ctx->cmap, color_name[i], &color)) {
|
||||||
printf("could not parse color \"%s\"\n", color_name[i]);
|
printf("could not parse color \"%s\"\n", color_name[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
colors[i] = wmalloc(sizeof(RColor));
|
colors[i] = malloc(sizeof(RColor));
|
||||||
colors[i]->red = color.red >> 8;
|
colors[i]->red = color.red >> 8;
|
||||||
colors[i]->green = color.green >> 8;
|
colors[i]->green = color.green >> 8;
|
||||||
colors[i]->blue = color.blue >> 8;
|
colors[i]->blue = color.blue >> 8;
|
||||||
@@ -149,10 +149,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
getchar();
|
getchar();
|
||||||
|
|
||||||
wfree(color_name);
|
free(color_name);
|
||||||
for (i = 0; i < ncolors + 1; i++)
|
for (i = 0; i < ncolors + 1; i++)
|
||||||
wfree(colors[i]);
|
free(colors[i]);
|
||||||
wfree(colors);
|
free(colors);
|
||||||
|
|
||||||
RDestroyContext(ctx);
|
RDestroyContext(ctx);
|
||||||
RShutdown();
|
RShutdown();
|
||||||
|
|||||||
@@ -31,8 +31,6 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
|
||||||
|
|
||||||
#ifdef USE_XSHM
|
#ifdef USE_XSHM
|
||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
@@ -65,7 +63,7 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
|
|||||||
RXImage *rximg;
|
RXImage *rximg;
|
||||||
Visual *visual = context->visual;
|
Visual *visual = context->visual;
|
||||||
|
|
||||||
rximg = wmalloc(sizeof(RXImage));
|
rximg = malloc(sizeof(RXImage));
|
||||||
if (!rximg) {
|
if (!rximg) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -73,14 +71,14 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
|
|||||||
#ifndef USE_XSHM
|
#ifndef USE_XSHM
|
||||||
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
|
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
|
||||||
if (!rximg->image) {
|
if (!rximg->image) {
|
||||||
wfree(rximg);
|
free(rximg);
|
||||||
RErrorCode = RERR_XERROR;
|
RErrorCode = RERR_XERROR;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
rximg->image->data = wmalloc(rximg->image->bytes_per_line * height);
|
rximg->image->data = malloc(rximg->image->bytes_per_line * height);
|
||||||
if (!rximg->image->data) {
|
if (!rximg->image->data) {
|
||||||
XDestroyImage(rximg->image);
|
XDestroyImage(rximg->image);
|
||||||
wfree(rximg);
|
free(rximg);
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -92,14 +90,14 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
|
|||||||
rximg->is_shared = 0;
|
rximg->is_shared = 0;
|
||||||
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
|
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
|
||||||
if (!rximg->image) {
|
if (!rximg->image) {
|
||||||
wfree(rximg);
|
free(rximg);
|
||||||
RErrorCode = RERR_XERROR;
|
RErrorCode = RERR_XERROR;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
rximg->image->data = wmalloc(rximg->image->bytes_per_line * height);
|
rximg->image->data = malloc(rximg->image->bytes_per_line * height);
|
||||||
if (!rximg->image->data) {
|
if (!rximg->image->data) {
|
||||||
XDestroyImage(rximg->image);
|
XDestroyImage(rximg->image);
|
||||||
wfree(rximg);
|
free(rximg);
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -175,7 +173,7 @@ void RDestroyXImage(RContext * context, RXImage * rximage)
|
|||||||
XDestroyImage(rximage->image);
|
XDestroyImage(rximage->image);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
wfree(rximage);
|
free(rximage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned getDepth(Display * dpy, Drawable d)
|
static unsigned getDepth(Display * dpy, Drawable d)
|
||||||
@@ -207,7 +205,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ximg) {
|
if (!ximg) {
|
||||||
ximg = wmalloc(sizeof(RXImage));
|
ximg = malloc(sizeof(RXImage));
|
||||||
if (!ximg) {
|
if (!ximg) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -216,7 +214,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
|
|||||||
ximg->image = XGetImage(context->dpy, d, x, y, width, height, AllPlanes, ZPixmap);
|
ximg->image = XGetImage(context->dpy, d, x, y, width, height, AllPlanes, ZPixmap);
|
||||||
}
|
}
|
||||||
#else /* !USE_XSHM */
|
#else /* !USE_XSHM */
|
||||||
ximg = wmalloc(sizeof(RXImage));
|
ximg = malloc(sizeof(RXImage));
|
||||||
if (!ximg) {
|
if (!ximg) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -226,7 +224,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
|
|||||||
#endif /* !USE_XSHM */
|
#endif /* !USE_XSHM */
|
||||||
|
|
||||||
if (ximg->image == NULL) {
|
if (ximg->image == NULL) {
|
||||||
wfree(ximg);
|
free(ximg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user