X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftaglist.c;h=8b4acf173106f98e78c960a14eb2add07cd408e1;hb=f44240dc075f338630e1f02de3baca03f8806da8;hp=e16f84a0b96a48f042d64043c0968dca950cfd68;hpb=b4d2af74c98317254799a2e1642dce508afc9345;p=swftools.git diff --git a/lib/python/taglist.c b/lib/python/taglist.c index e16f84a..8b4acf1 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_new", (int)taglist, taglist->ob_refcnt); - taglist->tagmap = tagmap_new(); taglist->taglist = PyList_New(0); return (PyObject*)taglist; } @@ -29,7 +27,9 @@ PyObject * taglist_new2(TAG*tag) { TagListObject* taglist = PyObject_New(TagListObject, &TagListClass); mylog("+%08x(%d) taglist_new2 tag=%08x", (int)taglist, taglist->ob_refcnt, tag); - taglist->tagmap = tagmap_new(); + PyObject* tagmap = tagmap_new(); + + swf_FoldAllTags(tag); int nr=0; TAG*t = tag; @@ -48,24 +48,27 @@ PyObject * taglist_new2(TAG*tag) nr = 0; t = tag; while(t) { - PyObject*newtag = tag_new2(t, taglist->tagmap); + 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)) { int id = swf_GetDefineID(t); - tagmap_addMapping(taglist->tagmap, id, newtag); + 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; @@ -81,11 +84,16 @@ 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; } //---------------------------------------------------------------------------- @@ -134,11 +142,9 @@ static PyObject * taglist_optimizeOrder(PyObject* self, PyObject* args) static void taglist_dealloc(PyObject* self) { TagListObject*taglist = (TagListObject*)self; - mylog("-%08x(%d) taglist_dealloc\n", (int)self, self->ob_refcnt); + 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; - Py_DECREF(taglist->tagmap); - taglist->tagmap= 0; PyObject_Del(self); } //---------------------------------------------------------------------------- @@ -184,14 +190,12 @@ static PyObject * taglist_concat(PyObject * self, PyObject* list) PyObject*tag = 0; PY_ASSERT_TYPE(self, &TagListClass); TagListObject*taglist = (TagListObject*)self; - mylog(" %08x(%d) taglist_concat %08x", (int)self, self->ob_refcnt, list); + mylog(" %08x(%d) taglist_concat %08x(%d)", (int)self, self->ob_refcnt, list, list->ob_refcnt); if (PyArg_Parse(list, "O!", &TagClass, &tag)) { - mylog(" %08x(%d) taglist_concat: Tag %08x", (int)self, self->ob_refcnt, tag); list = tag_getDependencies(tag); int l = PyList_Size(list); int t; - mylog(" %08x(%d) taglist_concat: Tag: %d dependencies", (int)self, self->ob_refcnt, l); for(t=0;tob_refcnt, tag); + mylog(" %08x(%d) taglist_concat: Adding Tag %08x(%d)", (int)self, self->ob_refcnt, tag, tag->ob_refcnt); PyList_Append(taglist->taglist, tag); + } else { + mylog(" %08x(%d) taglist_concat: Already contains Tag %08x(%d)", (int)self, self->ob_refcnt, tag, tag->ob_refcnt); } - mylog(" %08x(%d) taglist_concat: done", (int)self, self->ob_refcnt); Py_INCREF(self); return self; /* copy tag, so we don't have to do INCREF(tag) (and don't @@ -232,7 +237,6 @@ static PyObject * taglist_concat(PyObject * self, PyObject* list) if (PyList_Check(list)) { int l = PyList_Size(list); int t; - mylog(" %08x(%d) taglist_concat: List", (int)self, self->ob_refcnt); for(t=0;tob_refcnt); TagListObject*taglist2 = (TagListObject*)list; return taglist_concat(self, taglist2->taglist); @@ -288,7 +291,7 @@ static PySequenceMethods taglist_as_sequence = sq_ass_slice: 0, // x[i:j] = v intintobjargproc sq_contains: taglist_contains, //??? }; -static PyTypeObject TagListClass = +PyTypeObject TagListClass = { PyObject_HEAD_INIT(NULL) 0,