Got rid of complain() on GTK+.

This commit is contained in:
Pietro Gagliardi 2016-05-13 21:00:12 -04:00
parent 59eebb1e48
commit 0205f2e5ca
15 changed files with 55 additions and 36 deletions

View File

@ -37,6 +37,9 @@ ifeq ($(TOOLCHAIN),gcc)
else
LDFLAGS += -Wl,-rpath,'$$ORIGIN'
endif
ifneq ($(findstring cpp-,$(EXAMPLE)),)
LDFLAGS += -pthread
endif
else
# TODO is there an equivalent to -L?
LDFLAGS += $(OUTDIR)/libui.lib

View File

@ -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, ...);
#define implbug(...) _implbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__)
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
extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr);

View File

@ -43,6 +43,7 @@ void uninitAlloc(void)
[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]);
[str release];
}
void *uiAlloc(size_t size, const char *type)

View File

@ -335,7 +335,7 @@ int sendAreaEvents(NSEvent *e)
void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height)
{
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)];
}
@ -347,7 +347,7 @@ void uiAreaQueueRedrawAll(uiArea *a)
void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height)
{
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)];
// don't worry about the return value; it just says whether scrolling was needed
}

View File

@ -9,7 +9,7 @@ void realbug(const char *file, const char *line, const char *func, const char *p
NSString *formatted;
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];
[str appendString:formatted];
[formatted release];

View File

@ -10,6 +10,7 @@ CFILES += \
unix/combobox.c \
unix/control.c \
unix/datetimepicker.c \
unix/debug.c \
unix/draw.c \
unix/drawmatrix.c \
unix/drawpath.c \

View File

@ -20,18 +20,27 @@ void initAlloc(void)
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)
{
char *str = NULL;
if (allocations->len == 0) {
g_ptr_array_free(allocations, TRUE);
return;
}
fprintf(stderr, "[libui] leaked allocations:\n");
g_ptr_array_foreach(allocations, uninitComplain, NULL);
complain("either you left something around or there's a bug in libui");
g_ptr_array_foreach(allocations, uninitComplain, &str);
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);
g_free(str);
}
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);
*s = new;
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);
return DATA(out);
}
@ -67,9 +76,9 @@ void *uiRealloc(void *p, size_t new, const char *type)
void uiFree(void *p)
{
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);
g_free(p);
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);
}

View File

@ -485,7 +485,7 @@ uiUnixControlAllDefaults(uiArea)
void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height)
{
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->scrollHeight = height;
gtk_widget_queue_resize(a->areaWidget);

14
unix/debug.c Normal file
View File

@ -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();
}

View File

@ -37,7 +37,7 @@ static cairo_pattern_t *mkbrush(uiDrawBrush *b)
// case uiDrawBrushTypeImage:
}
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)));
switch (b->Type) {
case uiDrawBrushTypeLinearGradient:

View File

@ -43,7 +43,7 @@ void uiDrawFreePath(uiDrawPath *p)
static void add(uiDrawPath *p, struct piece *piece)
{
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);
}
@ -145,7 +145,7 @@ void runPath(uiDrawPath *p, cairo_t *cr)
void (*arc)(cairo_t *, double, double, double, double, double);
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);
for (i = 0; i < p->pieces->len; i++) {
piece = &g_array_index(p->pieces, struct piece, i);

View File

@ -109,7 +109,7 @@ void uiMenuItemDisable(uiMenuItem *item)
void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data)
{
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->onClickedData = data;
}
@ -135,7 +135,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
uiMenuItem *item;
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);
@ -196,7 +196,7 @@ uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name)
uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
{
if (hasQuit)
complain("attempt to add multiple Quit menu items");
userbug("You cannot have multiple Quit menu items in the same program.");
hasQuit = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeQuit, NULL);
@ -205,7 +205,7 @@ uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
{
if (hasPreferences)
complain("attempt to add multiple Preferences menu items");
userbug("You cannot have multiple Preferences menu items in the same program.");
hasPreferences = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typePreferences, NULL);
@ -214,7 +214,7 @@ uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
uiMenuItem *uiMenuAppendAboutItem(uiMenu *m)
{
if (hasAbout)
complain("attempt to add multiple About menu items");
userbug("You cannot have multiple About menu items in the same program.");
hasAbout = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeAbout, NULL);
@ -230,7 +230,7 @@ uiMenu *uiNewMenu(const char *name)
uiMenu *m;
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)
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);
w = (struct menuItemWindow *) g_hash_table_lookup(item->windows, widget);
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);
fmi->i++;
}
@ -353,7 +353,8 @@ void uninitMenus(void)
for (j = 0; j < m->items->len; j++) {
item = g_array_index(m->items, uiMenuItem *, j);
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_hash_table_destroy(item->windows);
uiFree(item);

View File

@ -12,7 +12,7 @@ uiUnixControlAllDefaults(uiProgressBar)
void uiProgressBarSetValue(uiProgressBar *p, int value)
{
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);
}

View File

@ -49,8 +49,9 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
{
uiSpinbox *s;
// TODO just swap?
if (min >= max)
complain("error: min >= max in uiNewSpinbox()");
userbug("min >= max not allowed in uiNewSpinbox().");
uiUnixNewControl(uiSpinbox, s);

View File

@ -1,17 +1,6 @@
// 18 april 2015
#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)
{
if (margined)