PyRun_String and related functions causing garbage when calling a parsed function from C.
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon May 14 02:38:16 EDT 2007
En Sun, 13 May 2007 17:58:17 -0300, <joeedh at gmail.com> escribió:
> Hi I'm getting extremely odd behavior. First of all, why isn't
> PyEval_EvalCode documented anywhere? Anyway, I'm working on
> blender's
> python integration (it embeds python, as opposed to python embedding
> it). I have a function that executes a string buffer of python code,
> fetches a function from its global dictionary then calls it.
Why don't you use a documented function like PyRun_String or similar, as
in the subject line?
> /*Now for the fun part! Try and find the functions we need.*/
> while ( PyDict_Next(globals, &ppos, &gkey, &gval) ) {
> if ( PyString_Check(gkey) && strcmp(PyString_AsString(gkey),
> "doConstraint")==0 ) {
> if (PyFunction_Check(gval) ) {
> retval = PyObject_CallObject(gval,
> Py_BuildValue("OOO",
> srcmat, tarmat, idprop));
> Py_XDECREF( retval );
> } else {
> printf("ERROR: doConstraint is supposed to be a
> function!\n");
> }
> break;
> }
> }
I'd use PyDict_Get_Item_String (iterating over a dict just to locate a key
is rather silly).
And, if you are going to use the return value from PyObject_CallObject
(retval), don't decref it!!! (you even decref it twice).
--
Gabriel Genellina
More information about the Python-list
mailing list