2fdc0e1701cbbd9bb0b491647186440e6c70c863
[swftools.git] / lib / python / pyutils.c
1 #include <Python.h>
2 #include <stdarg.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6
7 char* setError(char*format, ...)
8 {
9     char buf[1024];
10     int l;
11     va_list arglist;
12     va_start(arglist, format);
13     vsprintf(buf, format, arglist);
14     va_end(arglist);
15     l = strlen(buf);
16     while(l && buf[l-1]=='\n') {
17         buf[l-1] = 0;
18         l--;
19     }
20     return strdup(buf);
21 }
22
23 static int verbose = 1;
24 void mylog(char*format, ...)
25 {
26     char buf[1024];
27     int l;
28     va_list arglist;
29     if(!verbose)
30         return;
31     va_start(arglist, format);
32     vsprintf(buf, format, arglist);
33     va_end(arglist);
34     l = strlen(buf);
35     while(l && buf[l-1]=='\n') {
36         buf[l-1] = 0;
37         l--;
38     }
39     fprintf(stderr, "[SWF] %s\n", buf);
40     fflush(stderr);
41 }
42
43 #define PY_NONE Py_BuildValue("s", 0)
44
45 PyObject* FindMethodMore(PyObject*ret, PyMethodDef f[], PyObject*self, char* a)
46 {
47     if(ret==NULL) {
48         ret = Py_FindMethod(f, self, a);
49     } else {
50         if(!strcmp(a, "__methods__")) {
51             /* we are being dir()ed. Complete the function table */
52             PyObject* add = Py_FindMethod(f, self, a);
53             int t;
54             mylog("taglist_getattr: append common funtions %08x %08x\n", ret, add);
55             for(t=0;t<PyList_Size(add);t++)
56                 PyList_Append(ret, PyList_GetItem(add, t));
57         }
58     }
59     return ret;
60 }
61
62 void dummy_dealloc(PyObject* self)
63 {
64     PyObject_Del(self);
65 }
66