These macros can lead to surprising results in user code:
86 +#define ccsObjectRef(o) \ 87 + ((o)->object).refcnt++; 88 + 89 +#define ccsObjectUnref(o, freeFunc) \ 90 + ((o)->object).refcnt--; \ 91 + if (!((o)->object).refcnt) \ 92 + freeFunc (o)
Example of problem:
if (false) ccsObjectUnref(o, f);
will call f(o).
Rewrite as: 86 +#define ccsObjectRef(o) \ 87 + do { ((o)->object).refcnt++ } while(false) 88 + 89 +#define ccsObjectUnref(o, freeFunc) \ 90 + do { ((o)->object).refcnt--; \ 91 + if (!((o)->object).refcnt) \ 92 + freeFunc (o) } while(false)
PS It feels awkward to require freeFunc as a parameter, but I don't have a cleaner alternative suggestion just now.
« Back to merge proposal
These macros can lead to surprising results in user code:
86 +#define ccsObjectRef(o) \ .refcnt+ +; .refcnt- -; \ >object) .refcnt) \
87 + ((o)->object)
88 +
89 +#define ccsObjectUnref(o, freeFunc) \
90 + ((o)->object)
91 + if (!((o)-
92 + freeFunc (o)
Example of problem:
if (false) ccsObjectUnref(o, f);
will call f(o).
Rewrite as: .refcnt+ + } while(false) .refcnt- -; \ >object) .refcnt) \
86 +#define ccsObjectRef(o) \
87 + do { ((o)->object)
88 +
89 +#define ccsObjectUnref(o, freeFunc) \
90 + do { ((o)->object)
91 + if (!((o)-
92 + freeFunc (o) } while(false)
PS It feels awkward to require freeFunc as a parameter, but I don't have a cleaner alternative suggestion just now.