diff --git a/doc/tutorial/doc/html/index.html b/doc/tutorial/doc/html/index.html index 175ffe68..c324f065 100644 --- a/doc/tutorial/doc/html/index.html +++ b/doc/tutorial/doc/html/index.html @@ -66,6 +66,7 @@
Derived Object types
Extracting C++ objects
Enums
+
Creating boost::python::object from PyObject*
Embedding
Using the interpreter
@@ -132,7 +133,7 @@ - +

Last revised: December 26, 2011 at 21:51:27 GMT

Last revised: December 26, 2011 at 21:58:39 GMT


diff --git a/doc/tutorial/doc/html/python/object.html b/doc/tutorial/doc/html/python/object.html index e05c47ec..7bc2aa25 100644 --- a/doc/tutorial/doc/html/python/object.html +++ b/doc/tutorial/doc/html/python/object.html @@ -30,6 +30,7 @@
Derived Object types
Extracting C++ objects
Enums
+
Creating boost::python::object from PyObject*

Python is dynamically typed, unlike C++ which is statically typed. Python variables @@ -314,6 +315,32 @@ ; +

+

+Creating boost::python::object from PyObject* +

+

+ When you want a boost::python::object to manage a pointer to PyObject* + pyobj one does: +

+
boost::python::object o(boost::python::handle<>(pyobj));
+
+

+ In this case, the o object, + manages the pyobj, it won’t + increase the reference count on construction. +

+

+ Otherwise, to use a borrowed reference: +

+
boost::python::object o(boost::python::handle<>(boost::python::borrowed(pyobj)));
+
+

+ In this case, Py_INCREF is + called, so pyobj is not destructed + when object o goes out of scope. +

+
diff --git a/doc/tutorial/doc/tutorial.qbk b/doc/tutorial/doc/tutorial.qbk index 94ecc55b..204c5004 100644 --- a/doc/tutorial/doc/tutorial.qbk +++ b/doc/tutorial/doc/tutorial.qbk @@ -1302,6 +1302,23 @@ create a new scope around a class: [def PyModule_GetDict [@http://www.python.org/doc/current/api/moduleObjects.html#l2h-594 PyModule_GetDict]] [endsect] + +[section:creating_python_object Creating `boost::python::object` from `PyObject*`] + +When you want a `boost::python::object` to manage a pointer to `PyObject*` pyobj one does: + + boost::python::object o(boost::python::handle<>(pyobj)); + +In this case, the `o` object, manages the `pyobj`, it won’t increase the reference count on construction. + +Otherwise, to use a borrowed reference: + + boost::python::object o(boost::python::handle<>(boost::python::borrowed(pyobj))); + +In this case, `Py_INCREF` is called, so `pyobj` is not destructed when object o goes out of scope. + +[endsect] [/ creating_python_object ] + [endsect] [/ Object Interface] [section Embedding] diff --git a/include/boost/python/detail/config.hpp b/include/boost/python/detail/config.hpp index acafc037..76595ebb 100644 --- a/include/boost/python/detail/config.hpp +++ b/include/boost/python/detail/config.hpp @@ -76,13 +76,13 @@ # if BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY # if defined(BOOST_PYTHON_SOURCE) -# define BOOST_PYTHON_DECL __attribute__ ((visibility("default"))) +# define BOOST_PYTHON_DECL __attribute__ ((__visibility__("default"))) # define BOOST_PYTHON_BUILD_DLL # else # define BOOST_PYTHON_DECL # endif # define BOOST_PYTHON_DECL_FORWARD -# define BOOST_PYTHON_DECL_EXCEPTION __attribute__ ((visibility("default"))) +# define BOOST_PYTHON_DECL_EXCEPTION __attribute__ ((__visibility__("default"))) # elif (defined(_WIN32) || defined(__CYGWIN__)) # if defined(BOOST_PYTHON_SOURCE) # define BOOST_PYTHON_DECL __declspec(dllexport) diff --git a/include/boost/python/module_init.hpp b/include/boost/python/module_init.hpp index 54d87e4b..a9536c88 100644 --- a/include/boost/python/module_init.hpp +++ b/include/boost/python/module_init.hpp @@ -76,7 +76,7 @@ extern "C" __declspec(dllexport) _BOOST_PYTHON_MODULE_INIT(name) # define BOOST_PYTHON_MODULE_INIT(name) \ void BOOST_PP_CAT(init_module_,name)(); \ -extern "C" __attribute__ ((visibility("default"))) _BOOST_PYTHON_MODULE_INIT(name) +extern "C" __attribute__ ((__visibility__("default"))) _BOOST_PYTHON_MODULE_INIT(name) # else