473,387 Members | 1,573 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,387 software developers and data experts.

TR: embeded python progam into visual C++ application crash



-----Message d'origine-----
De : fabien.lyon [mailto:fa*********@isismpp.fr]
Envoyé : mercredi 30 mai 2007 20:16
À : 'p**********@python.org'
Objet : RE: embeded python progam into visual C++ application crash

hello,
The C++ application uses a python module which wraps commands set for CVS
management:
checkout, checkin and tag.
We used python2.5.1 and Visual C++ 6.0
2.5.1 is compiled with Visual Studio 2005 - I hope you had no problems
with VC++ 6.0?
The problem we get is:
After a good import and definition of python functions we have a random
unhandled exception (from python25.dll) when calling python interface
function several times.
All the python module has been tested using the python IDLE.
This the C++ sequence code we used:

Py_initialize()
Py_Import("moduleName")
cvs_init() // cvs view initialisation handled
by
python script init()
cvs_set_tag() // cvs commit and tag handled by python
script settag()
// the exception occured here
>Neither Py_initialize nor Py_Import functions exist - so please post
actual code.
>--
Gabriel Genellina
Ho sorry you are right (this pb disturbs me too much).
Investigation and efforts has been helpfull, so we have found the problem.
This is the following description :

void InterfaceTestConfigPython_C::InitCVS(CString path_vue_bench_p, CString
path_vue_test_p)
{
PyObject *pArgs= NULL, *pValue= NULL;
PyObject *pPathVueBench= NULL, *pPathVueTest= NULL ;

//python objects for each python function argument
pPathVueBench = PyString_FromString((LPCTSTR)path_vue_bench_p);
pPathVueTest = PyString_FromString((LPCTSTR)path_vue_test_p);

//python object to collect all arguments
pArgs = PyTuple_New(2);
PyTuple_SetItem(pArgs, 0, pPathVueBench);
PyTuple_SetItem(pArgs, 1, pPathVueTest);

// python function call
pValue = PyObject_CallObject(pFuncInit_m, pArgs);

// clean up memory
Py_DECREF(pArgs);

// process return value
if (pValue != NULL)
{
....
// clean up memory
Py_DECREF(pValue);
}

// clean up memory
Py_DECREF(pPathVueBench );
Py_DECREF(pPathVueTest);
}

The problem we get come from a wrong code. The last two lines, calling
Py_DECREF, are not mandatory and make the python interpreter in a bad day.
When the InitCVS() function call Py_DECREF(pArgs) the memory allocated for
pPathVueBench and pPathVueTest is free (i guess) because the
PyTuple_SetItem(pArgs, 0, pPathVueBench) steals the reference of the python
object you add into the tuple pArgs like the python documentation tells. So
we have suppressed the last clean up memory
in the InitCVS() function and now the program is running as expected.

I join the C++ object code if this can help someone.


May 31 '07 #1
0 1333

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

Similar topics

3
by: dan_roman | last post by:
Hi, I developed a script with a nice interface in Tkinter that allows me to edit some formulas and to generate an Excel worksheet with VBA macros within it. The script runs perfectlly in Office...
0
by: fabien.lyon | last post by:
hello, The C++ application uses a python module which wraps commands set for CVS management: checkout, checkin and tag. We used python2.5.1 and Visual C++ 6.0 The problem we get is: After a...
3
by: Johnson | last post by:
I'm not sure if this is an IIS 5.1 issue or ASP.NET issue, or Visual Studio 2008 issue -- thus posting to 3 groups. Please don't be offended. The problem I'm encountering is that Visual Studio...
1
by: NitinSawant | last post by:
Is there any Visual sourcesafe like application which is web based (can be installed on a remote website) and can be integrated with visual studio .net? Regards, Nitin
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.