replaced libart with new polygon code
[swftools.git] / lib / as3 / pool.c
index bedc23b..ec089a0 100644 (file)
@@ -250,7 +250,7 @@ namespace_t* namespace_new(U8 access, const char*name)
     ns->name = name?strdup(name):0;
     return ns;
 }
-namespace_t* namespace_new_undefined(const char*name) {
+namespace_t* namespace_new_namespace(const char*name) {
     return namespace_new(0x08, name); // public?
 }
 namespace_t* namespace_new_package(const char*name) {
@@ -275,7 +275,7 @@ namespace_t* namespace_new_private(const char*name) {
 void namespace_destroy(namespace_t*n)
 {
     if(n) {
-        free(n->name);n->name=0;
+        free((char*)n->name);n->name=0;
         n->access=0x00;
         free(n);
     }
@@ -634,9 +634,6 @@ type_t multiname_type = {
 
 // ------------------------------- constants -------------------------------------
 
-#define NS_TYPE(x) ((x) == 0x08 || (x) == 0x16 || (x) == 0x17 || (x) == 0x18 ||  \
-                                   (x) == 0x19 || (x) == 0x1a || (x) == 0x05)
-
 #define UNIQUE_CONSTANT(x) ((x) == CONSTANT_TRUE || (x) == CONSTANT_FALSE || (x) == CONSTANT_NULL || (x) == CONSTANT_UNDEFINED)
 
 constant_t* constant_new_int(int i) 
@@ -660,7 +657,7 @@ constant_t* constant_new_float(double f)
     c->type = CONSTANT_FLOAT;
     return c;
 }
-constant_t* constant_new_string(char*s)
+constant_t* constant_new_string(const char*s)
 {
     NEW(constant_t,c);
     c->s = string_new4(s);
@@ -706,6 +703,18 @@ constant_t* constant_new_undefined()
     c->type = CONSTANT_UNDEFINED;
     return c;
 }
+constant_t* constant_clone(constant_t*other)
+{
+    if(!other) return 0;
+    constant_t*c = malloc(sizeof(constant_t));
+    memcpy(c, other, sizeof(constant_t));
+    if(NS_TYPE(c->type)) {
+        c->ns = namespace_clone(other->ns);
+    } else if(c->type == CONSTANT_STRING) {
+        c->s = string_dup3(other->s);
+    }
+    return c;
+}
 constant_t* constant_fromindex(pool_t*pool, int index, int type)
 {
     if(!index) {
@@ -791,6 +800,10 @@ int constant_get_index(pool_t*pool, constant_t*c)
         return pool_register_float(pool, c->f);
     } else if(c->type == CONSTANT_STRING) {
         return pool_register_string2(pool, c->s);
+    } else if(c->type == CONSTANT_UNDEFINED) {
+        /* write undefined with index 0 (and no type). Otherwise, the FlashPlayer 
+           seems to throw an "attempt to read out of bounds" exception */
+        return 0;
     } else if(!constant_has_index(c)) {
         return 1;
     } else {