Skip to content

Commit 6b6b729

Browse files
committed
Use _PyIndex_Check in _PyEval_SliceIndex
1 parent 5691dd5 commit 6b6b729

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright (c) 2024, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2023 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
#ifndef Py_INTERNAL_ABSTRACT_H
7+
#define Py_INTERNAL_ABSTRACT_H
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#ifndef Py_BUILD_CORE
13+
# error "this header requires Py_BUILD_CORE define"
14+
#endif
15+
16+
// Fast inlined version of PyIndex_Check()
17+
static inline int
18+
_PyIndex_Check(PyObject *obj)
19+
{
20+
PyNumberMethods *tp_as_number = Py_TYPE(obj)->tp_as_number;
21+
return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
22+
}
23+
24+
PyObject *_PyNumber_PowerNoMod(PyObject *lhs, PyObject *rhs);
25+
PyObject *_PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs);
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif
30+
#endif /* !Py_INTERNAL_ABSTRACT_H */

graalpython/com.oracle.graal.python.cext/src/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
#include "capi.h"
4242

43+
#include "pycore_abstract.h" // _PyIndex_Check()
4344
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
4445
#include "pycore_pyerrors.h" // _PyErr_Fetch()
4546
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -170,8 +171,7 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
170171
PyThreadState *tstate = _PyThreadState_GET();
171172
if (!Py_IsNone(v)) {
172173
Py_ssize_t x;
173-
// GraalPy change: don't use '_PyIndex_Check'
174-
if (PyIndex_Check(v)) {
174+
if (_PyIndex_Check(v)) {
175175
x = PyNumber_AsSsize_t(v, NULL);
176176
if (x == -1 && _PyErr_Occurred(tstate))
177177
return 0;

mx.graalpython/copyrights/overrides

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ graalpython/com.oracle.graal.python.cext/include/floatobject.h,python.copyright
143143
graalpython/com.oracle.graal.python.cext/include/frameobject.h,python.copyright
144144
graalpython/com.oracle.graal.python.cext/include/genericaliasobject.h,python.copyright
145145
graalpython/com.oracle.graal.python.cext/include/import.h,python.copyright
146+
graalpython/com.oracle.graal.python.cext/include/internal/pycore_abstract.h,python.copyright
146147
graalpython/com.oracle.graal.python.cext/include/internal/pycore_atomic.h,python.copyright
147148
graalpython/com.oracle.graal.python.cext/include/internal/pycore_blocks_output_buffer.h,python.copyright
148149
graalpython/com.oracle.graal.python.cext/include/internal/pycore_call.h,python.copyright

0 commit comments

Comments
 (0)