From be568b1153206a067fd09c0f7d2dcea3d7dbaa68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 22 Nov 2020 09:54:55 +0100 Subject: [PATCH] Object: assert callbacks exists Improves stacktraces. Current stacktrace: ./htop(backtrace+0x5b)[0x45d98b] ./htop(CRT_handleSIGSEGV+0x189)[0x4eb5e9] /lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7fbbfb1ea140] New: ./htop(backtrace+0x5b)[0x45d98b] ./htop(CRT_handleSIGSEGV+0x189)[0x4eb7f9] /lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f62b0a65140] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x141)[0x7f62b089ac41] /lib/x86_64-linux-gnu/libc.so.6(abort+0x123)[0x7f62b0884537] /lib/x86_64-linux-gnu/libc.so.6(+0x2540f)[0x7f62b088440f] /lib/x86_64-linux-gnu/libc.so.6(+0x345c2)[0x7f62b08935c2] ./htop(Vector_delete+0x873)[0x54b303] ./htop(Panel_done+0x7b)[0x51abbb] ./htop[0x4ed8ee] ./htop(Vector_delete+0x414)[0x54aea4] ./htop(ScreenManager_delete+0x37)[0x536ea7] ./htop[0x4d9d1a] ./htop[0x4d5516] ./htop[0x5078d7] ./htop(ScreenManager_run+0x69f)[0x5388bf] ./htop(main+0x7c6)[0x4fcf76] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7f62b0885cca] ./htop(_start+0x2a)[0x42688a] --- Object.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Object.h b/Object.h index 05a9a72d..2c3ba9f9 100644 --- a/Object.h +++ b/Object.h @@ -8,6 +8,10 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + +#include + #include "RichString.h" #include "XUtils.h" // IWYU pragma: keep @@ -26,10 +30,10 @@ typedef void(*Object_Delete)(Object*); #define Object_getClass(obj_) ((const Object*)(obj_))->klass #define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) (class_)) -#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_)) +#define Object_delete(obj_) (assert(Object_getClass(obj_)->delete), Object_getClass(obj_)->delete((Object*)(obj_))) #define Object_displayFn(obj_) Object_getClass(obj_)->display -#define Object_display(obj_, str_) Object_getClass(obj_)->display((const Object*)(obj_), str_) -#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_) +#define Object_display(obj_, str_) (assert(Object_getClass(obj_)->display), Object_getClass(obj_)->display((const Object*)(obj_), str_)) +#define Object_compare(obj_, other_) (assert(Object_getClass(obj_)->compare), Object_getClass(obj_)->compare((const void*)(obj_), other_)) #define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))