X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftaglist.c;h=a5d28d1a6dfd7275e3c0c94d041100f1746fa4a9;hb=4ca7f5a76f6cd8a8397ecb1078b87e038719a050;hp=27b3a6662ea48777cbf9bb7582ce40e1bedf417a;hpb=726d172d02228a2e9b084efba8d3173994343c2b;p=swftools.git diff --git a/lib/python/taglist.c b/lib/python/taglist.c index 27b3a66..a5d28d1 100644 --- a/lib/python/taglist.c +++ b/lib/python/taglist.c @@ -13,14 +13,12 @@ typedef struct { PyObject_HEAD PyObject* taglist; - PyObject* tagmap; } TagListObject; //---------------------------------------------------------------------------- PyObject * taglist_new() { TagListObject* taglist = PyObject_New(TagListObject, &TagListClass); - mylog("+%08x(%d) taglist_new2", (int)taglist, taglist->ob_refcnt); - taglist->tagmap = tagmap_new(); + mylog("+%08x(%d) taglist_new", (int)taglist, taglist->ob_refcnt); taglist->taglist = PyList_New(0); return (PyObject*)taglist; } @@ -28,30 +26,49 @@ PyObject * taglist_new() PyObject * taglist_new2(TAG*tag) { TagListObject* taglist = PyObject_New(TagListObject, &TagListClass); - mylog("+%08x(%d) taglist_new2", (int)taglist, taglist->ob_refcnt); - taglist->tagmap = tagmap_new(); + mylog("+%08x(%d) taglist_new2 tag=%08x", (int)taglist, taglist->ob_refcnt, tag); + PyObject* tagmap = tagmap_new(); + + swf_FoldAllTags(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); nr = 0; t = tag; while(t) { - PyObject*newtag = tag_new(tag); + PyObject*newtag = tag_new2(t, tagmap); + if(newtag==NULL) { + // pass through exception + Py_DECREF(tagmap); + 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(tagmap, id, newtag); } nr++; t=t->next; } + Py_DECREF(tagmap); return (PyObject*)taglist; } //---------------------------------------------------------------------------- TAG* taglist_getTAGs(PyObject*self) { + PyObject* tagmap = tagmap_new(); if(!PY_CHECK_TYPE(self,&TagListClass)) { PyErr_SetString(PyExc_Exception, setError("Not a taglist (%08x).", self)); return 0; @@ -67,10 +84,17 @@ TAG* taglist_getTAGs(PyObject*self) mylog(" %08x(%d) taglist_getTAGs", (int)self, self->ob_refcnt); for(t=0;ttaglist, t); - tag = tag_getTAG(item, tag, taglist->tagmap); + tag = tag_getTAG(item, tag, tagmap); + if(!tag) { + //pass through errors + Py_DECREF(tagmap); + return 0; + } if(!firstTag) firstTag = tag; + mylog(" %08x(%d) taglist_getTAGs: added tag %08x", (int)self, self->ob_refcnt, tag); } + Py_DECREF(tagmap); return firstTag; } //---------------------------------------------------------------------------- @@ -122,8 +146,6 @@ static void taglist_dealloc(PyObject* self) mylog("-%08x(%d) taglist_dealloc\n", (int)self, self->ob_refcnt); Py_DECREF(taglist->taglist); taglist->taglist = 0; - Py_DECREF(taglist->tagmap); - taglist->tagmap= 0; PyObject_Del(self); } //---------------------------------------------------------------------------- @@ -150,7 +172,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); @@ -158,11 +180,9 @@ static int taglist_contains(PyObject * self, PyObject * tag) for(t=0;tob_refcnt); return 1; } } - mylog(" %08x(%d) taglist_contains: no", (int)self, self->ob_refcnt); return 0; } //---------------------------------------------------------------------------- @@ -261,7 +281,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 =