Skip to content

Commit d4ebd10

Browse files
committed
[GR-25013] Update stdlib to CPython 3.8.5
PullRequest: graalpython/1177
2 parents 78ed628 + 9f8e3fd commit d4ebd10

File tree

211 files changed

+3049
-1284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+3049
-1284
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ typedef struct {
9494
#define CO_ITERABLE_COROUTINE 0x0100
9595
#define CO_ASYNC_GENERATOR 0x0200
9696

97-
/* These are no longer used. */
98-
#if 0
99-
#define CO_GENERATOR_ALLOWED 0x1000
100-
#endif
101-
#define CO_FUTURE_DIVISION 0x2000
102-
#define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */
103-
#define CO_FUTURE_WITH_STATEMENT 0x8000
104-
#define CO_FUTURE_PRINT_FUNCTION 0x10000
105-
#define CO_FUTURE_UNICODE_LITERALS 0x20000
106-
107-
#define CO_FUTURE_BARRY_AS_BDFL 0x40000
108-
#define CO_FUTURE_GENERATOR_STOP 0x80000
109-
#define CO_FUTURE_ANNOTATIONS 0x100000
97+
/* bpo-39562: These constant values are changed in Python 3.9
98+
to prevent collision with compiler flags. CO_FUTURE_ and PyCF_
99+
constants must be kept unique. PyCF_ constants can use bits from
100+
0x0100 to 0x10000. CO_FUTURE_ constants use bits starting at 0x20000. */
101+
#define CO_FUTURE_DIVISION 0x20000
102+
#define CO_FUTURE_ABSOLUTE_IMPORT 0x40000 /* do absolute imports by default */
103+
#define CO_FUTURE_WITH_STATEMENT 0x80000
104+
#define CO_FUTURE_PRINT_FUNCTION 0x100000
105+
#define CO_FUTURE_UNICODE_LITERALS 0x200000
106+
107+
#define CO_FUTURE_BARRY_AS_BDFL 0x400000
108+
#define CO_FUTURE_GENERATOR_STOP 0x800000
109+
#define CO_FUTURE_ANNOTATIONS 0x1000000
110110

111111
/* This value is found in the co_cell2arg array when the associated cell
112112
variable does not correspond to an argument. */

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
2424
CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
2525
CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
2626
#define PyCF_MASK_OBSOLETE (CO_NESTED)
27+
28+
/* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
29+
PyCF_ constants can use bits from 0x0100 to 0x10000.
30+
CO_FUTURE_ constants use bits starting at 0x20000. */
2731
#define PyCF_SOURCE_IS_UTF8 0x0100
2832
#define PyCF_DONT_IMPLY_DEDENT 0x0200
2933
#define PyCF_ONLY_AST 0x0400
3034
#define PyCF_IGNORE_COOKIE 0x0800
3135
#define PyCF_TYPE_COMMENTS 0x1000
3236
#define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
37+
#define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \
38+
PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT)
3339

3440
#ifndef Py_LIMITED_API
3541
typedef struct {

graalpython/com.oracle.graal.python.cext/include/cpython/pystate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct _ts {
6060
struct _ts *next;
6161
PyInterpreterState *interp;
6262

63+
/* Borrowed reference to the current frame (it can be NULL) */
6364
struct _frame *frame;
6465
int recursion_depth;
6566
char overflowed; /* The stack has overflowed. Allow 50 more calls

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ of data it contains. An object's type is fixed when it is created.
3434
Types themselves are represented as objects; an object contains a
3535
pointer to the corresponding type object. The type itself has a type
3636
pointer pointing to the object representing the type 'type', which
37-
contains a pointer to itself!).
37+
contains a pointer to itself!.
3838
3939
Objects do not float around in memory; once allocated an object keeps
4040
the same size and address. Objects that must hold variable-size data

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
/*--start constants--*/
2424
#define PY_MAJOR_VERSION 3
2525
#define PY_MINOR_VERSION 8
26-
#define PY_MICRO_VERSION 2
26+
#define PY_MICRO_VERSION 5
2727
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
2828
#define PY_RELEASE_SERIAL 0
2929

3030
/* Version as a string */
31-
#define PY_VERSION "3.8.2"
31+
#define PY_VERSION "3.8.5"
3232
/*--end constants--*/
3333

3434
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.

graalpython/com.oracle.graal.python.cext/modules/_cpython_struct.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,10 @@ prepare_s(PyStructObject *self)
12911291
size_t ncodes;
12921292

12931293
fmt = PyBytes_AS_STRING(self->s_format);
1294+
if (strlen(fmt) != (size_t)PyBytes_GET_SIZE(self->s_format)) {
1295+
PyErr_SetString(StructError, "embedded null character");
1296+
return -1;
1297+
}
12941298

12951299
f = whichtable(&fmt);
12961300

@@ -2371,6 +2375,9 @@ PyInit__cpython_struct(void)
23712375
"unknown" float format */
23722376
if (ptr->format == 'd' || ptr->format == 'f')
23732377
break;
2378+
/* Skip _Bool, semantics are different for standard size */
2379+
if (ptr->format == '?')
2380+
break;
23742381
ptr->pack = native->pack;
23752382
ptr->unpack = native->unpack;
23762383
break;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
*NormalizationTest.test_bug_834676
21
*graalpython.lib-python.3.test.test_normalization.NormalizationTest.test_bug_834676

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
119119
public static final String NAME = "Python";
120120
public static final int MAJOR = 3;
121121
public static final int MINOR = 8;
122-
public static final int MICRO = 2;
122+
public static final int MICRO = 5;
123123
public static final String VERSION = MAJOR + "." + MINOR + "." + MICRO;
124124

125125
public static final String MIME_TYPE = "text/x-python";

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public enum PythonBuiltinClassType implements TruffleObject {
118118
PRLock("RLock", "_thread"),
119119
PSemLock("SemLock", "_multiprocessing"),
120120
PSocket("socket", "_socket"),
121+
PJavaSignalHandler("java_signal_handler"),
121122
PStaticmethod("staticmethod", BuiltinNames.BUILTINS),
122123
PClassmethod("classmethod", BuiltinNames.BUILTINS),
123124
PScandirIterator("ScandirIterator", "posix"),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@
7171
import com.oracle.truffle.api.library.CachedLibrary;
7272
import com.oracle.truffle.api.object.HiddenKey;
7373

74+
import sun.misc.SignalHandler;
75+
7476
@CoreFunctions(defineModule = "_signal")
7577
public class SignalModuleBuiltins extends PythonBuiltins {
76-
private static ConcurrentHashMap<Integer, Object> signalHandlers = new ConcurrentHashMap<>();
78+
private static final ConcurrentHashMap<Integer, Object> signalHandlers = new ConcurrentHashMap<>();
79+
private static final ConcurrentHashMap<Integer, SignalHandler> defaultSignalHandlers = new ConcurrentHashMap<>();
7780

7881
private static final HiddenKey signalQueueKey = new HiddenKey("signalQueue");
7982
private final ConcurrentLinkedDeque<SignalTriggerAction> signalQueue = new ConcurrentLinkedDeque<>();
@@ -172,22 +175,34 @@ int alarmOvf(PInt seconds) {
172175
}
173176
}
174177

178+
@TruffleBoundary
179+
private static Object handlerToPython(SignalHandler handler, int signum) {
180+
if (handler == sun.misc.SignalHandler.SIG_DFL) {
181+
return Signals.SIG_DFL;
182+
} else if (handler == sun.misc.SignalHandler.SIG_IGN) {
183+
return Signals.SIG_IGN;
184+
} else if (handler instanceof Signals.PythonSignalHandler) {
185+
return signalHandlers.getOrDefault(signum, PNone.NONE);
186+
} else {
187+
// Save default JVM handlers to be restored later
188+
defaultSignalHandlers.put(signum, handler);
189+
return Signals.SIG_DFL;
190+
}
191+
}
192+
175193
@Builtin(name = "getsignal", minNumOfPositionalArgs = 1)
176194
@GenerateNodeFactory
177195
abstract static class GetSignalNode extends PythonUnaryBuiltinNode {
178196
@Specialization
179197
@TruffleBoundary
180198
Object getsignal(int signum) {
181-
int currentSignalHandler = Signals.getCurrentSignalHandler(signum);
182-
if (currentSignalHandler == Signals.SIG_UNKNOWN) {
183-
if (signalHandlers.containsKey(signum)) {
184-
return signalHandlers.get(signum);
185-
} else {
186-
return PNone.NONE;
187-
}
188-
} else {
189-
return currentSignalHandler;
190-
}
199+
return handlerToPython(Signals.getCurrentSignalHandler(signum), signum);
200+
}
201+
202+
@Specialization(limit = "3")
203+
Object getsignal(Object signum,
204+
@CachedLibrary("signum") PythonObjectLibrary lib) {
205+
return getsignal(lib.asSize(signum));
191206
}
192207
}
193208

@@ -218,21 +233,19 @@ Object signalId(@SuppressWarnings("unused") PythonModule self, Object signal, Ob
218233

219234
@TruffleBoundary
220235
private Object signal(int signum, int id) {
221-
Object retval;
236+
SignalHandler oldHandler;
222237
try {
223-
retval = Signals.setSignalHandler(signum, id);
224-
} catch (IllegalArgumentException e) {
225-
throw raise(PythonErrorType.TypeError, ErrorMessages.SIGNAL_MUST_BE_SIGIGN_SIGDFL_OR_CALLABLE_OBJ);
226-
}
227-
if ((int) retval == Signals.SIG_UNKNOWN) {
228-
if (signalHandlers.containsKey(signum)) {
229-
retval = signalHandlers.get(signum);
238+
if (id == Signals.SIG_DFL && defaultSignalHandlers.containsKey(signum)) {
239+
oldHandler = Signals.setSignalHandler(signum, defaultSignalHandlers.get(signum));
230240
} else {
231-
retval = PNone.NONE;
241+
oldHandler = Signals.setSignalHandler(signum, id);
232242
}
243+
} catch (IllegalArgumentException e) {
244+
throw raise(PythonErrorType.TypeError, ErrorMessages.SIGNAL_MUST_BE_SIGIGN_SIGDFL_OR_CALLABLE_OBJ);
233245
}
234-
signalHandlers.put(signum, id);
235-
return retval;
246+
Object result = handlerToPython(oldHandler, signum);
247+
signalHandlers.remove(signum);
248+
return result;
236249
}
237250

238251
@Specialization(guards = "handlerLib.isCallable(handler)", limit = "1")
@@ -248,25 +261,19 @@ Object signalHandler(PythonModule self, Object signal, Object handler,
248261
private Object signal(PythonModule self, int signum, Object handler, ReadAttributeFromObjectNode readQueueNode, ReadAttributeFromObjectNode readSemaNode) {
249262
ConcurrentLinkedDeque<SignalTriggerAction> queue = getQueue(self, readQueueNode);
250263
Semaphore semaphore = getSemaphore(self, readSemaNode);
251-
Object retval;
264+
SignalHandler oldHandler;
252265
SignalTriggerAction signalTrigger = new SignalTriggerAction(handler, signum);
253266
try {
254-
retval = Signals.setSignalHandler(signum, () -> {
267+
oldHandler = Signals.setSignalHandler(signum, () -> {
255268
queue.add(signalTrigger);
256269
semaphore.release();
257270
});
258271
} catch (IllegalArgumentException e) {
259272
throw raise(PythonErrorType.ValueError, e);
260273
}
261-
if ((int) retval == Signals.SIG_UNKNOWN) {
262-
if (signalHandlers.containsKey(signum)) {
263-
retval = signalHandlers.get(signum);
264-
} else {
265-
retval = PNone.NONE;
266-
}
267-
}
274+
Object result = handlerToPython(oldHandler, signum);
268275
signalHandlers.put(signum, handler);
269-
return retval;
276+
return result;
270277
}
271278

272279
@SuppressWarnings("unchecked")
@@ -299,7 +306,6 @@ private static Semaphore getSemaphore(PythonModule self, ReadAttributeFromObject
299306
final class Signals {
300307
static final int SIG_DFL = 0;
301308
static final int SIG_IGN = 1;
302-
static final int SIG_UNKNOWN = -1;
303309
private static final int SIGMAX = 31;
304310
static final String[] signalNames = new String[SIGMAX + 1];
305311

@@ -342,7 +348,7 @@ synchronized static void scheduleAlarm(long seconds) {
342348
new Thread(new Alarm(seconds)).start();
343349
}
344350

345-
private static class PythonSignalHandler implements sun.misc.SignalHandler {
351+
static class PythonSignalHandler implements sun.misc.SignalHandler {
346352
private final Runnable handler;
347353

348354
public PythonSignalHandler(Runnable handler) {
@@ -360,13 +366,17 @@ static String signalNumberToName(int signum) {
360366
}
361367

362368
@TruffleBoundary
363-
synchronized static int setSignalHandler(int signum, Runnable handler) throws IllegalArgumentException {
364-
sun.misc.SignalHandler oldH = sun.misc.Signal.handle(new sun.misc.Signal(signalNumberToName(signum)), new PythonSignalHandler(handler));
365-
return handlerToInt(oldH);
369+
synchronized static SignalHandler setSignalHandler(int signum, Runnable handler) throws IllegalArgumentException {
370+
return setSignalHandler(signum, new PythonSignalHandler(handler));
366371
}
367372

368373
@TruffleBoundary
369-
synchronized static int setSignalHandler(int signum, int handler) throws IllegalArgumentException {
374+
synchronized static SignalHandler setSignalHandler(int signum, SignalHandler handler) throws IllegalArgumentException {
375+
return sun.misc.Signal.handle(new sun.misc.Signal(signalNumberToName(signum)), handler);
376+
}
377+
378+
@TruffleBoundary
379+
synchronized static SignalHandler setSignalHandler(int signum, int handler) throws IllegalArgumentException {
370380
sun.misc.SignalHandler h;
371381
if (handler == SIG_DFL) {
372382
h = sun.misc.SignalHandler.SIG_DFL;
@@ -375,34 +385,24 @@ synchronized static int setSignalHandler(int signum, int handler) throws Illegal
375385
} else {
376386
throw new IllegalArgumentException();
377387
}
378-
return handlerToInt(sun.misc.Signal.handle(new sun.misc.Signal(signalNumberToName(signum)), h));
388+
return sun.misc.Signal.handle(new sun.misc.Signal(signalNumberToName(signum)), h);
379389
}
380390

381391
@TruffleBoundary
382-
synchronized static int getCurrentSignalHandler(int signum) {
392+
synchronized static SignalHandler getCurrentSignalHandler(int signum) {
383393
// To check what the current signal handler, we install default to get the current one
384394
// and immediately replace it again.
385395
sun.misc.SignalHandler oldH;
386396
try {
387397
oldH = sun.misc.Signal.handle(new sun.misc.Signal(signalNumberToName(signum)), sun.misc.SignalHandler.SIG_DFL);
388398
} catch (IllegalArgumentException e) {
389-
return SIG_DFL;
399+
return sun.misc.SignalHandler.SIG_DFL;
390400
}
391401
try {
392402
sun.misc.Signal.handle(new sun.misc.Signal(signalNumberToName(signum)), oldH);
393403
} catch (IllegalArgumentException e) {
394-
return SIG_DFL;
395-
}
396-
return handlerToInt(oldH);
397-
}
398-
399-
private static int handlerToInt(sun.misc.SignalHandler oldH) {
400-
if (oldH == sun.misc.SignalHandler.SIG_DFL) {
401-
return SIG_DFL;
402-
} else if (oldH == sun.misc.SignalHandler.SIG_IGN) {
403-
return SIG_IGN;
404-
} else {
405-
return SIG_UNKNOWN;
404+
return sun.misc.SignalHandler.SIG_DFL;
406405
}
406+
return oldH;
407407
}
408408
}

0 commit comments

Comments
 (0)