Adapting Boost Python library detection to Boost >= 1.67. Closes #4288.
parent
748c9d817d
commit
30e42009c0
5 changed files with 120 additions and 12 deletions
@ -0,0 +1,22 @@ |
||||
#define PY_SSIZE_T_CLEAN |
||||
#include <Python.h> |
||||
#include <boost/python.hpp> |
||||
|
||||
struct World |
||||
{ |
||||
void set(std::string msg) { this->msg = msg; } |
||||
std::string greet() { return msg; } |
||||
std::string version() { return std::to_string(PY_MAJOR_VERSION) + "." + std::to_string(PY_MINOR_VERSION); } |
||||
std::string msg; |
||||
}; |
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(MOD_NAME) |
||||
{ |
||||
using namespace boost::python; |
||||
class_<World>("World") |
||||
.def("greet", &World::greet) |
||||
.def("set", &World::set) |
||||
.def("version", &World::version) |
||||
; |
||||
} |
@ -0,0 +1,27 @@ |
||||
import sys |
||||
sys.path.append(sys.argv[1]) |
||||
|
||||
# import compiled python module depending on version of python we are running with |
||||
if sys.version_info[0] == 2: |
||||
import python2_module |
||||
|
||||
if sys.version_info[0] == 3: |
||||
import python3_module |
||||
|
||||
|
||||
def run(): |
||||
msg = 'howdy' |
||||
if sys.version_info[0] == 2: |
||||
w = python2_module.World() |
||||
|
||||
if sys.version_info[0] == 3: |
||||
w = python3_module.World() |
||||
|
||||
w.set(msg) |
||||
|
||||
assert(msg == w.greet()) |
||||
version_string = str(sys.version_info[0]) + "." + str(sys.version_info[1]) |
||||
assert(version_string == w.version()) |
||||
|
||||
if __name__ == '__main__': |
||||
run() |
Loading…
Reference in new issue