Skip to content

Commit 23d0576

Browse files
committed
revert commit 68c288e.
1 parent 68c288e commit 23d0576

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

include/pyshim.hh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,14 @@ static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
118118
#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject *)(ob), size)
119119
#endif
120120

121+
/**
122+
* @brief Shim for `PyObject_CallOneArg`.
123+
* `PyObject_CallOneArg` is not available in Python < 3.9
124+
*/
125+
#if PY_VERSION_HEX < 0x03090000 // Python version is less than 3.9
126+
inline PyObject *PyObject_CallOneArg(PyObject *func, PyObject *arg) {
127+
return PyObject_CallFunction(func, "O", arg);
128+
}
129+
#endif
130+
121131
#endif // #ifndef PythonMonkey_py_version_shim_

src/ExceptionType.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <Python.h>
2323
#include <frameobject.h>
24+
#include "include/pyshim.hh"
2425

2526

2627
PyObject *ExceptionType::getPyObject(JSContext *cx, JS::HandleObject error) {
@@ -30,7 +31,7 @@ PyObject *ExceptionType::getPyObject(JSContext *cx, JS::HandleObject error) {
3031
PyObject *errStr = getExceptionString(cx, JS::ExceptionStack(cx, errValue, errStack), true);
3132

3233
// Construct a new SpiderMonkeyError python object
33-
PyObject *pyObject = _PyObject_CallOneArg(SpiderMonkeyError, errStr); // _PyErr_CreateException, https://github.com/python/cpython/blob/3.9/Python/errors.c#L100
34+
PyObject *pyObject = PyObject_CallOneArg(SpiderMonkeyError, errStr); // _PyErr_CreateException, https://github.com/python/cpython/blob/3.9/Python/errors.c#L100
3435
Py_XDECREF(errStr);
3536

3637
// Preserve the original JS Error object as the Python Exception's `jsError` attribute for lossless two-way conversion

src/IntType.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <js/BigInt.h>
1616

1717
#include <Python.h>
18+
#include "include/pyshim.hh"
1819

1920
#include <vector>
2021

@@ -100,7 +101,7 @@ PyObject *IntType::getPyObject(JSContext *cx, JS::BigInt *bigint) {
100101
// Cast to a pythonmonkey.bigint to differentiate it from a normal Python int,
101102
// allowing Py<->JS two-way BigInt conversion.
102103
// We don't do `Py_SET_TYPE` because `_PyLong_FromByteArray` may cache and reuse objects for small ints
103-
PyObject *pyObject = _PyObject_CallOneArg(getPythonMonkeyBigInt(), pyIntObj); // pyObject = pythonmonkey.bigint(pyIntObj)
104+
PyObject *pyObject = PyObject_CallOneArg(getPythonMonkeyBigInt(), pyIntObj); // pyObject = pythonmonkey.bigint(pyIntObj)
104105
Py_DECREF(pyIntObj);
105106

106107
// Set the sign bit

src/PromiseType.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <js/Promise.h>
2121

2222
#include <Python.h>
23+
#include "include/pyshim.hh"
2324

2425
// slot ids to access the python object in JS callbacks
2526
#define PY_FUTURE_OBJ_SLOT 0
@@ -40,7 +41,7 @@ static bool onResolvedCb(JSContext *cx, unsigned argc, JS::Value *vp) {
4041
if (state == JS::PromiseState::Rejected && !PyExceptionInstance_Check(result)) {
4142
// Wrap the result object into a SpiderMonkeyError object
4243
// because only *Exception objects can be thrown in Python `raise` statement and alike
43-
PyObject *wrapped = _PyObject_CallOneArg(SpiderMonkeyError, result); // wrapped = SpiderMonkeyError(result)
44+
PyObject *wrapped = PyObject_CallOneArg(SpiderMonkeyError, result); // wrapped = SpiderMonkeyError(result)
4445
// Preserve the original JS value as the `jsError` attribute for lossless conversion back
4546
PyObject *originalJsErrCapsule = DictType::getPyObject(cx, resultArg);
4647
PyObject_SetAttrString(wrapped, "jsError", originalJsErrCapsule);

0 commit comments

Comments
 (0)