astitcher commented on code in PR #369: URL: https://github.com/apache/qpid-proton/pull/369#discussion_r864414337
########## c/src/core/object/object.c: ########## @@ -58,50 +67,130 @@ pn_cid_t pn_class_id(const pn_class_t *clazz) return clazz->cid; } +static inline void *pni_object_new(const pn_class_t *clazz, size_t size) +{ + void *object = NULL; + pni_head_t *head = (pni_head_t *) pni_mem_zallocate(clazz, sizeof(pni_head_t) + size); + if (head != NULL) { + object = head + 1; + head->clazz = clazz; + head->refcount = 1; + } + return object; +} + +static inline void pni_object_incref(void *object) { + if (object) { + pni_head(object)->refcount++; + } +} + +static inline int pni_object_refcount(void *object) +{ + assert(object); + return pni_head(object)->refcount; +} + +static inline void pni_object_decref(void *object) +{ + pni_head_t *head = pni_head(object); + assert(head->refcount > 0); + head->refcount--; +} + +static inline void pni_object_free(void *object) +{ + pni_head_t *head = pni_head(object); + pni_mem_deallocate(head->clazz, head); +} + +void pn_object_incref(void *object) { + pni_object_incref(object); +} + +static inline void *pni_class_new(const pn_class_t *clazz, size_t size) { + return clazz->newinst + ? clazz->newinst(clazz, size) + : pni_object_new(clazz, size); +} + +static inline void pni_class_incref(const pn_class_t *clazz, void *object) { + if (clazz->incref) { + clazz->incref(object); + } else { + pni_object_incref(object); + } +} + Review Comment: I personally find the ternary easier to read! But I'm happy to change it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org