strings are now stored as string_t*
authorkramm <kramm>
Tue, 30 Dec 2008 22:55:14 +0000 (22:55 +0000)
committerkramm <kramm>
Tue, 30 Dec 2008 22:55:14 +0000 (22:55 +0000)
lib/as3/code.c
lib/as3/mkabc.py
lib/as3/opcodes.c
lib/as3/opcodes.h

index e92d6c9..37339e5 100644 (file)
@@ -325,7 +325,8 @@ code_t*code_parse(TAG*tag, int len, abc_file_t*file, pool_t*pool, codelookup_t**
                 int j = swf_GetS24(tag);
                 data = (void*)(ptroff_t)j;
             } else if(*p == 's') { // string
-                data = strdup((char*)pool_lookup_string(pool, swf_GetU30(tag)));
+                string_t s = pool_lookup_string2(pool, swf_GetU30(tag));
+                data = string_dup3(&s);
             } else if(*p == 'D') { // debug
                 /*type, usually 1*/
                 U8 type = swf_GetU8(tag);
@@ -494,7 +495,7 @@ static int opcode_write(TAG*tag, code_t*c, pool_t*pool, abc_file_t*file, int len
                 skip = (c->branch->pos) - c->pos - 4;
             len += swf_SetS24(tag, skip);
         } else if(*p == 's') { // string
-            int index = pool_register_string(pool, data);
+            int index = pool_register_string2(pool, (string_t*)data);
             len += swf_SetU30(tag, index);
         } else if(*p == 'D') { // debug statement
             if(tag)
@@ -926,7 +927,9 @@ int code_dump(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*p
                     else
                         fprintf(fo, "%08x", c->branch);
                 } else if(*p == 's') {
-                    fprintf(fo, "\"%s\"", data);
+                    char*s = string_escape((string_t*)data);
+                    fprintf(fo, "\"%s\"", s);
+                    free(s);
                 } else if(*p == 'D') {
                     fprintf(fo, "[register %02x=%s]", (ptroff_t)c->data[1], (char*)c->data[0]);
                 } else if(*p == 'S') {
@@ -1074,7 +1077,9 @@ code_t*code_dup(code_t*c)
         while(*p) {
             if(*p == '2') { //multiname
                 c->data[pos] = multiname_clone(c->data[pos]);
-            } else if(*p == 's' || *p == 'D') {
+            } else if(*p == 's') {
+                c->data[pos] = string_dup3(c->data[pos]);
+            } else if(*p == 'D') {
                 c->data[pos] = strdup(c->data[pos]);
             } else if(*p == 'f') {
                 double old = *(double*)c->data[pos];
index 82283ab..551560a 100644 (file)
@@ -43,7 +43,7 @@ for line in fi.readlines():
         op,name,params = m.group(1),m.group(2),m.group(3)
 
         iterations=1
-        if "2" in params:
+        if "2" in params or "s" in params:
             iterations=2
 
         for iteration in range(iterations):
@@ -62,7 +62,10 @@ for line in fi.readlines():
                     else:
                         type,pname="multiname_t*","name"
                 elif c == "s":
-                    type,pname="char*","s"
+                    if iteration==0:
+                        type,pname="char*","name"
+                    else:
+                        type,pname="string_t*","s"
                 elif c in "nubs":
                     type,pname="int","v"
                 elif c == "m":
@@ -120,7 +123,10 @@ for line in fi.readlines():
                 elif(c == "b"):
                     foc.write("    self->data[%d] = (void*)(ptroff_t)%s;\n" % (i,pname))
                 elif(c == "s"):
-                    foc.write("    self->data[%d] = strdup(%s);\n" % (i,pname))
+                    if iteration==0:
+                        foc.write("    self->data[%d] = string_new4(%s);\n" % (i,pname))
+                    else:
+                        foc.write("    self->data[%d] = string_dup3(%s);\n" % (i,pname))
                 elif(c == "m"):
                     foc.write("    self->data[%d] = %s;\n" % (i,pname))
                 elif(c == "c"):
index c6b9203..b5def9d 100644 (file)
@@ -225,10 +225,16 @@ code_t* abc_debug(code_t*prev, void* debuginfo)
     /* FIXME: write debuginfo debuginfo */
     return self;
 }
-code_t* abc_debugfile(code_t*prev, char* s)
+code_t* abc_debugfile(code_t*prev, char* name)
 {
     code_t*self = add_opcode(prev, 0xf1);
-    self->data[0] = strdup(s);
+    self->data[0] = string_new4(name);
+    return self;
+}
+code_t* abc_debugfile2(code_t*prev, string_t* s)
+{
+    code_t*self = add_opcode(prev, 0xf1);
+    self->data[0] = string_dup3(s);
     return self;
 }
 code_t* abc_debugline(code_t*prev, int v)
@@ -281,10 +287,16 @@ code_t* abc_dup(code_t*prev)
     code_t*self = add_opcode(prev, 0x2a);
     return self;
 }
-code_t* abc_dxns(code_t*prev, char* s)
+code_t* abc_dxns(code_t*prev, char* name)
+{
+    code_t*self = add_opcode(prev, 0x06);
+    self->data[0] = string_new4(name);
+    return self;
+}
+code_t* abc_dxns2(code_t*prev, string_t* s)
 {
     code_t*self = add_opcode(prev, 0x06);
-    self->data[0] = strdup(s);
+    self->data[0] = string_dup3(s);
     return self;
 }
 code_t* abc_dxnslate(code_t*prev)
@@ -790,10 +802,16 @@ code_t* abc_pushshort(code_t*prev, int v)
     self->data[0] = (void*)(ptroff_t)v;
     return self;
 }
-code_t* abc_pushstring(code_t*prev, char* s)
+code_t* abc_pushstring(code_t*prev, char* name)
+{
+    code_t*self = add_opcode(prev, 0x2c);
+    self->data[0] = string_new4(name);
+    return self;
+}
+code_t* abc_pushstring2(code_t*prev, string_t* s)
 {
     code_t*self = add_opcode(prev, 0x2c);
-    self->data[0] = strdup(s);
+    self->data[0] = string_dup3(s);
     return self;
 }
 code_t* abc_pushtrue(code_t*prev)
index 85035be..cf0fbdb 100644 (file)
@@ -117,9 +117,12 @@ code_t* abc_convert_s(code_t*prev);
 code_t* abc_debug(code_t*prev, void* debuginfo);
 #define debug(method,debuginfo) (method->code = abc_debug(method->code,debuginfo))
 #define OPCODE_DEBUG 0xef
-code_t* abc_debugfile(code_t*prev, char* s);
-#define debugfile(method,s) (method->code = abc_debugfile(method->code,s))
+code_t* abc_debugfile(code_t*prev, char* name);
+#define debugfile(method,name) (method->code = abc_debugfile(method->code,name))
 #define OPCODE_DEBUGFILE 0xf1
+code_t* abc_debugfile2(code_t*prev, string_t* s);
+#define debugfile2(method,s) (method->code = abc_debugfile2(method->code,s))
+#define OPCODE_DEBUGFILE2 0xf1
 code_t* abc_debugline(code_t*prev, int v);
 #define debugline(method,v) (method->code = abc_debugline(method->code,v))
 #define OPCODE_DEBUGLINE 0xf0
@@ -147,9 +150,12 @@ code_t* abc_divide(code_t*prev);
 code_t* abc_dup(code_t*prev);
 #define dup(method) (method->code = abc_dup(method->code))
 #define OPCODE_DUP 0x2a
-code_t* abc_dxns(code_t*prev, char* s);
-#define dxns(method,s) (method->code = abc_dxns(method->code,s))
+code_t* abc_dxns(code_t*prev, char* name);
+#define dxns(method,name) (method->code = abc_dxns(method->code,name))
 #define OPCODE_DXNS 0x06
+code_t* abc_dxns2(code_t*prev, string_t* s);
+#define dxns2(method,s) (method->code = abc_dxns2(method->code,s))
+#define OPCODE_DXNS2 0x06
 code_t* abc_dxnslate(code_t*prev);
 #define dxnslate(method) (method->code = abc_dxnslate(method->code))
 #define OPCODE_DXNSLATE 0x07
@@ -411,9 +417,12 @@ code_t* abc_pushscope(code_t*prev);
 code_t* abc_pushshort(code_t*prev, int v);
 #define pushshort(method,v) (method->code = abc_pushshort(method->code,v))
 #define OPCODE_PUSHSHORT 0x25
-code_t* abc_pushstring(code_t*prev, char* s);
-#define pushstring(method,s) (method->code = abc_pushstring(method->code,s))
+code_t* abc_pushstring(code_t*prev, char* name);
+#define pushstring(method,name) (method->code = abc_pushstring(method->code,name))
 #define OPCODE_PUSHSTRING 0x2c
+code_t* abc_pushstring2(code_t*prev, string_t* s);
+#define pushstring2(method,s) (method->code = abc_pushstring2(method->code,s))
+#define OPCODE_PUSHSTRING2 0x2c
 code_t* abc_pushtrue(code_t*prev);
 #define pushtrue(method) (method->code = abc_pushtrue(method->code))
 #define OPCODE_PUSHTRUE 0x26