From f155414617de37ab49c81f8d9fa352dc31e77d80 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Thu, 31 Oct 2024 18:59:24 -0400 Subject: [PATCH] add traces for library.c and xlib.c, also another internal function for dpy Signed-off-by: Thomas E. Dickey --- src/file.c | 18 +++++--- src/library.c | 104 ++++++++++++++++++++++++++++++++++------------- src/xcursorint.h | 18 +++++--- src/xlib.c | 71 ++++++++++++++++++++++---------- 4 files changed, 148 insertions(+), 63 deletions(-) diff --git a/src/file.c b/src/file.c index c37cd0a..31f883e 100644 --- a/src/file.c +++ b/src/file.c @@ -43,10 +43,10 @@ void _XcursorTrace(const char *fmt, ...) } } -unsigned _XcursorReturnUint(unsigned code) +void *_XcursorReturnAddr(void *addr) { - _XcursorTrace(T_RETURN(u), code); - return code; + _XcursorTrace(T_RETURN(p), addr); + return addr; } int _XcursorReturnCode(int code) @@ -55,10 +55,16 @@ int _XcursorReturnCode(int code) return code; } -void *_XcursorReturnAddr(void *addr) +unsigned long _XcursorReturnLong(unsigned long code) { - _XcursorTrace(T_RETURN(p), addr); - return addr; + _XcursorTrace(T_RETURN(lu), code); + return code; +} + +unsigned _XcursorReturnUint(unsigned code) +{ + _XcursorTrace(T_RETURN(u), code); + return code; } void _XcursorReturnVoid(void) diff --git a/src/library.c b/src/library.c index 0d206a5..d483aff 100644 --- a/src/library.c +++ b/src/library.c @@ -315,8 +315,11 @@ XcursorLibraryLoadImage (const char *file, const char *theme, int size) FILE *f = NULL; XcursorImage *image = NULL; + enterFunc((T_CALLED(XcursorLibraryLoadImage) "(\"%s\",\"%s\", %d)\n", + NonNull(file), NonNull(theme), size)); + if (!file) - return NULL; + returnAddr(NULL); if (theme) f = XcursorScanTheme (theme, file); @@ -327,7 +330,7 @@ XcursorLibraryLoadImage (const char *file, const char *theme, int size) image = XcursorFileLoadImage (f, size); fclose (f); } - return image; + returnAddr(image); } static XcursorImages * @@ -362,8 +365,11 @@ XcursorLibraryLoadImages (const char *file, const char *theme, int size) FILE *f = NULL; XcursorImages *images = NULL; + enterFunc((T_CALLED(XcursorLibraryLoadImages) "(\"%s\", \"%s\", %d)\n", + NonNull(file), NonNull(theme), size)); + if (!file) - return NULL; + returnAddr(NULL); if (theme) f = XcursorScanTheme (theme, file); @@ -376,17 +382,20 @@ XcursorLibraryLoadImages (const char *file, const char *theme, int size) XcursorImagesSetName (images, file); fclose (f); } - return images; + returnAddr(images); } Cursor XcursorLibraryLoadCursor (Display *dpy, const char *file) { XcursorImages *images; - Cursor cursor; + Cursor cursor = 0; + + enterFunc((T_CALLED(XcursorLibraryLoadCursor) "(%p, \"%s\")\n", + (void*)dpy, NonNull(file))); if (!file) - return 0; + returnLong(cursor); images = _XcursorLibraryLoadImages (dpy, file); if (!images) @@ -394,16 +403,17 @@ XcursorLibraryLoadCursor (Display *dpy, const char *file) int id = XcursorLibraryShape (file); if (id >= 0) - return _XcursorCreateFontCursor (dpy, (unsigned) id); - else - return 0; + cursor = _XcursorCreateFontCursor (dpy, (unsigned) id); } - cursor = XcursorImagesLoadCursor (dpy, images); - XcursorImagesDestroy (images); + else + { + cursor = XcursorImagesLoadCursor (dpy, images); + XcursorImagesDestroy (images); #if defined HAVE_XFIXES && XFIXES_MAJOR >= 2 - XFixesSetCursorName (dpy, cursor, file); + XFixesSetCursorName (dpy, cursor, file); #endif - return cursor; + } + returnLong(cursor); } XcursorCursors * @@ -412,8 +422,11 @@ XcursorLibraryLoadCursors (Display *dpy, const char *file) XcursorImages *images; XcursorCursors *cursors; + enterFunc((T_CALLED(XcursorLibraryLoadCursors) "(%p, \"%s\")\n", + (void*)dpy, NonNull(file))); + if (!file) - return NULL; + returnAddr(NULL); images = _XcursorLibraryLoadImages (dpy, file); if (!images) @@ -443,7 +456,7 @@ XcursorLibraryLoadCursors (Display *dpy, const char *file) cursors = XcursorImagesLoadCursors (dpy, images); XcursorImagesDestroy (images); } - return cursors; + returnAddr(cursors); } static const char _XcursorStandardNames[] = @@ -543,44 +556,75 @@ XcursorImage * XcursorShapeLoadImage (unsigned int shape, const char *theme, int size) { unsigned int id = shape >> 1; + XcursorImage *result = NULL; + + enterFunc((T_CALLED(XcursorShapeLoadImage) "(%u, \"%s\", %d)\n", + shape, NonNull(theme), size)); if (id < NUM_STANDARD_NAMES) - return XcursorLibraryLoadImage (STANDARD_NAME (id), theme, size); - else - return NULL; + result = XcursorLibraryLoadImage (STANDARD_NAME (id), theme, size); + + returnAddr(result); +} + +XcursorImages * +_XcursorShapeLoadImages (Display *dpy, unsigned int shape) +{ + unsigned int id = shape >> 1; + XcursorImages *result = NULL; + + enterFunc((T_CALLED(_XcursorShapeLoadImages) "(%p, %u)\n", + (void*)dpy, shape)); + + if (id < NUM_STANDARD_NAMES) + result = _XcursorLibraryLoadImages (dpy, STANDARD_NAME (id)); + + returnAddr(result); } XcursorImages * XcursorShapeLoadImages (unsigned int shape, const char *theme, int size) { unsigned int id = shape >> 1; + XcursorImages *result = NULL; + + enterFunc((T_CALLED(XcursorShapeLoadImages) "(%u, \"%s\", %d)\n", + shape, NonNull(theme), size)); if (id < NUM_STANDARD_NAMES) - return XcursorLibraryLoadImages (STANDARD_NAME (id), theme, size); - else - return NULL; + result = XcursorLibraryLoadImages (STANDARD_NAME (id), theme, size); + + returnAddr(result); } Cursor XcursorShapeLoadCursor (Display *dpy, unsigned int shape) { unsigned int id = shape >> 1; + Cursor result = None; + + enterFunc((T_CALLED(XcursorShapeLoadCursor) "(%p, %u)\n", + (void*)dpy, shape)); if (id < NUM_STANDARD_NAMES) - return XcursorLibraryLoadCursor (dpy, STANDARD_NAME (id)); - else - return 0; + result = XcursorLibraryLoadCursor (dpy, STANDARD_NAME (id)); + + returnLong(result); } XcursorCursors * XcursorShapeLoadCursors (Display *dpy, unsigned int shape) { unsigned int id = shape >> 1; + XcursorCursors *result = NULL; + + enterFunc((T_CALLED(XcursorShapeLoadCursors) "(%p, %u)\n", + (void*)dpy, shape)); if (id < NUM_STANDARD_NAMES) - return XcursorLibraryLoadCursors (dpy, STANDARD_NAME (id)); - else - return NULL; + result = XcursorLibraryLoadCursors (dpy, STANDARD_NAME (id)); + + returnAddr(result); } int @@ -588,6 +632,8 @@ XcursorLibraryShape (const char *library) { int low, high; + enterFunc((T_CALLED(XcursorLibraryShape) "(%s)\n", NonNull(library))); + low = 0; high = NUM_STANDARD_NAMES - 1; while (low < high - 1) @@ -595,7 +641,7 @@ XcursorLibraryShape (const char *library) int mid = (low + high) >> 1; int c = strcmp (library, STANDARD_NAME (mid)); if (c == 0) - return (mid << 1); + returnCode(mid << 1); if (c > 0) low = mid; else @@ -607,5 +653,5 @@ XcursorLibraryShape (const char *library) return (low << 1); low++; } - return -1; + returnCode(-1); } diff --git a/src/xcursorint.h b/src/xcursorint.h index 2ece011..36e4698 100644 --- a/src/xcursorint.h +++ b/src/xcursorint.h @@ -125,24 +125,30 @@ _XcursorFileLoadImages (FILE *file, int size, XcursorBool resize); XcursorImages * _XcursorFilenameLoadImages (const char *file, int size, XcursorBool resize); +XcursorImages * +_XcursorShapeLoadImages (Display *dpy, unsigned int shape); + #ifdef DEBUG_XCURSOR void _XcursorTrace(const char *fmt, ...) __attribute__((format(printf,1,2))); -unsigned _XcursorReturnUint(unsigned code); -int _XcursorReturnCode(int code); void *_XcursorReturnAddr(void *addr); +int _XcursorReturnCode(int code); +unsigned long _XcursorReturnLong(unsigned long code); +unsigned _XcursorReturnUint(unsigned code); void _XcursorReturnVoid(void); #define T_CALLED(func) "called: { " #func #define T_RETURN(form) "return: } %" #form "\n" #define enterFunc(params) _XcursorTrace params -#define returnUint(code) return _XcursorReturnUint(code) -#define returnCode(code) return _XcursorReturnCode(code) #define returnAddr(addr) return _XcursorReturnAddr(addr) +#define returnCode(code) return _XcursorReturnCode(code) +#define returnLong(code) return _XcursorReturnLong(code) +#define returnUint(code) return _XcursorReturnUint(code) #define returnVoid() do { _XcursorReturnVoid(); return; } while (0) #else #define enterFunc(params) /* nothing */ -#define returnUint(code) return (code) -#define returnCode(code) return (code) #define returnAddr(addr) return (addr) +#define returnCode(code) return (code) +#define returnLong(code) return (code) +#define returnUint(code) return (code) #define returnVoid() return #endif diff --git a/src/xlib.c b/src/xlib.c index 63f0225..0d83770 100644 --- a/src/xlib.c +++ b/src/xlib.c @@ -1,4 +1,5 @@ /* + * Copyright © 2024 Thomas E. Dickey * Copyright © 2002 Keith Packard * * Permission to use, copy, modify, distribute, and sell this software and its @@ -90,19 +91,23 @@ XcursorTryShapeCursor (Display *dpy, { Cursor cursor = None; + enterFunc((T_CALLED(XcursorTryShapeCursor) "(%p, %lu, %lu, %u, %u, %p, %p)\n", + (void*)dpy, source_font, mask_font, + source_char, mask_char, + (const void*)foreground, + (const void*)background)); + if (!dpy || !source_font || !mask_font || !foreground || !background) - return 0; + returnLong(None); if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) - return None; + returnLong(None); if (source_font == mask_font && _XcursorFontIsCursor (dpy, source_font) && source_char + 1 == mask_char) { - int size = XcursorGetDefaultSize (dpy); - char *theme = XcursorGetTheme (dpy); - XcursorImages *images = XcursorShapeLoadImages (source_char, theme, size); + XcursorImages *images = _XcursorShapeLoadImages (dpy, source_char); if (images) { @@ -110,7 +115,7 @@ XcursorTryShapeCursor (Display *dpy, XcursorImagesDestroy (images); } } - return cursor; + returnLong(cursor); } void @@ -126,18 +131,21 @@ XcursorNoticeCreateBitmap (Display *dpy, int replace = 0; XcursorBitmapInfo *bmi; + enterFunc((T_CALLED(XcursorNoticeCreateBitmap) "(%p, %lu, %u, %u)\n", + (void*)dpy, pid, width, height)); + if (!dpy) - return; + returnVoid(); if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) - return; + returnVoid(); if (width > MAX_BITMAP_CURSOR_SIZE || height > MAX_BITMAP_CURSOR_SIZE) - return; + returnVoid(); info = _XcursorGetDisplayInfo (dpy); if (!info) - return; + returnVoid(); LockDisplay (dpy); replace = 0; @@ -164,6 +172,8 @@ XcursorNoticeCreateBitmap (Display *dpy, bmi->height = height; bmi->has_image = False; UnlockDisplay (dpy); + + returnVoid(); } static XcursorBitmapInfo * @@ -247,8 +257,11 @@ XcursorImageHash (XImage *image, int low_addr; Bool bit_swap; + enterFunc((T_CALLED(XcursorImageHash) "(%p, %p)\n", + (void*)image, (void*)hash)); + if (!image) - return; + returnVoid(); for (i = 0; i < XCURSOR_BITMAP_HASH_SIZE; i++) hash[i] = 0; @@ -295,6 +308,8 @@ XcursorImageHash (XImage *image, } line += image->bytes_per_line; } + + returnVoid(); } static Bool @@ -320,26 +335,29 @@ XcursorNoticePutBitmap (Display *dpy, { XcursorBitmapInfo *bmi; + enterFunc((T_CALLED(XcursorNoticePutBitmap ) "(%p, %lu, %p)\n", + (void*)dpy, draw, (void*)image)); + if (!dpy || !image) - return; + returnVoid(); if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) - return; + returnVoid(); if (image->width > MAX_BITMAP_CURSOR_SIZE || image->height > MAX_BITMAP_CURSOR_SIZE) - return; + returnVoid(); bmi = _XcursorGetBitmap (dpy, (Pixmap) draw); if (!bmi) - return; + returnVoid(); /* * Make sure the image fills the bitmap */ if (image->width != (int)bmi->width || image->height != (int)bmi->height) { bmi->bitmap = 0; - return; + returnVoid(); } /* * If multiple images are placed in the same bitmap, @@ -348,7 +366,7 @@ XcursorNoticePutBitmap (Display *dpy, if (bmi->has_image) { bmi->bitmap = 0; - return; + returnVoid(); } /* * Make sure the image is valid @@ -356,7 +374,7 @@ XcursorNoticePutBitmap (Display *dpy, if (image->bytes_per_line & ((image->bitmap_unit >> 3) - 1)) { bmi->bitmap = 0; - return; + returnVoid(); } /* * Hash the image @@ -387,6 +405,7 @@ XcursorNoticePutBitmap (Display *dpy, } } bmi->has_image = True; + returnVoid(); } Cursor @@ -407,19 +426,27 @@ XcursorTryShapeBitmapCursor (Display *dpy, (void) x; /* UNUSED */ (void) y; /* UNUSED */ + enterFunc((T_CALLED(XcursorTryShapeBitmapCursor) + "(%p, %lu, %lu, %p, %p, %u, %u)\n", + (void*)dpy, + source, mask, + (void*)foreground, + (void*)background, + x, y)); + if (!dpy || !foreground || !background) - return 0; + returnLong(None); if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) - return None; + returnLong(None); bmi = _XcursorGetBitmap (dpy, source); if (!bmi || !bmi->has_image) - return None; + returnLong(None); for (i = 0; i < XCURSOR_BITMAP_HASH_SIZE; i++) sprintf (name + 2 * i, "%02x", bmi->hash[i]); cursor = XcursorLibraryLoadCursor (dpy, name); if (_XcursorLogDiscover()) printf ("Cursor hash %s returns 0x%x\n", name, (unsigned int) cursor); - return cursor; + returnLong(cursor); }