embedded AND extended C code

Neil Macneale mac4-devnull at theory.org
Thu Aug 16 00:04:36 EDT 2001


Hi All-

I am calling Py_InitModule to load modules before, but I have only used it
in functions that at were meant to extend python only. IE, in initmodule()
functions. Now I am calling it from a C function of a program which embeds
python. Basically, I am both embedding the interpreter in a C program, and
I am extending the interpreter with C code.

The code below does not work. The treemaker.py file makes use of
charstar.strFromAddr(), but when I run it, it says that the global charstar
does not exist.  Is there some step I am missing?

Thanks, Neil Macneale

[snip]

PyObject * strFromAddr(PyObject * self, PyObject * args){
    char * addr = NULL;
    
    if(!PyArg_ParseTuple(args, "i", &addr)) return NULL;
    return Py_BuildValue("s", addr);

}

static PyMethodDef charStarMethods[] = {
    {"strFromAddr",  strFromAddr,  METH_VARARGS },
    {NULL,NULL}
};


void init_treemaker(char * progName){
    Py_SetProgramName(progName);
    Py_Initialize();

    Py_InitModule("charstar", charStarMethods);
    
    PyRun_SimpleString("import treemaker");
    PyRun_SimpleString("treemaker.initialize()");
   
}


[snip]

-- 

If you want to email me, remove the '-devnull' from my email address



More information about the Python-list mailing list