astitcher commented on code in PR #369:
URL: https://github.com/apache/qpid-proton/pull/369#discussion_r864414485
##########
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);
+ }
+}
+
+static inline void pni_class_decref(const pn_class_t *clazz, void *object) {
+ if (clazz->decref) {
+ clazz->decref(object);
+ } else {
+ pni_object_decref(object);
+ }
+}
+
+static inline int pni_class_refcount(const pn_class_t *clazz, void *object) {
+ return clazz->refcount
+ ? clazz->refcount(object)
+ : pni_object_refcount(object);
+}
+
+static inline void pni_class_free(const pn_class_t *clazz, void *object) {
+ if (clazz->free) {
+ clazz->free(object);
+ } else {
+ pni_object_free(object);
+ }
+}
+
void *pn_class_new(const pn_class_t *clazz, size_t size)
{
assert(clazz);
- void *object = clazz->newinst(clazz, size);
- if (clazz->initialize) {
+ void *object = pni_class_new(clazz, size);
+ if (object && clazz->initialize) {
clazz->initialize(object);
}
return object;
}
void *pn_class_incref(const pn_class_t *clazz, void *object)
{
- assert(clazz);
if (object) {
- clazz = clazz->reify(object);
- clazz->incref(object);
+ if (clazz==PN_OBJECT) {
Review Comment:
These lines have gone anyway now.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]