Skip to content

Commit 1698432

Browse files
authored
Sync pythoncapi_compat.h (#20143)
1 parent 054f721 commit 1698432

File tree

5 files changed

+410
-13
lines changed

5 files changed

+410
-13
lines changed

mypyc/lib-rt/exc_ops.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "pythoncapi_compat.h"
2+
13
// Exception related primitive operations
24
//
35
// These are registered in mypyc.primitives.exc_ops.
@@ -24,7 +26,7 @@ void CPy_Reraise(void) {
2426
}
2527

2628
void CPyErr_SetObjectAndTraceback(PyObject *type, PyObject *value, PyObject *traceback) {
27-
if (!PyType_Check(type) && value == Py_None) {
29+
if (!PyType_Check(type) && Py_IsNone(value)) {
2830
// The first argument must be an exception instance
2931
value = type;
3032
type = (PyObject *)Py_TYPE(value);

mypyc/lib-rt/librt_internal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "pythoncapi_compat.h"
2+
13
#define PY_SSIZE_T_CLEAN
24
#include <Python.h>
35
#include <stdint.h>
@@ -245,7 +247,7 @@ write_bool(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwname
245247
PyErr_SetString(PyExc_TypeError, "value must be a bool");
246248
return NULL;
247249
}
248-
if (unlikely(write_bool_internal(data, value == Py_True) == CPY_NONE_ERROR)) {
250+
if (unlikely(write_bool_internal(data, Py_IsTrue(value)) == CPY_NONE_ERROR)) {
249251
return NULL;
250252
}
251253
Py_INCREF(Py_None);

mypyc/lib-rt/misc_ops.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "pythoncapi_compat.h"
2+
13
// Misc primitive operations + C helpers
24
//
35
// These are registered in mypyc.primitives.misc_ops.
@@ -750,7 +752,7 @@ CPy_Super(PyObject *builtins, PyObject *self) {
750752

751753
static bool import_single(PyObject *mod_id, PyObject **mod_static,
752754
PyObject *globals_id, PyObject *globals_name, PyObject *globals) {
753-
if (*mod_static == Py_None) {
755+
if (Py_IsNone(*mod_static)) {
754756
CPyModule *mod = PyImport_Import(mod_id);
755757
if (mod == NULL) {
756758
return false;

0 commit comments

Comments
 (0)