[gjs] GI: use flags instead of a boolean for the no-copy argument



commit a107c3209ce2335812b61321cbdfd03496273097
Author: Johan Bilien <jobi litl com>
Date:   Tue Mar 24 16:54:37 2009 +0000

    GI: use flags instead of a boolean for the no-copy argument
    
    in gjs_boxed_from_c_struct.
---
 gi/arg.c   |    3 ++-
 gi/boxed.c |   10 +++++-----
 gi/boxed.h |   39 ++++++++++++++++++++++-----------------
 gi/value.c |    6 +++++-
 4 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/gi/arg.c b/gi/arg.c
index 24c525a..2e3ddc9 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -933,7 +933,8 @@ gjs_value_from_g_argument (JSContext  *context,
 
             if (symbol_type == GI_INFO_TYPE_STRUCT || symbol_type == GI_INFO_TYPE_BOXED) {
                 JSObject *obj;
-                obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)symbol_info, arg->v_pointer, FALSE);
+                obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)symbol_info, arg->v_pointer,
+                                              GJS_BOXED_CREATION_NONE);
                 if (obj)
                     value = OBJECT_TO_JSVAL(obj);
 
diff --git a/gi/boxed.c b/gi/boxed.c
index 9304723..1bb57f0 100644
--- a/gi/boxed.c
+++ b/gi/boxed.c
@@ -1220,10 +1220,10 @@ gjs_define_boxed_class(JSContext    *context,
 }
 
 JSObject*
-gjs_boxed_from_c_struct(JSContext    *context,
-                        GIStructInfo *info,
-                        void         *gboxed,
-                        gboolean      no_copy)
+gjs_boxed_from_c_struct(JSContext             *context,
+                        GIStructInfo          *info,
+                        void                  *gboxed,
+                        GjsBoxedCreationFlags  flags)
 {
     JSObject *proto;
 
@@ -1240,7 +1240,7 @@ gjs_boxed_from_c_struct(JSContext    *context,
     unthreadsafe_template_for_constructor.info = info;
     unthreadsafe_template_for_constructor.gboxed = gboxed;
     unthreadsafe_template_for_constructor.parent_jsval = JSVAL_NULL;
-    unthreadsafe_template_for_constructor.no_copy = no_copy;
+    unthreadsafe_template_for_constructor.no_copy = (flags & GJS_BOXED_CREATION_NO_COPY) != 0;
 
     return gjs_construct_object_dynamic(context, proto,
                                         0, NULL);
diff --git a/gi/boxed.h b/gi/boxed.h
index 1f81b03..3ac1ba0 100644
--- a/gi/boxed.h
+++ b/gi/boxed.h
@@ -32,26 +32,31 @@
 
 G_BEGIN_DECLS
 
+typedef enum {
+    GJS_BOXED_CREATION_NONE    =  0,
+    GJS_BOXED_CREATION_NO_COPY = (1 << 0)
+} GjsBoxedCreationFlags;
+
 /* Hack for now... why doesn't gobject-introspection have this? */
 typedef GIStructInfo GIBoxedInfo;
 
-JSBool    gjs_define_boxed_class       (JSContext    *context,
-                                        JSObject     *in_object,
-                                        GIBoxedInfo  *info,
-                                        JSObject    **constructor_p,
-                                        JSObject    **prototype_p);
-JSObject* gjs_lookup_boxed_constructor (JSContext    *context,
-                                        GIBoxedInfo  *info);
-JSObject* gjs_lookup_boxed_prototype   (JSContext    *context,
-                                        GIBoxedInfo  *info);
-JSClass*  gjs_lookup_boxed_class       (JSContext    *context,
-                                        GIBoxedInfo  *info);
-void*     gjs_c_struct_from_boxed      (JSContext    *context,
-                                        JSObject     *obj);
-JSObject* gjs_boxed_from_c_struct      (JSContext    *context,
-                                        GIStructInfo *info,
-                                        void         *gboxed,
-                                        gboolean      no_copy);
+JSBool    gjs_define_boxed_class       (JSContext             *context,
+                                        JSObject              *in_object,
+                                        GIBoxedInfo           *info,
+                                        JSObject             **constructor_p,
+                                        JSObject             **prototype_p);
+JSObject* gjs_lookup_boxed_constructor (JSContext             *context,
+                                        GIBoxedInfo           *info);
+JSObject* gjs_lookup_boxed_prototype   (JSContext             *context,
+                                        GIBoxedInfo           *info);
+JSClass*  gjs_lookup_boxed_class       (JSContext             *context,
+                                        GIBoxedInfo           *info);
+void*     gjs_c_struct_from_boxed      (JSContext             *context,
+                                        JSObject              *obj);
+JSObject* gjs_boxed_from_c_struct      (JSContext             *context,
+                                        GIStructInfo          *info,
+                                        void                  *gboxed,
+                                        GjsBoxedCreationFlags  flags);
 
 G_END_DECLS
 
diff --git a/gi/value.c b/gi/value.c
index aed44c7..0f37dd5 100644
--- a/gi/value.c
+++ b/gi/value.c
@@ -561,11 +561,13 @@ gjs_value_from_g_value_internal(JSContext    *context,
         obj = gjs_object_from_g_object(context, gobj);
         *value_p = OBJECT_TO_JSVAL(obj);
     } else if (g_type_is_a(gtype, G_TYPE_BOXED)) {
+        GjsBoxedCreationFlags boxed_flags;
         GIBaseInfo *info;
         void *gboxed;
         JSObject *obj;
 
         gboxed = g_value_get_boxed(gvalue);
+        boxed_flags = GJS_BOXED_CREATION_NONE;
 
         /* The only way to differentiate unions and structs is from
          * their g-i info as both GBoxed */
@@ -581,7 +583,9 @@ gjs_value_from_g_value_internal(JSContext    *context,
         switch (g_base_info_get_type(info)) {
         case GI_INFO_TYPE_BOXED:
         case GI_INFO_TYPE_STRUCT:
-            obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)info, gboxed, no_copy);
+            if (no_copy)
+                boxed_flags |= GJS_BOXED_CREATION_NO_COPY;
+            obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)info, gboxed, boxed_flags);
             break;
         case GI_INFO_TYPE_UNION:
             obj = gjs_union_from_c_union(context, (GIUnionInfo *)info, gboxed);



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