From e0f800d5eb016c4c1a128b081a2eef092ce50a07 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 15:39:28 -0400 Subject: [PATCH 01/21] Started cleaning up the common/ folder. Backed up the current uipriv.h. --- common/OLD_uipriv.h | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 common/OLD_uipriv.h diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h new file mode 100644 index 00000000..02676a16 --- /dev/null +++ b/common/OLD_uipriv.h @@ -0,0 +1,66 @@ +// 6 april 2015 + +// this must go outside other extern "C" blocks, otherwise we'll get double-declaration errors +#include "utf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include "controlsigs.h" + +extern uiInitOptions options; + +extern void *uiAlloc(size_t, const char *); +#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T)) +extern void *uiRealloc(void *, size_t, const char *); +extern void uiFree(void *); + +// ugh, this was only introduced in MSVC 2015... +#ifdef _MSC_VER +#define __func__ __FUNCTION__ +#endif +extern void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap); +#define _ns2(s) #s +#define _ns(s) _ns2(s) +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(...) _userbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__) + +// control.c +extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); + +// shouldquit.c +extern int shouldQuit(void); + +// areaevents.c +typedef struct clickCounter clickCounter; +// you should call Reset() to zero-initialize a new instance +// it doesn't matter that all the non-count fields are zero: the first click will fail the curButton test straightaway, so it'll return 1 and set the rest of the structure accordingly +struct clickCounter { + int curButton; + int rectX0; + int rectY0; + int rectX1; + int rectY1; + uintptr_t prevTime; + int count; +}; +int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist); +extern void clickCounterReset(clickCounter *); +extern int fromScancode(uintptr_t, uiAreaKeyEvent *); + +// matrix.c +extern void fallbackSkew(uiDrawMatrix *, double, double, double, double); +extern void scaleCenter(double, double, double *, double *); +extern void fallbackTransformSize(uiDrawMatrix *, double *, double *); + +// OS-specific text.* files +extern int uiprivStricmp(const char *a, const char *b); + +#ifdef __cplusplus +} +#endif From 4a57b15d09179baf3192467c1b50bdf42f68b3ed Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 15:49:45 -0400 Subject: [PATCH 02/21] Renamed the common options variable to uiprivOptions. --- common/OLD_uipriv.h | 18 ------------------ common/uipriv.h | 11 ++++------- darwin/main.m | 4 ++-- unix/main.c | 4 ++-- windows/init.cpp | 6 +++--- 5 files changed, 11 insertions(+), 32 deletions(-) diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h index 02676a16..453871d7 100644 --- a/common/OLD_uipriv.h +++ b/common/OLD_uipriv.h @@ -1,17 +1,3 @@ -// 6 april 2015 - -// this must go outside other extern "C" blocks, otherwise we'll get double-declaration errors -#include "utf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include "controlsigs.h" - -extern uiInitOptions options; extern void *uiAlloc(size_t, const char *); #define uiNew(T) ((T *) uiAlloc(sizeof (T), #T)) @@ -60,7 +46,3 @@ extern void fallbackTransformSize(uiDrawMatrix *, double *, double *); // OS-specific text.* files extern int uiprivStricmp(const char *a, const char *b); - -#ifdef __cplusplus -} -#endif diff --git a/common/uipriv.h b/common/uipriv.h index 02676a16..5f0f287d 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -1,17 +1,14 @@ // 6 april 2015 - -// this must go outside other extern "C" blocks, otherwise we'll get double-declaration errors +#include +#include +#include "controlsigs.h" #include "utf.h" #ifdef __cplusplus extern "C" { #endif -#include -#include -#include "controlsigs.h" - -extern uiInitOptions options; +extern uiInitOptions uiprivOptions; extern void *uiAlloc(size_t, const char *); #define uiNew(T) ((T *) uiAlloc(sizeof (T), #T)) diff --git a/darwin/main.m b/darwin/main.m index 865fb942..1bc6bfc3 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -106,12 +106,12 @@ static BOOL stepsIsRunning; @end -uiInitOptions options; +uiInitOptions uiprivOptions; const char *uiInit(uiInitOptions *o) { @autoreleasepool { - options = *o; + uiprivOptions = *o; app = [[applicationClass sharedApplication] retain]; // don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy! // see https://github.com/andlabs/ui/issues/6 diff --git a/unix/main.c b/unix/main.c index 2998bf31..1d7e7a76 100644 --- a/unix/main.c +++ b/unix/main.c @@ -1,14 +1,14 @@ // 6 april 2015 #include "uipriv_unix.h" -uiInitOptions options; +uiInitOptions uiprivOptions; const char *uiInit(uiInitOptions *o) { GError *err = NULL; const char *msg; - options = *o; + uiprivOptions = *o; if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) { msg = g_strdup(err->message); g_error_free(err); diff --git a/windows/init.cpp b/windows/init.cpp index cfe63b9a..2c25d3d4 100644 --- a/windows/init.cpp +++ b/windows/init.cpp @@ -39,8 +39,8 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value) #define ieLastErr(msg) initerr("=" msg, L"GetLastError() ==", GetLastError()) #define ieHRESULT(msg, hr) initerr("=" msg, L"HRESULT", (DWORD) hr) -// LONGTERM make common -uiInitOptions options; +// LONGTERM put this declaration in a common file +uiInitOptions uiprivOptions; #define wantedICCClasses ( \ ICC_STANDARD_CLASSES | /* user32.dll controls */ \ @@ -62,7 +62,7 @@ const char *uiInit(uiInitOptions *o) INITCOMMONCONTROLSEX icc; HRESULT hr; - options = *o; + uiprivOptions = *o; initAlloc(); From 72e8b9a1983801fb7ab65de35011de85ecd734ca Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 15:53:27 -0400 Subject: [PATCH 03/21] Started FINALLY renaming uiAlloc(), uiNew(), uiRealloc(), and uiFree() into uipriv* forms. This handles the common folder. --- common/OLD_uipriv.h | 5 ----- common/attribute.c | 2 +- common/attrstr.h | 6 ------ common/control.c | 4 ++-- common/uipriv.h | 8 ++++---- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h index 453871d7..64d82ad1 100644 --- a/common/OLD_uipriv.h +++ b/common/OLD_uipriv.h @@ -1,9 +1,4 @@ -extern void *uiAlloc(size_t, const char *); -#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T)) -extern void *uiRealloc(void *, size_t, const char *); -extern void uiFree(void *); - // ugh, this was only introduced in MSVC 2015... #ifdef _MSC_VER #define __func__ __FUNCTION__ diff --git a/common/attribute.c b/common/attribute.c index 5054d1c1..4a8f0160 100644 --- a/common/attribute.c +++ b/common/attribute.c @@ -85,7 +85,7 @@ uiAttribute *uiNewFamilyAttribute(const char *family) uiAttribute *a; a = newAttribute(uiAttributeTypeFamily); - a->u.family = (char *) uiAlloc((strlen(family) + 1) * sizeof (char), "char[] (uiAttribute)"); + a->u.family = (char *) uiprivAlloc((strlen(family) + 1) * sizeof (char), "char[] (uiAttribute)"); strcpy(a->u.family, family); return a; } diff --git a/common/attrstr.h b/common/attrstr.h index 2f4e42b4..54e43feb 100644 --- a/common/attrstr.h +++ b/common/attrstr.h @@ -1,11 +1,5 @@ // 19 february 2018 -// TODO remove when done migrating these functions -#define uiprivNew(x) uiNew(x) -#define uiprivAlloc(x, y) uiAlloc(x, y) -#define uiprivRealloc(x, y, z) uiRealloc(x, y, z) -#define uiprivFree(x) uiFree(x) - // attribute.c extern uiAttribute *uiprivAttributeRetain(uiAttribute *a); extern void uiprivAttributeRelease(uiAttribute *a); diff --git a/common/control.c b/common/control.c index 28066461..e46e322c 100644 --- a/common/control.c +++ b/common/control.c @@ -63,7 +63,7 @@ uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const c { uiControl *c; - c = (uiControl *) uiAlloc(size, typenamestr); + c = (uiControl *) uiprivAlloc(size, typenamestr); c->Signature = uiControlSignature; c->OSSignature = OSsig; c->TypeSignature = typesig; @@ -74,7 +74,7 @@ void uiFreeControl(uiControl *c) { if (uiControlParent(c) != NULL) userbug("You cannot destroy a uiControl while it still has a parent. (control: %p)", c); - uiFree(c); + uiprivFree(c); } void uiControlVerifySetParent(uiControl *c, uiControl *parent) diff --git a/common/uipriv.h b/common/uipriv.h index 5f0f287d..69062c87 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -10,10 +10,10 @@ extern "C" { extern uiInitOptions uiprivOptions; -extern void *uiAlloc(size_t, const char *); -#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T)) -extern void *uiRealloc(void *, size_t, const char *); -extern void uiFree(void *); +extern void *uiprivAlloc(size_t, const char *); +#define uiprivNew(T) ((T *) uiprivAlloc(sizeof (T), #T)) +extern void *uiprivRealloc(void *, size_t, const char *); +extern void uiprivFree(void *); // ugh, this was only introduced in MSVC 2015... #ifdef _MSC_VER From 8ca32f098fffd17e3209bb6cfb239432fcd6238e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 16:05:24 -0400 Subject: [PATCH 04/21] uiAlloc() et al -> uiprivAlloc() et al, OS X code. --- darwin/alloc.m | 12 ++++++------ darwin/draw.m | 20 ++++++++++---------- darwin/fontmatch.m | 4 ++-- darwin/fontvariation.m | 4 ++-- darwin/grid.m | 32 ++++++++++++++++---------------- darwin/image.m | 10 +++++----- darwin/map.m | 4 ++-- darwin/menu.m | 8 ++++---- darwin/scrollview.m | 4 ++-- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/darwin/alloc.m b/darwin/alloc.m index 0bbb8996..0012c853 100644 --- a/darwin/alloc.m +++ b/darwin/alloc.m @@ -41,7 +41,7 @@ void uninitAlloc(void) [str release]; } -void *uiAlloc(size_t size, const char *type) +void *uiprivAlloc(size_t size, const char *type) { void *out; @@ -57,17 +57,17 @@ void *uiAlloc(size_t size, const char *type) 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; size_t *s; if (p == NULL) - return uiAlloc(new, type); + return uiprivAlloc(new, type); p = BASE(p); out = realloc(p, EXTRA + new); if (out == NULL) { - fprintf(stderr, "memory exhausted in uiRealloc()\n"); + fprintf(stderr, "memory exhausted in uiprivRealloc()\n"); abort(); } s = SIZE(out); @@ -79,10 +79,10 @@ void *uiRealloc(void *p, size_t new, const char *type) return DATA(out); } -void uiFree(void *p) +void uiprivFree(void *p) { if (p == NULL) - implbug("attempt to uiFree(NULL)"); + implbug("attempt to uiprivFree(NULL)"); p = BASE(p); free(p); [allocations removeObject:[NSValue valueWithPointer:p]]; diff --git a/darwin/draw.m b/darwin/draw.m index b4be6e7f..b52b5a57 100644 --- a/darwin/draw.m +++ b/darwin/draw.m @@ -12,7 +12,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode) { uiDrawPath *p; - p = uiNew(uiDrawPath); + p = uiprivNew(uiDrawPath); p->path = CGPathCreateMutable(); p->fillMode = mode; return p; @@ -21,7 +21,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode) void uiDrawFreePath(uiDrawPath *p) { CGPathRelease((CGPathRef) (p->path)); - uiFree(p); + uiprivFree(p); } void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) @@ -108,7 +108,7 @@ uiDrawContext *newContext(CGContextRef ctxt, CGFloat height) { uiDrawContext *c; - c = uiNew(uiDrawContext); + c = uiprivNew(uiDrawContext); c->c = ctxt; c->height = height; return c; @@ -116,7 +116,7 @@ uiDrawContext *newContext(CGContextRef ctxt, CGFloat height) void freeContext(uiDrawContext *c) { - uiFree(c); + uiprivFree(c); } // a stroke is identical to a fill of a stroked path @@ -160,7 +160,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro // create a temporary path identical to the previous one dashPath = (CGPathRef) path->path; if (p->NumDashes != 0) { - dashes = (CGFloat *) uiAlloc(p->NumDashes * sizeof (CGFloat), "CGFloat[]"); + dashes = (CGFloat *) uiprivAlloc(p->NumDashes * sizeof (CGFloat), "CGFloat[]"); for (i = 0; i < p->NumDashes; i++) dashes[i] = p->Dashes[i]; dashPath = CGPathCreateCopyByDashingPath(path->path, @@ -168,7 +168,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro p->DashPhase, dashes, p->NumDashes); - uiFree(dashes); + uiprivFree(dashes); } // the documentation is wrong: this produces a path suitable for calling CGPathCreateCopyByStrokingPath(), not for filling directly // the cast is safe; we never modify the CGPathRef and always cast it back to a CGPathRef anyway @@ -224,8 +224,8 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b) // TODO add NULL check to other uses of CGColorSpace // make the gradient - colors = uiAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]"); - locations = uiAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]"); + colors = uiprivAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]"); + locations = uiprivAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]"); for (i = 0; i < b->NumStops; i++) { colors[i * 4 + 0] = b->Stops[i].R; colors[i * 4 + 1] = b->Stops[i].G; @@ -234,8 +234,8 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b) locations[i] = b->Stops[i].Pos; } gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, b->NumStops); - uiFree(locations); - uiFree(colors); + uiprivFree(locations); + uiprivFree(colors); // because we're mucking with clipping, we need to save the graphics state and restore it later CGContextSaveGState(ctxt); diff --git a/darwin/fontmatch.m b/darwin/fontmatch.m index ea075e53..2c240b95 100644 --- a/darwin/fontmatch.m +++ b/darwin/fontmatch.m @@ -365,7 +365,7 @@ static CTFontDescriptorRef matchStyle(CTFontDescriptorRef against, uiFontDescrip if ([d variation] != NULL) axisDict = uiprivMakeVariationAxisDict([d variationAxes], [d table:kCTFontTableAvar]); - closeness = (struct closeness *) uiAlloc(n * sizeof (struct closeness), "struct closeness[]"); + closeness = (struct closeness *) uiprivAlloc(n * sizeof (struct closeness), "struct closeness[]"); for (i = 0; i < n; i++) { uiFontDescriptor fields; @@ -409,7 +409,7 @@ static CTFontDescriptorRef matchStyle(CTFontDescriptorRef against, uiFontDescrip // release everything if (axisDict != nil) [axisDict release]; - uiFree(closeness); + uiprivFree(closeness); CFRelease(matching); // and release the original descriptor since we no longer need it CFRelease(against); diff --git a/darwin/fontvariation.m b/darwin/fontvariation.m index b5a3591a..6dfb3ab1 100644 --- a/darwin/fontvariation.m +++ b/darwin/fontvariation.m @@ -187,7 +187,7 @@ static fixed1616 *avarExtract(CFDataRef table, CFIndex index, size_t *n) } nEntries = nextuint16be(); *n = nEntries * 2; - entries = (fixed1616 *) uiAlloc(*n * sizeof (fixed1616), "fixed1616[]"); + entries = (fixed1616 *) uiprivAlloc(*n * sizeof (fixed1616), "fixed1616[]"); p = entries; for (i = 0; i < *n; i++) { *p++ = fixed214ToFixed1616((fixed214) nextuint16be()); @@ -247,7 +247,7 @@ fail: - (void)dealloc { if (self->avarMappings != NULL) { - uiFree(self->avarMappings); + uiprivFree(self->avarMappings); self->avarMappings = NULL; } [super dealloc]; diff --git a/darwin/grid.m b/darwin/grid.m index d5c5fb1e..fc98cc9f 100644 --- a/darwin/grid.m +++ b/darwin/grid.m @@ -288,11 +288,11 @@ struct uiGrid { // now build a topological map of the grid gg[y][x] // also figure out which cells contain spanned views so they can be ignored later // treat hidden controls by keeping the indices -1 - gg = (int **) uiAlloc(ycount * sizeof (int *), "int[][]"); - gspan = (BOOL **) uiAlloc(ycount * sizeof (BOOL *), "BOOL[][]"); + gg = (int **) uiprivAlloc(ycount * sizeof (int *), "int[][]"); + gspan = (BOOL **) uiprivAlloc(ycount * sizeof (BOOL *), "BOOL[][]"); for (y = 0; y < ycount; y++) { - gg[y] = (int *) uiAlloc(xcount * sizeof (int), "int[]"); - gspan[y] = (BOOL *) uiAlloc(xcount * sizeof (BOOL), "BOOL[]"); + gg[y] = (int *) uiprivAlloc(xcount * sizeof (int), "int[]"); + gspan[y] = (BOOL *) uiprivAlloc(xcount * sizeof (BOOL), "BOOL[]"); for (x = 0; x < xcount; x++) gg[y][x] = -1; // empty } @@ -344,9 +344,9 @@ struct uiGrid { // now build a topological map of the grid's views gv[y][x] // for any empty cell, create a dummy view - gv = (NSView ***) uiAlloc(ycount * sizeof (NSView **), "NSView *[][]"); + gv = (NSView ***) uiprivAlloc(ycount * sizeof (NSView **), "NSView *[][]"); for (y = 0; y < ycount; y++) { - gv[y] = (NSView **) uiAlloc(xcount * sizeof (NSView *), "NSView *[]"); + gv[y] = (NSView **) uiprivAlloc(xcount * sizeof (NSView *), "NSView *[]"); for (x = 0; x < xcount; x++) if (gg[y][x] == -1) { gv[y][x] = [[NSView alloc] initWithFrame:NSZeroRect]; @@ -360,8 +360,8 @@ struct uiGrid { } // now figure out which rows and columns really expand - hexpand = (BOOL *) uiAlloc(xcount * sizeof (BOOL), "BOOL[]"); - vexpand = (BOOL *) uiAlloc(ycount * sizeof (BOOL), "BOOL[]"); + hexpand = (BOOL *) uiprivAlloc(xcount * sizeof (BOOL), "BOOL[]"); + vexpand = (BOOL *) uiprivAlloc(ycount * sizeof (BOOL), "BOOL[]"); // first, which don't span for (gc in self->children) { if (!uiControlVisible(gc.c)) @@ -522,16 +522,16 @@ struct uiGrid { // TODO make all expanding rows/columns the same height/width // and finally clean up - uiFree(hexpand); - uiFree(vexpand); + uiprivFree(hexpand); + uiprivFree(vexpand); for (y = 0; y < ycount; y++) { - uiFree(gg[y]); - uiFree(gv[y]); - uiFree(gspan[y]); + uiprivFree(gg[y]); + uiprivFree(gv[y]); + uiprivFree(gspan[y]); } - uiFree(gg); - uiFree(gv); - uiFree(gspan); + uiprivFree(gg); + uiprivFree(gv); + uiprivFree(gspan); } - (void)append:(gridChild *)gc diff --git a/darwin/image.m b/darwin/image.m index b62de31d..aa1b945b 100644 --- a/darwin/image.m +++ b/darwin/image.m @@ -11,23 +11,23 @@ uiImage *uiNewImage(double width, double height) { uiImage *i; - i = uiNew(uiImage); + i = uiprivNew(uiImage); i->size = NSMakeSize(width, height); i->i = [[NSImage alloc] initWithSize:i->size]; i->swizzled = [NSMutableArray new]; return i; } -void uiFreeImage(uiImage *i) +void Image(uiImage *i) { NSValue *v; [i->i release]; // to be safe, do this after releasing the image for (v in i->swizzled) - uiFree([v pointerValue]); + uiprivFree([v pointerValue]); [i->swizzled release]; - uiFree(i); + uiprivFree(i); } void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride) @@ -40,7 +40,7 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in // OS X demands that R and B are in the opposite order from what we expect // we must swizzle :( // LONGTERM test on a big-endian system - swizzled = (uint8_t *) uiAlloc((pixelStride * pixelHeight * 4) * sizeof (uint8_t), "uint8_t[]"); + swizzled = (uint8_t *) uiprivAlloc((pixelStride * pixelHeight * 4) * sizeof (uint8_t), "uint8_t[]"); bp = (uint8_t *) pixels; sp = swizzled; for (y = 0; y < pixelHeight * pixelStride; y += pixelStride) diff --git a/darwin/map.m b/darwin/map.m index 46a7b8d2..4eaa057d 100644 --- a/darwin/map.m +++ b/darwin/map.m @@ -12,7 +12,7 @@ struct mapTable *newMap(void) { struct mapTable *m; - m = uiNew(struct mapTable); + m = uiprivNew(struct mapTable); m->m = [[NSMapTable alloc] initWithKeyOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality) valueOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality) capacity:0]; @@ -24,7 +24,7 @@ void mapDestroy(struct mapTable *m) if ([m->m count] != 0) implbug("attempt to destroy map with items inside"); [m->m release]; - uiFree(m); + uiprivFree(m); } void *mapGet(struct mapTable *m, void *key) diff --git a/darwin/menu.m b/darwin/menu.m index 735cac50..11a98e63 100644 --- a/darwin/menu.m +++ b/darwin/menu.m @@ -241,7 +241,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name) if (menusFinalized) userbug("You can't create a new menu item after menus have been finalized."); - item = uiNew(uiMenuItem); + item = uiprivNew(uiMenuItem); item->type = type; switch (item->type) { @@ -319,7 +319,7 @@ uiMenu *uiNewMenu(const char *name) if (menus == nil) menus = [NSMutableArray new]; - m = uiNew(uiMenu); + m = uiprivNew(uiMenu); m->menu = [[NSMenu alloc] initWithTitle:toNSString(name)]; // use automatic menu item enabling for all menus for consistency's sake @@ -359,10 +359,10 @@ void uninitMenus(void) v = (NSValue *) obj; mi = (uiMenuItem *) [v pointerValue]; - uiFree(mi); + uiprivFree(mi); }]; [m->items release]; - uiFree(m); + uiprivFree(m); }]; [menus release]; } diff --git a/darwin/scrollview.m b/darwin/scrollview.m index b0b4040c..b583a00f 100644 --- a/darwin/scrollview.m +++ b/darwin/scrollview.m @@ -39,7 +39,7 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa [sv setAllowsMagnification:NO]; [sv setDocumentView:p->DocumentView]; - d = uiNew(struct scrollViewData); + d = uiprivNew(struct scrollViewData); scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll); *dout = d; @@ -57,5 +57,5 @@ void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hsc void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d) { - uiFree(d); + uiprivFree(d); } From 099c4ff631911cacc435dd1972561ef847562f3e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 16:36:03 -0400 Subject: [PATCH 05/21] uiAlloc() et al -> uiprivAlloc() et al, GTK+ code. --- unix/alloc.c | 14 +++++++------- unix/child.c | 4 ++-- unix/draw.c | 4 ++-- unix/drawpath.c | 4 ++-- unix/graphemes.c | 10 +++++----- unix/image.c | 8 ++++---- unix/main.c | 2 +- unix/menu.c | 12 ++++++------ 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/unix/alloc.c b/unix/alloc.c index 0291bd49..98eb0e32 100644 --- a/unix/alloc.c +++ b/unix/alloc.c @@ -43,7 +43,7 @@ void uninitAlloc(void) g_free(str); } -void *uiAlloc(size_t size, const char *type) +void *uiprivAlloc(size_t size, const char *type) { void *out; @@ -54,13 +54,13 @@ void *uiAlloc(size_t size, const char *type) 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; size_t *s; if (p == NULL) - return uiAlloc(new, type); + return uiprivAlloc(new, type); p = BASE(p); out = g_realloc(p, EXTRA + new); 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); *s = new; 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); return DATA(out); } -void uiFree(void *p) +void uiprivFree(void *p) { if (p == NULL) - implbug("attempt to uiFree(NULL)"); + implbug("attempt to uiprivFree(NULL)"); p = BASE(p); g_free(p); 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); } diff --git a/unix/child.c b/unix/child.c index b4a09677..b6e48807 100644 --- a/unix/child.c +++ b/unix/child.c @@ -33,7 +33,7 @@ struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parent if (child == NULL) return NULL; - c = uiNew(struct child); + c = uiprivNew(struct child); c->c = child; c->widget = GTK_WIDGET(uiControlHandle(c->c)); @@ -82,7 +82,7 @@ void childRemove(struct child *c) if (c->box != NULL) gtk_widget_destroy(c->box); - uiFree(c); + uiprivFree(c); } void childDestroy(struct child *c) diff --git a/unix/draw.c b/unix/draw.c index b4d18049..1eacee33 100644 --- a/unix/draw.c +++ b/unix/draw.c @@ -6,7 +6,7 @@ uiDrawContext *newContext(cairo_t *cr, GtkStyleContext *style) { uiDrawContext *c; - c = uiNew(uiDrawContext); + c = uiprivNew(uiDrawContext); c->cr = cr; c->style = style; return c; @@ -15,7 +15,7 @@ uiDrawContext *newContext(cairo_t *cr, GtkStyleContext *style) void freeContext(uiDrawContext *c) { // free neither cr nor style; we own neither - uiFree(c); + uiprivFree(c); } static cairo_pattern_t *mkbrush(uiDrawBrush *b) diff --git a/unix/drawpath.c b/unix/drawpath.c index a0165fb8..384743dc 100644 --- a/unix/drawpath.c +++ b/unix/drawpath.c @@ -28,7 +28,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode) { uiDrawPath *p; - p = uiNew(uiDrawPath); + p = uiprivNew(uiDrawPath); p->pieces = g_array_new(FALSE, TRUE, sizeof (struct piece)); p->fillMode = mode; return p; @@ -37,7 +37,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode) void uiDrawFreePath(uiDrawPath *p) { g_array_free(p->pieces, TRUE); - uiFree(p); + uiprivFree(p); } static void add(uiDrawPath *p, struct piece *piece) diff --git a/unix/graphemes.c b/unix/graphemes.c index 296e655f..b5edb95a 100644 --- a/unix/graphemes.c +++ b/unix/graphemes.c @@ -16,11 +16,11 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len) size_t i; size_t *op; - g = uiNew(struct graphemes); + g = uiprivNew(struct graphemes); // TODO see if we can use the utf routines 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, -1, NULL, logattrs, lenchars + 1); @@ -31,8 +31,8 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len) if (logattrs[i].is_cursor_position != 0) g->len++; - g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)"); - g->graphemesToPoints = (size_t *) uiAlloc((g->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 *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)"); // compute the graphemesToPoints array // 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 *op++ = i; - uiFree(logattrs); + uiprivFree(logattrs); return g; } diff --git a/unix/image.c b/unix/image.c index a79e550f..1bdf0d64 100644 --- a/unix/image.c +++ b/unix/image.c @@ -14,14 +14,14 @@ static void freeImageRep(gpointer item) buf = cairo_image_surface_get_data(cs); cairo_surface_destroy(cs); - uiFree(buf); + uiprivFree(buf); } uiImage *uiNewImage(double width, double height) { uiImage *i; - i = uiNew(uiImage); + i = uiprivNew(uiImage); i->width = width; i->height = height; i->images = g_ptr_array_new_with_free_func(freeImageRep); @@ -31,7 +31,7 @@ uiImage *uiNewImage(double width, double height) void uiFreeImage(uiImage *i) { g_ptr_array_free(i->images, TRUE); - uiFree(i); + uiprivFree(i); } 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; 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; for (y = 0; y < pixelStride * pixelHeight; y += pixelStride) { memmove(p, src + y, cstride); diff --git a/unix/main.c b/unix/main.c index 1d7e7a76..a0cd7835 100644 --- a/unix/main.c +++ b/unix/main.c @@ -99,7 +99,7 @@ void uiQueueMain(void (*f)(void *data), void *data) { 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 q = g_new0(struct queued, 1); q->f = f; diff --git a/unix/menu.c b/unix/menu.c index 5ccb4a51..1d950c5f 100644 --- a/unix/menu.c +++ b/unix/menu.c @@ -137,7 +137,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name) if (menusFinalized) 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); @@ -234,7 +234,7 @@ uiMenu *uiNewMenu(const char *name) if (menus == NULL) menus = g_array_new(FALSE, TRUE, sizeof (uiMenu *)); - m = uiNew(uiMenu); + m = uiprivNew(uiMenu); 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); } gtk_menu_shell_append(submenu, menuitem); - ww = uiNew(struct menuItemWindow); + ww = uiprivNew(struct menuItemWindow); ww->w = w; ww->signal = signal; 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); if (g_hash_table_remove(item->windows, widget) == FALSE) implbug("GtkMenuItem %p not in menu item's item/window map", widget); - uiFree(w); + uiprivFree(w); 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); g_free(item->name); g_hash_table_destroy(item->windows); - uiFree(item); + uiprivFree(item); } g_array_free(m->items, TRUE); - uiFree(m); + uiprivFree(m); } g_array_free(menus, TRUE); } From c6bb4636929f146b557521e22854c3f86e683f88 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 18:12:58 -0400 Subject: [PATCH 06/21] uiAlloc() et al -> uiprivAlloc() et al, Windows code. --- windows/alloc.cpp | 10 +++++----- windows/attrstr.cpp | 2 +- windows/button.cpp | 2 +- windows/checkbox.cpp | 2 +- windows/colordialog.cpp | 20 ++++++++++---------- windows/combobox.cpp | 2 +- windows/datetimepicker.cpp | 14 +++++++------- windows/debug.cpp | 10 +++++----- windows/draw.cpp | 12 ++++++------ windows/drawpath.cpp | 4 ++-- windows/drawtext.cpp | 10 +++++----- windows/dwrite.cpp | 2 +- windows/editablecombo.cpp | 2 +- windows/fontdialog.cpp | 20 ++++++++++---------- windows/form.cpp | 2 +- windows/graphemes.cpp | 6 +++--- windows/grid.cpp | 4 ++-- windows/group.cpp | 2 +- windows/init.cpp | 6 +++--- windows/label.cpp | 2 +- windows/menu.cpp | 24 ++++++++++++------------ windows/multilineentry.cpp | 6 +++--- windows/radiobuttons.cpp | 2 +- windows/spinbox.cpp | 4 ++-- windows/stddialogs.cpp | 4 ++-- windows/tab.cpp | 2 +- windows/tabpage.cpp | 4 ++-- windows/text.cpp | 16 ++++++++-------- windows/uipriv_windows.hpp | 4 ++-- windows/utf16.cpp | 10 +++++----- windows/window.cpp | 2 +- 31 files changed, 106 insertions(+), 106 deletions(-) diff --git a/windows/alloc.cpp b/windows/alloc.cpp index 23201f75..244b2380 100644 --- a/windows/alloc.cpp +++ b/windows/alloc.cpp @@ -27,7 +27,7 @@ void uninitAlloc(void) #define rawBytes(pa) (&((*pa)[0])) -void *uiAlloc(size_t size, const char *type) +void *uiprivAlloc(size_t size, const char *type) { byteArray *out; @@ -37,13 +37,13 @@ void *uiAlloc(size_t size, const char *type) return rawBytes(out); } -void *uiRealloc(void *_p, size_t size, const char *type) +void *uiprivRealloc(void *_p, size_t size, const char *type) { uint8_t *p = (uint8_t *) _p; byteArray *arr; if (p == NULL) - return uiAlloc(size, type); + return uiprivAlloc(size, type); arr = heap[p]; // TODO does this fill in? arr->resize(size, 0); @@ -52,12 +52,12 @@ void *uiRealloc(void *_p, size_t size, const char *type) return rawBytes(arr); } -void uiFree(void *_p) +void uiprivFree(void *_p) { uint8_t *p = (uint8_t *) _p; if (p == NULL) - implbug("attempt to uiFree(NULL)"); + implbug("attempt to uiprivFree(NULL)"); types.erase(heap[p]); delete heap[p]; heap.erase(p); diff --git a/windows/attrstr.cpp b/windows/attrstr.cpp index 9ea0f755..740ac43e 100644 --- a/windows/attrstr.cpp +++ b/windows/attrstr.cpp @@ -295,7 +295,7 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute hr = p->layout->SetFontFamilyName(wfamily, range); if (hr != S_OK) logHRESULT(L"error applying family name attribute", hr); - uiFree(wfamily); + uiprivFree(wfamily); break; case uiAttributeTypeSize: hr = p->layout->SetFontSize( diff --git a/windows/button.cpp b/windows/button.cpp index 3b12e726..d8913ec7 100644 --- a/windows/button.cpp +++ b/windows/button.cpp @@ -95,7 +95,7 @@ uiButton *uiNewButton(const char *text) BS_PUSHBUTTON | WS_TABSTOP, hInstance, NULL, TRUE); - uiFree(wtext); + uiprivFree(wtext); uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); uiButtonOnClicked(b, defaultOnClicked, NULL); diff --git a/windows/checkbox.cpp b/windows/checkbox.cpp index be425c00..3d8c92e3 100644 --- a/windows/checkbox.cpp +++ b/windows/checkbox.cpp @@ -108,7 +108,7 @@ uiCheckbox *uiNewCheckbox(const char *text) BS_CHECKBOX | WS_TABSTOP, hInstance, NULL, TRUE); - uiFree(wtext); + uiprivFree(wtext); uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c)); uiCheckboxOnToggled(c, defaultOnToggled, NULL); diff --git a/windows/colordialog.cpp b/windows/colordialog.cpp index 2efe72c8..d3d9bde9 100644 --- a/windows/colordialog.cpp +++ b/windows/colordialog.cpp @@ -228,7 +228,7 @@ static void updateDouble(HWND hwnd, double d, HWND whichChanged) return; str = ftoutf16(d); setWindowText(hwnd, str); - uiFree(str); + uiprivFree(str); } static void updateDialog(struct colorDialog *c, HWND whichChanged) @@ -259,22 +259,22 @@ static void updateDialog(struct colorDialog *c, HWND whichChanged) if (whichChanged != c->editRInt) { str = itoutf16(rb); setWindowText(c->editRInt, str); - uiFree(str); + uiprivFree(str); } if (whichChanged != c->editGInt) { str = itoutf16(gb); setWindowText(c->editGInt, str); - uiFree(str); + uiprivFree(str); } if (whichChanged != c->editBInt) { str = itoutf16(bb); setWindowText(c->editBInt, str); - uiFree(str); + uiprivFree(str); } if (whichChanged != c->editAInt) { str = itoutf16(ab); setWindowText(c->editAInt, str); - uiFree(str); + uiprivFree(str); } if (whichChanged != c->editHex) { @@ -956,7 +956,7 @@ static struct colorDialog *beginColorDialog(HWND hwnd, LPARAM lParam) { struct colorDialog *c; - c = uiNew(struct colorDialog); + c = uiprivNew(struct colorDialog); c->hwnd = hwnd; c->out = (struct colorDialogRGBA *) lParam; // load initial values now @@ -995,7 +995,7 @@ static void endColorDialog(struct colorDialog *c, INT_PTR code) { if (EndDialog(c->hwnd, code) == 0) logLastError(L"error ending color dialog"); - uiFree(c); + uiprivFree(c); } // TODO make this void on the font dialog too @@ -1020,7 +1020,7 @@ static double editDouble(HWND hwnd) s = windowText(hwnd); d = _wtof(s); - uiFree(s); + uiprivFree(s); return d; } @@ -1111,7 +1111,7 @@ static int editInt(HWND hwnd) s = windowText(hwnd); i = _wtoi(s); - uiFree(s); + uiprivFree(s); return i; } @@ -1176,7 +1176,7 @@ static void hexChanged(struct colorDialog *c) buf = windowText(c->editHex); is = hex2RGBA(buf, &r, &g, &b, &a); - uiFree(buf); + uiprivFree(buf); if (!is) return; rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); diff --git a/windows/combobox.cpp b/windows/combobox.cpp index 87c999ea..50f49dd7 100644 --- a/windows/combobox.cpp +++ b/windows/combobox.cpp @@ -66,7 +66,7 @@ void uiComboboxAppend(uiCombobox *c, const char *text) logLastError(L"error appending item to uiCombobox"); else if (res == (LRESULT) CB_ERRSPACE) logLastError(L"memory exhausted appending item to uiCombobox"); - uiFree(wtext); + uiprivFree(wtext); } int uiComboboxSelected(uiCombobox *c) diff --git a/windows/datetimepicker.cpp b/windows/datetimepicker.cpp index e105c2fd..342eb256 100644 --- a/windows/datetimepicker.cpp +++ b/windows/datetimepicker.cpp @@ -19,7 +19,7 @@ static WCHAR *expandYear(WCHAR *dts, int n) int ny = 0; // allocate more than we need to be safe - out = (WCHAR *) uiAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]"); + out = (WCHAR *) uiprivAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]"); q = out; for (p = dts; *p != L'\0'; p++) { // first, if the current character is a y, increment the number of consecutive ys @@ -73,17 +73,17 @@ static void setDateTimeFormat(HWND hwnd) ndate = GLI(LOCALE_SSHORTDATE, NULL, 0); if (ndate == 0) logLastError(L"error getting date string length"); - date = (WCHAR *) uiAlloc(ndate * sizeof (WCHAR), "WCHAR[]"); + date = (WCHAR *) uiprivAlloc(ndate * sizeof (WCHAR), "WCHAR[]"); if (GLI(LOCALE_SSHORTDATE, date, ndate) == 0) logLastError(L"error geting date string"); unexpandedDate = date; // so we can free it date = expandYear(unexpandedDate, ndate); - uiFree(unexpandedDate); + uiprivFree(unexpandedDate); ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0); if (ndate == 0) logLastError(L"error getting time string length"); - time = (WCHAR *) uiAlloc(ntime * sizeof (WCHAR), "WCHAR[]"); + time = (WCHAR *) uiprivAlloc(ntime * sizeof (WCHAR), "WCHAR[]"); if (GLI(LOCALE_STIMEFORMAT, time, ntime) == 0) logLastError(L"error geting time string"); @@ -91,9 +91,9 @@ static void setDateTimeFormat(HWND hwnd) if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0) logLastError(L"error applying format string to date/time picker"); - uiFree(datetime); - uiFree(time); - uiFree(date); + uiprivFree(datetime); + uiprivFree(time); + uiprivFree(date); } // control implementation diff --git a/windows/debug.cpp b/windows/debug.cpp index cfafffdc..9bfbbf0f 100644 --- a/windows/debug.cpp +++ b/windows/debug.cpp @@ -26,7 +26,7 @@ HRESULT _logLastError(debugargs, const WCHAR *s) if (useFormatted) LocalFree(formatted); // ignore error printDebug(msg); - uiFree(msg); + uiprivFree(msg); DebugBreak(); SetLastError(le); @@ -53,7 +53,7 @@ HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr) if (useFormatted) LocalFree(formatted); // ignore error printDebug(msg); - uiFree(msg); + uiprivFree(msg); DebugBreak(); return hr; @@ -71,14 +71,14 @@ void realbug(const char *file, const char *line, const char *func, const char *p va_end(ap2); n++; // terminating '\0' - msg = (char *) uiAlloc(n * sizeof (char), "char[]"); + msg = (char *) uiprivAlloc(n * sizeof (char), "char[]"); // includes terminating '\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx vsprintf_s(msg, n, format, ap); final = strf(L"[libui] %hs:%hs:%hs() %hs%hs\n", file, line, func, prefix, msg); - uiFree(msg); + uiprivFree(msg); printDebug(final); - uiFree(final); + uiprivFree(final); DebugBreak(); } diff --git a/windows/draw.cpp b/windows/draw.cpp index 5f4d29f1..2fc9eed9 100644 --- a/windows/draw.cpp +++ b/windows/draw.cpp @@ -107,7 +107,7 @@ uiDrawContext *newContext(ID2D1RenderTarget *rt) { uiDrawContext *c; - c = uiNew(uiDrawContext); + c = uiprivNew(uiDrawContext); c->rt = rt; c->states = new std::vector; resetTarget(c->rt); @@ -122,7 +122,7 @@ void freeContext(uiDrawContext *c) // TODO do this on other platforms userbug("You did not balance uiDrawSave() and uiDrawRestore() calls."); delete c->states; - uiFree(c); + uiprivFree(c); } static ID2D1Brush *makeSolidBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props) @@ -152,7 +152,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r size_t i; HRESULT hr; - stops = (D2D1_GRADIENT_STOP *) uiAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]"); + stops = (D2D1_GRADIENT_STOP *) uiprivAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]"); for (i = 0; i < b->NumStops; i++) { stops[i].position = b->Stops[i].Pos; stops[i].color.r = b->Stops[i].R; @@ -170,7 +170,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r if (hr != S_OK) logHRESULT(L"error creating stop collection", hr); - uiFree(stops); + uiprivFree(stops); return s; } @@ -365,7 +365,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP // TODO be sure to formally document this if (sp->NumDashes != 0) { dsp.dashStyle = D2D1_DASH_STYLE_CUSTOM; - dashes = (FLOAT *) uiAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]"); + dashes = (FLOAT *) uiprivAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]"); for (i = 0; i < sp->NumDashes; i++) dashes[i] = sp->Dashes[i] / sp->Thickness; } @@ -378,7 +378,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP if (hr != S_OK) logHRESULT(L"error creating stroke style", hr); if (sp->NumDashes != 0) - uiFree(dashes); + uiprivFree(dashes); cliplayer = applyClip(c); c->rt->DrawGeometry( diff --git a/windows/drawpath.cpp b/windows/drawpath.cpp index 045d11c0..8baa75a7 100644 --- a/windows/drawpath.cpp +++ b/windows/drawpath.cpp @@ -17,7 +17,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode fillmode) uiDrawPath *p; HRESULT hr; - p = uiNew(uiDrawPath); + p = uiprivNew(uiDrawPath); hr = d2dfactory->CreatePathGeometry(&(p->path)); if (hr != S_OK) logHRESULT(L"error creating path", hr); @@ -43,7 +43,7 @@ void uiDrawFreePath(uiDrawPath *p) // TODO close sink first? p->sink->Release(); p->path->Release(); - uiFree(p); + uiprivFree(p); } void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) diff --git a/windows/drawtext.cpp b/windows/drawtext.cpp index 85accab1..ec2ae152 100644 --- a/windows/drawtext.cpp +++ b/windows/drawtext.cpp @@ -38,7 +38,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p) FLOAT maxWidth; HRESULT hr; - tl = uiNew(uiDrawTextLayout); + tl = uiprivNew(uiDrawTextLayout); wDefaultFamily = toUTF16(p->DefaultFont->Family); hr = dwfactory->CreateTextFormat( @@ -51,7 +51,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p) // TODO use the current locale? L"", &(tl->format)); - uiFree(wDefaultFamily); + uiprivFree(wDefaultFamily); if (hr != S_OK) logHRESULT(L"error creating IDWriteTextFormat", hr); hr = tl->format->SetTextAlignment(dwriteAligns[p->Align]); @@ -95,14 +95,14 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p) void uiDrawFreeTextLayout(uiDrawTextLayout *tl) { - uiFree(tl->u16tou8); - uiFree(tl->u8tou16); + uiprivFree(tl->u16tou8); + uiprivFree(tl->u8tou16); for (auto p : *(tl->backgroundParams)) uiprivFree(p); delete tl->backgroundParams; tl->layout->Release(); tl->format->Release(); - uiFree(tl); + uiprivFree(tl); } // TODO make this shared code somehow diff --git a/windows/dwrite.cpp b/windows/dwrite.cpp index 24a4aa3a..4d6b6741 100644 --- a/windows/dwrite.cpp +++ b/windows/dwrite.cpp @@ -81,7 +81,7 @@ WCHAR *uiprivFontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStr if (hr != S_OK) logHRESULT(L"error getting length of font name", hr); // GetStringLength() does not include the null terminator, but GetString() does - wname = (WCHAR *) uiAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]"); + wname = (WCHAR *) uiprivAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]"); hr = names->GetString(index, wname, length + 1); if (hr != S_OK) logHRESULT(L"error getting font name", hr); diff --git a/windows/editablecombo.cpp b/windows/editablecombo.cpp index 9e1fdbfb..138618d7 100644 --- a/windows/editablecombo.cpp +++ b/windows/editablecombo.cpp @@ -76,7 +76,7 @@ void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text) logLastError(L"error appending item to uiEditableCombobox"); else if (res == (LRESULT) CB_ERRSPACE) logLastError(L"memory exhausted appending item to uiEditableCombobox"); - uiFree(wtext); + uiprivFree(wtext); } char *uiEditableComboboxText(uiEditableCombobox *c) diff --git a/windows/fontdialog.cpp b/windows/fontdialog.cpp index 2d10a1ae..ea02a416 100644 --- a/windows/fontdialog.cpp +++ b/windows/fontdialog.cpp @@ -121,7 +121,7 @@ static WCHAR *cbGetItemText(HWND cb, WPARAM item) len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0); if (len == (LRESULT) CB_ERR) logLastError(L"error getting item text length from combobox"); - text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); + text = (WCHAR *) uiprivAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); if (SendMessageW(cb, CB_GETLBTEXT, item, (LPARAM) text) != len) logLastError(L"error getting item text from combobox"); return text; @@ -138,7 +138,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter) text = windowText(cb); pos = SendMessageW(cb, CB_FINDSTRINGEXACT, (WPARAM) (-1), (LPARAM) text); if (pos == (LRESULT) CB_ERR) { - uiFree(text); + uiprivFree(text); return FALSE; } cbSetCurSel(cb, (WPARAM) pos); @@ -147,7 +147,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter) if (restoreAfter) if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE) logLastError(L"error restoring old combobox text"); - uiFree(text); + uiprivFree(text); // and restore the selection like above // TODO isn't there a 32-bit version of this if (SendMessageW(cb, CB_SETEDITSEL, 0, MAKELPARAM(selStart, selEnd)) != (LRESULT) TRUE) @@ -254,7 +254,7 @@ static void familyChanged(struct fontDialog *f) logHRESULT(L"error getting font for filling styles box", hr); label = fontStyleName(f->fc, font); pos = cbAddString(f->styleCombobox, label); - uiFree(label); + uiprivFree(label); cbSetItemData(f->styleCombobox, (WPARAM) pos, (LPARAM) font); if (font->GetWeight() == weight && font->GetStyle() == style && @@ -386,7 +386,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt &format); if (hr != S_OK) logHRESULT(L"error creating IDWriteTextFormat", hr); - uiFree(family); + uiprivFree(family); rect.left = 0; rect.top = 0; @@ -402,7 +402,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt format->Release(); if (exists) - uiFree(sample); + uiprivFree(sample); black->Release(); } @@ -466,7 +466,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam) HWND samplePlacement; HRESULT hr; - f = uiNew(struct fontDialog); + f = uiprivNew(struct fontDialog); f->hwnd = hwnd; f->params = (struct fontDialogParams *) lParam; @@ -482,7 +482,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam) logHRESULT(L"error getting font family", hr); wname = uiprivFontCollectionFamilyName(f->fc, family); pos = cbAddString(f->familyCombobox, wname); - uiFree(wname); + uiprivFree(wname); cbSetItemData(f->familyCombobox, (WPARAM) pos, (LPARAM) family); } @@ -506,7 +506,7 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code) uiprivFontCollectionFree(f->fc); if (EndDialog(f->hwnd, code) == 0) logLastError(L"error ending font dialog"); - uiFree(f); + uiprivFree(f); } static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam) @@ -681,7 +681,7 @@ WCHAR *uiprivFontDialogParamsToString(struct fontDialogParams *params) WCHAR *text; // TODO dynamically allocate - text = (WCHAR *) uiAlloc(512 * sizeof (WCHAR), "WCHAR[]"); + text = (WCHAR *) uiprivAlloc(512 * sizeof (WCHAR), "WCHAR[]"); _snwprintf(text, 512, L"%s %s %g", params->familyName, params->styleName, diff --git a/windows/form.cpp b/windows/form.cpp index febcc693..ed194671 100644 --- a/windows/form.cpp +++ b/windows/form.cpp @@ -266,7 +266,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) SS_LEFT | SS_NOPREFIX, hInstance, NULL, TRUE); - uiFree(wlabel); + uiprivFree(wlabel); uiWindowsEnsureSetParentHWND(fc.label, f->hwnd); fc.stretchy = stretchy; uiControlSetParent(fc.c, uiControl(f)); diff --git a/windows/graphemes.cpp b/windows/graphemes.cpp index 63e4882f..266cf97f 100644 --- a/windows/graphemes.cpp +++ b/windows/graphemes.cpp @@ -17,7 +17,7 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len) WCHAR *str; size_t *pPTG, *pGTP; - g = uiNew(struct graphemes); + g = uiprivNew(struct graphemes); g->len = 0; str = (WCHAR *) s; @@ -27,8 +27,8 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len) // no need to worry about surrogates if we're just counting } - g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)"); - g->graphemesToPoints = (size_t *) uiAlloc((g->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 *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)"); pPTG = g->pointsToGraphemes; pGTP = g->graphemesToPoints; diff --git a/windows/grid.cpp b/windows/grid.cpp index c63cd1e4..61e78543 100644 --- a/windows/grid.cpp +++ b/windows/grid.cpp @@ -418,7 +418,7 @@ static void uiGridDestroy(uiControl *c) for (struct gridChild *gc : *(g->children)) { uiControlSetParent(gc->c, NULL); uiControlDestroy(gc->c); - uiFree(gc); + uiprivFree(gc); } delete g->indexof; delete g->children; @@ -565,7 +565,7 @@ static struct gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand userbug("You cannot have a negative xspan in a uiGrid cell."); if (yspan < 0) userbug("You cannot have a negative yspan in a uiGrid cell."); - gc = uiNew(struct gridChild); + gc = uiprivNew(struct gridChild); gc->c = c; gc->xspan = xspan; gc->yspan = yspan; diff --git a/windows/group.cpp b/windows/group.cpp index 8824c5a4..1a2cc6ed 100644 --- a/windows/group.cpp +++ b/windows/group.cpp @@ -208,7 +208,7 @@ uiGroup *uiNewGroup(const char *text) BS_GROUPBOX, hInstance, NULL, TRUE); - uiFree(wtext); + uiprivFree(wtext); if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE) logLastError(L"error subclassing groupbox to handle parent messages"); diff --git a/windows/init.cpp b/windows/init.cpp index 2c25d3d4..24831143 100644 --- a/windows/init.cpp +++ b/windows/init.cpp @@ -28,11 +28,11 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value) wmessage, value, value, sysmsg); - uiFree(wmessage); + uiprivFree(wmessage); if (hassysmsg) LocalFree(sysmsg); // ignore error out = toUTF8(wout); - uiFree(wout); + uiprivFree(wout); return out + 1; } @@ -157,7 +157,7 @@ void uiUninit(void) void uiFreeInitError(const char *err) { if (*(err - 1) == '-') - uiFree((void *) (err - 1)); + uiprivFree((void *) (err - 1)); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) diff --git a/windows/label.cpp b/windows/label.cpp index d74b7d18..94a0d88e 100644 --- a/windows/label.cpp +++ b/windows/label.cpp @@ -51,7 +51,7 @@ uiLabel *uiNewLabel(const char *text) SS_LEFTNOWORDWRAP | SS_NOPREFIX, hInstance, NULL, TRUE); - uiFree(wtext); + uiprivFree(wtext); return l; } diff --git a/windows/menu.cpp b/windows/menu.cpp index 6112fc13..46405faf 100644 --- a/windows/menu.cpp +++ b/windows/menu.cpp @@ -115,10 +115,10 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name) if (m->len >= m->cap) { m->cap += grow; - m->items = (uiMenuItem **) uiRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]"); + m->items = (uiMenuItem **) uiprivRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]"); } - item = uiNew(uiMenuItem); + item = uiprivNew(uiMenuItem); m->items[m->len] = item; m->len++; @@ -207,10 +207,10 @@ uiMenu *uiNewMenu(const char *name) userbug("You can not create a new menu after menus have been finalized."); if (len >= cap) { cap += grow; - menus = (uiMenu **) uiRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]"); + menus = (uiMenu **) uiprivRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]"); } - m = uiNew(uiMenu); + m = uiprivNew(uiMenu); menus[len] = m; len++; @@ -237,7 +237,7 @@ static void appendMenuItem(HMENU menu, uiMenuItem *item) if (item->len >= item->cap) { item->cap += grow; - item->hmenus = (HMENU *) uiRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]"); + item->hmenus = (HMENU *) uiprivRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]"); } item->hmenus[item->len] = menu; item->len++; @@ -348,22 +348,22 @@ void uninitMenus(void) for (i = 0; i < len; i++) { m = menus[i]; - uiFree(m->name); + uiprivFree(m->name); for (j = 0; j < m->len; j++) { item = m->items[j]; if (item->len != 0) // LONGTERM userbug()? implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); if (item->name != NULL) - uiFree(item->name); + uiprivFree(item->name); if (item->hmenus != NULL) - uiFree(item->hmenus); - uiFree(item); + uiprivFree(item->hmenus); + uiprivFree(item); } if (m->items != NULL) - uiFree(m->items); - uiFree(m); + uiprivFree(m->items); + uiprivFree(m); } if (menus != NULL) - uiFree(menus); + uiprivFree(menus); } diff --git a/windows/multilineentry.cpp b/windows/multilineentry.cpp index a32960cb..391f4855 100644 --- a/windows/multilineentry.cpp +++ b/windows/multilineentry.cpp @@ -76,7 +76,7 @@ void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text) e->inhibitChanged = TRUE; crlf = LFtoCRLF(text); uiWindowsSetWindowText(e->hwnd, text); - uiFree(crlf); + uiprivFree(crlf); e->inhibitChanged = FALSE; // don't queue the control for resize; entry sizes are independent of their contents } @@ -95,9 +95,9 @@ void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text) SendMessageW(e->hwnd, EM_SETSEL, n, n); crlf = LFtoCRLF(text); wtext = toUTF16(crlf); - uiFree(crlf); + uiprivFree(crlf); SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext); - uiFree(wtext); + uiprivFree(wtext); e->inhibitChanged = FALSE; } diff --git a/windows/radiobuttons.cpp b/windows/radiobuttons.cpp index 29cd2e66..0684a270 100644 --- a/windows/radiobuttons.cpp +++ b/windows/radiobuttons.cpp @@ -140,7 +140,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text) BS_RADIOBUTTON | groupTabStop, hInstance, NULL, TRUE); - uiFree(wtext); + uiprivFree(wtext); uiWindowsEnsureSetParentHWND(hwnd, r->hwnd); uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r)); r->hwnds->push_back(hwnd); diff --git a/windows/spinbox.cpp b/windows/spinbox.cpp index 8c4b666a..57fb8d64 100644 --- a/windows/spinbox.cpp +++ b/windows/spinbox.cpp @@ -48,10 +48,10 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) // This won't handle leading spaces, but spaces aren't allowed *anyway*. wtext = windowText(s->edit); if (wcscmp(wtext, L"-") == 0) { - uiFree(wtext); + uiprivFree(wtext); return TRUE; } - uiFree(wtext); + uiprivFree(wtext); // value() does the work for us value(s); (*(s->onChanged))(s, s->onChangedData); diff --git a/windows/stddialogs.cpp b/windows/stddialogs.cpp index 89d26bac..c6ac4557 100644 --- a/windows/stddialogs.cpp +++ b/windows/stddialogs.cpp @@ -114,8 +114,8 @@ static void msgbox(HWND parent, const char *title, const char *description, TASK if (hr != S_OK) logHRESULT(L"error showing task dialog", hr); - uiFree(wdescription); - uiFree(wtitle); + uiprivFree(wdescription); + uiprivFree(wtitle); } void uiMsgBox(uiWindow *parent, const char *title, const char *description) diff --git a/windows/tab.cpp b/windows/tab.cpp index 365f5a1f..e7239585 100644 --- a/windows/tab.cpp +++ b/windows/tab.cpp @@ -212,7 +212,7 @@ void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) item.pszText = wname; if (SendMessageW(t->tabHWND, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1) logLastError(L"error adding tab to uiTab"); - uiFree(wname); + uiprivFree(wname); // we need to do this because adding the first tab doesn't send a TCN_SELCHANGE; it just shows the page show = curpage(t); diff --git a/windows/tabpage.cpp b/windows/tabpage.cpp index 77df9a18..dc98fb88 100644 --- a/windows/tabpage.cpp +++ b/windows/tabpage.cpp @@ -83,7 +83,7 @@ struct tabPage *newTabPage(uiControl *child) struct tabPage *tp; HRESULT hr; - tp = uiNew(struct tabPage); + tp = uiprivNew(struct tabPage); // unfortunately this needs to be a proper dialog for EnableThemeDialogTexture() to work; CreateWindowExW() won't suffice if (CreateDialogParamW(hInstance, MAKEINTRESOURCE(rcTabPageDialog), @@ -114,7 +114,7 @@ void tabPageDestroy(struct tabPage *tp) uiWindowsControlSetParentHWND(uiWindowsControl(tp->child), NULL); // don't call EndDialog(); that's for the DialogBox() family of functions instead of CreateDialog() uiWindowsEnsureDestroyWindow(tp->hwnd); - uiFree(tp); + uiprivFree(tp); } void tabPageMinimumSize(struct tabPage *tp, int *width, int *height) diff --git a/windows/text.cpp b/windows/text.cpp index e3a23570..eafbe714 100644 --- a/windows/text.cpp +++ b/windows/text.cpp @@ -10,7 +10,7 @@ WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len) if (len != NULL) *len = n; // WM_GETTEXTLENGTH does not include the null terminator - text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); + text = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); // note the comparison: the size includes the null terminator, but the return does not if (GetWindowTextW(hwnd, text, n + 1) != n) { logLastError(L"error getting window text"); @@ -35,7 +35,7 @@ void setWindowText(HWND hwnd, WCHAR *wtext) void uiFreeText(char *text) { - uiFree(text); + uiprivFree(text); } int uiWindowsWindowTextWidth(HWND hwnd) @@ -78,11 +78,11 @@ int uiWindowsWindowTextWidth(HWND hwnd) if (ReleaseDC(hwnd, dc) == 0) logLastError(L"error releasing DC"); - uiFree(text); + uiprivFree(text); return size.cx; noTextOrError: - uiFree(text); + uiprivFree(text); return 0; } @@ -93,7 +93,7 @@ char *uiWindowsWindowText(HWND hwnd) wtext = windowText(hwnd); text = toUTF8(wtext); - uiFree(wtext); + uiprivFree(wtext); return text; } @@ -103,7 +103,7 @@ void uiWindowsSetWindowText(HWND hwnd, const char *text) wtext = toUTF16(text); setWindowText(hwnd, wtext); - uiFree(wtext); + uiprivFree(wtext); } int uiprivStricmp(const char *a, const char *b) @@ -114,7 +114,7 @@ int uiprivStricmp(const char *a, const char *b) wa = toUTF16(a); wb = toUTF16(b); ret = _wcsicmp(wa, wb); - uiFree(wb); - uiFree(wa); + uiprivFree(wb); + uiprivFree(wa); return ret; } diff --git a/windows/uipriv_windows.hpp b/windows/uipriv_windows.hpp index 3244b7b4..7fb00efa 100644 --- a/windows/uipriv_windows.hpp +++ b/windows/uipriv_windows.hpp @@ -29,8 +29,8 @@ extern BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult); extern void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam); // utf16.cpp -#define emptyUTF16() ((WCHAR *) uiAlloc(1 * sizeof (WCHAR), "WCHAR[]")) -#define emptyUTF8() ((char *) uiAlloc(1 * sizeof (char), "char[]")) +#define emptyUTF16() ((WCHAR *) uiprivAlloc(1 * sizeof (WCHAR), "WCHAR[]")) +#define emptyUTF8() ((char *) uiprivAlloc(1 * sizeof (char), "char[]")) extern WCHAR *toUTF16(const char *str); extern char *toUTF8(const WCHAR *wstr); extern WCHAR *utf16dup(const WCHAR *orig); diff --git a/windows/utf16.cpp b/windows/utf16.cpp index 21d2f8a5..6afd0b0e 100644 --- a/windows/utf16.cpp +++ b/windows/utf16.cpp @@ -13,7 +13,7 @@ WCHAR *toUTF16(const char *str) if (*str == '\0') // empty string return emptyUTF16(); n = utf8UTF16Count(str, 0); - wstr = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); + wstr = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); wp = wstr; while (*str) { str = utf8DecodeRune(str, 0, &rune); @@ -33,7 +33,7 @@ char *toUTF8(const WCHAR *wstr) if (*wstr == L'\0') // empty string return emptyUTF8(); n = utf16RuneCount(wstr, 0); - str = (char *) uiAlloc((n + 1) * sizeof (char), "char[]"); + str = (char *) uiprivAlloc((n + 1) * sizeof (char), "char[]"); sp = str; while (*wstr) { wstr = utf16DecodeRune(wstr, 0, &rune); @@ -49,7 +49,7 @@ WCHAR *utf16dup(const WCHAR *orig) size_t len; len = wcslen(orig); - out = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); + out = (WCHAR *) uiprivAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); wcscpy_s(out, len + 1, orig); return out; } @@ -79,7 +79,7 @@ WCHAR *vstrf(const WCHAR *format, va_list ap) va_end(ap2); n++; // terminating L'\0' - buf = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); + buf = (WCHAR *) uiprivAlloc(n * sizeof (WCHAR), "WCHAR[]"); // includes terminating L'\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx vswprintf_s(buf, n, format, ap); @@ -97,7 +97,7 @@ char *LFtoCRLF(const char *lfonly) char *out; len = strlen(lfonly); - crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]"); + crlf = (char *) uiprivAlloc((len * 2 + 1) * sizeof (char), "char[]"); out = crlf; for (i = 0; i < len; i++) { if (*lfonly == '\n') diff --git a/windows/window.cpp b/windows/window.cpp index 34baf545..2ea5b7ce 100644 --- a/windows/window.cpp +++ b/windows/window.cpp @@ -480,7 +480,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) NULL, NULL, hInstance, w); if (w->hwnd == NULL) logLastError(L"error creating window"); - uiFree(wtitle); + uiprivFree(wtitle); if (hasMenubar) { w->menubar = makeMenubar(); From f93973d3cbe4ecb1cd3f484227dee74c742b791f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 21:46:08 -0400 Subject: [PATCH 07/21] Migrated implbug() and userbug() to uipriv forms. --- common/OLD_uipriv.h | 12 ------------ common/control.c | 8 ++++---- common/debug.c | 8 ++++---- common/uipriv.h | 24 +++++++++++++++--------- common/userbugs.c | 2 +- darwin/alloc.m | 4 ++-- darwin/area.m | 4 ++-- darwin/box.m | 2 +- darwin/debug.m | 2 +- darwin/draw.m | 22 +++++++++++----------- darwin/form.m | 2 +- darwin/grid.m | 8 ++++---- darwin/main.m | 7 +++---- darwin/map.m | 2 +- darwin/menu.m | 12 ++++++------ darwin/progressbar.m | 2 +- unix/alloc.c | 8 ++++---- unix/area.c | 6 +++--- unix/debug.c | 2 +- unix/draw.c | 2 +- unix/drawpath.c | 4 ++-- unix/menu.c | 18 +++++++++--------- unix/progressbar.c | 2 +- windows/alloc.cpp | 4 ++-- windows/datetimepicker.cpp | 2 +- windows/debug.cpp | 2 +- windows/draw.cpp | 4 ++-- windows/drawpath.cpp | 2 +- windows/events.cpp | 16 ++++++++-------- windows/grid.cpp | 4 ++-- windows/menu.cpp | 22 +++++++++++----------- windows/progressbar.cpp | 2 +- 32 files changed, 107 insertions(+), 114 deletions(-) diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h index 64d82ad1..ac8ec0cc 100644 --- a/common/OLD_uipriv.h +++ b/common/OLD_uipriv.h @@ -1,16 +1,4 @@ -// ugh, this was only introduced in MSVC 2015... -#ifdef _MSC_VER -#define __func__ __FUNCTION__ -#endif -extern void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap); -#define _ns2(s) #s -#define _ns(s) _ns2(s) -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(...) _userbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__) - // control.c extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); diff --git a/common/control.c b/common/control.c index e46e322c..3b5b8286 100644 --- a/common/control.c +++ b/common/control.c @@ -73,7 +73,7 @@ uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const c void uiFreeControl(uiControl *c) { if (uiControlParent(c) != NULL) - userbug("You cannot destroy a uiControl while it still has a parent. (control: %p)", c); + uiprivUserBug("You cannot destroy a uiControl while it still has a parent. (control: %p)", c); uiprivFree(c); } @@ -82,12 +82,12 @@ void uiControlVerifySetParent(uiControl *c, uiControl *parent) uiControl *curParent; if (uiControlToplevel(c)) - userbug("You cannot give a toplevel uiControl a parent. (control: %p)", c); + uiprivUserBug("You cannot give a toplevel uiControl a parent. (control: %p)", c); curParent = uiControlParent(c); if (parent != NULL && curParent != NULL) - userbug("You cannot give a uiControl a parent while it already has one. (control: %p; current parent: %p; new parent: %p)", c, curParent, parent); + uiprivUserBug("You cannot give a uiControl a parent while it already has one. (control: %p; current parent: %p; new parent: %p)", c, curParent, parent); if (parent == NULL && curParent == NULL) - implbug("attempt to double unparent uiControl %p", c); + uiprivImplBug("attempt to double unparent uiControl %p", c); } int uiControlEnabledToUser(uiControl *c) diff --git a/common/debug.c b/common/debug.c index 97280b47..aa24e29f 100644 --- a/common/debug.c +++ b/common/debug.c @@ -2,20 +2,20 @@ #include "../ui.h" #include "uipriv.h" -void _implbug(const char *file, const char *line, const char *func, const char *format, ...) +void uiprivDoImplBug(const char *file, const char *line, const char *func, const char *format, ...) { va_list ap; va_start(ap, format); - realbug(file, line, func, "POSSIBLE IMPLEMENTATION BUG; CONTACT ANDLABS:\n", format, ap); + uiprivRealBug(file, line, func, "POSSIBLE IMPLEMENTATION BUG; CONTACT ANDLABS:\n", format, ap); va_end(ap); } -void _userbug(const char *file, const char *line, const char *func, const char *format, ...) +void uiprivDoUserBug(const char *file, const char *line, const char *func, const char *format, ...) { va_list ap; va_start(ap, format); - realbug(file, line, func, "You have a bug: ", format, ap); + uiprivRealBug(file, line, func, "You have a bug: ", format, ap); va_end(ap); } diff --git a/common/uipriv.h b/common/uipriv.h index 69062c87..530a9794 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -8,24 +8,30 @@ extern "C" { #endif +// OS-specific init.* or main.* files extern uiInitOptions uiprivOptions; +// OS-specific alloc.* files extern void *uiprivAlloc(size_t, const char *); #define uiprivNew(T) ((T *) uiprivAlloc(sizeof (T), #T)) extern void *uiprivRealloc(void *, size_t, const char *); extern void uiprivFree(void *); -// ugh, this was only introduced in MSVC 2015... +// debug.c and OS-specific debug.* files +// TODO get rid of this mess... +// ugh, __func__ was only introduced in MSVC 2015... #ifdef _MSC_VER -#define __func__ __FUNCTION__ +#define uiprivMacro__func__ __FUNCTION__ +#else +#define uiprivMacro__func__ __func__ #endif -extern void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap); -#define _ns2(s) #s -#define _ns(s) _ns2(s) -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(...) _userbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__) +extern void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap); +#define uiprivMacro_ns2(s) #s +#define uiprivMacro_ns(s) uiprivMacro_ns2(s) +extern void uiprivDoImplBug(const char *file, const char *line, const char *func, const char *format, ...); +#define uiprivImplBug(...) uiprivDoImplBug(__FILE__, uiprivMacro_ns(__LINE__), uiprivMacro__func__, __VA_ARGS__) +extern void uiprivDoUserBug(const char *file, const char *line, const char *func, const char *format, ...); +#define uiprivUserBug(...) uiprivDoUserBug(__FILE__, uiprivMacro_ns(__LINE__), uiprivMacro__func__, __VA_ARGS__) // control.c extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); diff --git a/common/userbugs.c b/common/userbugs.c index 0a85874c..09cc703d 100644 --- a/common/userbugs.c +++ b/common/userbugs.c @@ -4,5 +4,5 @@ void uiUserBugCannotSetParentOnToplevel(const char *type) { - userbug("You cannot make a %s a child of another uiControl,", type); + uiprivUserBug("You cannot make a %s a child of another uiControl,", type); } diff --git a/darwin/alloc.m b/darwin/alloc.m index 0012c853..fbafc153 100644 --- a/darwin/alloc.m +++ b/darwin/alloc.m @@ -37,7 +37,7 @@ void uninitAlloc(void) ptr = [v pointerValue]; [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]); + uiprivUserBug("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]; } @@ -82,7 +82,7 @@ void *uiprivRealloc(void *p, size_t new, const char *type) void uiprivFree(void *p) { if (p == NULL) - implbug("attempt to uiprivFree(NULL)"); + uiprivImplBug("attempt to uiprivFree(NULL)"); p = BASE(p); free(p); [allocations removeObject:[NSValue valueWithPointer:p]]; diff --git a/darwin/area.m b/darwin/area.m index 23162e6c..1442479a 100644 --- a/darwin/area.m +++ b/darwin/area.m @@ -390,7 +390,7 @@ int sendAreaEvents(NSEvent *e) void uiAreaSetSize(uiArea *a, int width, int height) { if (!a->scrolling) - userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a); + uiprivUserBug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a); [a->area setScrollingSize:NSMakeSize(width, height)]; } @@ -402,7 +402,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. (area: %p)", a); + uiprivUserBug("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 } diff --git a/darwin/box.m b/darwin/box.m index 18d536d5..6a1941ea 100644 --- a/darwin/box.m +++ b/darwin/box.m @@ -428,7 +428,7 @@ void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) // LONGTERM on other platforms // or at leat allow this and implicitly turn it into a spacer if (c == NULL) - userbug("You cannot add NULL to a uiBox."); + uiprivUserBug("You cannot add NULL to a uiBox."); [b->view append:c stretchy:stretchy]; } diff --git a/darwin/debug.m b/darwin/debug.m index c91c6a73..aff66e0d 100644 --- a/darwin/debug.m +++ b/darwin/debug.m @@ -3,7 +3,7 @@ // LONGTERM 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) +void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap) { NSMutableString *str; NSString *formatted; diff --git a/darwin/draw.m b/darwin/draw.m index b52b5a57..7ca854d2 100644 --- a/darwin/draw.m +++ b/darwin/draw.m @@ -27,7 +27,7 @@ void uiDrawFreePath(uiDrawPath *p) void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) { if (p->ended) - userbug("You cannot call uiDrawPathNewFigure() on a uiDrawPath that has already been ended. (path; %p)", p); + uiprivUserBug("You cannot call uiDrawPathNewFigure() on a uiDrawPath that has already been ended. (path; %p)", p); CGPathMoveToPoint(p->path, NULL, x, y); } @@ -37,7 +37,7 @@ void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, d double startx, starty; if (p->ended) - userbug("You cannot call uiDrawPathNewFigureWithArc() on a uiDrawPath that has already been ended. (path; %p)", p); + uiprivUserBug("You cannot call uiDrawPathNewFigureWithArc() on a uiDrawPath that has already been ended. (path; %p)", p); sinStart = sin(startAngle); cosStart = cos(startAngle); startx = xCenter + radius * cosStart; @@ -50,7 +50,7 @@ void uiDrawPathLineTo(uiDrawPath *p, double x, double y) { // TODO refine this to require being in a path if (p->ended) - implbug("attempt to add line to ended path in uiDrawPathLineTo()"); + uiprivImplBug("attempt to add line to ended path in uiDrawPathLineTo()"); CGPathAddLineToPoint(p->path, NULL, x, y); } @@ -60,7 +60,7 @@ void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radiu // TODO likewise if (p->ended) - implbug("attempt to add arc to ended path in uiDrawPathArcTo()"); + uiprivImplBug("attempt to add arc to ended path in uiDrawPathArcTo()"); if (sweep > 2 * uiPi) sweep = 2 * uiPi; cw = false; @@ -77,7 +77,7 @@ void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, doubl { // TODO likewise if (p->ended) - implbug("attempt to add bezier to ended path in uiDrawPathBezierTo()"); + uiprivImplBug("attempt to add bezier to ended path in uiDrawPathBezierTo()"); CGPathAddCurveToPoint(p->path, NULL, c1x, c1y, c2x, c2y, @@ -88,14 +88,14 @@ void uiDrawPathCloseFigure(uiDrawPath *p) { // TODO likewise if (p->ended) - implbug("attempt to close figure of ended path in uiDrawPathCloseFigure()"); + uiprivImplBug("attempt to close figure of ended path in uiDrawPathCloseFigure()"); CGPathCloseSubpath(p->path); } void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height) { if (p->ended) - userbug("You cannot call uiDrawPathAddRectangle() on a uiDrawPath that has already been ended. (path; %p)", p); + uiprivUserBug("You cannot call uiDrawPathAddRectangle() on a uiDrawPath that has already been ended. (path; %p)", p); CGPathAddRect(p->path, NULL, CGRectMake(x, y, width, height)); } @@ -132,7 +132,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro uiDrawPath p2; if (!path->ended) - userbug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path); + uiprivUserBug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path); switch (p->Cap) { case uiDrawLineCapFlat: @@ -280,7 +280,7 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b) void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b) { if (!path->ended) - userbug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path); + uiprivUserBug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path); CGContextAddPath(c->c, (CGPathRef) (path->path)); switch (b->Type) { case uiDrawBrushTypeSolid: @@ -294,7 +294,7 @@ void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b) // TODO return; } - userbug("Unknown brush type %d passed to uiDrawFill().", b->Type); + uiprivUserBug("Unknown brush type %d passed to uiDrawFill().", b->Type); } static void m2c(uiDrawMatrix *m, CGAffineTransform *c) @@ -425,7 +425,7 @@ void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m) void uiDrawClip(uiDrawContext *c, uiDrawPath *path) { if (!path->ended) - userbug("You cannot call uiDrawCilp() on a uiDrawPath that has not been ended. (path: %p)", path); + uiprivUserBug("You cannot call uiDrawCilp() on a uiDrawPath that has not been ended. (path: %p)", path); CGContextAddPath(c->c, (CGPathRef) (path->path)); switch (path->fillMode) { case uiDrawFillModeWinding: diff --git a/darwin/form.m b/darwin/form.m index 7cdb965a..613818a9 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -530,7 +530,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) // LONGTERM on other platforms // or at leat allow this and implicitly turn it into a spacer if (c == NULL) - userbug("You cannot add NULL to a uiForm."); + uiprivUserBug("You cannot add NULL to a uiForm."); [f->view append:toNSString(label) c:c stretchy:stretchy]; } diff --git a/darwin/grid.m b/darwin/grid.m index fc98cc9f..218a5f63 100644 --- a/darwin/grid.m +++ b/darwin/grid.m @@ -574,7 +574,7 @@ struct uiGrid { break; } if (!found) - userbug("Existing control %p is not in grid %p; you cannot add other controls next to it", c, self->g); + uiprivUserBug("Existing control %p is not in grid %p; you cannot add other controls next to it", c, self->g); switch (at) { case uiAtLeading: @@ -742,9 +742,9 @@ static gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand, uiAli gridChild *gc; if (xspan < 0) - userbug("You cannot have a negative xspan in a uiGrid cell."); + uiprivUserBug("You cannot have a negative xspan in a uiGrid cell."); if (yspan < 0) - userbug("You cannot have a negative yspan in a uiGrid cell."); + uiprivUserBug("You cannot have a negative yspan in a uiGrid cell."); gc = [gridChild new]; gc.xspan = xspan; gc.yspan = yspan; @@ -763,7 +763,7 @@ void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int ysp // LONGTERM on other platforms // or at leat allow this and implicitly turn it into a spacer if (c == NULL) - userbug("You cannot add NULL to a uiGrid."); + uiprivUserBug("You cannot add NULL to a uiGrid."); gc = toChild(c, xspan, yspan, hexpand, halign, vexpand, valign, g); gc.left = left; gc.top = top; diff --git a/darwin/main.m b/darwin/main.m index 1bc6bfc3..f3392ce6 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -57,7 +57,7 @@ static BOOL stepsIsRunning; NSEvent *e; if (!canQuit) - implbug("call to [NSApp terminate:] when not ready to terminate; definitely contact andlabs"); + uiprivImplBug("call to [NSApp terminate:] when not ready to terminate; definitely contact andlabs"); [realNSApp() stop:realNSApp()]; // stop: won't register until another event has passed; let's synthesize one @@ -139,9 +139,8 @@ const char *uiInit(uiInitOptions *o) void uiUninit(void) { - if (!globalPool) { - userbug("You must call uiInit() first!"); - } + if (!globalPool) + uiprivUserBug("You must call uiInit() first!"); [globalPool release]; @autoreleasepool { diff --git a/darwin/map.m b/darwin/map.m index 4eaa057d..190218a1 100644 --- a/darwin/map.m +++ b/darwin/map.m @@ -22,7 +22,7 @@ struct mapTable *newMap(void) void mapDestroy(struct mapTable *m) { if ([m->m count] != 0) - implbug("attempt to destroy map with items inside"); + uiprivImplBug("attempt to destroy map with items inside"); [m->m release]; uiprivFree(m); } diff --git a/darwin/menu.m b/darwin/menu.m index 11a98e63..ca6cce4b 100644 --- a/darwin/menu.m +++ b/darwin/menu.m @@ -80,17 +80,17 @@ static void mapItemReleaser(void *key, void *value) switch (smi->type) { case typeQuit: if (self->hasQuit) - userbug("You can't have multiple Quit menu items in one program."); + uiprivUserBug("You can't have multiple Quit menu items in one program."); self->hasQuit = YES; break; case typePreferences: if (self->hasPreferences) - userbug("You can't have multiple Preferences menu items in one program."); + uiprivUserBug("You can't have multiple Preferences menu items in one program."); self->hasPreferences = YES; break; case typeAbout: if (self->hasAbout) - userbug("You can't have multiple About menu items in one program."); + uiprivUserBug("You can't have multiple About menu items in one program."); self->hasAbout = YES; break; } @@ -212,7 +212,7 @@ void uiMenuItemDisable(uiMenuItem *item) void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data) { if (item->type == typeQuit) - userbug("You can't call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); + uiprivUserBug("You can't call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); item->onClicked = f; item->onClickedData = data; } @@ -239,7 +239,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name) uiMenuItem *item; if (menusFinalized) - userbug("You can't create a new menu item after menus have been finalized."); + uiprivUserBug("You can't create a new menu item after menus have been finalized."); item = uiprivNew(uiMenuItem); @@ -315,7 +315,7 @@ uiMenu *uiNewMenu(const char *name) uiMenu *m; if (menusFinalized) - userbug("You can't create a new menu after menus have been finalized."); + uiprivUserBug("You can't create a new menu after menus have been finalized."); if (menus == nil) menus = [NSMutableArray new]; diff --git a/darwin/progressbar.m b/darwin/progressbar.m index b5382281..1f5390ff 100644 --- a/darwin/progressbar.m +++ b/darwin/progressbar.m @@ -48,7 +48,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value) } if (value < 0 || value > 100) - userbug("Value %d out of range for a uiProgressBar.", value); + uiprivUserBug("Value %d out of range for a uiProgressBar.", value); // on 10.8 there's an animation when the progress bar increases, just like with Aero if (value == 100) { diff --git a/unix/alloc.c b/unix/alloc.c index 98eb0e32..2fdd2052 100644 --- a/unix/alloc.c +++ b/unix/alloc.c @@ -39,7 +39,7 @@ void uninitAlloc(void) return; } 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); + uiprivUserBug("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); } @@ -68,7 +68,7 @@ void *uiprivRealloc(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) - implbug("%p not found in allocations array in uiprivRealloc()", p); + uiprivImplBug("%p not found in allocations array in uiprivRealloc()", p); g_ptr_array_add(allocations, out); return DATA(out); } @@ -76,9 +76,9 @@ void *uiprivRealloc(void *p, size_t new, const char *type) void uiprivFree(void *p) { if (p == NULL) - implbug("attempt to uiprivFree(NULL)"); + uiprivImplBug("attempt to uiprivFree(NULL)"); p = BASE(p); g_free(p); if (g_ptr_array_remove(allocations, p) == FALSE) - implbug("%p not found in allocations array in uiprivFree()", p); + uiprivImplBug("%p not found in allocations array in uiprivFree()", p); } diff --git a/unix/area.c b/unix/area.c index 24cd9513..abf868ca 100644 --- a/unix/area.c +++ b/unix/area.c @@ -499,7 +499,7 @@ uiUnixControlAllDefaults(uiArea) void uiAreaSetSize(uiArea *a, int width, int height) { if (!a->scrolling) - userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a); + uiprivUserBug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a); a->scrollWidth = width; a->scrollHeight = height; gtk_widget_queue_resize(a->areaWidget); @@ -521,7 +521,7 @@ void uiAreaBeginUserWindowMove(uiArea *a) GtkWidget *toplevel; if (a->dragevent == NULL) - userbug("cannot call uiAreaBeginUserWindowMove() outside of a Mouse() with Down != 0"); + uiprivUserBug("cannot call uiAreaBeginUserWindowMove() outside of a Mouse() with Down != 0"); // TODO don't we have a libui function for this? did I scrap it? // TODO widget or areaWidget? toplevel = gtk_widget_get_toplevel(a->widget); @@ -561,7 +561,7 @@ void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge) GtkWidget *toplevel; if (a->dragevent == NULL) - userbug("cannot call uiAreaBeginUserWindowResize() outside of a Mouse() with Down != 0"); + uiprivUserBug("cannot call uiAreaBeginUserWindowResize() outside of a Mouse() with Down != 0"); // TODO don't we have a libui function for this? did I scrap it? // TODO widget or areaWidget? toplevel = gtk_widget_get_toplevel(a->widget); diff --git a/unix/debug.c b/unix/debug.c index c948db62..fd97c9ed 100644 --- a/unix/debug.c +++ b/unix/debug.c @@ -3,7 +3,7 @@ // LONGTERM 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) +void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap) { char *a, *b; diff --git a/unix/draw.c b/unix/draw.c index 1eacee33..15abb611 100644 --- a/unix/draw.c +++ b/unix/draw.c @@ -39,7 +39,7 @@ static cairo_pattern_t *mkbrush(uiDrawBrush *b) // case uiDrawBrushTypeImage: } if (cairo_pattern_status(pat) != CAIRO_STATUS_SUCCESS) - implbug("error creating pattern in mkbrush(): %s", + uiprivImplBug("error creating pattern in mkbrush(): %s", cairo_status_to_string(cairo_pattern_status(pat))); switch (b->Type) { case uiDrawBrushTypeLinearGradient: diff --git a/unix/drawpath.c b/unix/drawpath.c index 384743dc..28eeb981 100644 --- a/unix/drawpath.c +++ b/unix/drawpath.c @@ -43,7 +43,7 @@ void uiDrawFreePath(uiDrawPath *p) static void add(uiDrawPath *p, struct piece *piece) { if (p->ended) - userbug("You cannot modify a uiDrawPath that has been ended. (path: %p)", p); + uiprivUserBug("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) - userbug("You cannot draw with a uiDrawPath that has not been ended. (path: %p)", p); + uiprivUserBug("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); diff --git a/unix/menu.c b/unix/menu.c index 1d950c5f..3d02e939 100644 --- a/unix/menu.c +++ b/unix/menu.c @@ -109,7 +109,7 @@ void uiMenuItemDisable(uiMenuItem *item) void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data) { if (item->type == typeQuit) - userbug("You cannot call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); + uiprivUserBug("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) - userbug("You cannot create a new menu item after menus have been finalized."); + uiprivUserBug("You cannot create a new menu item after menus have been finalized."); item = uiprivNew(uiMenuItem); @@ -196,7 +196,7 @@ uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name) uiMenuItem *uiMenuAppendQuitItem(uiMenu *m) { if (hasQuit) - userbug("You cannot have multiple Quit menu items in the same program."); + uiprivUserBug("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) - userbug("You cannot have multiple Preferences menu items in the same program."); + uiprivUserBug("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) - userbug("You cannot have multiple About menu items in the same program."); + uiprivUserBug("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) - userbug("You cannot create a new menu after menus have been finalized."); + uiprivUserBug("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) - implbug("GtkMenuItem %p not in menu item's item/window map", widget); + uiprivImplBug("GtkMenuItem %p not in menu item's item/window map", widget); uiprivFree(w); fmi->i++; } @@ -353,8 +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) - // 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); + // TODO is this really a uiprivUserBug()? + uiprivImplBug("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); uiprivFree(item); diff --git a/unix/progressbar.c b/unix/progressbar.c index 9b543b04..b3681a6f 100644 --- a/unix/progressbar.c +++ b/unix/progressbar.c @@ -53,7 +53,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value) } if (value < 0 || value > 100) - userbug("Value %d is out of range for a uiProgressBar.", value); + uiprivUserBug("Value %d is out of range for a uiProgressBar.", value); gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100); } diff --git a/windows/alloc.cpp b/windows/alloc.cpp index 244b2380..321cca03 100644 --- a/windows/alloc.cpp +++ b/windows/alloc.cpp @@ -22,7 +22,7 @@ void uninitAlloc(void) // note the void * cast; otherwise it'll be treated as a string oss << (void *) (alloc.first) << " " << types[alloc.second] << "\n"; ossstr = oss.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", ossstr.c_str()); + uiprivUserBug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", ossstr.c_str()); } #define rawBytes(pa) (&((*pa)[0])) @@ -57,7 +57,7 @@ void uiprivFree(void *_p) uint8_t *p = (uint8_t *) _p; if (p == NULL) - implbug("attempt to uiprivFree(NULL)"); + uiprivImplBug("attempt to uiprivFree(NULL)"); types.erase(heap[p]); delete heap[p]; heap.erase(p); diff --git a/windows/datetimepicker.cpp b/windows/datetimepicker.cpp index 342eb256..6784fec2 100644 --- a/windows/datetimepicker.cpp +++ b/windows/datetimepicker.cpp @@ -44,7 +44,7 @@ static WCHAR *expandYear(WCHAR *dts, int n) if (*p == L'\'') break; if (*p == L'\0') - implbug("unterminated quote in system-provided locale date string in expandYear()"); + uiprivImplBug("unterminated quote in system-provided locale date string in expandYear()"); *q++ = *p; } // and fall through to copy the closing quote diff --git a/windows/debug.cpp b/windows/debug.cpp index 9bfbbf0f..bd512743 100644 --- a/windows/debug.cpp +++ b/windows/debug.cpp @@ -59,7 +59,7 @@ HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr) return hr; } -void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap) +void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap) { va_list ap2; char *msg; diff --git a/windows/draw.cpp b/windows/draw.cpp index 2fc9eed9..a5e5033a 100644 --- a/windows/draw.cpp +++ b/windows/draw.cpp @@ -120,7 +120,7 @@ void freeContext(uiDrawContext *c) c->currentClip->Release(); if (c->states->size() != 0) // TODO do this on other platforms - userbug("You did not balance uiDrawSave() and uiDrawRestore() calls."); + uiprivUserBug("You did not balance uiDrawSave() and uiDrawRestore() calls."); delete c->states; uiprivFree(c); } @@ -253,7 +253,7 @@ static ID2D1Brush *makeBrush(uiDrawBrush *b, ID2D1RenderTarget *rt) } // TODO do this on all platforms - userbug("Invalid brush type %d given to drawing operation.", b->Type); + uiprivUserBug("Invalid brush type %d given to drawing operation.", b->Type); // TODO dummy brush? return NULL; // make compiler happy } diff --git a/windows/drawpath.cpp b/windows/drawpath.cpp index 8baa75a7..34b15466 100644 --- a/windows/drawpath.cpp +++ b/windows/drawpath.cpp @@ -242,6 +242,6 @@ void uiDrawPathEnd(uiDrawPath *p) ID2D1PathGeometry *pathGeometry(uiDrawPath *p) { if (p->sink != NULL) - userbug("You cannot draw with a uiDrawPath that was not ended. (path: %p)", p); + uiprivUserBug("You cannot draw with a uiDrawPath that was not ended. (path: %p)", p); return p->path; } diff --git a/windows/events.cpp b/windows/events.cpp index 45e8d43d..c13d6d00 100644 --- a/windows/events.cpp +++ b/windows/events.cpp @@ -23,7 +23,7 @@ static std::map handlers; void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c) { if (handlers[hwnd].commandHandler != NULL) - implbug("already registered a WM_COMMAND handler to window handle %p", hwnd); + uiprivImplBug("already registered a WM_COMMAND handler to window handle %p", hwnd); handlers[hwnd].commandHandler = handler; handlers[hwnd].c = c; } @@ -31,7 +31,7 @@ void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c) { if (handlers[hwnd].notifyHandler != NULL) - implbug("already registered a WM_NOTIFY handler to window handle %p", hwnd); + uiprivImplBug("already registered a WM_NOTIFY handler to window handle %p", hwnd); handlers[hwnd].notifyHandler = handler; handlers[hwnd].c = c; } @@ -39,7 +39,7 @@ void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, H void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c) { if (handlers[hwnd].hscrollHandler != NULL) - implbug("already registered a WM_HSCROLL handler to window handle %p", hwnd); + uiprivImplBug("already registered a WM_HSCROLL handler to window handle %p", hwnd); handlers[hwnd].hscrollHandler = handler; handlers[hwnd].c = c; } @@ -47,21 +47,21 @@ void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd) { if (handlers[hwnd].commandHandler == NULL) - implbug("window handle %p not registered to receive WM_COMMAND events", hwnd); + uiprivImplBug("window handle %p not registered to receive WM_COMMAND events", hwnd); handlers[hwnd].commandHandler = NULL; } void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd) { if (handlers[hwnd].notifyHandler == NULL) - implbug("window handle %p not registered to receive WM_NOTIFY events", hwnd); + uiprivImplBug("window handle %p not registered to receive WM_NOTIFY events", hwnd); handlers[hwnd].notifyHandler = NULL; } void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd) { if (handlers[hwnd].hscrollHandler == NULL) - implbug("window handle %p not registered to receive WM_HSCROLL events", hwnd); + uiprivImplBug("window handle %p not registered to receive WM_HSCROLL events", hwnd); handlers[hwnd].hscrollHandler = NULL; } @@ -131,14 +131,14 @@ static std::map wininichanges; void uiWindowsRegisterReceiveWM_WININICHANGE(HWND hwnd) { if (wininichanges[hwnd]) - implbug("window handle %p already subscribed to receive WM_WINICHANGEs", hwnd); + uiprivImplBug("window handle %p already subscribed to receive WM_WINICHANGEs", hwnd); wininichanges[hwnd] = true; } void uiWindowsUnregisterReceiveWM_WININICHANGE(HWND hwnd) { if (!wininichanges[hwnd]) - implbug("window handle %p not registered to receive WM_WININICHANGEs", hwnd); + uiprivImplBug("window handle %p not registered to receive WM_WININICHANGEs", hwnd); wininichanges[hwnd] = false; } diff --git a/windows/grid.cpp b/windows/grid.cpp index 61e78543..cac87aff 100644 --- a/windows/grid.cpp +++ b/windows/grid.cpp @@ -562,9 +562,9 @@ static struct gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand struct gridChild *gc; if (xspan < 0) - userbug("You cannot have a negative xspan in a uiGrid cell."); + uiprivUserBug("You cannot have a negative xspan in a uiGrid cell."); if (yspan < 0) - userbug("You cannot have a negative yspan in a uiGrid cell."); + uiprivUserBug("You cannot have a negative yspan in a uiGrid cell."); gc = uiprivNew(struct gridChild); gc->c = c; gc->xspan = xspan; diff --git a/windows/menu.cpp b/windows/menu.cpp index 46405faf..09dfcf30 100644 --- a/windows/menu.cpp +++ b/windows/menu.cpp @@ -87,7 +87,7 @@ void uiMenuItemDisable(uiMenuItem *i) void uiMenuItemOnClicked(uiMenuItem *i, void (*f)(uiMenuItem *, uiWindow *, void *), void *data) { if (i->type == typeQuit) - userbug("You can not call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); + uiprivUserBug("You can not call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); i->onClicked = f; i->onClickedData = data; } @@ -111,7 +111,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name) uiMenuItem *item; if (menusFinalized) - userbug("You can not create a new menu item after menus have been finalized."); + uiprivUserBug("You can not create a new menu item after menus have been finalized."); if (m->len >= m->cap) { m->cap += grow; @@ -169,7 +169,7 @@ uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name) uiMenuItem *uiMenuAppendQuitItem(uiMenu *m) { if (hasQuit) - userbug("You can not have multiple Quit menu items in a program."); + uiprivUserBug("You can not have multiple Quit menu items in a program."); hasQuit = TRUE; newItem(m, typeSeparator, NULL); return newItem(m, typeQuit, NULL); @@ -178,7 +178,7 @@ uiMenuItem *uiMenuAppendQuitItem(uiMenu *m) uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m) { if (hasPreferences) - userbug("You can not have multiple Preferences menu items in a program."); + uiprivUserBug("You can not have multiple Preferences menu items in a program."); hasPreferences = TRUE; newItem(m, typeSeparator, NULL); return newItem(m, typePreferences, NULL); @@ -187,8 +187,8 @@ uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m) uiMenuItem *uiMenuAppendAboutItem(uiMenu *m) { if (hasAbout) - // TODO place these userbug strings in a header - userbug("You can not have multiple About menu items in a program."); + // TODO place these uiprivImplBug() and uiprivUserBug() strings in a header + uiprivUserBug("You can not have multiple About menu items in a program."); hasAbout = TRUE; newItem(m, typeSeparator, NULL); return newItem(m, typeAbout, NULL); @@ -204,7 +204,7 @@ uiMenu *uiNewMenu(const char *name) uiMenu *m; if (menusFinalized) - userbug("You can not create a new menu after menus have been finalized."); + uiprivUserBug("You can not create a new menu after menus have been finalized."); if (len >= cap) { cap += grow; menus = (uiMenu **) uiprivRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]"); @@ -293,7 +293,7 @@ void runMenuEvent(WORD id, uiWindow *w) } } // no match - implbug("unknown menu ID %hu in runMenuEvent()", id); + uiprivImplBug("unknown menu ID %hu in runMenuEvent()", id); found: // first toggle checkboxes, if any @@ -316,7 +316,7 @@ static void freeMenu(uiMenu *m, HMENU submenu) if (item->hmenus[j] == submenu) break; if (j >= item->len) - implbug("submenu handle %p not found in freeMenu()", submenu); + uiprivImplBug("submenu handle %p not found in freeMenu()", submenu); for (; j < item->len - 1; j++) item->hmenus[j] = item->hmenus[j + 1]; item->hmenus[j] = NULL; @@ -352,8 +352,8 @@ void uninitMenus(void) for (j = 0; j < m->len; j++) { item = m->items[j]; if (item->len != 0) - // LONGTERM userbug()? - implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); + // LONGTERM uiprivUserBug()? + uiprivImplBug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); if (item->name != NULL) uiprivFree(item->name); if (item->hmenus != NULL) diff --git a/windows/progressbar.cpp b/windows/progressbar.cpp index 3750eb6a..c3a67dd3 100644 --- a/windows/progressbar.cpp +++ b/windows/progressbar.cpp @@ -54,7 +54,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value) } if (value < 0 || value > 100) - userbug("Value %d is out of range for uiProgressBars.", value); + uiprivUserBug("Value %d is out of range for uiProgressBars.", value); if (value == 100) { // because we can't 101 SendMessageW(p->hwnd, PBM_SETRANGE32, 0, 101); From 59835a9bae97bbf8728b780ce5c2678a4e9ceb03 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 21:49:58 -0400 Subject: [PATCH 08/21] Removed the declaration of newControl(): it was completely unused, as it was superceded by uiAllocControl() long ago. --- common/OLD_uipriv.h | 3 --- common/uipriv.h | 3 --- 2 files changed, 6 deletions(-) diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h index ac8ec0cc..f42baf56 100644 --- a/common/OLD_uipriv.h +++ b/common/OLD_uipriv.h @@ -1,7 +1,4 @@ -// control.c -extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); - // shouldquit.c extern int shouldQuit(void); diff --git a/common/uipriv.h b/common/uipriv.h index 530a9794..4c179c47 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -33,9 +33,6 @@ extern void uiprivDoImplBug(const char *file, const char *line, const char *func extern void uiprivDoUserBug(const char *file, const char *line, const char *func, const char *format, ...); #define uiprivUserBug(...) uiprivDoUserBug(__FILE__, uiprivMacro_ns(__LINE__), uiprivMacro__func__, __VA_ARGS__) -// control.c -extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); - // shouldquit.c extern int shouldQuit(void); From f5be05f1437e777d50c9f8e35d5150aa6467e90b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 21:54:46 -0400 Subject: [PATCH 09/21] shouldQuit() -> uiprivShouldQuit(). --- common/OLD_uipriv.h | 3 --- common/shouldquit.c | 2 +- common/uipriv.h | 2 +- darwin/main.m | 2 +- darwin/menu.m | 2 +- unix/menu.c | 2 +- windows/menu.cpp | 2 +- windows/utilwin.cpp | 4 ++-- 8 files changed, 8 insertions(+), 11 deletions(-) diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h index f42baf56..b6e0581d 100644 --- a/common/OLD_uipriv.h +++ b/common/OLD_uipriv.h @@ -1,7 +1,4 @@ -// shouldquit.c -extern int shouldQuit(void); - // areaevents.c typedef struct clickCounter clickCounter; // you should call Reset() to zero-initialize a new instance diff --git a/common/shouldquit.c b/common/shouldquit.c index 4e7aa5c3..dddd879c 100644 --- a/common/shouldquit.c +++ b/common/shouldquit.c @@ -16,7 +16,7 @@ void uiOnShouldQuit(int (*f)(void *), void *data) onShouldQuitData = data; } -int shouldQuit(void) +int uiprivShouldQuit(void) { return (*onShouldQuit)(onShouldQuitData); } diff --git a/common/uipriv.h b/common/uipriv.h index 4c179c47..7d3ff297 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -34,7 +34,7 @@ extern void uiprivDoUserBug(const char *file, const char *line, const char *func #define uiprivUserBug(...) uiprivDoUserBug(__FILE__, uiprivMacro_ns(__LINE__), uiprivMacro__func__, __VA_ARGS__) // shouldquit.c -extern int shouldQuit(void); +extern int uiprivShouldQuit(void); // areaevents.c typedef struct clickCounter clickCounter; diff --git a/darwin/main.m b/darwin/main.m index f3392ce6..6d149fc3 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -91,7 +91,7 @@ static BOOL stepsIsRunning; { // for debugging NSLog(@"in applicationShouldTerminate:"); - if (shouldQuit()) { + if (uiprivShouldQuit()) { canQuit = YES; // this will call terminate:, which is the same as uiQuit() return NSTerminateNow; diff --git a/darwin/menu.m b/darwin/menu.m index ca6cce4b..79adbae6 100644 --- a/darwin/menu.m +++ b/darwin/menu.m @@ -71,7 +71,7 @@ static void mapItemReleaser(void *key, void *value) - (IBAction)onQuitClicked:(id)sender { - if (shouldQuit()) + if (uiprivShouldQuit()) uiQuit(); } diff --git a/unix/menu.c b/unix/menu.c index 3d02e939..17189c8e 100644 --- a/unix/menu.c +++ b/unix/menu.c @@ -81,7 +81,7 @@ static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data) static void onQuitClicked(uiMenuItem *item, uiWindow *w, void *data) { - if (shouldQuit()) + if (uiprivShouldQuit()) uiQuit(); } diff --git a/windows/menu.cpp b/windows/menu.cpp index 09dfcf30..65791bfb 100644 --- a/windows/menu.cpp +++ b/windows/menu.cpp @@ -68,7 +68,7 @@ static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data) static void onQuitClicked(uiMenuItem *item, uiWindow *w, void *data) { - if (shouldQuit()) + if (uiprivShouldQuit()) uiQuit(); } diff --git a/windows/utilwin.cpp b/windows/utilwin.cpp index 28950674..34b72ba8 100644 --- a/windows/utilwin.cpp +++ b/windows/utilwin.cpp @@ -23,8 +23,8 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L return lResult; switch (uMsg) { case WM_QUERYENDSESSION: - // TODO block handler - if (shouldQuit()) { + // TODO block handler (TODO figure out if this meant the Vista-style block handler or not) + if (uiprivShouldQuit()) { uiQuit(); return TRUE; } From 0dddf4a490c4fad781850002807294a444756e6a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 22:26:51 -0400 Subject: [PATCH 10/21] clickCounter -> uiprivClickCounter. --- common/OLD_uipriv.h | 17 ----------------- common/areaevents.c | 4 ++-- common/uipriv.h | 8 ++++---- unix/area.c | 10 +++++----- windows/area.cpp | 4 ++-- windows/area.hpp | 2 +- windows/areaevents.cpp | 12 ++++++------ 7 files changed, 20 insertions(+), 37 deletions(-) diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h index b6e0581d..29583b0c 100644 --- a/common/OLD_uipriv.h +++ b/common/OLD_uipriv.h @@ -1,21 +1,4 @@ -// areaevents.c -typedef struct clickCounter clickCounter; -// you should call Reset() to zero-initialize a new instance -// it doesn't matter that all the non-count fields are zero: the first click will fail the curButton test straightaway, so it'll return 1 and set the rest of the structure accordingly -struct clickCounter { - int curButton; - int rectX0; - int rectY0; - int rectX1; - int rectY1; - uintptr_t prevTime; - int count; -}; -int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist); -extern void clickCounterReset(clickCounter *); -extern int fromScancode(uintptr_t, uiAreaKeyEvent *); - // matrix.c extern void fallbackSkew(uiDrawMatrix *, double, double, double, double); extern void scaleCenter(double, double, double *, double *); diff --git a/common/areaevents.c b/common/areaevents.c index 189673a2..d913b763 100644 --- a/common/areaevents.c +++ b/common/areaevents.c @@ -16,7 +16,7 @@ TODO note the bits about asymmetry and g_rcClick initial value not mattering in // x, y, xdist, ydist, and c.rect must have the same units // so must time, maxTime, and c.prevTime -int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist) +int uiprivClickCounterClick(uiprivClickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist) { // different button than before? if so, don't count if (button != c->curButton) @@ -50,7 +50,7 @@ int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, return c->count; } -void clickCounterReset(clickCounter *c) +void uiprivClickCounterReset(uiprivClickCounter *c) { c->curButton = 0; c->rectX0 = 0; diff --git a/common/uipriv.h b/common/uipriv.h index 7d3ff297..363450a8 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -37,10 +37,10 @@ extern void uiprivDoUserBug(const char *file, const char *line, const char *func extern int uiprivShouldQuit(void); // areaevents.c -typedef struct clickCounter clickCounter; +typedef struct uiprivClickCounter uiprivClickCounter; // you should call Reset() to zero-initialize a new instance // it doesn't matter that all the non-count fields are zero: the first click will fail the curButton test straightaway, so it'll return 1 and set the rest of the structure accordingly -struct clickCounter { +struct uiprivClickCounter { int curButton; int rectX0; int rectY0; @@ -49,8 +49,8 @@ struct clickCounter { uintptr_t prevTime; int count; }; -int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist); -extern void clickCounterReset(clickCounter *); +extern int uiprivClickCounterClick(uiprivClickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist); +extern void uiprivClickCounterReset(uiprivClickCounter *); extern int fromScancode(uintptr_t, uiAreaKeyEvent *); // matrix.c diff --git a/unix/area.c b/unix/area.c index abf868ca..ca245bb0 100644 --- a/unix/area.c +++ b/unix/area.c @@ -19,7 +19,7 @@ struct areaWidget { // construct-only parameters aare not set until after the init() function has returned // we need this particular object available during init(), so put it here instead of in uiArea // keep a pointer in uiArea for convenience, though - clickCounter cc; + uiprivClickCounter cc; }; struct areaWidgetClass { @@ -45,7 +45,7 @@ struct uiArea { int scrollHeight; // note that this is a pointer; see above - clickCounter *cc; + uiprivClickCounter *cc; // for user window drags GdkEventButton *dragevent; @@ -68,7 +68,7 @@ static void areaWidget_init(areaWidget *aw) gtk_widget_set_can_focus(GTK_WIDGET(aw), TRUE); - clickCounterReset(&(aw->cc)); + uiprivClickCounterReset(&(aw->cc)); } static void areaWidget_dispose(GObject *obj) @@ -261,7 +261,7 @@ static gboolean areaWidget_button_press_event(GtkWidget *w, GdkEventButton *e) // e->time is guint32 // e->x and e->y are floating-point; just make them 32-bit integers // maxTime and maxDistance... are gint, which *should* fit, hopefully... - me.Count = clickCounterClick(a->cc, me.Down, + me.Count = uiprivClickCounterClick(a->cc, me.Down, e->x, e->y, e->time, maxTime, maxDistance, maxDistance); @@ -309,7 +309,7 @@ static gboolean onCrossing(areaWidget *aw, int left) uiArea *a = aw->a; (*(a->ah->MouseCrossed))(a->ah, a, left); - clickCounterReset(a->cc); + uiprivClickCounterReset(a->cc); return GDK_EVENT_PROPAGATE; } diff --git a/windows/area.cpp b/windows/area.cpp index ab69ff15..0042fccc 100644 --- a/windows/area.cpp +++ b/windows/area.cpp @@ -168,7 +168,7 @@ uiArea *uiNewArea(uiAreaHandler *ah) a->ah = ah; a->scrolling = FALSE; - clickCounterReset(&(a->cc)); + uiprivClickCounterReset(&(a->cc)); // a->hwnd is assigned in areaWndProc() uiWindowsEnsureCreateControlHWND(0, @@ -190,7 +190,7 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) a->scrolling = TRUE; a->scrollWidth = width; a->scrollHeight = height; - clickCounterReset(&(a->cc)); + uiprivClickCounterReset(&(a->cc)); // a->hwnd is assigned in areaWndProc() uiWindowsEnsureCreateControlHWND(0, diff --git a/windows/area.hpp b/windows/area.hpp index 86a62de6..dfc2bc58 100644 --- a/windows/area.hpp +++ b/windows/area.hpp @@ -18,7 +18,7 @@ struct uiArea { int hwheelCarry; int vwheelCarry; - clickCounter cc; + uiprivClickCounter cc; BOOL capturing; BOOL inside; diff --git a/windows/areaevents.cpp b/windows/areaevents.cpp index 615c06ea..4bf55665 100644 --- a/windows/areaevents.cpp +++ b/windows/areaevents.cpp @@ -92,11 +92,11 @@ static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM l if (inClient && !a->inside) { a->inside = TRUE; (*(a->ah->MouseCrossed))(a->ah, a, 0); - clickCounterReset(&(a->cc)); + uiprivClickCounterReset(&(a->cc)); } else if (!inClient && a->inside) { a->inside = FALSE; (*(a->ah->MouseCrossed))(a->ah, a, 1); - clickCounterReset(&(a->cc)); + uiprivClickCounterReset(&(a->cc)); } } @@ -120,7 +120,7 @@ static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM l // GetMessageTime() returns LONG and GetDoubleClckTime() returns UINT, which are int32 and uint32, respectively, but we don't need to worry about the signedness because for the same bit widths and two's complement arithmetic, s1-s2 == u1-u2 if bits(s1)==bits(s2) and bits(u1)==bits(u2) (and Windows requires two's complement: http://blogs.msdn.com/b/oldnewthing/archive/2005/05/27/422551.aspx) // signedness isn't much of an issue for these calls anyway because http://stackoverflow.com/questions/24022225/what-are-the-sign-extension-rules-for-calling-windows-api-functions-stdcall-t and that we're only using unsigned values (think back to how you (didn't) handle signedness in assembly language) AND because of the above AND because the statistics below (time interval and width/height) really don't make sense if negative // GetSystemMetrics() returns int, which is int32 - me.Count = clickCounterClick(&(a->cc), me.Down, + me.Count = uiprivClickCounterClick(&(a->cc), me.Down, me.X, me.Y, GetMessageTime(), GetDoubleClickTime(), GetSystemMetrics(SM_CXDOUBLECLK) / 2, @@ -164,7 +164,7 @@ static void onMouseEntered(uiArea *a) track(a, TRUE); (*(a->ah->MouseCrossed))(a->ah, a, 0); // TODO figure out why we did this to begin with; either we do it on both GTK+ and Windows or not at all - clickCounterReset(&(a->cc)); + uiprivClickCounterReset(&(a->cc)); } // TODO genericize it so that it can be called above @@ -174,7 +174,7 @@ static void onMouseLeft(uiArea *a) a->inside = FALSE; (*(a->ah->MouseCrossed))(a->ah, a, 1); // TODO figure out why we did this to begin with; either we do it on both GTK+ and Windows or not at all - clickCounterReset(&(a->cc)); + uiprivClickCounterReset(&(a->cc)); } // we use VK_SNAPSHOT as a sentinel because libui will never support the print screen key; that key belongs to the user @@ -325,7 +325,7 @@ BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *l switch (uMsg) { case WM_ACTIVATE: // don't keep the double-click timer running if the user switched programs in between clicks - clickCounterReset(&(a->cc)); + uiprivClickCounterReset(&(a->cc)); *lResult = 0; return TRUE; case WM_MOUSEMOVE: From 24a4b0997c65ea052760657058b338c79046c5e2 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 22:31:17 -0400 Subject: [PATCH 11/21] fromScancode() -> uiprivFromScancode(). --- common/areaevents.c | 2 +- common/uipriv.h | 2 +- unix/area.c | 2 +- windows/areaevents.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/areaevents.c b/common/areaevents.c index d913b763..491a7283 100644 --- a/common/areaevents.c +++ b/common/areaevents.c @@ -151,7 +151,7 @@ static const struct { { 0xFFFF, 0 }, }; -int fromScancode(uintptr_t scancode, uiAreaKeyEvent *ke) +int uiprivFromScancode(uintptr_t scancode, uiAreaKeyEvent *ke) { int i; diff --git a/common/uipriv.h b/common/uipriv.h index 363450a8..8fc3d42e 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -51,7 +51,7 @@ struct uiprivClickCounter { }; extern int uiprivClickCounterClick(uiprivClickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist); extern void uiprivClickCounterReset(uiprivClickCounter *); -extern int fromScancode(uintptr_t, uiAreaKeyEvent *); +extern int uiprivFromScancode(uintptr_t, uiAreaKeyEvent *); // matrix.c extern void fallbackSkew(uiDrawMatrix *, double, double, double, double); diff --git a/unix/area.c b/unix/area.c index ca245bb0..cba1f5e7 100644 --- a/unix/area.c +++ b/unix/area.c @@ -411,7 +411,7 @@ static int areaKeyEvent(uiArea *a, int up, GdkEventKey *e) goto keyFound; } - if (fromScancode(e->hardware_keycode - 8, &ke)) + if (uiprivFromScancode(e->hardware_keycode - 8, &ke)) goto keyFound; // no supported key found; treat as unhandled diff --git a/windows/areaevents.cpp b/windows/areaevents.cpp index 4bf55665..c7014ecb 100644 --- a/windows/areaevents.cpp +++ b/windows/areaevents.cpp @@ -300,7 +300,7 @@ static int areaKeyEvent(uiArea *a, int up, WPARAM wParam, LPARAM lParam) } // and finally everything else - if (fromScancode((lParam >> 16) & 0xFF, &ke)) + if (uiprivFromScancode((lParam >> 16) & 0xFF, &ke)) goto keyFound; // not a supported key, assume unhandled From 01d6422664d56bbf3c9078ec3a7b2fbda39bd2ef Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 22:39:34 -0400 Subject: [PATCH 12/21] Added uipriv prefixes to the matrix functions. --- common/OLD_uipriv.h | 5 ----- common/matrix.c | 6 +++--- common/uipriv.h | 6 +++--- darwin/draw.m | 4 ++-- unix/drawmatrix.c | 4 ++-- windows/drawmatrix.cpp | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h index 29583b0c..95ab829c 100644 --- a/common/OLD_uipriv.h +++ b/common/OLD_uipriv.h @@ -1,8 +1,3 @@ -// matrix.c -extern void fallbackSkew(uiDrawMatrix *, double, double, double, double); -extern void scaleCenter(double, double, double *, double *); -extern void fallbackTransformSize(uiDrawMatrix *, double *, double *); - // OS-specific text.* files extern int uiprivStricmp(const char *a, const char *b); diff --git a/common/matrix.c b/common/matrix.c index 676885d1..93d4d357 100644 --- a/common/matrix.c +++ b/common/matrix.c @@ -18,7 +18,7 @@ void uiDrawMatrixSetIdentity(uiDrawMatrix *m) // see https://msdn.microsoft.com/en-us/library/windows/desktop/ff684171%28v=vs.85%29.aspx#skew_transform // TODO see if there's a way we can avoid the multiplication -void fallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) +void uiprivFallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) { uiDrawMatrix n; @@ -31,7 +31,7 @@ void fallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double ya uiDrawMatrixMultiply(m, &n); } -void scaleCenter(double xCenter, double yCenter, double *x, double *y) +void uiprivScaleCenter(double xCenter, double yCenter, double *x, double *y) { *x = xCenter - (*x * xCenter); *y = yCenter - (*y * yCenter); @@ -39,7 +39,7 @@ void scaleCenter(double xCenter, double yCenter, double *x, double *y) // the basic algorithm is from cairo // but it's the same algorithm as the transform point, just without M31 and M32 taken into account, so let's just do that instead -void fallbackTransformSize(uiDrawMatrix *m, double *x, double *y) +void uiprivFallbackTransformSize(uiDrawMatrix *m, double *x, double *y) { uiDrawMatrix m2; diff --git a/common/uipriv.h b/common/uipriv.h index 8fc3d42e..f9ad4c41 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -54,9 +54,9 @@ extern void uiprivClickCounterReset(uiprivClickCounter *); extern int uiprivFromScancode(uintptr_t, uiAreaKeyEvent *); // matrix.c -extern void fallbackSkew(uiDrawMatrix *, double, double, double, double); -extern void scaleCenter(double, double, double *, double *); -extern void fallbackTransformSize(uiDrawMatrix *, double *, double *); +extern void uiprivFallbackSkew(uiDrawMatrix *, double, double, double, double); +extern void uiprivScaleCenter(double, double, double *, double *); +extern void uiprivFallbackTransformSize(uiDrawMatrix *, double *, double *); // OS-specific text.* files extern int uiprivStricmp(const char *a, const char *b); diff --git a/darwin/draw.m b/darwin/draw.m index 7ca854d2..cf7d8f13 100644 --- a/darwin/draw.m +++ b/darwin/draw.m @@ -334,7 +334,7 @@ void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x m2c(m, &c); xt = x; yt = y; - scaleCenter(xCenter, yCenter, &xt, &yt); + uiprivScaleCenter(xCenter, yCenter, &xt, &yt); c = CGAffineTransformTranslate(c, xt, yt); c = CGAffineTransformScale(c, x, y); c = CGAffineTransformTranslate(c, -xt, -yt); @@ -354,7 +354,7 @@ void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount) void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) { - fallbackSkew(m, x, y, xamount, yamount); + uiprivFallbackSkew(m, x, y, xamount, yamount); } void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src) diff --git a/unix/drawmatrix.c b/unix/drawmatrix.c index ac7ac579..7d15d920 100644 --- a/unix/drawmatrix.c +++ b/unix/drawmatrix.c @@ -39,7 +39,7 @@ void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x m2c(m, &c); xt = x; yt = y; - scaleCenter(xCenter, yCenter, &xt, &yt); + uiprivScaleCenter(xCenter, yCenter, &xt, &yt); cairo_matrix_translate(&c, xt, yt); cairo_matrix_scale(&c, x, y); cairo_matrix_translate(&c, -xt, -yt); @@ -59,7 +59,7 @@ void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount) void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) { - fallbackSkew(m, x, y, xamount, yamount); + uiprivFallbackSkew(m, x, y, xamount, yamount); } void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src) diff --git a/windows/drawmatrix.cpp b/windows/drawmatrix.cpp index 090972a5..4ddc5e9a 100644 --- a/windows/drawmatrix.cpp +++ b/windows/drawmatrix.cpp @@ -113,5 +113,5 @@ void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y) void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y) { - fallbackTransformSize(m, x, y); + uiprivFallbackTransformSize(m, x, y); } From 8e2004cf6773cc8d880f269d4e0451af229e0729 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 22:43:14 -0400 Subject: [PATCH 13/21] struct graphemes -> uiprivGraphemes. Also deleted OLD_uipriv.h now that that one is settled. --- common/OLD_uipriv.h | 3 --- common/attrstr.c | 2 +- common/attrstr.h | 5 +++-- darwin/graphemes.m | 6 +++--- unix/graphemes.c | 6 +++--- windows/graphemes.cpp | 6 +++--- 6 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 common/OLD_uipriv.h diff --git a/common/OLD_uipriv.h b/common/OLD_uipriv.h deleted file mode 100644 index 95ab829c..00000000 --- a/common/OLD_uipriv.h +++ /dev/null @@ -1,3 +0,0 @@ - -// OS-specific text.* files -extern int uiprivStricmp(const char *a, const char *b); diff --git a/common/attrstr.c b/common/attrstr.c index ee2b1616..2445c330 100644 --- a/common/attrstr.c +++ b/common/attrstr.c @@ -18,7 +18,7 @@ struct uiAttributedString { size_t *u16tou8; // this is lazily created to keep things from getting *too* slow - struct graphemes *graphemes; + uiprivGraphemes *graphemes; }; static void resize(uiAttributedString *s, size_t u8, size_t u16) diff --git a/common/attrstr.h b/common/attrstr.h index 54e43feb..475589f3 100644 --- a/common/attrstr.h +++ b/common/attrstr.h @@ -28,10 +28,11 @@ extern size_t *uiprivAttributedStringCopyUTF8ToUTF16Table(const uiAttributedStri extern size_t *uiprivAttributedStringCopyUTF16ToUTF8Table(const uiAttributedString *s, size_t *n); // per-OS graphemes.c/graphemes.cpp/graphemes.m/etc. -struct graphemes { +typedef struct uiprivGraphemes uiprivGraphemes; +struct uiprivGraphemes { size_t len; size_t *pointsToGraphemes; size_t *graphemesToPoints; }; extern int uiprivGraphemesTakesUTF16(void); -extern struct graphemes *uiprivNewGraphemes(void *s, size_t len); +extern uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len); diff --git a/darwin/graphemes.m b/darwin/graphemes.m index 3fdbc17e..a92534f3 100644 --- a/darwin/graphemes.m +++ b/darwin/graphemes.m @@ -10,16 +10,16 @@ int uiprivGraphemesTakesUTF16(void) return 1; } -struct graphemes *uiprivNewGraphemes(void *s, size_t len) +uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len) { - struct graphemes *g; + uiprivGraphemes *g; UniChar *str = (UniChar *) s; CFStringRef cfstr; size_t ppos, gpos; CFRange range; size_t i; - g = uiprivNew(struct graphemes); + g = uiprivNew(uiprivGraphemes); cfstr = CFStringCreateWithCharactersNoCopy(NULL, str, len, kCFAllocatorNull); if (cfstr == NULL) { diff --git a/unix/graphemes.c b/unix/graphemes.c index b5edb95a..952f1ef8 100644 --- a/unix/graphemes.c +++ b/unix/graphemes.c @@ -7,16 +7,16 @@ int uiprivGraphemesTakesUTF16(void) return 0; } -struct graphemes *uiprivNewGraphemes(void *s, size_t len) +uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len) { - struct graphemes *g; + uiprivGraphemes *g; char *text = (char *) s; size_t lenchars; PangoLogAttr *logattrs; size_t i; size_t *op; - g = uiprivNew(struct graphemes); + g = uiprivNew(uiprivGraphemes); // TODO see if we can use the utf routines lenchars = g_utf8_strlen(text, -1); diff --git a/windows/graphemes.cpp b/windows/graphemes.cpp index 266cf97f..c11dd203 100644 --- a/windows/graphemes.cpp +++ b/windows/graphemes.cpp @@ -11,13 +11,13 @@ int uiprivGraphemesTakesUTF16(void) return 1; } -struct graphemes *uiprivNewGraphemes(void *s, size_t len) +uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len) { - struct graphemes *g; + uiprivGraphemes *g; WCHAR *str; size_t *pPTG, *pGTP; - g = uiprivNew(struct graphemes); + g = uiprivNew(uiprivGraphemes); g->len = 0; str = (WCHAR *) s; From c3992cc6473c640c2d260d4e7e18bd95464614f1 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 23:08:57 -0400 Subject: [PATCH 14/21] uipriv-ized utf.c. --- common/attrstr.c | 12 ++++++------ common/controlsigs.h | 2 ++ common/utf.c | 41 +++++++++++++++++++++-------------------- common/utf.h | 36 ++++++++++++++++++++---------------- windows/utf16.cpp | 12 ++++++------ 5 files changed, 55 insertions(+), 48 deletions(-) diff --git a/common/attrstr.c b/common/attrstr.c index 2445c330..f2cdb66b 100644 --- a/common/attrstr.c +++ b/common/attrstr.c @@ -93,11 +93,11 @@ static void u8u16len(const char *str, size_t *n8, size_t *n16) *n8 = 0; *n16 = 0; while (*str) { - str = utf8DecodeRune(str, 0, &rune); + str = uiprivUTF8DecodeRune(str, 0, &rune); // TODO document the use of the function vs a pointer subtract here // TODO also we need to consider namespace collision with utf.h... - *n8 += utf8EncodeRune(rune, buf); - *n16 += utf16EncodeRune(rune, buf16); + *n8 += uiprivUTF8EncodeRune(rune, buf); + *n16 += uiprivUTF16EncodeRune(rune, buf16); } } @@ -179,9 +179,9 @@ void uiAttributedStringInsertAtUnattributed(uiAttributedString *s, const char *s while (*str) { size_t n; - str = utf8DecodeRune(str, 0, &rune); - n = utf8EncodeRune(rune, buf); - n16 = utf16EncodeRune(rune, buf16); + str = uiprivUTF8DecodeRune(str, 0, &rune); + n = uiprivUTF8EncodeRune(rune, buf); + n16 = uiprivUTF16EncodeRune(rune, buf16); s->s[old] = buf[0]; s->u8tou16[old] = old16; if (n > 1) { diff --git a/common/controlsigs.h b/common/controlsigs.h index 1cbf18d5..06397187 100644 --- a/common/controlsigs.h +++ b/common/controlsigs.h @@ -1,5 +1,7 @@ // 24 april 2016 +// TODO if I don't decide to remove these outright, should they be renamed uiprivTypeNameSignature? these aren't real symbols, so... + #define uiAreaSignature 0x41726561 #define uiBoxSignature 0x426F784C #define uiButtonSignature 0x42746F6E diff --git a/common/utf.c b/common/utf.c index 9efb9493..5577529b 100644 --- a/common/utf.c +++ b/common/utf.c @@ -1,5 +1,6 @@ // utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/ // 10 november 2016 +// function names have been altered to avoid namespace collisions in libui static builds (see utf.h) #include "utf.h" // this code imitates Go's unicode/utf8 and unicode/utf16 @@ -9,7 +10,7 @@ // encoded must be at most 4 bytes // TODO clean this code up somehow -size_t utf8EncodeRune(uint32_t rune, char *encoded) +size_t uiprivUTF8EncodeRune(uint32_t rune, char *encoded) { uint8_t b, c, d, e; size_t n; @@ -72,7 +73,7 @@ done: return n; } -const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune) +const char *uiprivUTF8DecodeRune(const char *s, size_t nElem, uint32_t *rune) { uint8_t b, c; uint8_t lowestAllowed, highestAllowed; @@ -172,7 +173,7 @@ const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune) } // encoded must have at most 2 elements -size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded) +size_t uiprivUTF16EncodeRune(uint32_t rune, uint16_t *encoded) { uint16_t low, high; @@ -198,7 +199,7 @@ size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded) } // TODO see if this can be cleaned up somehow -const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune) +const uint16_t *uiprivUTF16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune) { uint16_t high, low; @@ -240,7 +241,7 @@ const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune) // TODO find a way to reduce the code in all of these somehow // TODO find a way to remove u as well -size_t utf8RuneCount(const char *s, size_t nElem) +size_t uiprivUTF8RuneCount(const char *s, size_t nElem) { size_t len; uint32_t rune; @@ -251,7 +252,7 @@ size_t utf8RuneCount(const char *s, size_t nElem) len = 0; t = s; while (nElem != 0) { - u = utf8DecodeRune(t, nElem, &rune); + u = uiprivUTF8DecodeRune(t, nElem, &rune); len++; nElem -= u - t; t = u; @@ -260,13 +261,13 @@ size_t utf8RuneCount(const char *s, size_t nElem) } len = 0; while (*s) { - s = utf8DecodeRune(s, nElem, &rune); + s = uiprivUTF8DecodeRune(s, nElem, &rune); len++; } return len; } -size_t utf8UTF16Count(const char *s, size_t nElem) +size_t uiprivUTF8UTF16Count(const char *s, size_t nElem) { size_t len; uint32_t rune; @@ -278,8 +279,8 @@ size_t utf8UTF16Count(const char *s, size_t nElem) len = 0; t = s; while (nElem != 0) { - u = utf8DecodeRune(t, nElem, &rune); - len += utf16EncodeRune(rune, encoded); + u = uiprivUTF8DecodeRune(t, nElem, &rune); + len += uiprivUTF16EncodeRune(rune, encoded); nElem -= u - t; t = u; } @@ -287,13 +288,13 @@ size_t utf8UTF16Count(const char *s, size_t nElem) } len = 0; while (*s) { - s = utf8DecodeRune(s, nElem, &rune); - len += utf16EncodeRune(rune, encoded); + s = uiprivUTF8DecodeRune(s, nElem, &rune); + len += uiprivUTF16EncodeRune(rune, encoded); } return len; } -size_t utf16RuneCount(const uint16_t *s, size_t nElem) +size_t uiprivUTF16RuneCount(const uint16_t *s, size_t nElem) { size_t len; uint32_t rune; @@ -304,7 +305,7 @@ size_t utf16RuneCount(const uint16_t *s, size_t nElem) len = 0; t = s; while (nElem != 0) { - u = utf16DecodeRune(t, nElem, &rune); + u = uiprivUTF16DecodeRune(t, nElem, &rune); len++; nElem -= u - t; t = u; @@ -313,13 +314,13 @@ size_t utf16RuneCount(const uint16_t *s, size_t nElem) } len = 0; while (*s) { - s = utf16DecodeRune(s, nElem, &rune); + s = uiprivUTF16DecodeRune(s, nElem, &rune); len++; } return len; } -size_t utf16UTF8Count(const uint16_t *s, size_t nElem) +size_t uiprivUTF16UTF8Count(const uint16_t *s, size_t nElem) { size_t len; uint32_t rune; @@ -331,8 +332,8 @@ size_t utf16UTF8Count(const uint16_t *s, size_t nElem) len = 0; t = s; while (nElem != 0) { - u = utf16DecodeRune(t, nElem, &rune); - len += utf8EncodeRune(rune, encoded); + u = uiprivUTF16DecodeRune(t, nElem, &rune); + len += uiprivUTF8EncodeRune(rune, encoded); nElem -= u - t; t = u; } @@ -340,8 +341,8 @@ size_t utf16UTF8Count(const uint16_t *s, size_t nElem) } len = 0; while (*s) { - s = utf16DecodeRune(s, nElem, &rune); - len += utf8EncodeRune(rune, encoded); + s = uiprivUTF16DecodeRune(s, nElem, &rune); + len += uiprivUTF8EncodeRune(rune, encoded); } return len; } diff --git a/common/utf.h b/common/utf.h index b810a49d..41e556f8 100644 --- a/common/utf.h +++ b/common/utf.h @@ -1,25 +1,29 @@ // utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/ // 10 november 2016 +// note the overridden names with uipriv at the beginning; this avoids potential symbol clashes when building libui as a static library +// LONGTERM find a way to encode the name overrides directly into the utf library + #ifdef __cplusplus extern "C" { #endif +// TODO (for utf itself as well) should this go outside the extern "C" block or not #include #include // if nElem == 0, assume the buffer has no upper limit and is '\0' terminated // otherwise, assume buffer is NOT '\0' terminated but is bounded by nElem *elements* -extern size_t utf8EncodeRune(uint32_t rune, char *encoded); -extern const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune); -extern size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded); -extern const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune); +extern size_t uiprivUTF8EncodeRune(uint32_t rune, char *encoded); +extern const char *uiprivUTF8DecodeRune(const char *s, size_t nElem, uint32_t *rune); +extern size_t uiprivUTF16EncodeRune(uint32_t rune, uint16_t *encoded); +extern const uint16_t *uiprivUTF16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune); -extern size_t utf8RuneCount(const char *s, size_t nElem); -extern size_t utf8UTF16Count(const char *s, size_t nElem); -extern size_t utf16RuneCount(const uint16_t *s, size_t nElem); -extern size_t utf16UTF8Count(const uint16_t *s, size_t nElem); +extern size_t uiprivUTF8RuneCount(const char *s, size_t nElem); +extern size_t uiprivUTF8UTF16Count(const char *s, size_t nElem); +extern size_t uiprivUTF16RuneCount(const uint16_t *s, size_t nElem); +extern size_t uiprivUTF16UTF8Count(const uint16_t *s, size_t nElem); #ifdef __cplusplus } @@ -33,27 +37,27 @@ extern size_t utf16UTF8Count(const uint16_t *s, size_t nElem); // TODO same for UniChar/unichar on Mac? if both are unsigned then we have nothing to worry about #if defined(_MSC_VER) -inline size_t utf16EncodeRune(uint32_t rune, __wchar_t *encoded) +inline size_t uiprivUTF16EncodeRune(uint32_t rune, __wchar_t *encoded) { - return utf16EncodeRune(rune, reinterpret_cast(encoded)); + return uiprivUTF16EncodeRune(rune, reinterpret_cast(encoded)); } -inline const __wchar_t *utf16DecodeRune(const __wchar_t *s, size_t nElem, uint32_t *rune) +inline const __wchar_t *uiprivUTF16DecodeRune(const __wchar_t *s, size_t nElem, uint32_t *rune) { const uint16_t *ret; - ret = utf16DecodeRune(reinterpret_cast(s), nElem, rune); + ret = uiprivUTF16DecodeRune(reinterpret_cast(s), nElem, rune); return reinterpret_cast(ret); } -inline size_t utf16RuneCount(const __wchar_t *s, size_t nElem) +inline size_t uiprivUTF16RuneCount(const __wchar_t *s, size_t nElem) { - return utf16RuneCount(reinterpret_cast(s), nElem); + return uiprivUTF16RuneCount(reinterpret_cast(s), nElem); } -inline size_t utf16UTF8Count(const __wchar_t *s, size_t nElem) +inline size_t uiprivUTF16UTF8Count(const __wchar_t *s, size_t nElem) { - return utf16UTF8Count(reinterpret_cast(s), nElem); + return uiprivUTF16UTF8Count(reinterpret_cast(s), nElem); } #endif diff --git a/windows/utf16.cpp b/windows/utf16.cpp index 6afd0b0e..b9e57599 100644 --- a/windows/utf16.cpp +++ b/windows/utf16.cpp @@ -12,12 +12,12 @@ WCHAR *toUTF16(const char *str) if (*str == '\0') // empty string return emptyUTF16(); - n = utf8UTF16Count(str, 0); + n = uiprivUTF8UTF16Count(str, 0); wstr = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); wp = wstr; while (*str) { - str = utf8DecodeRune(str, 0, &rune); - n = utf16EncodeRune(rune, wp); + str = uiprivUTF8DecodeRune(str, 0, &rune); + n = uiprivUTF16EncodeRune(rune, wp); wp += n; } return wstr; @@ -32,12 +32,12 @@ char *toUTF8(const WCHAR *wstr) if (*wstr == L'\0') // empty string return emptyUTF8(); - n = utf16RuneCount(wstr, 0); + n = uiprivUTF16RuneCount(wstr, 0); str = (char *) uiprivAlloc((n + 1) * sizeof (char), "char[]"); sp = str; while (*wstr) { - wstr = utf16DecodeRune(wstr, 0, &rune); - n = utf8EncodeRune(rune, sp); + wstr = uiprivUTF16DecodeRune(wstr, 0, &rune); + n = uiprivUTF8EncodeRune(rune, sp); sp += n; } return str; From fcc26ab9a97ce14dc1bc3334e8901683b1aacc85 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 23:10:11 -0400 Subject: [PATCH 15/21] =?UTF-8?q?Fixed=20a=20serious=20bug=20in=20windows/?= =?UTF-8?q?utf16.cpp=20that=20went=20unnoticed=20for=20this=20long:=20we?= =?UTF-8?q?=20wanted=20utf16UTF8Count(),=20not=20utf16RuneCount(),=20in=20?= =?UTF-8?q?toUTF8();=20any=20non-ASCII=20text=20had=20the=20wrong=20number?= =?UTF-8?q?=20of=20bytes,=20and=20thus=20random=20heap=20corruption.=20The?= =?UTF-8?q?=20string=20"=E9=8E=BF=E5=B6=84=E7=B6=94=E9=8E=B4=E6=84=AC?= =?UTF-8?q?=E5=A7=9B=E7=80=B9=E5=B1=BE=E5=9E=9A=E9=8A=86"=20(taken=20from?= =?UTF-8?q?=20the=20completely=20unrelated=20#337)=20and=20the=20Set=20But?= =?UTF-8?q?ton=20Text=20button=20was=20enough=20to=20trigger=20this.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- windows/utf16.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/utf16.cpp b/windows/utf16.cpp index b9e57599..131759e9 100644 --- a/windows/utf16.cpp +++ b/windows/utf16.cpp @@ -32,7 +32,7 @@ char *toUTF8(const WCHAR *wstr) if (*wstr == L'\0') // empty string return emptyUTF8(); - n = uiprivUTF16RuneCount(wstr, 0); + n = uiprivUTF16UTF8Count(wstr, 0); str = (char *) uiprivAlloc((n + 1) * sizeof (char), "char[]"); sp = str; while (*wstr) { From b3df05eb8eefd2270f6fcbd62b709f9a237cfda8 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 15 Apr 2018 23:16:04 -0400 Subject: [PATCH 16/21] More TODOs. (This was originally added in a prior commit but I forgot to mention it; I wanted it to be LONGTERM but forgot about that the first time.) --- common/controlsigs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/controlsigs.h b/common/controlsigs.h index 06397187..944afa9b 100644 --- a/common/controlsigs.h +++ b/common/controlsigs.h @@ -1,6 +1,6 @@ // 24 april 2016 -// TODO if I don't decide to remove these outright, should they be renamed uiprivTypeNameSignature? these aren't real symbols, so... +// LONGTERM if I don't decide to remove these outright, should they be renamed uiprivTypeNameSignature? these aren't real symbols, so... #define uiAreaSignature 0x41726561 #define uiBoxSignature 0x426F784C From 7cd88ddd03cd912aeca3f6d6f8acf2d15b0bcc5a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 16 Apr 2018 01:33:21 -0400 Subject: [PATCH 17/21] More notes. --- _notes/misc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_notes/misc b/_notes/misc index 5d40d908..2fd78a92 100644 --- a/_notes/misc +++ b/_notes/misc @@ -184,3 +184,9 @@ https://msdn.microsoft.com/en-us/library/windows/desktop/aa969513(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa969527(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/dd388198(v=vs.85).aspx I hope the MFC ribbon can have customizable colors too, otherwise I'll have to do some serious image processing... + +windows debugging +https://msdn.microsoft.com/en-us/library/windows/desktop/hh780351(v=vs.85).aspx + https://msdn.microsoft.com/en-us/library/windows/desktop/ff476881(v=vs.85).aspx#Debug + https://msdn.microsoft.com/en-us/library/windows/desktop/hh780343(v=vs.85).aspx + https://msdn.microsoft.com/en-us/library/windows/desktop/dn457937(v=vs.85).aspx From 750f4214b72c42924c9fd5dfbd4d40d3c9352193 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 16 Apr 2018 02:31:24 -0400 Subject: [PATCH 18/21] Cleaned up private symbols (and in one case, explicit initialization) of symbols in all *.c files in common/. Now to decide what to do about whether uipriv.h should include ui.h and if attrstr.h should even stay, and then I can merge this back. --- common/control.c | 4 ++-- common/shouldquit.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/control.c b/common/control.c index 3b5b8286..98cb94aa 100644 --- a/common/control.c +++ b/common/control.c @@ -57,14 +57,14 @@ void uiControlDisable(uiControl *c) (*(c->Disable))(c); } -#define uiControlSignature 0x7569436F +#define uiprivControlSignature 0x7569436F uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr) { uiControl *c; c = (uiControl *) uiprivAlloc(size, typenamestr); - c->Signature = uiControlSignature; + c->Signature = uiprivControlSignature; c->OSSignature = OSsig; c->TypeSignature = typesig; return c; diff --git a/common/shouldquit.c b/common/shouldquit.c index dddd879c..df57b6c5 100644 --- a/common/shouldquit.c +++ b/common/shouldquit.c @@ -8,7 +8,7 @@ static int defaultOnShouldQuit(void *data) } static int (*onShouldQuit)(void *) = defaultOnShouldQuit; -static void *onShouldQuitData; +static void *onShouldQuitData = NULL; void uiOnShouldQuit(int (*f)(void *), void *data) { From ee986363c86ceaaa73eaf083735c050a3d8458b7 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 16 Apr 2018 20:35:47 -0400 Subject: [PATCH 19/21] More notes. --- _notes/misc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/_notes/misc b/_notes/misc index 2fd78a92..649d6cb4 100644 --- a/_notes/misc +++ b/_notes/misc @@ -190,3 +190,8 @@ https://msdn.microsoft.com/en-us/library/windows/desktop/hh780351(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ff476881(v=vs.85).aspx#Debug https://msdn.microsoft.com/en-us/library/windows/desktop/hh780343(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/dn457937(v=vs.85).aspx + +more OS2 stuff +https://www.google.com/search?q=%22ibm+graphics+development+toolkit%22&ie=utf-8&oe=utf-8&client=firefox-b-1 +https://www.google.com/search?q=%22os%2F2+graphics+development+toolkit%22&ie=utf-8&oe=utf-8&client=firefox-b-1 +http://www.edm2.com/index.php/IBM_OS/2_Developer%27s_Packages From 4df47a6ee8a05f1109b60f6bd45f65c957ac3deb Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 17 Apr 2018 21:04:04 -0400 Subject: [PATCH 20/21] Decided what to do about uipriv.h including ui.h (uipriv_OS.h* wrecks that plan, so make a note of us not doing it). Now to just decide what to do about attrstr.h and then we can merge back. --- common/uipriv.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common/uipriv.h b/common/uipriv.h index f9ad4c41..6441ada5 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -1,4 +1,5 @@ // 6 april 2015 +// note: this file should not include ui.h, as the OS-specific ui_*.h files are included between that one and this one in the OS-specific uipriv_*.h* files #include #include #include "controlsigs.h" From 52dc39a5537432c34cd1cdd17faf10fff77bb86f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 18 Apr 2018 00:54:24 -0400 Subject: [PATCH 21/21] Decided to keep attrstr.h for now; removed extern "C" hack from attrstr.hpp on Windows and moved it into attrstr.h. Let's merge back. --- common/attrstr.h | 8 ++++++++ windows/attrstr.hpp | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/attrstr.h b/common/attrstr.h index 475589f3..69ada5c1 100644 --- a/common/attrstr.h +++ b/common/attrstr.h @@ -1,5 +1,9 @@ // 19 february 2018 +#ifdef __cplusplus +extern "C" { +#endif + // attribute.c extern uiAttribute *uiprivAttributeRetain(uiAttribute *a); extern void uiprivAttributeRelease(uiAttribute *a); @@ -36,3 +40,7 @@ struct uiprivGraphemes { }; extern int uiprivGraphemesTakesUTF16(void); extern uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len); + +#ifdef __cplusplus +} +#endif diff --git a/windows/attrstr.hpp b/windows/attrstr.hpp index 449000ed..bd522ca1 100644 --- a/windows/attrstr.hpp +++ b/windows/attrstr.hpp @@ -1,7 +1,5 @@ // 11 march 2018 -extern "C" { #include "../common/attrstr.h" -} // dwrite.cpp extern IDWriteFactory *dwfactory;