Skip to content

Commit ff3106a

Browse files
committed
[GR-51961] Keep our C file structure closer to CPython, part 1
PullRequest: graalpython/3192
2 parents 98bfcef + 32f8373 commit ff3106a

File tree

17 files changed

+22852
-1232
lines changed

17 files changed

+22852
-1232
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* --- Internal Unicode Operations ---------------------------------------- */
1818

1919
#ifndef USE_UNICODE_WCHAR_CACHE
20-
# define USE_UNICODE_WCHAR_CACHE 1
20+
# define USE_UNICODE_WCHAR_CACHE 0 // GraalPy change
2121
#endif /* USE_UNICODE_WCHAR_CACHE */
2222

2323
/* Since splitting on whitespace is an important use case, and

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ extern "C" {
1313
# error "this header requires Py_BUILD_CORE define"
1414
#endif
1515

16-
// #include "pycore_pystate.h" // _PyThreadState_GET()
16+
#if 0 // GraalPy change
17+
#include "pycore_pystate.h" // _PyThreadState_GET()
18+
#endif // GraalPy change
1719

1820
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(
1921
PyThreadState *tstate,
@@ -95,8 +97,7 @@ _PyObject_VectorcallTstate(PyThreadState *tstate, PyObject *callable,
9597
return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwnames);
9698
}
9799
res = func(callable, args, nargsf, kwnames);
98-
// return _Py_CheckFunctionResult(tstate, callable, res, NULL);
99-
return res;
100+
return _Py_CheckFunctionResult(tstate, callable, res, NULL);
100101
}
101102

102103

@@ -109,9 +110,8 @@ _PyObject_CallNoArgsTstate(PyThreadState *tstate, PyObject *func) {
109110
// Private static inline function variant of public PyObject_CallNoArgs()
110111
static inline PyObject *
111112
_PyObject_CallNoArgs(PyObject *func) {
112-
// PyThreadState *tstate = _PyThreadState_GET();
113-
// return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
114-
return _PyObject_VectorcallTstate(NULL, func, NULL, 0, NULL);
113+
PyThreadState *tstate = NULL; // GraalPy change: don't get thread state
114+
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
115115
}
116116

117117

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2022 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -24,7 +24,8 @@ extern void _PyErr_FiniTypes(PyInterpreterState *);
2424

2525
static inline PyObject* _PyErr_Occurred(PyThreadState *tstate)
2626
{
27-
return PyErr_Occured();
27+
// GraalPy change
28+
return PyErr_Occurred();
2829
}
2930

3031
static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2022, 2024, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2022 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -67,7 +67,7 @@ struct _Py_tuple_state {
6767
#endif
6868
};
6969

70-
#define _PyTuple_ITEMS(op) (PySequence_FAST_ITEMS(op))
70+
#define _PyTuple_ITEMS(op) (PySequence_Fast_ITEMS(op))
7171

7272
extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
7373
extern PyObject *_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -176,13 +176,3 @@ int PyErr_WarnExplicitFormat(PyObject *category,
176176
return ret;
177177
}
178178

179-
PyObject* _PyErr_FormatFromCause(PyObject *exception, const char *format, ...) {
180-
// dummy implementation that ignores the cause
181-
va_list args;
182-
va_start(args, format);
183-
PyObject* formatted_msg = PyUnicode_FromFormatV(format, args);
184-
va_end(args);
185-
Graal_PyTruffleErr_CreateAndSetException(exception, formatted_msg);
186-
return NULL;
187-
}
188-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,14 @@ void bytearray_releasebuffer(PyByteArrayObject *obj, Py_buffer *view) {
6464
Py_ssize_t PyByteArray_Size(PyObject *self) {
6565
return PyByteArray_GET_SIZE(self);
6666
}
67+
68+
PyObject* PyByteArray_FromStringAndSize(const char* str, Py_ssize_t sz) {
69+
if (sz < 0) {
70+
PyErr_SetString(PyExc_SystemError, "Negative size passed to PyByteArray_FromStringAndSize");
71+
return NULL;
72+
}
73+
if (str != NULL) {
74+
return GraalPyTruffleByteArray_FromStringAndSize(str, sz);
75+
}
76+
return GraalPyTruffle_ByteArray_EmptyWithCapacity(sz);
77+
}

0 commit comments

Comments
 (0)