libseed: Fix passing a union out to a C function
authorTim Horton <hortont424@gmail.com>
Tue, 12 Jan 2010 06:35:35 +0000 (01:35 -0500)
committerTim Horton <hortont424@gmail.com>
Tue, 12 Jan 2010 06:35:35 +0000 (01:35 -0500)
The parent class of seed_union was set to seed_union (undefined at that point);
I believe it should be seed_pointer, just like seed_struct

libseed/seed-structs.c
libseed/seed-structs.h
libseed/seed-types.c

index 73d0e48..5abeabe 100644 (file)
@@ -541,6 +541,12 @@ JSObjectRef
 seed_make_union (JSContextRef ctx, gpointer younion, GIBaseInfo * info)
 {
   JSObjectRef object;
+
+  if (younion == NULL)
+    {
+      return JSValueMakeNull (ctx);
+    }
+
   seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
 
   priv->pointer = younion;
@@ -659,7 +665,7 @@ seed_structs_init (void)
   seed_pointer_class = JSClassCreate (&seed_pointer_def);
   seed_struct_def.parentClass = seed_pointer_class;
   seed_struct_class = JSClassCreate (&seed_struct_def);
-  seed_union_def.parentClass = seed_union_class;
+  seed_union_def.parentClass = seed_pointer_class;
   seed_union_class = JSClassCreate (&seed_union_def);
   seed_boxed_def.parentClass = seed_struct_class;
   seed_boxed_class = JSClassCreate (&seed_boxed_def);
index 1c066f7..3d4ebb3 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef _SEED_STRUCT_H
 #define _SEED_STRUCT_H
 extern JSClassRef seed_struct_class;
+extern JSClassRef seed_union_class;
 
 JSObjectRef seed_make_union (JSContextRef ctx, gpointer younion,
                             GIBaseInfo * info);
index 39abb9f..67060be 100644 (file)
@@ -542,8 +542,8 @@ seed_gi_make_argument (JSContextRef ctx,
 
        arg->v_pointer = NULL;
 
-       if (interface_type == GI_INFO_TYPE_OBJECT
-           || interface_type == GI_INFO_TYPE_INTERFACE)
+       if (interface_type == GI_INFO_TYPE_OBJECT ||
+           interface_type == GI_INFO_TYPE_INTERFACE)
          {
            gobject = seed_value_to_object (ctx, value, exception);
            required_gtype =
@@ -584,10 +584,13 @@ seed_gi_make_argument (JSContextRef ctx,
            g_base_info_unref (interface);
            break;
          }
-       else if (interface_type == GI_INFO_TYPE_STRUCT)
+       else if (interface_type == GI_INFO_TYPE_STRUCT ||
+                interface_type == GI_INFO_TYPE_UNION)
          {
            if (JSValueIsObjectOfClass (ctx, value, seed_struct_class))
              arg->v_pointer = seed_pointer_get_pointer (ctx, value);
+           else if (JSValueIsObjectOfClass (ctx, value, seed_union_class))
+             arg->v_pointer = seed_pointer_get_pointer (ctx, value);
            else
              {
                GType type =