Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about embedding python in C++

0 views
Skip to first unread message

TheShadow

unread,
Aug 23, 2007, 1:44:45 PM8/23/07
to
When extending python in c/c++ after you register a module is there a
way in c/c++ to check if they were correctly registered?

Cause I'm having the problem where when I execute the the python
script it finds the module but none of the functions.

Farshid Lashkari

unread,
Aug 23, 2007, 1:57:55 PM8/23/07
to

Are you calling Py_InitModule(...) in your initmodule function? If so,
Py_InitModule(...) returns a reference to the module object. You can use
this object to double check that your function names exist in the
modules dictionary. Most likely, there is an error in your code. If you
post it, it would be easier to tell what the problem is.

-Farshid

TheShadow

unread,
Aug 23, 2007, 2:34:01 PM8/23/07
to

Hrmm I forgot about the module init function... I was just calling
Py_initModule()

TheShadow

unread,
Aug 23, 2007, 3:17:21 PM8/23/07
to
On Aug 23, 11:57 am, Farshid Lashkari <n...@spam.com> wrote:

Alright that was a dead end. Here is the source code.

bool CPythonModule::Register()
{
bool bReturn = false;
unsigned int uiSize = static_cast<unsigned
int>(m_LPyMethodDefs.size());
if (m_LPyMethodDefs.size() > 0)
{
m_pEmbMethods = new PyMethodDef[m_LPyMethodDefs.size()+1];
unsigned int uiCounter = 0;

IterQPyMethodDefs iterMethods = m_LPyMethodDefs.begin();

while (m_LPyMethodDefs.end() != iterMethods)
{
m_pEmbMethods[uiCounter].ml_name =
m_LPyMethodDefs.front().sName.c_str();
m_pEmbMethods[uiCounter].ml_meth =
m_LPyMethodDefs.front().pFunction;
m_pEmbMethods[uiCounter].ml_flags = m_LPyMethodDefs.front().iFlags;
m_pEmbMethods[uiCounter].ml_doc =
m_LPyMethodDefs.front().sDoc.c_str();

++uiCounter;
++iterMethods;
}

PyMethodDef PyMethodNullDef = {NULL, NULL, 0, NULL};

m_pEmbMethods[uiSize] = PyMethodNullDef;

Py_InitModule(m_sModuleName.c_str(),m_pEmbMethods);

//PythonInterfaceInst->RegisterModule(this);

m_pInitFunc();

bReturn = true;
}
return bReturn;
}

TheShadow

unread,
Aug 23, 2007, 3:28:35 PM8/23/07
to

Forget I said anything I found my bug... I was using m_LPyMethodDefs
instead of my iterator... hurray for writing code at 12am :P

0 new messages