mirror of
https://github.com/schoebel/mars
synced 2025-04-18 13:15:33 +00:00
infra: tighten NULL pointer checking
This commit is contained in:
parent
1f4f044914
commit
58618cc29d
@ -639,7 +639,8 @@ INLINE struct OBJTYPE##_object *BRITYPE##_alloc_##OBJTYPE(struct BRITYPE##_brick
|
||||
\
|
||||
INLINE void BRITYPE##_free_##OBJTYPE(struct OBJTYPE##_object *object) \
|
||||
{ \
|
||||
generic_free((struct generic_object*)object); \
|
||||
generic_free((struct generic_object *)object); \
|
||||
SET_PTR_NULL(object); \
|
||||
} \
|
||||
\
|
||||
INLINE struct BRITYPE##_##OBJTYPE##_aspect *BRITYPE##_##OBJTYPE##_get_aspect(struct BRITYPE##_brick *brick, struct OBJTYPE##_object *obj) \
|
||||
|
@ -71,6 +71,20 @@ do { \
|
||||
#define CHECK_PTR_DEAD(ptr,label) /*empty*/
|
||||
#endif
|
||||
|
||||
/* Counterpart of CHECK_PTR_NULL().
|
||||
* Most of the consequences should be caught by the compiler,
|
||||
* without producing code (potentially except some debugging code).
|
||||
* Otherwise, or when dump_stack()ing at runtime, code inspection should be
|
||||
* tightened.
|
||||
* So this is essentially a self-check against common bugs, often introduced
|
||||
* during reorgs.
|
||||
*/
|
||||
#ifdef BRICK_CHECKING
|
||||
#define SET_PTR_NULL(ptr) (ptr) = NULL
|
||||
#else
|
||||
#define SET_PTR_NULL(ptr) /* empty */
|
||||
#endif
|
||||
|
||||
#define CHECK_PTR_NULL(ptr,label) \
|
||||
do { \
|
||||
CHECK_PTR_DEAD(ptr, label); \
|
||||
|
Loading…
Reference in New Issue
Block a user