Got rid of complain() on GTK+.
This commit is contained in:
parent
59eebb1e48
commit
0205f2e5ca
|
@ -37,6 +37,9 @@ ifeq ($(TOOLCHAIN),gcc)
|
||||||
else
|
else
|
||||||
LDFLAGS += -Wl,-rpath,'$$ORIGIN'
|
LDFLAGS += -Wl,-rpath,'$$ORIGIN'
|
||||||
endif
|
endif
|
||||||
|
ifneq ($(findstring cpp-,$(EXAMPLE)),)
|
||||||
|
LDFLAGS += -pthread
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
# TODO is there an equivalent to -L?
|
# TODO is there an equivalent to -L?
|
||||||
LDFLAGS += $(OUTDIR)/libui.lib
|
LDFLAGS += $(OUTDIR)/libui.lib
|
||||||
|
|
|
@ -19,7 +19,7 @@ extern void realbug(const char *file, const char *line, const char *func, const
|
||||||
extern void _implbug(const char *file, const char *line, const char *func, const char *format, ...);
|
extern void _implbug(const char *file, const char *line, const char *func, const char *format, ...);
|
||||||
#define implbug(...) _implbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__)
|
#define implbug(...) _implbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__)
|
||||||
extern void _userbug(const char *file, const char *line, const char *func, const char *format, ...);
|
extern void _userbug(const char *file, const char *line, const char *func, const char *format, ...);
|
||||||
#define userbug(...) _implbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__)
|
#define userbug(...) _userbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__)
|
||||||
|
|
||||||
// control.c
|
// control.c
|
||||||
extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr);
|
extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr);
|
||||||
|
|
|
@ -43,6 +43,7 @@ void uninitAlloc(void)
|
||||||
[str appendString:[NSString stringWithFormat:@"%p %s\n", ptr, *TYPE(ptr)]];
|
[str appendString:[NSString stringWithFormat:@"%p %s\n", ptr, *TYPE(ptr)]];
|
||||||
}
|
}
|
||||||
userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", [str UTF8String]);
|
userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", [str UTF8String]);
|
||||||
|
[str release];
|
||||||
}
|
}
|
||||||
|
|
||||||
void *uiAlloc(size_t size, const char *type)
|
void *uiAlloc(size_t size, const char *type)
|
||||||
|
|
|
@ -335,7 +335,7 @@ int sendAreaEvents(NSEvent *e)
|
||||||
void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height)
|
void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height)
|
||||||
{
|
{
|
||||||
if (!a->scrolling)
|
if (!a->scrolling)
|
||||||
userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (uiArea: %p)", a);
|
userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a);
|
||||||
[a->area setFrameSize:NSMakeSize(width, height)];
|
[a->area setFrameSize:NSMakeSize(width, height)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ void uiAreaQueueRedrawAll(uiArea *a)
|
||||||
void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height)
|
void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height)
|
||||||
{
|
{
|
||||||
if (!a->scrolling)
|
if (!a->scrolling)
|
||||||
userbug("You cannot call uiAreaScrollTo() on a non-scrolling uiArea. (uiArea: %p)", a);
|
userbug("You cannot call uiAreaScrollTo() on a non-scrolling uiArea. (area: %p)", a);
|
||||||
[a->area scrollRectToVisible:NSMakeRect(x, y, width, height)];
|
[a->area scrollRectToVisible:NSMakeRect(x, y, width, height)];
|
||||||
// don't worry about the return value; it just says whether scrolling was needed
|
// don't worry about the return value; it just says whether scrolling was needed
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ void realbug(const char *file, const char *line, const char *func, const char *p
|
||||||
NSString *formatted;
|
NSString *formatted;
|
||||||
|
|
||||||
str = [NSMutableString new];
|
str = [NSMutableString new];
|
||||||
[str appendString:[NSString stringWithFormat:@"[libui] %s:%s:%s %s", file, line, func, prefix]];
|
[str appendString:[NSString stringWithFormat:@"[libui] %s:%s:%s() %s", file, line, func, prefix]];
|
||||||
formatted = [[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:ap];
|
formatted = [[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:ap];
|
||||||
[str appendString:formatted];
|
[str appendString:formatted];
|
||||||
[formatted release];
|
[formatted release];
|
||||||
|
|
|
@ -10,6 +10,7 @@ CFILES += \
|
||||||
unix/combobox.c \
|
unix/combobox.c \
|
||||||
unix/control.c \
|
unix/control.c \
|
||||||
unix/datetimepicker.c \
|
unix/datetimepicker.c \
|
||||||
|
unix/debug.c \
|
||||||
unix/draw.c \
|
unix/draw.c \
|
||||||
unix/drawmatrix.c \
|
unix/drawmatrix.c \
|
||||||
unix/drawpath.c \
|
unix/drawpath.c \
|
||||||
|
|
23
unix/alloc.c
23
unix/alloc.c
|
@ -20,18 +20,27 @@ void initAlloc(void)
|
||||||
|
|
||||||
static void uninitComplain(gpointer ptr, gpointer data)
|
static void uninitComplain(gpointer ptr, gpointer data)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "[libui] %p %s\n", ptr, *TYPE(ptr));
|
char **str = (char **) data;
|
||||||
|
char *str2;
|
||||||
|
|
||||||
|
if (*str == NULL)
|
||||||
|
*str = g_strdup_printf("");
|
||||||
|
str2 = g_strdup_printf("%s%p %s\n", *str, ptr, *TYPE(ptr));
|
||||||
|
g_free(*str);
|
||||||
|
*str = str2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitAlloc(void)
|
void uninitAlloc(void)
|
||||||
{
|
{
|
||||||
|
char *str = NULL;
|
||||||
|
|
||||||
if (allocations->len == 0) {
|
if (allocations->len == 0) {
|
||||||
g_ptr_array_free(allocations, TRUE);
|
g_ptr_array_free(allocations, TRUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "[libui] leaked allocations:\n");
|
g_ptr_array_foreach(allocations, uninitComplain, &str);
|
||||||
g_ptr_array_foreach(allocations, uninitComplain, NULL);
|
userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", str);
|
||||||
complain("either you left something around or there's a bug in libui");
|
g_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *uiAlloc(size_t size, const char *type)
|
void *uiAlloc(size_t size, const char *type)
|
||||||
|
@ -59,7 +68,7 @@ void *uiRealloc(void *p, size_t new, const char *type)
|
||||||
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
|
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
|
||||||
*s = new;
|
*s = new;
|
||||||
if (g_ptr_array_remove(allocations, p) == FALSE)
|
if (g_ptr_array_remove(allocations, p) == FALSE)
|
||||||
complain("%p not found in allocations array in uiRealloc()", p);
|
implbug("%p not found in allocations array in uiRealloc()", p);
|
||||||
g_ptr_array_add(allocations, out);
|
g_ptr_array_add(allocations, out);
|
||||||
return DATA(out);
|
return DATA(out);
|
||||||
}
|
}
|
||||||
|
@ -67,9 +76,9 @@ void *uiRealloc(void *p, size_t new, const char *type)
|
||||||
void uiFree(void *p)
|
void uiFree(void *p)
|
||||||
{
|
{
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
complain("attempt to uiFree(NULL); there's a bug somewhere");
|
implbug("attempt to uiFree(NULL); there's a bug somewhere");
|
||||||
p = BASE(p);
|
p = BASE(p);
|
||||||
g_free(p);
|
g_free(p);
|
||||||
if (g_ptr_array_remove(allocations, p) == FALSE)
|
if (g_ptr_array_remove(allocations, p) == FALSE)
|
||||||
complain("%p not found in allocations array in uiFree()", p);
|
implbug("%p not found in allocations array in uiFree()", p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,7 +485,7 @@ uiUnixControlAllDefaults(uiArea)
|
||||||
void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height)
|
void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height)
|
||||||
{
|
{
|
||||||
if (!a->scrolling)
|
if (!a->scrolling)
|
||||||
complain("attempt to call uiAreaSetSize() on a non-scrolling uiArea");
|
userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a);
|
||||||
a->scrollWidth = width;
|
a->scrollWidth = width;
|
||||||
a->scrollHeight = height;
|
a->scrollHeight = height;
|
||||||
gtk_widget_queue_resize(a->areaWidget);
|
gtk_widget_queue_resize(a->areaWidget);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// 13 may 2016
|
||||||
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
|
// TODO don't halt on release builds
|
||||||
|
|
||||||
|
void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
char *a, *b;
|
||||||
|
|
||||||
|
a = g_strdup_printf("[libui] %s:%s:%s() %s", file, line, func, prefix);
|
||||||
|
b = g_strdup_vprintf(format, ap);
|
||||||
|
g_critical("%s%s", a, b);
|
||||||
|
G_BREAKPOINT();
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ static cairo_pattern_t *mkbrush(uiDrawBrush *b)
|
||||||
// case uiDrawBrushTypeImage:
|
// case uiDrawBrushTypeImage:
|
||||||
}
|
}
|
||||||
if (cairo_pattern_status(pat) != CAIRO_STATUS_SUCCESS)
|
if (cairo_pattern_status(pat) != CAIRO_STATUS_SUCCESS)
|
||||||
complain("error creating pattern in mkbrush(): %s",
|
implbug("error creating pattern in mkbrush(): %s",
|
||||||
cairo_status_to_string(cairo_pattern_status(pat)));
|
cairo_status_to_string(cairo_pattern_status(pat)));
|
||||||
switch (b->Type) {
|
switch (b->Type) {
|
||||||
case uiDrawBrushTypeLinearGradient:
|
case uiDrawBrushTypeLinearGradient:
|
||||||
|
|
|
@ -43,7 +43,7 @@ void uiDrawFreePath(uiDrawPath *p)
|
||||||
static void add(uiDrawPath *p, struct piece *piece)
|
static void add(uiDrawPath *p, struct piece *piece)
|
||||||
{
|
{
|
||||||
if (p->ended)
|
if (p->ended)
|
||||||
complain("path ended in add()");
|
userbug("You cannot modify a uiDrawPath that has been ended. (path: %p)", p);
|
||||||
g_array_append_vals(p->pieces, piece, 1);
|
g_array_append_vals(p->pieces, piece, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ void runPath(uiDrawPath *p, cairo_t *cr)
|
||||||
void (*arc)(cairo_t *, double, double, double, double, double);
|
void (*arc)(cairo_t *, double, double, double, double, double);
|
||||||
|
|
||||||
if (!p->ended)
|
if (!p->ended)
|
||||||
complain("path not ended in runPath()");
|
userbug("You cannot draw with a uiDrawPath that has not been ended. (path: %p)", p);
|
||||||
cairo_new_path(cr);
|
cairo_new_path(cr);
|
||||||
for (i = 0; i < p->pieces->len; i++) {
|
for (i = 0; i < p->pieces->len; i++) {
|
||||||
piece = &g_array_index(p->pieces, struct piece, i);
|
piece = &g_array_index(p->pieces, struct piece, i);
|
||||||
|
|
17
unix/menu.c
17
unix/menu.c
|
@ -109,7 +109,7 @@ void uiMenuItemDisable(uiMenuItem *item)
|
||||||
void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data)
|
void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data)
|
||||||
{
|
{
|
||||||
if (item->type == typeQuit)
|
if (item->type == typeQuit)
|
||||||
complain("attempt to call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead");
|
userbug("You cannot call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
|
||||||
item->onClicked = f;
|
item->onClicked = f;
|
||||||
item->onClickedData = data;
|
item->onClickedData = data;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
|
||||||
uiMenuItem *item;
|
uiMenuItem *item;
|
||||||
|
|
||||||
if (menusFinalized)
|
if (menusFinalized)
|
||||||
complain("attempt to create a new menu item after menus have been finalized");
|
userbug("You cannot create a new menu item after menus have been finalized.");
|
||||||
|
|
||||||
item = uiNew(uiMenuItem);
|
item = uiNew(uiMenuItem);
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name)
|
||||||
uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
|
uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
|
||||||
{
|
{
|
||||||
if (hasQuit)
|
if (hasQuit)
|
||||||
complain("attempt to add multiple Quit menu items");
|
userbug("You cannot have multiple Quit menu items in the same program.");
|
||||||
hasQuit = TRUE;
|
hasQuit = TRUE;
|
||||||
newItem(m, typeSeparator, NULL);
|
newItem(m, typeSeparator, NULL);
|
||||||
return newItem(m, typeQuit, NULL);
|
return newItem(m, typeQuit, NULL);
|
||||||
|
@ -205,7 +205,7 @@ uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
|
||||||
uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
|
uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
|
||||||
{
|
{
|
||||||
if (hasPreferences)
|
if (hasPreferences)
|
||||||
complain("attempt to add multiple Preferences menu items");
|
userbug("You cannot have multiple Preferences menu items in the same program.");
|
||||||
hasPreferences = TRUE;
|
hasPreferences = TRUE;
|
||||||
newItem(m, typeSeparator, NULL);
|
newItem(m, typeSeparator, NULL);
|
||||||
return newItem(m, typePreferences, NULL);
|
return newItem(m, typePreferences, NULL);
|
||||||
|
@ -214,7 +214,7 @@ uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
|
||||||
uiMenuItem *uiMenuAppendAboutItem(uiMenu *m)
|
uiMenuItem *uiMenuAppendAboutItem(uiMenu *m)
|
||||||
{
|
{
|
||||||
if (hasAbout)
|
if (hasAbout)
|
||||||
complain("attempt to add multiple About menu items");
|
userbug("You cannot have multiple About menu items in the same program.");
|
||||||
hasAbout = TRUE;
|
hasAbout = TRUE;
|
||||||
newItem(m, typeSeparator, NULL);
|
newItem(m, typeSeparator, NULL);
|
||||||
return newItem(m, typeAbout, NULL);
|
return newItem(m, typeAbout, NULL);
|
||||||
|
@ -230,7 +230,7 @@ uiMenu *uiNewMenu(const char *name)
|
||||||
uiMenu *m;
|
uiMenu *m;
|
||||||
|
|
||||||
if (menusFinalized)
|
if (menusFinalized)
|
||||||
complain("attempt to create a new menu after menus have been finalized");
|
userbug("You cannot create a new menu after menus have been finalized.");
|
||||||
if (menus == NULL)
|
if (menus == NULL)
|
||||||
menus = g_array_new(FALSE, TRUE, sizeof (uiMenu *));
|
menus = g_array_new(FALSE, TRUE, sizeof (uiMenu *));
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ static void freeMenuItem(GtkWidget *widget, gpointer data)
|
||||||
item = g_array_index(fmi->items, uiMenuItem *, fmi->i);
|
item = g_array_index(fmi->items, uiMenuItem *, fmi->i);
|
||||||
w = (struct menuItemWindow *) g_hash_table_lookup(item->windows, widget);
|
w = (struct menuItemWindow *) g_hash_table_lookup(item->windows, widget);
|
||||||
if (g_hash_table_remove(item->windows, widget) == FALSE)
|
if (g_hash_table_remove(item->windows, widget) == FALSE)
|
||||||
complain("GtkMenuItem %p not in menu item's item/window map", widget);
|
implbug("GtkMenuItem %p not in menu item's item/window map", widget);
|
||||||
uiFree(w);
|
uiFree(w);
|
||||||
fmi->i++;
|
fmi->i++;
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,8 @@ void uninitMenus(void)
|
||||||
for (j = 0; j < m->items->len; j++) {
|
for (j = 0; j < m->items->len; j++) {
|
||||||
item = g_array_index(m->items, uiMenuItem *, j);
|
item = g_array_index(m->items, uiMenuItem *, j);
|
||||||
if (g_hash_table_size(item->windows) != 0)
|
if (g_hash_table_size(item->windows) != 0)
|
||||||
complain("menu item %p (%s) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
|
// TODO is this really a userbug()?
|
||||||
|
implbug("menu item %p (%s) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
|
||||||
g_free(item->name);
|
g_free(item->name);
|
||||||
g_hash_table_destroy(item->windows);
|
g_hash_table_destroy(item->windows);
|
||||||
uiFree(item);
|
uiFree(item);
|
||||||
|
|
|
@ -12,7 +12,7 @@ uiUnixControlAllDefaults(uiProgressBar)
|
||||||
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
||||||
{
|
{
|
||||||
if (value < 0 || value > 100)
|
if (value < 0 || value > 100)
|
||||||
complain("value %d out of range in progressbarSetValue()", value);
|
userbug("Value %d is out of range for a uiProgressBar.", value);
|
||||||
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
|
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,9 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
|
||||||
{
|
{
|
||||||
uiSpinbox *s;
|
uiSpinbox *s;
|
||||||
|
|
||||||
|
// TODO just swap?
|
||||||
if (min >= max)
|
if (min >= max)
|
||||||
complain("error: min >= max in uiNewSpinbox()");
|
userbug("min >= max not allowed in uiNewSpinbox().");
|
||||||
|
|
||||||
uiUnixNewControl(uiSpinbox, s);
|
uiUnixNewControl(uiSpinbox, s);
|
||||||
|
|
||||||
|
|
11
unix/util.c
11
unix/util.c
|
@ -1,17 +1,6 @@
|
||||||
// 18 april 2015
|
// 18 april 2015
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
void complain(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char *msg;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
msg = g_strdup_vprintf(fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
g_error("[libui] %s\n", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMargined(GtkContainer *c, int margined)
|
void setMargined(GtkContainer *c, int margined)
|
||||||
{
|
{
|
||||||
if (margined)
|
if (margined)
|
||||||
|
|
Loading…
Reference in New Issue