Skip to content

Commit 42c331d

Browse files
committed
[GR-44294][GR-44354] Improve compatiblity with pyspark
PullRequest: graalpython/2875
2 parents 7d14b00 + 7be3c05 commit 42c331d

File tree

21 files changed

+563
-136
lines changed

21 files changed

+563
-136
lines changed

graalpython/com.oracle.graal.python.cext/include/sliceobject.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1+
/* Copyright (c) 2018, 2023, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2020 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -58,9 +58,9 @@ PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length,
5858
((*(slicelen) = 0), -1) : \
5959
((*(slicelen) = PySlice_AdjustIndices((length), (start), (stop), *(step))), \
6060
0))
61-
PyAPI_FUNC(PyObject*) PySlice_Start(PyObject *slice);
62-
PyAPI_FUNC(PyObject*) PySlice_Stop(PyObject *slice);
63-
PyAPI_FUNC(PyObject*) PySlice_Step(PyObject *slice);
61+
PyAPI_FUNC(PyObject*) PySlice_Start(PySliceObject *slice);
62+
PyAPI_FUNC(PyObject*) PySlice_Stop(PySliceObject *slice);
63+
PyAPI_FUNC(PyObject*) PySlice_Step(PySliceObject *slice);
6464
PyAPI_FUNC(int) PySlice_Unpack(PyObject *slice,
6565
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
6666
PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length,

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,6 @@ static void PyTruffle_Log(int level, const char* format, ... ) {
923923
va_list args;
924924
va_start(args, format);
925925
vsprintf(buffer,format, args);
926-
printf("logg\n");
927926
#ifndef EXCLUDE_POLYGLOT_API
928927
GraalPyTruffle_LogString(level, polyglot_from_string(buffer, SRC_CS));
929928
#else

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ int PyTruffle_AllocMemory(size_t size) {
109109
}
110110

111111
void PyTruffle_FreeMemory(size_t size) {
112-
PyTruffle_AllocatedMemory -= size;
112+
if (PyTruffle_AllocatedMemory < size) {
113+
PyTruffle_Log(PY_TRUFFLE_LOG_INFO, "PyTruffle_FreeMemory: assertion failure: underflow of memory allocation tracking\n");
114+
PyTruffle_AllocatedMemory = size;
115+
}
116+
PyTruffle_AllocatedMemory -= size;
113117
}
114118

115119
/* This is our version of 'PyObject_Free' which is also able to free Sulong handles. */
@@ -189,22 +193,25 @@ void* PyMem_RawCalloc(size_t nelem, size_t elsize) {
189193

190194
void* PyMem_RawRealloc(void *ptr, size_t new_size) {
191195
mem_head_t* old;
196+
size_t old_size;
192197

193198
if (ptr != NULL) {
194199
old = AS_MEM_HEAD(ptr);
195-
196-
// account for the difference in size
197-
if (old->size >= new_size) {
198-
PyTruffle_FreeMemory(old->size - new_size);
199-
} else {
200-
if (PyTruffle_AllocMemory(new_size - old->size)) {
201-
return NULL;
202-
}
203-
}
200+
old_size = old->size;
204201
} else {
205202
old = NULL;
203+
old_size = 0;
206204
}
207205

206+
// account for the difference in size
207+
if (old_size >= new_size) {
208+
PyTruffle_FreeMemory(old_size - new_size);
209+
} else {
210+
if (PyTruffle_AllocMemory(new_size - old_size)) {
211+
return NULL;
212+
}
213+
}
214+
208215
mem_head_t* ptr_with_head = (mem_head_t*) realloc(old, new_size + sizeof(mem_head_t));
209216
ptr_with_head->size = new_size;
210217
return FROM_MEM_HEAD(ptr_with_head);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1+
/* Copyright (c) 2018, 2023, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2017 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -117,14 +117,14 @@ Py_ssize_t PySlice_AdjustIndices(Py_ssize_t length, Py_ssize_t *start, Py_ssize_
117117
return 0;
118118
}
119119

120-
PyObject* PySlice_Start(PyObject *slice) {
120+
PyObject* PySlice_Start(PySliceObject *slice) {
121121
return PySliceObject_start(slice);
122122
}
123123

124-
PyObject* PySlice_Stop(PyObject *slice) {
124+
PyObject* PySlice_Stop(PySliceObject *slice) {
125125
return PySliceObject_stop(slice);
126126
}
127127

128-
PyObject* PySlice_Step(PyObject *slice) {
128+
PyObject* PySlice_Step(PySliceObject *slice) {
129129
return PySliceObject_step(slice);
130130
}

graalpython/com.oracle.graal.python.jni/src/capi_forwards.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,18 +3670,18 @@ PyAPI_FUNC(PyObject*) PySlice_New(PyObject* a, PyObject* b, PyObject* c) {
36703670
PyObject* result = (PyObject*) GraalPySlice_New(a, b, c);
36713671
return result;
36723672
}
3673-
PyObject* (*__target__PySlice_Start)(PyObject*) = NULL;
3674-
PyAPI_FUNC(PyObject*) PySlice_Start(PyObject* a) {
3673+
PyObject* (*__target__PySlice_Start)(PySliceObject*) = NULL;
3674+
PyAPI_FUNC(PyObject*) PySlice_Start(PySliceObject* a) {
36753675
PyObject* result = (PyObject*) __target__PySlice_Start(a);
36763676
return result;
36773677
}
3678-
PyObject* (*__target__PySlice_Step)(PyObject*) = NULL;
3679-
PyAPI_FUNC(PyObject*) PySlice_Step(PyObject* a) {
3678+
PyObject* (*__target__PySlice_Step)(PySliceObject*) = NULL;
3679+
PyAPI_FUNC(PyObject*) PySlice_Step(PySliceObject* a) {
36803680
PyObject* result = (PyObject*) __target__PySlice_Step(a);
36813681
return result;
36823682
}
3683-
PyObject* (*__target__PySlice_Stop)(PyObject*) = NULL;
3684-
PyAPI_FUNC(PyObject*) PySlice_Stop(PyObject* a) {
3683+
PyObject* (*__target__PySlice_Stop)(PySliceObject*) = NULL;
3684+
PyAPI_FUNC(PyObject*) PySlice_Stop(PySliceObject* a) {
36853685
PyObject* result = (PyObject*) __target__PySlice_Stop(a);
36863686
return result;
36873687
}

graalpython/com.oracle.graal.python.test/src/tests/test_object.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -168,5 +168,13 @@ def bar(self):
168168
AAA().foo()
169169
CCC().bar()
170170

171+
171172
def test_reduce_ex_with_none():
172-
assert_raises(TypeError, object(), None)
173+
assert_raises(TypeError, object(), None)
174+
175+
176+
def test_descr_call_with_none():
177+
descr = object.__dict__['__class__']
178+
assert None.__class__ is type(None)
179+
assert descr.__get__(None, type(None)) is descr
180+
assert_raises(TypeError, descr.__get__, None, None)

0 commit comments

Comments
 (0)