taglist no longer contain an END tag
[swftools.git] / lib / python / taglist.c
index 9caf3b2..e16f84a 100644 (file)
@@ -33,7 +33,14 @@ PyObject * taglist_new2(TAG*tag)
 
     int nr=0;
     TAG*t = tag;
-    while(t) {nr++;t=t->next;}
+    TAG*last = t;
+    while(t) {nr++;last=t;t=t->next;}
+
+    if(last && last->id==ST_END) {
+       swf_DeleteTag(last);
+       nr--;
+    }
+
     taglist->taglist = PyList_New(nr);
     
     mylog("+%08x(%d) taglist_new2: %d items", (int)taglist, taglist->ob_refcnt, nr);
@@ -41,10 +48,15 @@ PyObject * taglist_new2(TAG*tag)
     nr = 0;
     t = tag;
     while(t) {
-       PyObject*newtag = tag_new2(tag, taglist->tagmap);
+       PyObject*newtag = tag_new2(t, taglist->tagmap);
+       if(newtag==NULL) {
+           // pass through exception
+           return NULL;
+       }
        PyList_SET_ITEM(taglist->taglist,nr,newtag);Py_INCREF(newtag);
        if(swf_isDefiningTag(t)) {
-           tagmap_add(taglist->tagmap, newtag);
+           int id = swf_GetDefineID(t);
+           tagmap_addMapping(taglist->tagmap, id, newtag);
        }
        nr++;
        t=t->next;
@@ -72,6 +84,7 @@ TAG* taglist_getTAGs(PyObject*self)
        tag = tag_getTAG(item, tag, taglist->tagmap);
        if(!firstTag)
            firstTag = tag;
+       mylog(" %08x(%d) taglist_getTAGs: added tag %08x", (int)self, self->ob_refcnt, tag);
     }
     return firstTag;
 }
@@ -152,7 +165,7 @@ static int taglist_length(PyObject * self)
 //----------------------------------------------------------------------------
 static int taglist_contains(PyObject * self, PyObject * tag)
 {
-    mylog(" %08x(%d) taglist_contains %08x", (int)self, self->ob_refcnt, tag);
+    /* TODO: optimize! */
     TagListObject*taglist = (TagListObject*)self;
     PyObject*list = taglist->taglist;
     int l = PyList_Size(list);
@@ -160,11 +173,9 @@ static int taglist_contains(PyObject * self, PyObject * tag)
     for(t=0;t<l;t++) {
        PyObject*item = PyList_GetItem(list, t);
        if(item == tag) {
-           mylog(" %08x(%d) taglist_contains: yes", (int)self, self->ob_refcnt);
            return 1;
        }
     }
-    mylog(" %08x(%d) taglist_contains: no", (int)self, self->ob_refcnt);
     return 0;
 }
 //----------------------------------------------------------------------------
@@ -263,7 +274,7 @@ static PyObject * taglist_item(PyObject * self, int index)
     PyObject*tag;
     mylog(" %08x(%d) taglist_item(%d)", (int)self, self->ob_refcnt, index);
     tag = PyList_GetItem(taglist->taglist, index);
-    Py_INCREF(tag); //TODO-REF
+    Py_INCREF(tag);
     return tag;
 }
 static PySequenceMethods taglist_as_sequence =