Skip to content

Commit 872c1d3

Browse files
committed
full test suite compiles with PyPy now, crash in PyIter_Next
1 parent b5ac95e commit 872c1d3

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

include/pybind11/eval.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,15 @@ object eval_file(str fname, object global = object(), object local = object()) {
9595
pybind11_fail("File \"" + fname_str + "\" could not be opened!");
9696
}
9797

98+
#if PY_VERSION_HEX < 0x03000000 && defined(PYPY_VERSION)
99+
PyObject *result = PyRun_File(f, fname_str.c_str(), start, global.ptr(),
100+
local.ptr());
101+
(void) closeFile;
102+
#else
98103
PyObject *result = PyRun_FileEx(f, fname_str.c_str(), start, global.ptr(),
99104
local.ptr(), closeFile);
105+
#endif
106+
100107
if (!result)
101108
throw error_already_set();
102109
return reinterpret_steal<object>(result);

include/pybind11/functional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ template <typename Return, typename... Args> struct type_caster<std::function<Re
3636
captured variables), in which case the roundtrip can be avoided.
3737
*/
3838
if (PyCFunction_Check(src_.ptr())) {
39-
auto c = reinterpret_borrow<capsule>(PyCFunction_GetSelf(src_.ptr()));
39+
auto c = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(src_.ptr()));
4040
auto rec = (function_record *) c;
4141
using FunctionType = Return (*) (Args...);
4242

include/pybind11/pybind11.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ class module : public object {
568568
}
569569

570570
module def_submodule(const char *name, const char *doc = nullptr) {
571-
std::string full_name = std::string(PyModule_GetName(m_ptr))
571+
std::string full_name = attr("__name__").cast<std::string>()
572572
+ std::string(".") + std::string(name);
573573
auto result = reinterpret_borrow<module>(PyImport_AddModule(full_name.c_str()));
574574
if (doc && options::show_user_defined_docstrings())
@@ -1256,9 +1256,12 @@ template <typename Type> class enum_ : public class_<Type> {
12561256
PyObject *dict = ((PyTypeObject *) this->m_ptr)->tp_dict;
12571257
PyObject *key, *value;
12581258
ssize_t pos = 0;
1259-
while (PyDict_Next(dict, &pos, &key, &value))
1259+
1260+
while (PyDict_Next(dict, &pos, &key, &value)) {
12601261
if (PyObject_IsInstance(value, this->m_ptr))
12611262
m_parent.attr(key) = value;
1263+
}
1264+
12621265
return *this;
12631266
}
12641267

@@ -1642,6 +1645,20 @@ class gil_scoped_release {
16421645
PyThreadState *tstate;
16431646
bool disassoc;
16441647
};
1648+
#elif defined(PYPY_VERSION)
1649+
class gil_scoped_acquire {
1650+
PyGILState_STATE state;
1651+
public:
1652+
gil_scoped_acquire() { state = PyGILState_Ensure(); }
1653+
~gil_scoped_acquire() { PyGILState_Release(state); }
1654+
};
1655+
1656+
class gil_scoped_release {
1657+
PyThreadState *state;
1658+
public:
1659+
gil_scoped_release() { state = PyEval_SaveThread(); }
1660+
~gil_scoped_release() { PyEval_RestoreThread(state); }
1661+
};
16451662
#else
16461663
class gil_scoped_acquire { };
16471664
class gil_scoped_release { };

include/pybind11/stl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ template <typename Type, typename Value> struct list_caster {
138138
auto value_ = reinterpret_steal<object>(value_conv::cast(value, policy, parent));
139139
if (!value_)
140140
return handle();
141-
PyList_SET_ITEM(l.ptr(), index++, value_.release().ptr()); // steals a reference
141+
PyList_SET_ITEM(l.ptr(), (ssize_t) index++, value_.release().ptr()); // steals a reference
142142
}
143143
return l.release();
144144
}
@@ -179,7 +179,7 @@ template <typename Type, size_t Size> struct type_caster<std::array<Type, Size>>
179179
auto value_ = reinterpret_steal<object>(value_conv::cast(value, policy, parent));
180180
if (!value_)
181181
return handle();
182-
PyList_SET_ITEM(l.ptr(), index++, value_.release().ptr()); // steals a reference
182+
PyList_SET_ITEM(l.ptr(), (ssize_t) index++, value_.release().ptr()); // steals a reference
183183
}
184184
return l.release();
185185
}

tests/test_multiple_inheritance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "pybind11_tests.h"
1212

13+
#if !defined(PYPY_VERSION)
1314

1415
struct Base1 {
1516
Base1(int i) : i(i) { }
@@ -82,3 +83,5 @@ test_initializer multiple_inheritance_nonexplicit([](py::module &m) {
8283
m.def("bar_base2a", [](Base2a *b) { return b->bar(); });
8384
m.def("bar_base2a_sharedptr", [](std::shared_ptr<Base2a> b) { return b->bar(); });
8485
});
86+
87+
#endif

0 commit comments

Comments
 (0)