[gjs: 9/13] gtype: Make finalize function a no-op



commit 940fab9acaadde48991bf5d0b4310f7e844ecdfb
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Apr 1 20:59:42 2019 -0700

    gtype: Make finalize function a no-op
    
    GType objects don't allocate any memory for their private data. Instead,
    they just store their GType value in the JSObject's private data pointer
    slot. Since nothing is allocated, nothing needs to be freed in the
    finalize function.
    
    We are required to have a finalize function because of the
    GJS_DEFINE_PROTO_ABSTRACT macro used to define this JSClass. However, we
    can just make it empty. The statements currently in there seem useless.

 gi/gtype.cpp | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
---
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 9d3263c0..1b10ea99 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -45,15 +45,9 @@ GJS_DEFINE_PROTO_ABSTRACT("GIRepositoryGType", gtype,
 /* priv_from_js adds a "*", so this returns "void *" */
 GJS_DEFINE_PRIV_FROM_JS(void, gjs_gtype_class);
 
-static void
-gjs_gtype_finalize(JSFreeOp *fop,
-                   JSObject *obj)
-{
-    GType gtype = GPOINTER_TO_SIZE(JS_GetPrivate(obj));
-
-    /* proto doesn't have a private set */
-    if (G_UNLIKELY(gtype == 0))
-        return;
+static void gjs_gtype_finalize(JSFreeOp*, JSObject*) {
+    // No private data is allocated, it's stuffed directly in the private field
+    // of JSObject, so nothing to free
 }
 
 GJS_JSAPI_RETURN_CONVENTION


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]