added tag_setattr, added sprite support
[swftools.git] / lib / python / taglist.c
index 8b4acf1..d606ab3 100644 (file)
@@ -15,6 +15,16 @@ typedef struct {
     PyObject* taglist;
 } TagListObject;
 //----------------------------------------------------------------------------
+static void taglist_showcontents(PyObject* self)
+{
+    TagListObject*taglist = (TagListObject*)self;
+    int t, l = PyList_Size(taglist->taglist);
+    for(t=0;t<l;t++) {
+       PyObject*item = PyList_GetItem(taglist->taglist, t);
+       mylog(" %08x(%d) taglist_showcontents   item=%08x(%d)\n", (int)self, self->ob_refcnt, item, item->ob_refcnt);
+    }
+}
+//----------------------------------------------------------------------------
 PyObject * taglist_new()
 {
     TagListObject* taglist = PyObject_New(TagListObject, &TagListClass);
@@ -29,22 +39,19 @@ PyObject * taglist_new2(TAG*tag)
     mylog("+%08x(%d) taglist_new2 tag=%08x", (int)taglist, taglist->ob_refcnt, tag);
     PyObject* tagmap = tagmap_new();
 
-    swf_FoldAllTags(tag);
-
-    int nr=0;
+    int nr=0, len=0;
     TAG*t = tag;
     TAG*last = t;
-    while(t) {nr++;last=t;t=t->next;}
+    while(t) {len++;last=t;t=t->next;}
 
     if(last && last->id==ST_END) {
-       swf_DeleteTag(last);
-       nr--;
+       swf_DeleteTag(last); last = 0;
+       len--;
+       if(len==0) tag = 0;
     }
 
-    taglist->taglist = PyList_New(nr);
+    taglist->taglist = PyList_New(len);
     
-    mylog("+%08x(%d) taglist_new2: %d items", (int)taglist, taglist->ob_refcnt, nr);
-
     nr = 0;
     t = tag;
     while(t) {
@@ -61,6 +68,7 @@ PyObject * taglist_new2(TAG*tag)
        }
        nr++;
        t=t->next;
+       Py_DECREF(newtag);
     }
     Py_DECREF(tagmap);
     return (PyObject*)taglist;
@@ -139,15 +147,6 @@ static PyObject * taglist_optimizeOrder(PyObject* self, PyObject* args)
     return PY_NONE;
 }
 //----------------------------------------------------------------------------
-static void taglist_dealloc(PyObject* self)
-{
-    TagListObject*taglist = (TagListObject*)self;
-    mylog("-%08x(%d) taglist_dealloc list=%08x(%d)\n", (int)self, self->ob_refcnt, taglist->taglist, taglist->taglist->ob_refcnt);
-    Py_DECREF(taglist->taglist);
-    taglist->taglist = 0;
-    PyObject_Del(self);
-}
-//----------------------------------------------------------------------------
 static PyMethodDef taglist_functions[] =
 {{"foldAll", taglist_foldAll, METH_VARARGS, "fold all sprites (movieclips) in the list"},
  {"unfoldAll", taglist_unfoldAll, METH_VARARGS, "unfold (expand) all sprites (movieclips) in the list"},
@@ -280,6 +279,16 @@ static PyObject * taglist_item(PyObject * self, int index)
     Py_INCREF(tag);
     return tag;
 }
+//----------------------------------------------------------------------------
+static void taglist_dealloc(PyObject* self)
+{
+    TagListObject*taglist = (TagListObject*)self;
+    mylog("-%08x(%d) taglist_dealloc list=%08x(%d)\n", (int)self, self->ob_refcnt, taglist->taglist, taglist->taglist->ob_refcnt);
+    Py_DECREF(taglist->taglist);
+    taglist->taglist = 0;
+    PyObject_Del(self);
+}
+//----------------------------------------------------------------------------
 static PySequenceMethods taglist_as_sequence =
 {
     sq_length: taglist_length, // len(obj)