mylog("+%08x(%d) f_load\n", (int)swf, swf->ob_refcnt);
memset(&swf->swf, 0, sizeof(SWF));
- swf->filename = strdup(filename);
if(!filename) {
PyErr_SetString(PyExc_Exception, setError("Couldn't open file %s", filename));
return 0;
}
+ swf->filename = strdup(filename);
fi = open(filename,O_RDONLY|O_BINARY);
if (fi<0) {
PyErr_SetString(PyExc_Exception, setError("Couldn't open file %s", filename));
int fi;
char*filename = 0;
int compress = 0;
-
+
if(!self)
return NULL;
}
close(fi);
- /* TODO: why is this segfaulting?? */
- /* swf_FreeTags(swf);
- swf->firstTag = 0;*/
+ //swf_FreeTags(swf);
+ /*{ TAG * t = swf->firstTag;
+ while (t)
+ {
+ mylog("tag: %08x\n",t);
+ mylog(" id: %d (%s)\n", t->id, swf_TagGetName(t));
+ mylog(" data: %08x (%d bytes)\n", t->data, t->len);
+ mylog(" next: %08x\n", t->next);
+ TAG * tnew = t->next;
+ mylog("->free data\n");
+ if (t->data) free(t->data);
+ mylog("->free tag\n");
+ free(t);
+ t = tnew;
+ }
+ }*/
+ swf->firstTag = 0;
return PY_NONE;
}
if(!swf->swf.firstTag)
return NULL;
swf_WriteCGI(&swf->swf);
+ swf_FreeTags(&swf->swf);
swf->swf.firstTag = 0;
return PY_NONE;
}
return 0;
} else if(!strcmp(a, "tags")) {
PyObject* taglist;
- /*if (!PyArg_Parse(o, "O!", &TagListClass, &taglist));
- goto err;*/
- // TODO: check if it's really a taglist
taglist = o;
+ PY_ASSERT_TYPE(taglist,&TagListClass);
Py_DECREF(swf->taglist);
swf->taglist = taglist;
Py_INCREF(swf->taglist);
{"verbose", (PyCFunction)module_verbose, METH_KEYWORDS, "Set the module verbosity"},
{0,0,0,0}
};
-
+
void initSWF(void)
{
PyObject*module;
all_methods = addMethods(all_methods, LoggingMethods);
module = Py_InitModule("SWF", all_methods);
+
+ /* Python doesn't copy the PyMethodDef struct, so we need
+ to keep it around */
+ // free(all_methods)
}
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <memory.h>
#include <Python.h>
+
int main(int argn, char*argv[])
{
+ void* dummy = malloc(4096);
return Py_Main(argn, argv);
}
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii|i", kwlist, &r,&g,&b,&a))
return NULL;
color = PyObject_New(ColorObject, &ColorClass);
+ mylog("+%08x(%d) color_new(%d,%d,%d,%d)\n", (int)color, color->ob_refcnt, r,g,b,a);
color->rgba.r = r;
color->rgba.g = g;
color->rgba.b = b;
}
return color->rgba;
}
+void color_dealloc(PyObject* self)
+{
+ mylog("-%08x(%d) color_dealloc\n", (int)self, self->ob_refcnt);
+ PyObject_Del(self);
+}
PyTypeObject ColorClass =
{
PyObject_HEAD_INIT(NULL)
tp_name: "Color",
tp_basicsize: sizeof(ColorObject),
tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
+ tp_dealloc: color_dealloc,
tp_print: 0,
tp_getattr: color_getattr,
tp_setattr: color_setattr,
&box.xmax,
&box.ymax));
return NULL;
+ mylog("+%08x(%d) bbox_new(%d,%d,%d,%d)\n", (int)self, self->ob_refcnt, box.xmin, box.ymin, box.xmax,box.ymax);
bbox = PyObject_New(BBoxObject, &BBoxClass);
bbox->bbox = box;
return (PyObject*)bbox;
mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, a, o);
return 1;
}
+void bbox_dealloc(PyObject* self)
+{
+ mylog("-%08x(%d) bbox_dealloc\n", (int)self, self->ob_refcnt);
+ PyObject_Del(self);
+}
SRECT bbox_getBBox(PyObject*self)
{
BBoxObject*bbox= 0;
tp_name: "BBox",
tp_basicsize: sizeof(BBoxObject),
tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
+ tp_dealloc: bbox_dealloc,
tp_print: 0,
tp_getattr: bbox_getattr,
tp_setattr: bbox_setattr,
MatrixObject*matrix = (MatrixObject*)self;
return matrix->matrix;
}
+void matrix_dealloc(PyObject* self)
+{
+ mylog("-%08x(%d) matrix_dealloc", self, self->ob_refcnt);
+ PyObject_Del(self);
+}
PyTypeObject MatrixClass =
{
PyObject_HEAD_INIT(NULL)
tp_name: "Matrix",
tp_basicsize: sizeof(MatrixObject),
tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
+ tp_dealloc: matrix_dealloc,
tp_print: 0,
tp_getattr: matrix_getattr,
tp_setattr: matrix_setattr,
}
return cxform->cxform;
}
+void colortransform_dealloc(PyObject* self)
+{
+ mylog("-%08x(%d) colortransform_dealloc", self, self->ob_refcnt);
+ PyObject_Del(self);
+}
PyTypeObject CXFormClass =
{
PyObject_HEAD_INIT(NULL)
tp_name: "ColorTransform",
tp_basicsize: sizeof(CXFormObject),
tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
+ tp_dealloc: colortransform_dealloc,
tp_print: 0,
tp_getattr: colortransform_getattr,
tp_setattr: colortransform_setattr,
{
return 0;
}
-GRADIENT colortransform_getGradient(PyObject*self)
+GRADIENT gradient_getGradient(PyObject*self)
{
GradientObject*gradient = 0;
if (!PyArg_Parse(self, "O!", &gradient, &gradient)) {
}
return gradient->gradient;
}
+void gradient_dealloc(PyObject* self)
+{
+ mylog("-%08x(%d) gradient_dealloc", self, self->ob_refcnt);
+ PyObject_Del(self);
+}
PyTypeObject GradientClass =
{
PyObject_HEAD_INIT(NULL)
tp_name: "Gradient",
tp_basicsize: sizeof(GradientObject),
tp_itemsize: 0,
- tp_dealloc: dummy_dealloc,
+ tp_dealloc: gradient_dealloc,
tp_print: 0,
tp_getattr: gradient_getattr,
tp_setattr: gradient_setattr,
buf[l-1] = 0;
l--;
}
- fprintf(stdout, "[SWF] %s\n", buf);
- fflush(stdout);
+ fprintf(stderr, "[SWF] %s\n", buf);
+ fflush(stderr);
}
#define PY_NONE Py_BuildValue("s", 0)
if(obj1) for(num1=0;obj1[num1].ml_name;num1++);
if(obj2) for(num2=0;obj2[num2].ml_name;num2++);
PyMethodDef* result = malloc(sizeof(PyMethodDef)*(num1+num2+1));
- memcpy(result, obj1, num1*sizeof(PyMethodDef));
- memcpy(&result[num1], obj2, (num2+1)*sizeof(PyMethodDef));
- //free(obj1)?
+ if(obj1)
+ memcpy(result, obj1, num1*sizeof(PyMethodDef));
+ if(obj2)
+ memcpy(&result[num1], obj2, (num2+1)*sizeof(PyMethodDef));
+ if(obj1)
+ free(obj1);
return result;
}
void setVerbosity(int _verbose)
static void tag_dealloc(PyObject * self)
{
TagObject*tag = (TagObject*)self;
- mylog("-%08x(%d) tag_dealoc\n", (int)self, self->ob_refcnt);
+ if(tag->tag)
+ mylog("-%08x(%d) tag_dealoc [%s]\n", (int)self, self->ob_refcnt, swf_TagGetName(tag->tag));
+ else
+ mylog("-%08x(%d) tag_dealoc [?]\n", (int)self, self->ob_refcnt);
if(tag->placeobject) {
swf_PlaceObjectFree(tag->placeobject);
tag->placeobject = 0;
swf_SetU8(tag->tag, rgba.r);
swf_SetU8(tag->tag, rgba.g);
swf_SetU8(tag->tag, rgba.b);
- mylog(" %08x(%d) SetBackgroundColor(%02x,%02x,%02x)\n", (int)tag, tag->ob_refcnt, rgba.r, rgba.g, rgba.b);
+ mylog(" %08x(%d) SetBackgroundColor(%02x,%02x,%02x) (colorobj=%08x(%d))\n", (int)tag, tag->ob_refcnt, rgba.r, rgba.g, rgba.b, color, color->ob_refcnt);
return (PyObject*)tag;
}
//----------------------------------------------------------------------------
return NULL;
font = swf_LoadFont(filename);
- mylog("font=%08x",font);
if(!font) {
PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename));
return NULL;
mylog("+%08x(%d) DefineFont\n", (int)tag, tag->ob_refcnt);
return (PyObject*)tag;
}
+static SWFFONT* fonttag_getSWFFONT(PyObject*self)
+{
+ PY_ASSERT_TYPE(self, &TagClass);
+ TagObject*font = (TagObject*)self;
+ return font->font;
+}
//----------------------------------------------------------------------------
static PyObject* f_Protect(PyObject* self, PyObject* args, PyObject* kwargs)
{
int size = 0;
RGBA rgba = {255,0,0,0};
PyObject*color = 0;
- TagObject*font = 0;
+ PyObject*font = 0;
SRECT r;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!u#i|O!", kwlist, &TagClass, &font, &text, &textlen, &size, &ColorClass, &color))
tag = (TagObject*)tag_new();
- /* notice: we do modify the (passed) font object here,
- for the swf_SetDefineText call, who will write out the font id. */
- font->font->id = tagmap_add(tag->tagmap,(PyObject*)font); // add dependency on font
+ int font_id = tagmap_add(tag->tagmap, font); // add dependency on font
+
+ fonttag_getSWFFONT(font)->id = font_id;
tag ->tag= swf_InsertTag(0, ST_DEFINETEXT2);
swf_SetU16(tag->tag, /*ID*/0);
- r = swf_SetDefineText(tag->tag, font->font, &rgba, text, size);
- mylog("+%08x(%d) DefineText %08x -> %08x\n", (int)tag, tag->ob_refcnt);
+ r = swf_SetDefineText(tag->tag, fonttag_getSWFFONT(font), &rgba, text, size);
+ mylog("+%08x(%d) DefineText tag=%08x \n", (int)tag, tag->ob_refcnt);
+
+ //Py_DECREF(unicode16);
+ //Py_DECREF(unicode8);
+ //free(text);
return (PyObject*)tag;
}
&ratio,
&name,
&clipdepth,
- &action
+ &ActionClass, &action
))
return NULL;
po->depth = depth;
po->id = tagmap_add(tag->tagmap,(PyObject*)character);
swf_SetPlaceObject(tag->tag, po);
- mylog("+%08x(%d) PlaceObject %08x\n", (int)tag, tag->ob_refcnt, character);
+ mylog("+%08x(%d) PlaceObject %08x(%d)\n", (int)tag, tag->ob_refcnt, character, character->ob_refcnt);
+
return (PyObject*)tag;
}
{
TagObject*tag = (TagObject*)self;
+ mylog(" %08x(%d) tag_getTAG: tag=%08x id=%d (%s)", (int)self, self->ob_refcnt, tag->tag, tag->tag->id, swf_TagGetName(tag->tag));
+
TAG* t = swf_InsertTag(prevTag, tag->tag->id);
swf_SetBlock(t, tag->tag->data, tag->tag->len);
-
- mylog(" %08x(%d) tag_getTAG tagmap=%08x tag=%08x/%08x\n", (int)self, self->ob_refcnt, tagmap, tag->tag, t);
-
+
if(swf_isDefiningTag(t)) {
int newid = tagmap_add(tagmap, self);
swf_SetDefineID(t, newid);
PyObject* obj = tagmap_id2obj(tag->tagmap, id);
if(obj==NULL) {
PyErr_SetString(PyExc_Exception, setError("Internal error: id %d not known in taglist:"));
+ free(positions);
return 0;
}
int newid = tagmap_obj2id(tagmap, obj);
PUT16(&t->data[positions[i]], newid);
}
+ free(positions);
return t;
}
PyObject* tag_getDependencies(PyObject*self)
{
- mylog(" %08x(%d) tag_getDependencies\n", (int)self, self->ob_refcnt);
TagObject*tag = (TagObject*)self;
+ mylog(" %08x(%d) tag_getDependencies id=%d tag=%s\n", (int)self, self->ob_refcnt, tag->tag->id, swf_TagGetName(tag->tag));
return tagmap_getObjectList(tag->tagmap);
}
+int tag_print (PyObject * self, FILE * fi, int flags)
+{
+ mylog(" %08x(%d) tag_print flags=%08x\n", (int)self, self->ob_refcnt, flags);
+ return 0;
+}
+
PyTypeObject TagClass =
{
PyObject_HEAD_INIT(NULL)
tp_basicsize: sizeof(TagObject),
tp_itemsize: 0,
tp_dealloc: tag_dealloc,
- tp_print: 0,
+ tp_print: tag_print,
tp_getattr: tag_getattr,
};
static PyMethodDef TagMethods[] =
}
if(!firstTag)
firstTag = tag;
- mylog(" %08x(%d) taglist_getTAGs: added tag %08x", (int)self, self->ob_refcnt, tag);
}
Py_DECREF(tagmap);
return firstTag;
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;
PyObject_Del(self);
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;t<l;t++) {
PyObject*item = PyList_GetItem(list, t);
PyObject*_self = taglist_concat(self, item);
self = _self;
}
if(!taglist_contains(self, tag)) {
- mylog(" %08x(%d) taglist_concat: Adding Tag %08x", (int)self, self->ob_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
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;t<l;t++) {
PyObject*item = PyList_GetItem(list, t);
if(!PY_CHECK_TYPE(item, &TagClass)) {
}
PyErr_Clear();
if (PY_CHECK_TYPE(list, &TagListClass)) {
- mylog(" %08x(%d) taglist_concat: TagList", (int)self, self->ob_refcnt);
TagListObject*taglist2 = (TagListObject*)list;
return taglist_concat(self, taglist2->taglist);
sq_ass_slice: 0, // x[i:j] = v intintobjargproc
sq_contains: taglist_contains, //???
};
-static PyTypeObject TagListClass =
+PyTypeObject TagListClass =
{
PyObject_HEAD_INIT(NULL)
0,
//----------------------------------------------------------------------------
int tagmap_obj2id(PyObject* self, PyObject* obj)
{
- mylog(" %08x(%d) tagmap_obj2id %08x", (int)self, self->ob_refcnt, obj);
TagMapObject*tagmap = (TagMapObject*)self;
PyObject*id = PyDict_GetItem(tagmap->obj2id, obj);
if(id == 0)
TagMapObject*tagmap = (TagMapObject*)self;
PyObject*id = PyLong_FromLong(_id);
PyObject*obj = PyDict_GetItem(tagmap->id2obj, id);
- mylog(" %08x(%d) tagmap_id2obj %d->%08x", (int)self, self->ob_refcnt, _id, obj);
Py_DECREF(id);
return obj;
}
//----------------------------------------------------------------------------
int tagmap_getFreeID(PyObject*self)
{
- mylog(" %08x(%d) tagmap_getFreeID", (int)self, self->ob_refcnt);
TagMapObject*tagmap = (TagMapObject*)self;
int last = tagmap->currentID;
do {
//----------------------------------------------------------------------------
void tagmap_dealloc(PyObject* self)
{
- mylog("-%08x(%d) tagmap_dealloc", (int)self, self->ob_refcnt);
TagMapObject*tagmap = (TagMapObject*)self;
+ mylog("-%08x(%d) tagmap_dealloc %08x(%d) %08x(%d), %08x(%d)", (int)self, self->ob_refcnt,
+ tagmap->obj2id, tagmap->obj2id->ob_refcnt ,
+ tagmap->id2obj, tagmap->id2obj->ob_refcnt ,
+ tagmap->objlist, tagmap->objlist->ob_refcnt);
+
Py_DECREF(tagmap->obj2id);
tagmap->obj2id = 0;
Py_DECREF(tagmap->id2obj);
{
mylog(" %08x(%d) tagmap_getObjectList", (int)self, self->ob_refcnt);
TagMapObject*tagmap = (TagMapObject*)self;
- Py_INCREF(tagmap->objlist);
return tagmap->objlist;
}
//----------------------------------------------------------------------------