uiAlloc() et al -> uiprivAlloc() et al, GTK+ code.

This commit is contained in:
Pietro Gagliardi 2018-04-15 16:36:03 -04:00
parent 8ca32f098f
commit 099c4ff631
8 changed files with 29 additions and 29 deletions

View File

@ -43,7 +43,7 @@ void uninitAlloc(void)
g_free(str); g_free(str);
} }
void *uiAlloc(size_t size, const char *type) void *uiprivAlloc(size_t size, const char *type)
{ {
void *out; void *out;
@ -54,13 +54,13 @@ void *uiAlloc(size_t size, const char *type)
return DATA(out); return DATA(out);
} }
void *uiRealloc(void *p, size_t new, const char *type) void *uiprivRealloc(void *p, size_t new, const char *type)
{ {
void *out; void *out;
size_t *s; size_t *s;
if (p == NULL) if (p == NULL)
return uiAlloc(new, type); return uiprivAlloc(new, type);
p = BASE(p); p = BASE(p);
out = g_realloc(p, EXTRA + new); out = g_realloc(p, EXTRA + new);
s = SIZE(out); s = SIZE(out);
@ -68,17 +68,17 @@ 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)
implbug("%p not found in allocations array in uiRealloc()", p); implbug("%p not found in allocations array in uiprivRealloc()", p);
g_ptr_array_add(allocations, out); g_ptr_array_add(allocations, out);
return DATA(out); return DATA(out);
} }
void uiFree(void *p) void uiprivFree(void *p)
{ {
if (p == NULL) if (p == NULL)
implbug("attempt to uiFree(NULL)"); implbug("attempt to uiprivFree(NULL)");
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)
implbug("%p not found in allocations array in uiFree()", p); implbug("%p not found in allocations array in uiprivFree()", p);
} }

View File

@ -33,7 +33,7 @@ struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parent
if (child == NULL) if (child == NULL)
return NULL; return NULL;
c = uiNew(struct child); c = uiprivNew(struct child);
c->c = child; c->c = child;
c->widget = GTK_WIDGET(uiControlHandle(c->c)); c->widget = GTK_WIDGET(uiControlHandle(c->c));
@ -82,7 +82,7 @@ void childRemove(struct child *c)
if (c->box != NULL) if (c->box != NULL)
gtk_widget_destroy(c->box); gtk_widget_destroy(c->box);
uiFree(c); uiprivFree(c);
} }
void childDestroy(struct child *c) void childDestroy(struct child *c)

View File

@ -6,7 +6,7 @@ uiDrawContext *newContext(cairo_t *cr, GtkStyleContext *style)
{ {
uiDrawContext *c; uiDrawContext *c;
c = uiNew(uiDrawContext); c = uiprivNew(uiDrawContext);
c->cr = cr; c->cr = cr;
c->style = style; c->style = style;
return c; return c;
@ -15,7 +15,7 @@ uiDrawContext *newContext(cairo_t *cr, GtkStyleContext *style)
void freeContext(uiDrawContext *c) void freeContext(uiDrawContext *c)
{ {
// free neither cr nor style; we own neither // free neither cr nor style; we own neither
uiFree(c); uiprivFree(c);
} }
static cairo_pattern_t *mkbrush(uiDrawBrush *b) static cairo_pattern_t *mkbrush(uiDrawBrush *b)

View File

@ -28,7 +28,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
{ {
uiDrawPath *p; uiDrawPath *p;
p = uiNew(uiDrawPath); p = uiprivNew(uiDrawPath);
p->pieces = g_array_new(FALSE, TRUE, sizeof (struct piece)); p->pieces = g_array_new(FALSE, TRUE, sizeof (struct piece));
p->fillMode = mode; p->fillMode = mode;
return p; return p;
@ -37,7 +37,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
void uiDrawFreePath(uiDrawPath *p) void uiDrawFreePath(uiDrawPath *p)
{ {
g_array_free(p->pieces, TRUE); g_array_free(p->pieces, TRUE);
uiFree(p); uiprivFree(p);
} }
static void add(uiDrawPath *p, struct piece *piece) static void add(uiDrawPath *p, struct piece *piece)

View File

@ -16,11 +16,11 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
size_t i; size_t i;
size_t *op; size_t *op;
g = uiNew(struct graphemes); g = uiprivNew(struct graphemes);
// TODO see if we can use the utf routines // TODO see if we can use the utf routines
lenchars = g_utf8_strlen(text, -1); lenchars = g_utf8_strlen(text, -1);
logattrs = (PangoLogAttr *) uiAlloc((lenchars + 1) * sizeof (PangoLogAttr), "PangoLogAttr[] (graphemes)"); logattrs = (PangoLogAttr *) uiprivAlloc((lenchars + 1) * sizeof (PangoLogAttr), "PangoLogAttr[] (graphemes)");
pango_get_log_attrs(text, len, pango_get_log_attrs(text, len,
-1, NULL, -1, NULL,
logattrs, lenchars + 1); logattrs, lenchars + 1);
@ -31,8 +31,8 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
if (logattrs[i].is_cursor_position != 0) if (logattrs[i].is_cursor_position != 0)
g->len++; g->len++;
g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)"); g->pointsToGraphemes = (size_t *) uiprivAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)"); g->graphemesToPoints = (size_t *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
// compute the graphemesToPoints array // compute the graphemesToPoints array
// TODO merge with the next for loop somehow? // TODO merge with the next for loop somehow?
@ -58,6 +58,6 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
// and do the last one // and do the last one
*op++ = i; *op++ = i;
uiFree(logattrs); uiprivFree(logattrs);
return g; return g;
} }

View File

@ -14,14 +14,14 @@ static void freeImageRep(gpointer item)
buf = cairo_image_surface_get_data(cs); buf = cairo_image_surface_get_data(cs);
cairo_surface_destroy(cs); cairo_surface_destroy(cs);
uiFree(buf); uiprivFree(buf);
} }
uiImage *uiNewImage(double width, double height) uiImage *uiNewImage(double width, double height)
{ {
uiImage *i; uiImage *i;
i = uiNew(uiImage); i = uiprivNew(uiImage);
i->width = width; i->width = width;
i->height = height; i->height = height;
i->images = g_ptr_array_new_with_free_func(freeImageRep); i->images = g_ptr_array_new_with_free_func(freeImageRep);
@ -31,7 +31,7 @@ uiImage *uiNewImage(double width, double height)
void uiFreeImage(uiImage *i) void uiFreeImage(uiImage *i)
{ {
g_ptr_array_free(i->images, TRUE); g_ptr_array_free(i->images, TRUE);
uiFree(i); uiprivFree(i);
} }
void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride) void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride)
@ -43,7 +43,7 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in
int y; int y;
cstride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, pixelWidth); cstride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, pixelWidth);
buf = (unsigned char *) uiAlloc((cstride * pixelHeight * 4) * sizeof (unsigned char), "unsigned char[]"); buf = (unsigned char *) uiprivAlloc((cstride * pixelHeight * 4) * sizeof (unsigned char), "unsigned char[]");
p = buf; p = buf;
for (y = 0; y < pixelStride * pixelHeight; y += pixelStride) { for (y = 0; y < pixelStride * pixelHeight; y += pixelStride) {
memmove(p, src + y, cstride); memmove(p, src + y, cstride);

View File

@ -99,7 +99,7 @@ void uiQueueMain(void (*f)(void *data), void *data)
{ {
struct queued *q; struct queued *q;
// we have to use g_new0()/g_free() because uiAlloc() is only safe to call on the main thread // we have to use g_new0()/g_free() because uiprivAlloc() is only safe to call on the main thread
// for some reason it didn't affect me, but it did affect krakjoe // for some reason it didn't affect me, but it did affect krakjoe
q = g_new0(struct queued, 1); q = g_new0(struct queued, 1);
q->f = f; q->f = f;

View File

@ -137,7 +137,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
if (menusFinalized) if (menusFinalized)
userbug("You cannot 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 = uiprivNew(uiMenuItem);
g_array_append_val(m->items, item); g_array_append_val(m->items, item);
@ -234,7 +234,7 @@ uiMenu *uiNewMenu(const char *name)
if (menus == NULL) if (menus == NULL)
menus = g_array_new(FALSE, TRUE, sizeof (uiMenu *)); menus = g_array_new(FALSE, TRUE, sizeof (uiMenu *));
m = uiNew(uiMenu); m = uiprivNew(uiMenu);
g_array_append_val(menus, m); g_array_append_val(menus, m);
@ -260,7 +260,7 @@ static void appendMenuItem(GtkMenuShell *submenu, uiMenuItem *item, uiWindow *w)
singleSetChecked(GTK_CHECK_MENU_ITEM(menuitem), item->checked, signal); singleSetChecked(GTK_CHECK_MENU_ITEM(menuitem), item->checked, signal);
} }
gtk_menu_shell_append(submenu, menuitem); gtk_menu_shell_append(submenu, menuitem);
ww = uiNew(struct menuItemWindow); ww = uiprivNew(struct menuItemWindow);
ww->w = w; ww->w = w;
ww->signal = signal; ww->signal = signal;
g_hash_table_insert(item->windows, menuitem, ww); g_hash_table_insert(item->windows, menuitem, ww);
@ -309,7 +309,7 @@ static void freeMenuItem(GtkWidget *widget, gpointer data)
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)
implbug("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); uiprivFree(w);
fmi->i++; fmi->i++;
} }
@ -357,10 +357,10 @@ void uninitMenus(void)
implbug("menu item %p (%s) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); 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); uiprivFree(item);
} }
g_array_free(m->items, TRUE); g_array_free(m->items, TRUE);
uiFree(m); uiprivFree(m);
} }
g_array_free(menus, TRUE); g_array_free(menus, TRUE);
} }