473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error on crude test of embedding python in c++ HELP PLEASE

I wrote a program to test calling c function from python code embedding in c
as following, it cause error after running a while(about 398 circle). I
test it in msvc6, python2.3, windows 2k, could anyone tell me why this
happened since i just work according to the document? Thanks first.

Donnie Leen
source code:
#include <Python.h>

static PyObject* pymyfun( PyObject* self, PyObject* args )
{
return Py_None; // do nothing
}
static PyMethodDef emb_methods[] = {
{ "fun", pymyfun, METH_VARARGS, "doc." },
{NULL, NULL, 0, NULL}
};

void main( )
{
Py_Initialize( );

PyObject* r = Py_InitModule( "mymodule", emb_methods );
PyRun_SimpleString( "import mymodule" );
while ( 1 )
{
// error occur after 398 loops here
PyRun_SimpleString( "mymodule.fun( 'testest' )" );
}

Py_Finalize();
}

Jul 18 '05 #1
2 1370
"Donnie Leen" <Ki*********@yeah.net> writes:
I wrote a program to test calling c function from python code embedding in c
as following, it cause error after running a while(about 398 circle). I
test it in msvc6, python2.3, windows 2k, could anyone tell me why this
happened since i just work according to the document? Thanks first.

Donnie Leen
source code:
#include <Python.h>

static PyObject* pymyfun( PyObject* self, PyObject* args )
{
return Py_None; // do nothing
You forgot an Py_INCREF here:
Py_INCREF(Py_None);
return Py_None; // do nothing
}
static PyMethodDef emb_methods[] = {
{ "fun", pymyfun, METH_VARARGS, "doc." },
{NULL, NULL, 0, NULL}
};

void main( )
{
Py_Initialize( );

PyObject* r = Py_InitModule( "mymodule", emb_methods );
PyRun_SimpleString( "import mymodule" );
while ( 1 )
{
// error occur after 398 loops here
PyRun_SimpleString( "mymodule.fun( 'testest' )" );
}

Py_Finalize();
}

Jul 18 '05 #2
Got it, thanks :)

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
0
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
2
by: John Dean | last post by:
Hi Could somebody, please tell me where I can find information about embedding Python into a C/C++ application. The example in the docs is rather simple. I am looking for something a bit more...
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
4
by: | last post by:
Hi, Today is my first day of working on python. I want to execute python script through C++ program. I found one very good article with example at http://docs.python.org/ext/pure-embedding.html....
1
by: could.net | last post by:
I use boost 1.33_1, there's an example on boost::python named embedding.cpp. When I tried to build and run it in visual studio 2005, I got an error on this line: std::string hello() { return...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
1
by: Eric_Dexter | last post by:
I compiled the comand line example and I am getting an error when I try to use the program when the program is cleaning up (I don't know that it would prevent the program from running though I will...
6
towsie
by: towsie | last post by:
Hi, I would be very grateful if someone could have a look at the staement below and help me find the Syntax Error. ("Select origin_of_sale as Origin, Category, Crude.F3 as Customer,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.