Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions graalpython/com.oracle.graal.python.cext/src/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,6 @@ PyIndex_Check(PyObject *obj)
return _PyIndex_Check(obj);
}


#if 0 // GraalPy change
/* Return a Python int from the object item.
Can return an instance of int subclass.
Raise TypeError if the result is not an int
Expand All @@ -1470,6 +1468,12 @@ _PyNumber_Index(PyObject *item)
if (PyLong_Check(item)) {
return Py_NewRef(item);
}

// GraalPy change: upcall for managed objects
if (points_to_py_handle_space(item)) {
return GraalPyPrivate_PyNumber_Index(item);
}

if (!_PyIndex_Check(item)) {
PyErr_Format(PyExc_TypeError,
"'%.200s' object cannot be interpreted "
Expand Down Expand Up @@ -1511,11 +1515,14 @@ PyNumber_Index(PyObject *item)
{
PyObject *result = _PyNumber_Index(item);
if (result != NULL && !PyLong_CheckExact(result)) {
Py_SETREF(result, _PyLong_Copy((PyLongObject *)result));
if (points_to_py_handle_space(result)) {
Py_SETREF(result, GraalPyPrivate_PyNumber_IndexCopy(result));
} else {
Py_SETREF(result, _PyLong_Copy((PyLongObject *)result));
}
}
return result;
}
#endif // GraalPy change

/* Return an error on Overflow only if err is not NULL*/

Expand Down Expand Up @@ -2880,10 +2887,15 @@ _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls)
return recursive_issubclass(derived, cls);
}


#endif // GraalPy change
PyObject *
PyObject_GetIter(PyObject *o)
{
// GraalPy change: upcall for managed objects
if (points_to_py_handle_space(o)) {
return GraalPyPrivate_Object_GetIter(o);
}

PyTypeObject *t = Py_TYPE(o);
getiterfunc f;

Expand All @@ -2905,7 +2917,7 @@ PyObject_GetIter(PyObject *o)
return res;
}
}

#if 0 // GraalPy change
PyObject *
PyObject_GetAIter(PyObject *o) {
PyTypeObject *t = Py_TYPE(o);
Expand All @@ -2924,15 +2936,15 @@ PyObject_GetAIter(PyObject *o) {
}
return it;
}

#endif // GraalPy change
int
PyIter_Check(PyObject *obj)
{
PyTypeObject *tp = Py_TYPE(obj);
return (tp->tp_iternext != NULL &&
tp->tp_iternext != &_PyObject_NextNotImplemented);
}

#if 0 // GraalPy change
int
PyAIter_Check(PyObject *obj)
{
Expand Down
9 changes: 6 additions & 3 deletions graalpython/com.oracle.graal.python.cext/src/dictobject.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2024, 2025, Oracle and/or its affiliates.
/* Copyright (c) 2024, 2026, Oracle and/or its affiliates.
* Copyright (C) 1996-2024 Python Software Foundation
*
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
Expand Down Expand Up @@ -3086,17 +3086,20 @@ PyDict_Copy(PyObject *o)
Py_DECREF(copy);
return NULL;
}

#endif // GraalPy change
Py_ssize_t
PyDict_Size(PyObject *mp)
{
if (mp == NULL || !PyDict_Check(mp)) {
PyErr_BadInternalCall();
return -1;
}
if (points_to_py_handle_space(mp)) {
return GraalPyPrivate_Object_Size(mp);
}
return ((PyDictObject *)mp)->ma_used;
}

#if 0 // GraalPy change
PyObject *
PyDict_Keys(PyObject *mp)
{
Expand Down
58 changes: 52 additions & 6 deletions graalpython/com.oracle.graal.python.cext/src/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,16 @@ PyLong_FromLong(long ival)
return PyLong_FromLongLong((long long) ival);
}

#if 0 // GraalPy change
#define PYLONG_FROM_UINT(INT_TYPE, ival) \
do { \
if ((ival) <= INT32_MAX) { \
return int32_to_pointer((int)(ival)); \
} \
return GraalPyPrivate_Long_FromUnsignedLongLong((unsigned long long)(ival)); \
} while(0)

#if 0 // GraalPy change
#define PYLONG_FROM_UINT_CPYTHON(INT_TYPE, ival) \
do { \
if (IS_SMALL_UINT(ival)) { \
return get_small_int((sdigit)(ival)); \
Expand All @@ -359,6 +367,7 @@ PyLong_FromLong(long ival)
} \
return (PyObject *)v; \
} while(0)
#endif // GraalPy change

/* Create a new int object from a C unsigned long int */

Expand Down Expand Up @@ -404,6 +413,7 @@ PyLong_FromDouble(double dval)
return PyLong_FromLong((long)dval);
}

#if 0 // GraalPy change
PyLongObject *v;
double frac;
int i, ndig, expo, neg;
Expand Down Expand Up @@ -439,8 +449,9 @@ PyLong_FromDouble(double dval)
_PyLong_FlipSign(v);
}
return (PyObject *)v;
}
#endif // GraalPy change
return GraalPyPrivate_Long_FromDouble(dval);
}

/* Checking for overflow in PyLong_AsLong is a PITA since C doesn't define
* anything about what happens when a signed integer operation overflows,
Expand Down Expand Up @@ -615,20 +626,27 @@ PyLong_AsUnsignedLongMask(PyObject *op)
return (unsigned long) GraalPyPrivate_Long_AsPrimitive(op, MODE_COERCE_MASK, sizeof(unsigned long));
}

#if 0 // GraalPy change
int
_PyLong_Sign(PyObject *vv)
{
assert(vv != NULL);
if (points_to_py_int_handle(vv)) {
int64_t value = pointer_to_int64(vv);
return (value > 0) - (value < 0);
}

PyLongObject *v = (PyLongObject *)vv;

assert(v != NULL);
assert(PyLong_Check(v));
#if 0 // GraalPy change
if (_PyLong_IsCompact(v)) {
return _PyLong_CompactSign(v);
}
return _PyLong_NonCompactSign(v);
}
#endif // GraalPy change
return 1 - (GraalPyPrivate_Long_lv_tag(v) & SIGN_MASK);
}

static int
bit_length_digit(digit x)
Expand All @@ -640,10 +658,19 @@ bit_length_digit(digit x)
return _Py_bit_length((unsigned long)x);
}

#if 0 // GraalPy change
size_t
_PyLong_NumBits(PyObject *vv)
{
assert(vv != NULL);
if (points_to_py_int_handle(vv)) {
int64_t value = pointer_to_int64(vv);
unsigned long magnitude = value < 0 ? (unsigned long)-value : (unsigned long)value;
return (size_t)_Py_bit_length(magnitude);
}

return GraalPyPrivate_Long_NumBits(vv);

#if 0 // GraalPy change
PyLongObject *v = (PyLongObject *)vv;
size_t result = 0;
Py_ssize_t ndigits;
Expand All @@ -669,8 +696,10 @@ _PyLong_NumBits(PyObject *vv)
PyErr_SetString(PyExc_OverflowError, "int has too many bits "
"to express in a platform size_t");
return (size_t)-1;
#endif // GraalPy change
}

#if 0 // GraalPy change
PyObject *
_PyLong_FromByteArray(const unsigned char* bytes, size_t n,
int little_endian, int is_signed)
Expand Down Expand Up @@ -929,9 +958,9 @@ PyLong_FromVoidPtr(void *p)
return PyLong_FromUnsignedLongLong((uint64_t)p);
}

#if 0 // GraalPy change
/* Get a C pointer from an int object. */

#if 0 // GraalPy change
void *
PyLong_AsVoidPtr(PyObject *vv)
{
Expand Down Expand Up @@ -964,6 +993,16 @@ PyLong_AsVoidPtr(PyObject *vv)
return NULL;
return (void *)x;
}
#else
void *
PyLong_AsVoidPtr(PyObject *vv)
{
if (points_to_py_int_handle(vv)) {
return (void *)(uintptr_t)pointer_to_int64(vv);
}

return (void *)GraalPyPrivate_Long_AsVoidPtr(vv);
}
#endif // GraalPy change

/* Initial long long support by Chris Herborth (chrish@qnx.com), later
Expand Down Expand Up @@ -6178,6 +6217,13 @@ PyUnstable_Long_CompactValue(const PyLongObject* op) {

#endif // GraalPy change

#undef PyUnstable_Long_IsCompact

int
PyUnstable_Long_IsCompact(const PyLongObject* op) {
return GraalPyPrivate_Long_lv_tag(op) < (2 << NON_SIZE_BITS);
}

#undef PyUnstable_Long_CompactValue

Py_ssize_t PyUnstable_Long_CompactValue(const PyLongObject *op) {
Expand Down
7 changes: 4 additions & 3 deletions graalpython/com.oracle.graal.python.cext/src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,6 @@ PyObject_GenericSetDict(PyObject *obj, PyObject *value, void *context)
}


#if 0 // GraalPy change
/* Test a value used as condition, e.g., in a while or if statement.
Return -1 if an error occurred */

Expand All @@ -1790,6 +1789,9 @@ PyObject_IsTrue(PyObject *v)
return 0;
if (v == Py_None)
return 0;
// GraalPy change: upcall for managed objects
if (points_to_py_handle_space(v))
return GraalPyPrivate_Object_IsTrue(v);
else if (Py_TYPE(v)->tp_as_number != NULL &&
Py_TYPE(v)->tp_as_number->nb_bool != NULL)
res = (*Py_TYPE(v)->tp_as_number->nb_bool)(v);
Expand All @@ -1804,7 +1806,6 @@ PyObject_IsTrue(PyObject *v)
/* if it is negative, it should be either -1 or -2 */
return (res > 0) ? 1 : Py_SAFE_DOWNCAST(res, Py_ssize_t, int);
}
#endif // GraalPy change

/* equivalent of 'not v'
Return -1 if an error occurred */
Expand All @@ -1819,7 +1820,6 @@ PyObject_Not(PyObject *v)
return res == 0;
}

#if 0 // GraalPy change
/* Test whether an object can be called */

int
Expand All @@ -1830,6 +1830,7 @@ PyCallable_Check(PyObject *x)
return Py_TYPE(x)->tp_call != NULL;
}

#if 0 // GraalPy change

/* Helper for PyObject_Dir without arguments: returns the local scope. */
static PyObject *
Expand Down
Loading
Loading