-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Boost.Python equivalent of test_smart_ptr_private_first_base under py…
…bind11 PR #2672. pybind/pybind11#2672 (comment)
- Loading branch information
Ralf W. Grosse-Kunstleve
committed
Dec 21, 2020
0 parents
commit debf3a5
Showing
7 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Experimental stuff using cctbx_project/libtbx build tools. | ||
|
||
## Example bootstrap | ||
``` | ||
cd clone # Any name. | ||
git clone https://github.com/SCons/scons.git | ||
git clone https://github.com/cctbx/boost.git | ||
git clone https://github.com/cctbx/cctbx_project.git | ||
git clone https://github.com/rwgk/rwgk_tbx.git | ||
mkdir bintbx # Any other name. | ||
cd bintbx | ||
python3 ../cctbx_project/libtbx/configure.py --compiler=clang rwgk_tbx | ||
source setpaths.sh | ||
make | ||
libtbx.python ../rwgk_tbx/tst_smart_ptr_private_first_base.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import libtbx.load_env | ||
Import("env_etc", "env_no_includes_boost_python_ext") | ||
env = env_no_includes_boost_python_ext.Clone() | ||
env_etc.enable_more_warnings(env=env) | ||
env_etc.include_registry.append( | ||
env=env, | ||
paths=[ | ||
env_etc.libtbx_include, | ||
env_etc.boost_adaptbx_include, | ||
env_etc.boost_include, | ||
env_etc.python_include]) | ||
env.SharedLibrary( | ||
target="#lib/rwgk_tbx_smart_ptr_private_first_base_ext", | ||
source="smart_ptr_private_first_base_ext.cpp") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"optional_modules": ["boost"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from __future__ import absolute_import, division, print_function | ||
import boost_adaptbx.boost.python as bp | ||
ext = bp.import_ext("rwgk_tbx_smart_ptr_private_first_base_ext") | ||
from rwgk_tbx_smart_ptr_private_first_base_ext import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Boost.Python equivalent of test_smart_ptr_private_first_base under | ||
// pybind11 PR #2672: | ||
// https://github.com/pybind/pybind11/pull/2672#issuecomment-748543648 | ||
|
||
#include <boost/python/class.hpp> | ||
#include <boost/python/def.hpp> | ||
#include <boost/python/module.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace { | ||
|
||
struct base { | ||
base() : base_id(100) {} | ||
virtual ~base() = default; | ||
virtual int id() const { return base_id; } | ||
int base_id; | ||
}; | ||
|
||
struct private_first_base { // Any class with a virtual function will do. | ||
virtual void some_other_virtual_function() const {} | ||
virtual ~private_first_base() = default; | ||
}; | ||
|
||
struct drvd : private private_first_base, public base { | ||
int id() const override { return 2 * base_id; } | ||
}; | ||
|
||
inline std::shared_ptr<drvd> make_shared_drvd() { | ||
return std::shared_ptr<drvd>(new drvd); | ||
} | ||
|
||
inline int pass_shared_base(std::shared_ptr<base> b) { return b->id(); } | ||
|
||
} // namespace | ||
|
||
BOOST_PYTHON_MODULE(rwgk_tbx_smart_ptr_private_first_base_ext) | ||
{ | ||
namespace py = boost::python; | ||
|
||
py::class_<base, std::shared_ptr<base>>("base"); | ||
py::class_<drvd, py::bases<base>, std::shared_ptr<drvd>>("drvd"); | ||
|
||
py::def("make_shared_drvd", make_shared_drvd); | ||
py::def("pass_shared_base", pass_shared_base); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import rwgk_tbx.smart_ptr_private_first_base as m | ||
import sys | ||
|
||
def run(args): | ||
assert not args | ||
d = m.make_shared_drvd() | ||
i = m.pass_shared_base(d) | ||
assert i == 200 | ||
print("Done.") | ||
|
||
if (__name__ == "__main__"): | ||
run(sys.argv[1:]) |