Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hb_atexit redefinition #3412

Closed
jesusdesantos opened this issue Feb 3, 2022 · 0 comments
Closed

Allow hb_atexit redefinition #3412

jesusdesantos opened this issue Feb 3, 2022 · 0 comments

Comments

@jesusdesantos
Copy link

Our library (using harfbuzz internally) exposes memory callbacks to our clients to implement custom allocators and leak detectors.

We also expose a Finalize point in the library where all allocations not released are counted as leaks.

Harfbuzz is doing a few allocations that are expected to be freed at atexit time (or never, depending on the implementation). These allocations count as leaks in our library. To solve this, we modified Harfbuzz to allow pre-defining hb_atexit (before hb.hh defines it).

We redefine hb_atexit to push each function into an internal list. These functions are manually invoked at Finalize time.

The changes to the code are very simple, not sure if aligned with the design of the library but I would love to have this upstream.

+#ifndef hb_atexit
 #  if !HB_USE_ATEXIT
 #    define hb_atexit(_) HB_STMT_START { if (0) (_) (); } HB_STMT_END
 #  else /* HB_USE_ATEXIT */
 #    ifdef HAVE_ATEXIT
 #      define hb_atexit atexit
 #    else
        template <void (*function) (void)> struct hb_atexit_t { ~hb_atexit_t () { function (); } };
 #      define hb_atexit(f) static hb_atexit_t<f> _hb_atexit_##__LINE__;
+#    endif
@behdad behdad closed this as completed in 9177953 Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant