[C++-sig] Problem extending python (using external DLL)
Aurélien MAIGNAN
amaignan at gmail.com
Fri Jun 6 15:31:43 CEST 2008
Hi
I've got a problem that need an more exp person than me to deal with it :
I've got a naive class for testing interfacing with python using
boost.python.
Since we use OSG 1.2 for our work, I also wanted to do basic stuff using
this library
(http://www.openscenegraph.org/projects/osg/wiki/Downloads/PreviousReleasessee
1.2 version of OSG)
problem is that doesn't work anymore when using this lib.
So i worked around this issue and after a while (up to now in fact)
it result in this more simple problem (minimize the code to highlight the
problem) :
I have a code like this in C++ :
.h
#ifndef HELLOMONDE_H
#define HELLOMONDE_H
#include <string>
#include <iostream>
#include <GL/glaux.h>
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osg/MatrixTransform>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgText/Text>
#include <osgText/Font>
#include <osgText/String>
#include <osgProducer/Viewer>
#include <osg/PositionAttitudeTransform>
#include <boost/python.hpp>
using namespace std;
using namespace boost::python;
class PyCpp
{
private :
string _s;
bool misFileNameNativeStyle(const std::string& fileName)
{
#ifdef WIN32
return fileName.find('/') == std::string::npos; // return true if no
unix style slash exist
#else
return fileName.find('\\') == std::string::npos; // return true if no
windows style slash exist
#endif
};
public :
PyCpp(string s);
void call_myfunc();
void set(string s);
string get();
};
inline void PyCpp::set(string s){_s = s;}
inline string PyCpp::get(){return _s;}
#endif
.c++
#include "PyCpp.h"
using namespace std;
PyCpp::PyCpp(string s):_s(s){}
void PyCpp::call_myfunc()
{
std::string ap = "C:/WINDOWS/Fonts/impact.ttf";
misFileNameNativeStyle(ap); // * LINE 1 *
osgDB::isFileNameNativeStyle(ap);// * LINE 2 *
}
wrapping file :
.cpp
// This file has been generated by Py++.
#include "boost/python.hpp"
#include "f:/testpythoncpp/pycpp/pycpp.h"
namespace bp = boost::python;
BOOST_PYTHON_MODULE(PyCpp_ext){
bp::class_< PyCpp >( "PyCpp", bp::init< std::string >(( bp::arg("s") ))
)
.def(
"get"
, &::PyCpp::get )
.def(
"set"
, &::PyCpp::set
, ( bp::arg("s") ) )
.def(
"call_myfunc"
, &::PyCpp::call_myfunc
);
bp::implicitly_convertible< std::string, PyCpp >();
}
.py (for the local test)
import PyCpp_ext
myPy = PyCpp_ext.PyCpp("bonjour monde")
print myPy.get()
myPy.call_myfunc()
osgDB::FileNameUtils.cpp
....
blablabla
....
bool osgDB::isFileNameNativeStyle(const std::string& fileName)
{
#ifdef WIN32
return fileName.find('/') == std::string::npos; // return true if no
unix style slash exist
#else
return fileName.find('\\') == std::string::npos; // return true if no
windows style slash exist
#endif
}
....
blablabla
....
So as you can see i rewrote my own osgDB::isFileNameNativeStyle() function
(called misFileNameNativeStyle()) and the inner code is the same
and finally the jamroot file :
# Copyright David Abrahams 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# Specify the path to the Boost project. If you move this project,
# adjust this path to refer to the Boost root directory.
use-project boost
: "C:/Program Files/boost/boost_1_35_0" ;
# Set up the project-wide requirements that everything uses the
# boost_python library from the project whose global ID is
# /boost/python.
project
: requirements <library>/boost/python//boost_python
<library>C:/libs/OSG_OP_OT-1.2/OpenSceneGraph/lib/osg.lib
<library>C:/libs/OSG_OP_OT-1.2/OpenSceneGraph/lib/osgProducer.lib
<library>C:/libs/OSG_OP_OT-1.2/OpenSceneGraph/lib/osgText.lib
<library>C:/libs/OSG_OP_OT-1.2/OpenSceneGraph/lib/osgGA.lib
<library>C:/libs/OSG_OP_OT-1.2/OpenSceneGraph/lib/osgDB.lib
<library>C:/libs/OSG_OP_OT-1.2/OpenSceneGraph/lib/Producer.lib
: requirements <include>C:/libs/OSG_OP_OT-1.2/OpenSceneGraph/include
;
# Declare the three extension modules. You can specify multiple
# source files after the colon separated by spaces.
python-extension PyCpp_ext : bindings.cpp PyCpp.h PyCpp.cpp
;
# A little "rule" (function) to clean up the syntax of declaring tests
# of these extension modules.
local rule run-test ( test-name : sources + )
{
import testing ;
testing.make-test run-pyd : $(sources) : : $(test-name) ;
}
# Declare test targets
run-test hello : PyCpp_ext PyCpp.py ;
So what's happen when using the bjam tools ? :
--> When * LINE 1 * is commented (/* */) or not the local test crash : you
can see a beautiful "send me a report" Microsoft style from python .exe with
this
AppName: python.exe AppVer: 0.0.0.0 ModName: msvcr80.dll
ModVer: 8.0.50727.1433 Offset: 000503e2
--> When * LINE 2 * is commented (/* */) it works !
Ok so i gone further in this and since I've access to the osg sources i
decided to recompile and rebuild the osgDB.dll
osgDB::FileNameUtils.cpp has been modified like this :
bool osgDB::isFileNameNativeStyle(const std::string& fileName)
{
fileName.find('/'); // * LINE 3 *
return true;
}
and the resulting new osdDB.dll generated used for the local test
Again what's happen ? :
--> When * LINE 3 * is commented (/* */) it works !
--> When * LINE 3 * isn't commented (/* */) it crash in the same way !!!
My guess is it's about the std::string::find(char) function .... but if so,
why does it work when called in my own function misFileNameNativeStyle()
????
If anyone could help me with this ;)
thanks,
Aurélien MAIGNAN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080606/9ed5eea7/attachment.htm>
More information about the Cplusplus-sig
mailing list