mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 06:02:14 +00:00
more fixes to get testcases work, includes module init and other minor fixes
[SVN r53285]
This commit is contained in:
@@ -79,7 +79,11 @@ void* enum_<T>::convertible_from_python(PyObject* obj)
|
||||
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;
|
||||
|
||||
@@ -18,36 +18,45 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
|
||||
// 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) \
|
||||
void init_module_##name(); \
|
||||
extern "C" __declspec(dllexport) void init##name() \
|
||||
# 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##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
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ struct make_instance_impl
|
||||
|
||||
// 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();
|
||||
|
||||
10
src/exec.cpp
10
src/exec.cpp
@@ -38,11 +38,19 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
|
||||
{
|
||||
// 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());
|
||||
|
||||
@@ -38,7 +38,11 @@ BOOST_PYTHON_DECL object operator op(object const& l, object const& r) \
|
||||
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_DECL object& operator op##=(object& l, object const& r) \
|
||||
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)
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace // slicing code copied directly out of the Python implementation
|
||||
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 @@ namespace // slicing code copied directly out of the Python implementation
|
||||
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 @@ namespace // slicing code copied directly out of the Python implementation
|
||||
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 @@ namespace // slicing code copied directly out of the Python implementation
|
||||
else
|
||||
return PySequence_SetSlice(u, ilow, ihigh, x);
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
{
|
||||
PyObject *slice = PySlice_New(v, w, NULL);
|
||||
if (slice != NULL) {
|
||||
int res;
|
||||
|
||||
Reference in New Issue
Block a user