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:
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