boost-python

Why is PyGILState_Release throwing Fatal Python Errors

断了今生、忘了曾经 提交于 2019-12-04 04:18:22
ANSWERED Ok, I solved this issue. Its all in how you initialize the thread state. You don't need to use ReleaseLock at all. Simply add InitThreads call to your module definition: BOOST_PYTHON_MODULE(ModuleName) { PyEval_InitThreads(); ... } Ok, I have attempted to diagnose this problem for hours and poured through what seems like every example on the web. Getting tired now so I may be missing something obvious but here is what is happening: I am wrapping a library in boost python. I am running a python script which imports the lib, constructs some objects and then receives callbacks from c++

MacOSX + Boost_Python + PyFTGL :- Symbol not found, expected in: flat namespace

喜你入骨 提交于 2019-12-04 03:05:31
问题 I am trying to install PyFTGL on MacOSX Yosemite. The python version I am using is 2.7 from macports. I have installed boost from macports specifying +python27. To install PyFTGL I built from source and edited the setup.py file from: module_ftgl_libs = [ 'GLU', 'GL', 'freetype', 'z', 'ftgl', 'boost_python', ] module_ftgl = Extension( 'FTGL', module_ftgl_src, include_dirs=module_ftgl_include_dirs, libraries=module_ftgl_libs ) to: module_ftgl_libs = [ 'freetype', 'z', 'ftgl', 'boost_python', ]

Need help getting started with Boost.Python

て烟熏妆下的殇ゞ 提交于 2019-12-04 03:02:13
I'm trying to build my first Boost.Python example. #include <iostream> #include <boost/python.hpp> using namespace boost::python; class Hello { public: std::string greet() { std::cout << "Hello World" << std::endl; } }; BOOST_PYTHON_MODULE(hello) { class_<Hello>("Hello") .def("greet", &Hello::greet); } int main() { std::cout << "Boost.Python Test" << std::endl; Hello hello; hello.greet(); return 0; } EDIT: Python development headers were missing, as @cdhowie has pointed out. I have found and included the required header files. Now the linker is complaining: 10:43:58 **** Build of configuration

How to expose raw byte buffers with Boost::Python?

末鹿安然 提交于 2019-12-04 02:53:00
I've got third party C++ library in which some class methods use raw byte buffers. I'm not quite sure how to deal in Boost::Python with it. C++ library header is something like: class CSomeClass { public: int load( unsigned char *& pInBufferData, int & iInBufferSize ); int save( unsigned char *& pOutBufferData, int & iOutBufferSize ); } In stuck with the Boost::Python code... class_<CSomeClass>("CSomeClass", init<>()) .def("load", &CSomeClass::load, (args(/* what do I put here??? */))) .def("save", &CSomeClass::save, (args(/* what do I put here??? */))) How do I wrap these raw buffers to

How to override the automatically created docstring data for Boost::Python?

雨燕双飞 提交于 2019-12-04 02:40:40
I am currently working developing a C++-based module for Python. I have found that Boost::Python is working quite well for what I want to accomplish. However, I am now running into some issues with the docstring that is being generated by Boost::Python. Given the following Boost::Python definitions: BOOST_PYTHON_MODULE(gcsmt) { class_<gcsmt::Units>("Units", "Sets the units used as input.", no_init) .def("PrintSupported", &gcsmt::Units::printSupported, "Print out all supported units.") .def("SetDefault", &gcsmt::Units::setDefaultUnit, "Sets the default unit to be used for inputs/outputs.")

Python method resolution mystery

南笙酒味 提交于 2019-12-04 01:32:20
问题 I can't figure out why this program is failing. #!/usr/bin/env python from __future__ import division, print_function from future_builtins import * import types import libui as ui from PyQt4 import QtCore import sip p = ui.QPoint() q = QtCore.QPoint() def _q_getattr(self, attr): print("get %s" % attr) value = getattr(sip.wrapinstance(self.myself(), QtCore.QPoint), attr) print("get2 %s returned %s" % (attr, value)) return value p.__getattr__ = types.MethodType(_q_getattr, p) print(p.__getattr_

what is wrong with c++ streams when using boost.python?

假如想象 提交于 2019-12-03 23:37:15
Update 2: I'm not sure why this is still being upvoted (March 2014). This appears to be fixed since I asked this question many years ago. Make sure you're using a recent version of boost. UPDATE: Perhaps C++ streams need to be initialized in order to format numbers, and the initialization is not happening when the shared library is loaded in Python? I am calling cout << 1 << "!" << endl; in a method that is exported to a shared library via boost.python. It doesn't print anything, but if I do cout << "%" << "!" << endl; it works. This is important because I want to do this: ostream& operator <<

Boost Python: polymorphic container?

久未见 提交于 2019-12-03 16:22:12
I have a method (or function) which returns a reference to a list of polymorphic objects: class A { }; class B : public A { }; std::list<boost::shared_ptr<A> >& getList(); How do I expose such a function in boost::python so that when iterating on the list in python, I would see the different types of A s and B s ? First, make sure your classes are indeed polymorphic (i.e. they have at least one virtual function or a virtual destructor). Your example above doesn't, though I'm sure your real use case does. Without that none of Boost.Python's RTTI-based machinery for polymorphism will work. Then,

boost::python: howto call a function that expects a pointer?

拟墨画扇 提交于 2019-12-03 14:36:32
I have a function that takes an int-pointer and exposed it via boost::python. How can I call this function from python? in C++ with boost::python: void foo(int* i); ... def("foo", foo); in python: import foo_ext i = 12 foo_ext.foo(i) results in Traceback (most recent call last): File "<stdin>", line 1, in <module> Boost.Python.ArgumentError: Python argument types in foo(int) did not match C++ signature: foo(int* i) So how to pass a pointer? Short answer is : You can't. Python does not have pointers Long answer is: There are assorted workarounds depending on use-case. I notice that you are

Boost Python Hello World example not working in Python

和自甴很熟 提交于 2019-12-03 13:36:16
I'm having a great deal of trouble using my c++ code from Visual C++ (wrapped by boost) in Python. Alright, so the tools I'm using are: Visual Studio 2010, BoostPro 1_47, Windows 7, and Python 2.7 (32-bit). I have the following code which compiles nicely in Visual Studio 2010: #define BOOST_PYTHON_STATIC_LIB #include <boost/python.hpp> using namespace boost::python; struct World { void set(std::string msg) { this->msg = msg; } std::string greet() { return msg; } std::string msg; }; BOOST_PYTHON_MODULE(hello) { class_<World>("World") .def("greet", &World::greet) .def("set", &World::set); } It's