static void _guiGtkMenuCascadeButton_destroyCallback (GuiObject widget, gpointer void_me) { (void) void_me; GuiMenu me = (GuiMenu) _GuiObject_getUserData (widget); if (! me) return; trace (U"destroying GuiButton ", Melder_pointer (my d_cascadeButton)); gtk_widget_destroy (GTK_WIDGET (my d_widget)); }
void _Melder_free (void **ptr) { if (*ptr == NULL) return; if (Melder_debug == 34) { Melder_casual (U"Melder_free\t", Melder_pointer (*ptr), U"\t?\t?"); } free (*ptr); *ptr = NULL; totalNumberOfDeallocations += 1; }
autoThing Thing_newFromClass (ClassInfo classInfo) { autoThing me (classInfo -> _new ()); trace (U"created ", classInfo -> className); theTotalNumberOfThings += 1; my classInfo = classInfo; Melder_assert (my name == nullptr); // confirm that _new called calloc, so that we see null pointers if (Melder_debug == 40) Melder_casual (U"created ", classInfo -> className, U" (", Melder_pointer (classInfo), U", ", me.get(), U")"); return me; }
static void _guiGtkMenu_destroyCallback (GuiObject widget, gpointer void_me) { (void) void_me; GuiMenu me = (GuiMenu) _GuiObject_getUserData (widget); trace (U"destroying GuiMenu ", Melder_pointer (me)); if (! me) return; // we could be destroying me my d_widget = NULL; // undangle if (my d_cascadeButton) my d_cascadeButton -> d_widget = NULL; // undangle if (my d_menuItem) my d_menuItem -> d_widget = NULL; // undangle forget (me); }
void * _Melder_malloc (int64 size) { if (size <= 0) Melder_throw (U"Can never allocate ", Melder_bigInteger (size), U" bytes."); if (sizeof (size_t) < 8 && size > SIZE_MAX) Melder_throw (U"Can never allocate ", Melder_bigInteger (size), U" bytes. Use a 64-bit edition of Praat instead?"); void *result = malloc ((size_t) size); // guarded cast if (result == NULL) Melder_throw (U"Out of memory: there is not enough room for another ", Melder_bigInteger (size), U" bytes."); if (Melder_debug == 34) { Melder_casual (U"Melder_malloc\t", Melder_pointer (result), U"\t", Melder_bigInteger (size), U"\t1"); } totalNumberOfAllocations += 1; totalAllocationSize += size; return result; }
char32 * Melder_dup (const char32 *string /* cattable */) { if (! string) return NULL; int64 size = (int64) str32len (string) + 1; // guaranteed to be positive if (sizeof (size_t) < 8 && size > SIZE_MAX / sizeof (char32)) Melder_throw (U"Can never allocate ", Melder_bigInteger (size), U" characters. Use a 64-bit edition of Praat instead?"); char32 *result = (char32 *) malloc ((size_t) size * sizeof (char32)); // guarded conversion if (result == NULL) Melder_throw (U"Out of memory: there is not enough room to duplicate a text of ", Melder_bigInteger (size - 1), U" characters."); str32cpy (result, string); if (Melder_debug == 34) { Melder_casual (U"Melder_dup\t", Melder_pointer (result), U"\t", Melder_bigInteger (size), U"\t4"); } totalNumberOfAllocations += 1; totalAllocationSize += size * (int64) sizeof (char32); return result; }
char * Melder_strdup (const char *string) { if (! string) return NULL; int64 size = (int64) strlen (string) + 1; if (sizeof (size_t) < 8 && size > SIZE_MAX) Melder_throw (U"Can never allocate ", Melder_bigInteger (size), U" bytes. Use a 64-bit edition of Praat instead?"); char *result = (char *) malloc ((size_t) size); if (result == NULL) Melder_throw (U"Out of memory: there is not enough room to duplicate a text of ", Melder_bigInteger (size - 1), U" characters."); strcpy (result, string); if (Melder_debug == 34) { Melder_casual (U"Melder_strdup\t", Melder_pointer (result), U"\t", Melder_bigInteger (size), U"\t1"); } totalNumberOfAllocations += 1; totalAllocationSize += size; return result; }
void * _Melder_calloc (int64 nelem, int64 elsize) { if (nelem <= 0) Melder_throw (U"Can never allocate ", Melder_bigInteger (nelem), U" elements."); if (elsize <= 0) Melder_throw (U"Can never allocate elements whose size is ", Melder_bigInteger (elsize), U" bytes."); if ((uint64_t) nelem > SIZE_MAX / (uint64_t) elsize) // guarded casts to unsigned Melder_throw (U"Can never allocate ", Melder_bigInteger (nelem), U" elements whose sizes are ", Melder_bigInteger (elsize), U" bytes each.", sizeof (size_t) < 8 ? U" Use a 64-bit edition of Praat instead?" : NULL); void *result = calloc ((size_t) nelem, (size_t) elsize); if (result == NULL) Melder_throw (U"Out of memory: there is not enough room for ", Melder_bigInteger (nelem), U" more elements whose sizes are ", elsize, U" bytes each."); if (Melder_debug == 34) { Melder_casual (U"Melder_calloc\t", Melder_pointer (result), U"\t", Melder_bigInteger (nelem), U"\t", Melder_bigInteger (elsize)); } totalNumberOfAllocations += 1; totalAllocationSize += nelem * elsize; return result; }
void * Melder_realloc (void *ptr, int64 size) { if (size <= 0) Melder_throw (U"Can never allocate ", Melder_bigInteger (size), U" bytes."); if (sizeof (size_t) < 8 && size > SIZE_MAX) Melder_throw (U"Can never allocate ", Melder_bigInteger (size), U" bytes. Use a 64-bit edition of Praat instead?"); void *result = realloc (ptr, (size_t) size); // will not show in the statistics... if (result == NULL) Melder_throw (U"Out of memory. Could not extend room to ", Melder_bigInteger (size), U" bytes."); if (ptr == NULL) { // is it like malloc? if (Melder_debug == 34) { Melder_casual (U"Melder_realloc\t", Melder_pointer (result), U"\t", Melder_bigInteger (size), U"\t1"); } totalNumberOfAllocations += 1; totalAllocationSize += size; } else if (result != ptr) { // did realloc do a malloc-and-free? totalNumberOfAllocations += 1; totalAllocationSize += size; totalNumberOfDeallocations += 1; totalNumberOfMovingReallocs += 1; } else { totalNumberOfReallocsInSitu += 1; } return result; }
static void _GuiGtkButton_destroyCallback (GuiObject widget, gpointer void_me) { (void) widget; iam (GuiButton); trace (U"destroying GuiButton ", Melder_pointer (me)); forget (me); }
static void _guiGtkMenuItem_destroyCallback (GuiObject widget, gpointer void_me) { (void) widget; iam (GuiMenuItem); trace (U"destroying GuiMenuItem ", Melder_pointer (me)); forget (me); }
static void _GuiGtkButton_destroyCallback (GuiObject /* widget */, gpointer userData) { GuiButton me = (GuiButton) userData; trace (U"destroying GuiButton ", Melder_pointer (me)); forget (me); }