]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Give sensible unique-ish strings for all objects.
authorCharlie Brej <cbrej@cs.man.ac.uk>
Sun, 4 Oct 2009 17:03:23 +0000 (18:03 +0100)
committerroot <cbrej@cs.man.ac.uk>
Sun, 4 Oct 2009 17:03:23 +0000 (18:03 +0100)
All objects can now be transformed into strings which allows them to be used as
hash indexes. Some rules do still apply. If an object is lost (freed....)
another object may take on the name of the lost one. The object address is used
to create a string in the form "#(0x123abc45)". NULL has the string "#NULL".
So arr[NULL] is the same as arr["#NULL"], and similar for the objects.

src/plugins/splash/script/script-object.c

index 95b96366a20975b66fbcad98bfaeafcb7a0927b8..1c9e902c67c29d93d4db59965b912f2b18f116a7 100644 (file)
@@ -303,16 +303,19 @@ bool script_obj_as_bool (script_obj_t *obj)
 
 char *script_obj_as_string (script_obj_t *obj)              /* reply is strdupped and may be NULL */
 {
+  char *reply;        
   script_obj_t *string_obj = script_obj_as_obj_type (obj, SCRIPT_OBJ_TYPE_STRING);
   if (string_obj) return strdup (string_obj->data.string);
   string_obj = script_obj_as_obj_type (obj, SCRIPT_OBJ_TYPE_NUMBER);
   if (string_obj)
     {
-        char *reply;        
         asprintf (&reply, "%g", string_obj->data.number);
         return reply;
     }
-  return NULL;
+  if (script_obj_is_null (obj))
+    return strdup("#NULL");
+  asprintf (&reply, "#(0x%x)", (int) obj);
+  return reply;
 }
 
 static void *script_obj_direct_as_native_of_class (script_obj_t *obj,