Skip to content

Commit 68c288e

Browse files
committed
refactor: _PyObject_CallOneArg is already an alias for PyObject_CallOneArg in all Python versions we support, so no need to do a shim on our own
This commit reverts `bcfcbf35ce5ae10bb3542052cdccadf48e95cdca`
1 parent bcfcbf3 commit 68c288e

File tree

4 files changed

+3
-16
lines changed

4 files changed

+3
-16
lines changed

include/pyshim.hh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,4 @@ 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-
131121
#endif // #ifndef PythonMonkey_py_version_shim_

src/ExceptionType.cc

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

2222
#include <Python.h>
2323
#include <frameobject.h>
24-
#include "include/pyshim.hh"
2524

2625

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

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

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

src/IntType.cc

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

1717
#include <Python.h>
18-
#include "include/pyshim.hh"
1918

2019
#include <vector>
2120

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

107106
// Set the sign bit

src/PromiseType.cc

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

2222
#include <Python.h>
23-
#include "include/pyshim.hh"
2423

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

0 commit comments

Comments
 (0)