|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53285 - in sandbox-branches/bhy/py3k: boost/python boost/python/object libs/python/src
From: divinekid_at_[hidden]
Date: 2009-05-26 13:05:56
Author: bhy
Date: 2009-05-26 13:05:53 EDT (Tue, 26 May 2009)
New Revision: 53285
URL: http://svn.boost.org/trac/boost/changeset/53285
Log:
more fixes to get testcases work, includes module init and other minor fixes
Text files modified:
sandbox-branches/bhy/py3k/boost/python/enum.hpp | 4 ++++
sandbox-branches/bhy/py3k/boost/python/module_init.hpp | 37 +++++++++++++++++++++++--------------
sandbox-branches/bhy/py3k/boost/python/object/make_instance.hpp | 2 +-
sandbox-branches/bhy/py3k/libs/python/src/exec.cpp | 10 +++++++++-
sandbox-branches/bhy/py3k/libs/python/src/object_operators.cpp | 8 ++++++++
sandbox-branches/bhy/py3k/libs/python/src/object_protocol.cpp | 10 ++++++++--
6 files changed, 53 insertions(+), 18 deletions(-)
Modified: sandbox-branches/bhy/py3k/boost/python/enum.hpp
==============================================================================
--- sandbox-branches/bhy/py3k/boost/python/enum.hpp (original)
+++ sandbox-branches/bhy/py3k/boost/python/enum.hpp 2009-05-26 13:05:53 EDT (Tue, 26 May 2009)
@@ -79,7 +79,11 @@
template <class T>
void enum_<T>::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data)
{
+#if PY_VERSION_HEX >= 0x03000000
+ T x = static_cast<T>(PyLong_AS_LONG(obj));
+#else
T x = static_cast<T>(PyInt_AS_LONG(obj));
+#endif
void* const storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
new (storage) T(x);
data->convertible = storage;
Modified: sandbox-branches/bhy/py3k/boost/python/module_init.hpp
==============================================================================
--- sandbox-branches/bhy/py3k/boost/python/module_init.hpp (original)
+++ sandbox-branches/bhy/py3k/boost/python/module_init.hpp 2009-05-26 13:05:53 EDT (Tue, 26 May 2009)
@@ -18,36 +18,45 @@
// TODO(bhy) Take care of this later.
// But any reseaon we don't use BOOST_PYTHON_DECL here?
-# if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE)
+# if PY_VERSION_HEX >= 0x03000000
+
+# define _BOOST_PYTHON_MODULE_INIT(name) \
+PyObject* PyInit_##name() \
+{ \
+ return boost::python::detail::init_module( \
+ #name,&init_module_##name); \
+} \
+void init_module_##name()
+
+# else
-# define BOOST_PYTHON_MODULE_INIT(name) \
-void init_module_##name(); \
-extern "C" __declspec(dllexport) void init##name() \
+# define _BOOST_PYTHON_MODULE_INIT(name) \
+void init##name() \
{ \
boost::python::detail::init_module( \
#name,&init_module_##name); \
} \
void init_module_##name()
+# endif
+
+# if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE)
+
+# define BOOST_PYTHON_MODULE_INIT(name) \
+void init_module_##name(); \
+extern "C" __declspec(dllexport) _BOOST_PYTHON_MODULE_INIT(name)
+
# elif BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY
# define BOOST_PYTHON_MODULE_INIT(name) \
void init_module_##name(); \
-extern "C" __attribute__ ((visibility("default"))) void init##name() \
-{ \
- boost::python::detail::init_module(#name, &init_module_##name); \
-} \
-void init_module_##name()
+extern "C" __attribute__ ((visibility("default"))) _BOOST_PYTHON_MODULE_INIT(name)
# else
# define BOOST_PYTHON_MODULE_INIT(name) \
void init_module_##name(); \
-extern "C" void init##name() \
-{ \
- boost::python::detail::init_module(#name, &init_module_##name); \
-} \
-void init_module_##name()
+extern "C" _BOOST_PYTHON_MODULE_INIT(name)
# endif
Modified: sandbox-branches/bhy/py3k/boost/python/object/make_instance.hpp
==============================================================================
--- sandbox-branches/bhy/py3k/boost/python/object/make_instance.hpp (original)
+++ sandbox-branches/bhy/py3k/boost/python/object/make_instance.hpp 2009-05-26 13:05:53 EDT (Tue, 26 May 2009)
@@ -43,7 +43,7 @@
// Note the position of the internally-stored Holder,
// for the sake of destruction
- instance->ob_size = offsetof(instance_t, storage);
+ Py_SIZE(instance) = offsetof(instance_t, storage);
// Release ownership of the python object
protect.cancel();
Modified: sandbox-branches/bhy/py3k/libs/python/src/exec.cpp
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/src/exec.cpp (original)
+++ sandbox-branches/bhy/py3k/libs/python/src/exec.cpp 2009-05-26 13:05:53 EDT (Tue, 26 May 2009)
@@ -38,11 +38,19 @@
{
// should be 'char const *' but older python versions don't use 'const' yet.
char *f = python::extract<char *>(filename);
+#if PY_VERSION_HEX >= 0x03000000
+ // TODO(bhy) temporary workaround for Python 3.
+ // should figure out a way to avoid binary incompatibilities as the Python 2
+ // version did.
+ FILE *fs = fopen(f, "r");
+#else
// Let python open the file to avoid potential binary incompatibilities.
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
python::handle<> file(pyfile);
- PyObject* result = PyRun_File(PyFile_AsFile(file.get()),
+ FILE *fs = PyFile_AsFile(file.get());
+#endif
+ PyObject* result = PyRun_File(fs,
f,
Py_file_input,
global.ptr(), local.ptr());
Modified: sandbox-branches/bhy/py3k/libs/python/src/object_operators.cpp
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/src/object_operators.cpp (original)
+++ sandbox-branches/bhy/py3k/libs/python/src/object_operators.cpp 2009-05-26 13:05:53 EDT (Tue, 26 May 2009)
@@ -38,7 +38,11 @@
BOOST_PYTHON_BINARY_OPERATOR(+, Add)
BOOST_PYTHON_BINARY_OPERATOR(-, Subtract)
BOOST_PYTHON_BINARY_OPERATOR(*, Multiply)
+#if PY_VERSION_HEX >= 0x03000000
+BOOST_PYTHON_BINARY_OPERATOR(/, TrueDivide)
+#else
BOOST_PYTHON_BINARY_OPERATOR(/, Divide)
+#endif
BOOST_PYTHON_BINARY_OPERATOR(%, Remainder)
BOOST_PYTHON_BINARY_OPERATOR(<<, Lshift)
BOOST_PYTHON_BINARY_OPERATOR(>>, Rshift)
@@ -58,7 +62,11 @@
BOOST_PYTHON_INPLACE_OPERATOR(+, Add)
BOOST_PYTHON_INPLACE_OPERATOR(-, Subtract)
BOOST_PYTHON_INPLACE_OPERATOR(*, Multiply)
+#if PY_VERSION_HEX >= 0x03000000
+BOOST_PYTHON_INPLACE_OPERATOR(/, TrueDivide)
+#else
BOOST_PYTHON_INPLACE_OPERATOR(/, Divide)
+#endif
BOOST_PYTHON_INPLACE_OPERATOR(%, Remainder)
BOOST_PYTHON_INPLACE_OPERATOR(<<, Lshift)
BOOST_PYTHON_INPLACE_OPERATOR(>>, Rshift)
Modified: sandbox-branches/bhy/py3k/libs/python/src/object_protocol.cpp
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/src/object_protocol.cpp (original)
+++ sandbox-branches/bhy/py3k/libs/python/src/object_protocol.cpp 2009-05-26 13:05:53 EDT (Tue, 26 May 2009)
@@ -103,6 +103,7 @@
static PyObject *
apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
{
+#if PY_VERSION_HEX < 0x03000000
PyTypeObject *tp = u->ob_type;
PySequenceMethods *sq = tp->tp_as_sequence;
@@ -114,7 +115,9 @@
return NULL;
return PySequence_GetSlice(u, ilow, ihigh);
}
- else {
+ else
+#endif
+ {
PyObject *slice = PySlice_New(v, w, NULL);
if (slice != NULL) {
PyObject *res = PyObject_GetItem(u, slice);
@@ -130,6 +133,7 @@
assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
/* u[v:w] = x */
{
+#if PY_VERSION_HEX < 0x03000000
PyTypeObject *tp = u->ob_type;
PySequenceMethods *sq = tp->tp_as_sequence;
@@ -144,7 +148,9 @@
else
return PySequence_SetSlice(u, ilow, ihigh, x);
}
- else {
+ else
+#endif
+ {
PyObject *slice = PySlice_New(v, w, NULL);
if (slice != NULL) {
int res;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk