Skip to content

Commit ede25fc

Browse files
committed
be explicit about bitwidths of tagged integers hiding in handles
1 parent a4d476e commit ede25fc

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

graalpython/com.oracle.graal.python.cext/include/graalpy/handles.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@
7575
#define points_to_py_float_handle(PTR) (((uint64_t)(uintptr_t)(PTR)) & FLOAT_TAG_BIT)
7676

7777
#define stub_to_pointer(STUB_PTR) ((uintptr_t)(((uint64_t)(uintptr_t)(PTR)) | HANDLE_TAG_BIT))
78-
#define int_to_pointer(INT) ((uintptr_t)((((uint64_t)(uint32_t)(INT) << 3) & _35_BIT_MASK) | HANDLE_TAG_BIT | INTEGER_TAG_BIT))
78+
#define int32_to_pointer(INT) ((uintptr_t)((((uint64_t)(uint32_t)(INT) << 3) & _35_BIT_MASK) | HANDLE_TAG_BIT | INTEGER_TAG_BIT))
7979
static inline PyObject* float_to_pointer(float dbl) {
8080
uint32_t float_bits;
8181
memcpy(&float_bits, &dbl, sizeof(float));
8282
return (PyObject *)(uintptr_t)(((((uint64_t)float_bits) << 3) & _35_BIT_MASK) | HANDLE_TAG_BIT | FLOAT_TAG_BIT);
8383
}
8484

8585
#define pointer_to_stub(PTR) ((PyObject*)(((uint64_t)(uintptr_t)(PTR)) & ~HANDLE_TAG_BIT))
86-
#define pointer_to_long(PTR) ((int64_t)(int32_t)(((uint64_t)(uintptr_t)(PTR)) >> 3))
86+
#define pointer_to_int64(PTR) ((int64_t)(int32_t)(((uint64_t)(uintptr_t)(PTR)) >> 3))
8787
static inline double pointer_to_double(PyObject* ptr) {
8888
uint32_t float_bits = (uint32_t)(((uint64_t)(uintptr_t)ptr) >> 3);
8989
float value;

graalpython/com.oracle.graal.python.cext/include/internal/pycore_long.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ static inline PyObject* _PyLong_GetZero(void)
7171
/* GraalVM change
7272
{ return (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS]; }
7373
*/
74-
{ return int_to_pointer(0); }
74+
{ return int32_to_pointer(0); }
7575

7676
// Return a borrowed reference to the one singleton.
7777
// The function cannot return NULL.
7878
static inline PyObject* _PyLong_GetOne(void)
7979
/* GraalVM change
8080
{ return (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+1]; }
8181
*/
82-
{ return int_to_pointer(1); }
82+
{ return int32_to_pointer(1); }
8383

8484
static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
8585
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ PyFloat_AsDouble(PyObject *op)
333333
// GraalPy change: upcall for managed
334334
if (points_to_py_handle_space(op)) {
335335
if (points_to_py_int_handle(op)) {
336-
return (double)pointer_to_long(op);
336+
return (double)pointer_to_int64(op);
337337
}
338338
return GraalPyPrivate_Float_AsDouble(op);
339339
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static PyObject *
8686
get_small_int(sdigit ival)
8787
{
8888
// GraalPy change - we tag 32-bit integers
89-
return int_to_pointer(ival);
89+
return int32_to_pointer(ival);
9090
}
9191

9292
#if 0 // GraalPy change
@@ -474,7 +474,7 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow)
474474
}
475475
if (points_to_py_int_handle(vv)) {
476476
*overflow = 0;
477-
return pointer_to_long(vv);
477+
return pointer_to_int64(vv);
478478
}
479479
long result = (long) GraalPyPrivate_Long_AsPrimitive(vv, MODE_COERCE_SIGNED, sizeof(long));
480480
if (result == -1L && PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_OverflowError)) {
@@ -494,7 +494,7 @@ PyLong_AsLong(PyObject *obj)
494494
{
495495
// GraalPy change: different implementation
496496
if (points_to_py_int_handle(obj)) {
497-
return pointer_to_long(obj);
497+
return pointer_to_int64(obj);
498498
}
499499
return (long) GraalPyPrivate_Long_AsPrimitive(obj, MODE_COERCE_SIGNED, sizeof(long));
500500
}
@@ -523,7 +523,7 @@ _PyLong_AsInt(PyObject *obj)
523523
Py_ssize_t
524524
PyLong_AsSsize_t(PyObject *vv) {
525525
if (points_to_py_int_handle(vv)) {
526-
return pointer_to_long(vv);
526+
return pointer_to_int64(vv);
527527
}
528528
return (Py_ssize_t) GraalPyPrivate_Long_AsPrimitive(vv, MODE_PINT_SIGNED, sizeof(Py_ssize_t));
529529
}
@@ -540,7 +540,7 @@ PyLong_AsUnsignedLong(PyObject *vv)
540540
return (unsigned long) -1;
541541
}
542542
if (points_to_py_int_handle(vv)) {
543-
long value = pointer_to_long(vv);
543+
long value = pointer_to_int64(vv);
544544
if (value < 0) {
545545
PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned int");
546546
return (unsigned long) -1;
@@ -558,7 +558,7 @@ PyLong_AsSize_t(PyObject *vv)
558558
{
559559
// GraalPy change: different implementation
560560
if (points_to_py_int_handle(vv)) {
561-
long value = pointer_to_long(vv);
561+
long value = pointer_to_int64(vv);
562562
if (value < 0) {
563563
PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned int");
564564
return (size_t) -1;
@@ -610,7 +610,7 @@ PyLong_AsUnsignedLongMask(PyObject *op)
610610
return (unsigned long) -1;
611611
}
612612
if (points_to_py_int_handle(op)) {
613-
return pointer_to_long(op);
613+
return pointer_to_int64(op);
614614
}
615615
return (unsigned long) GraalPyPrivate_Long_AsPrimitive(op, MODE_COERCE_MASK, sizeof(unsigned long));
616616
}
@@ -979,7 +979,7 @@ PyLong_FromLongLong(long long ival)
979979
{
980980
// GraalPy change: different implementation
981981
if ((int)ival == ival) {
982-
return int_to_pointer(ival);
982+
return int32_to_pointer(ival);
983983
} else {
984984
return GraalPyPrivate_Long_FromLongLong(ival);
985985
}
@@ -1006,7 +1006,7 @@ PyLong_AsLongLong(PyObject *vv)
10061006
return -1;
10071007
}
10081008
if (points_to_py_int_handle(vv)) {
1009-
return pointer_to_long(vv);
1009+
return pointer_to_int64(vv);
10101010
}
10111011
return (long long) GraalPyPrivate_Long_AsPrimitive(vv, MODE_COERCE_SIGNED, sizeof(long long));
10121012
}
@@ -1023,7 +1023,7 @@ PyLong_AsUnsignedLongLong(PyObject *vv)
10231023
return (unsigned long long)-1;
10241024
}
10251025
if (points_to_py_int_handle(vv)) {
1026-
long value = pointer_to_long(vv);
1026+
long value = pointer_to_int64(vv);
10271027
if (value < 0) {
10281028
PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned int");
10291029
return (unsigned long long) -1;
@@ -1076,7 +1076,7 @@ PyLong_AsUnsignedLongLongMask(PyObject *op)
10761076
return (unsigned long long)-1;
10771077
}
10781078
if (points_to_py_int_handle(op)) {
1079-
return pointer_to_long(op);
1079+
return pointer_to_int64(op);
10801080
}
10811081
return (unsigned long long) GraalPyPrivate_Long_AsPrimitive(op, MODE_COERCE_MASK, sizeof(unsigned long long));
10821082
}
@@ -6140,15 +6140,15 @@ PyUnstable_Long_CompactValue(const PyLongObject* op) {
61406140

61416141
Py_ssize_t PyUnstable_Long_CompactValue(const PyLongObject *op) {
61426142
if (points_to_py_int_handle(op)) {
6143-
return pointer_to_long(op);
6143+
return pointer_to_int64(op);
61446144
}
61456145
return GraalPyPrivate_Long_AsPrimitive((PyObject*) op, MODE_PINT_SIGNED, sizeof(Py_ssize_t));
61466146
}
61476147

61486148
// GraalPy additions
61496149
uintptr_t GraalPyPrivate_Long_lv_tag(const PyLongObject *op) {
61506150
if (points_to_py_int_handle(op)) {
6151-
int64_t t = pointer_to_long(op);
6151+
int64_t t = pointer_to_int64(op);
61526152
if (t == 0) {
61536153
return SIGN_ZERO;
61546154
}

0 commit comments

Comments
 (0)