Google Groups Home
Help | Sign in
Question about embedding python in C++
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
TheShadow  
View profile
 More options Aug 23 2007, 1:44 pm
Newsgroups: comp.lang.python
From: TheShadow <theshad...@gmail.com>
Date: Thu, 23 Aug 2007 17:44:45 -0000
Local: Thurs, Aug 23 2007 1:44 pm
Subject: Question about embedding python in C++
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.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Farshid Lashkari  
View profile
 More options Aug 23 2007, 1:57 pm
Newsgroups: comp.lang.python
From: Farshid Lashkari <n...@spam.com>
Date: Thu, 23 Aug 2007 10:57:55 -0700
Local: Thurs, Aug 23 2007 1:57 pm
Subject: Re: Question about embedding python in C++

TheShadow wrote:
> 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.

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TheShadow  
View profile
 More options Aug 23 2007, 2:34 pm
Newsgroups: comp.lang.python
From: TheShadow <theshad...@gmail.com>
Date: Thu, 23 Aug 2007 18:34:01 -0000
Local: Thurs, Aug 23 2007 2:34 pm
Subject: Re: Question about embedding python in C++
On Aug 23, 11:57 am, Farshid Lashkari <n...@spam.com> wrote:

> TheShadow wrote:
> > 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.

> 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

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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TheShadow  
View profile
 More options Aug 23 2007, 3:17 pm
Newsgroups: comp.lang.python
From: TheShadow <theshad...@gmail.com>
Date: Thu, 23 Aug 2007 19:17:21 -0000
Local: Thurs, Aug 23 2007 3:17 pm
Subject: Re: Question about embedding python in C++
On Aug 23, 11:57 am, Farshid Lashkari <n...@spam.com> wrote:

> TheShadow wrote:
> > 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.

> 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

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;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TheShadow  
View profile
 More options Aug 23 2007, 3:28 pm
Newsgroups: comp.lang.python
From: TheShadow <theshad...@gmail.com>
Date: Thu, 23 Aug 2007 19:28:35 -0000
Local: Thurs, Aug 23 2007 3:28 pm
Subject: Re: Question about embedding python in C++
On Aug 23, 1:17 pm, TheShadow <theshad...@gmail.com> wrote:

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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google