mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 02:36:19 +01:00
tests/constructor: Support systems where dlclose is a no-op
POSIX allows dlclose() implementations that are no-ops, and in such case library destructors run at application exit rather than dlclose(). That's the case, for example, of UNIX systems with the Musl LibC.
This commit is contained in:
parent
85e21ff757
commit
c4c39ea52a
@ -61,6 +61,9 @@ void string_add_exclusive (const char *string);
|
|||||||
MODULE_EXPORT
|
MODULE_EXPORT
|
||||||
int string_remove (const char *string);
|
int string_remove (const char *string);
|
||||||
|
|
||||||
|
MODULE_EXPORT
|
||||||
|
int string_find (const char *string);
|
||||||
|
|
||||||
MODULE_EXPORT
|
MODULE_EXPORT
|
||||||
void string_check (const char *string);
|
void string_check (const char *string);
|
||||||
|
|
||||||
@ -204,6 +207,19 @@ string_remove (const char *string)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**< private >
|
||||||
|
* string_find:
|
||||||
|
*
|
||||||
|
* @string: NULL-terminated string. Must not be empty
|
||||||
|
*
|
||||||
|
* Returns 1 if the string is present, 0 otherwise
|
||||||
|
*/
|
||||||
|
MODULE_EXPORT
|
||||||
|
int string_find (const char *string)
|
||||||
|
{
|
||||||
|
return string_find_index_ (string) < sizeof (buffer);
|
||||||
|
}
|
||||||
|
|
||||||
/**< private >
|
/**< private >
|
||||||
* string_check:
|
* string_check:
|
||||||
*
|
*
|
||||||
|
@ -40,6 +40,8 @@ void string_add_exclusive (const char *string);
|
|||||||
MODULE_IMPORT
|
MODULE_IMPORT
|
||||||
void string_check (const char *string);
|
void string_check (const char *string);
|
||||||
|
|
||||||
|
MODULE_IMPORT
|
||||||
|
int string_find (const char *string);
|
||||||
|
|
||||||
#if G_HAS_CONSTRUCTORS
|
#if G_HAS_CONSTRUCTORS
|
||||||
|
|
||||||
@ -66,9 +68,13 @@ dtor (void)
|
|||||||
{
|
{
|
||||||
string_add_exclusive (G_STRINGIFY (PREFIX) "_" "dtor");
|
string_add_exclusive (G_STRINGIFY (PREFIX) "_" "dtor");
|
||||||
|
|
||||||
#ifdef BUILD_TEST_EXECUTABLE
|
if (string_find ("app_dtor") && string_find ("lib_dtor"))
|
||||||
|
{
|
||||||
|
/* All destructors were invoked, this is the last.
|
||||||
|
* Call _Exit (EXIT_SUCCESS) to exit immediately
|
||||||
|
* with a success code */
|
||||||
_Exit (EXIT_SUCCESS);
|
_Exit (EXIT_SUCCESS);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* G_HAS_CONSTRUCTORS */
|
#endif /* G_HAS_CONSTRUCTORS */
|
||||||
@ -210,7 +216,12 @@ test_lib (gconstpointer data)
|
|||||||
unload_library ();
|
unload_library ();
|
||||||
|
|
||||||
#if G_HAS_DESTRUCTORS
|
#if G_HAS_DESTRUCTORS
|
||||||
string_check ("lib_" "dtor");
|
/* Destructors in dynamically-loaded libraries do not
|
||||||
|
* necessarily run on dlclose. On some systems dlclose
|
||||||
|
* is effectively a no-op (e.g with the Musl LibC) and
|
||||||
|
* destructors run at program exit */
|
||||||
|
g_test_message ("Destructors run on module unload: %s\n",
|
||||||
|
string_find ("lib_" "dtor") ? "yes" : "no");
|
||||||
#endif
|
#endif
|
||||||
#if defined (_WIN32) && defined (G_HAS_TLS_CALLBACKS)
|
#if defined (_WIN32) && defined (G_HAS_TLS_CALLBACKS)
|
||||||
string_check ("lib_" "tlscb_process_detach");
|
string_check ("lib_" "tlscb_process_detach");
|
||||||
|
Loading…
Reference in New Issue
Block a user