Skip to content

Commit a47f04b

Browse files
committed
Update Python inlined files: 3.12.7 (4.6)
1 parent eaf508b commit a47f04b

Some content is hidden

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

53 files changed

+17053
-6811
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,3 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(
107107

108108
PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(PyModuleDef*, int apiver);
109109
PyAPI_FUNC(int) _PyModule_Add(PyObject *, const char *, PyObject *);
110-
111-
PyAPI_DATA(const char *) _Py_PackageContext;

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

Lines changed: 94 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@
1515
#error "The maximum block size accepted by libbzip2 is UINT32_MAX."
1616
#endif
1717

18+
typedef struct {
19+
PyTypeObject *bz2_compressor_type;
20+
PyTypeObject *bz2_decompressor_type;
21+
} _bz2_state;
22+
23+
static inline _bz2_state *
24+
get_module_state(PyObject *module)
25+
{
26+
void *state = PyModule_GetState(module);
27+
assert(state != NULL);
28+
return (_bz2_state *)state;
29+
}
30+
31+
static struct PyModuleDef _bz2module;
32+
33+
static inline _bz2_state *
34+
find_module_state_by_def(PyTypeObject *type)
35+
{
36+
PyObject *module = PyType_GetModuleByDef(type, &_bz2module);
37+
assert(module != NULL);
38+
return get_module_state(module);
39+
}
40+
1841
/* On success, return value >= 0
1942
On failure, return -1 */
2043
static inline Py_ssize_t
@@ -81,19 +104,6 @@ OutputBuffer_OnError(_BlocksOutputBuffer *buffer)
81104
#define RELEASE_LOCK(obj) PyThread_release_lock((obj)->lock)
82105

83106

84-
typedef struct {
85-
PyTypeObject *bz2_compressor_type;
86-
PyTypeObject *bz2_decompressor_type;
87-
} _bz2_state;
88-
89-
static inline _bz2_state*
90-
get_bz2_state(PyObject *module)
91-
{
92-
void *state = PyModule_GetState(module);
93-
assert(state != NULL);
94-
return (_bz2_state *)state;
95-
}
96-
97107
typedef struct {
98108
PyObject_HEAD
99109
bz_stream bzs;
@@ -227,12 +237,14 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
227237

228238
/*[clinic input]
229239
module _bz2
230-
class _bz2.BZ2Compressor "BZ2Compressor *" "&BZ2Compressor_Type"
231-
class _bz2.BZ2Decompressor "BZ2Decompressor *" "&BZ2Decompressor_Type"
240+
class _bz2.BZ2Compressor "BZ2Compressor *" "clinic_state()->bz2_compressor_type"
241+
class _bz2.BZ2Decompressor "BZ2Decompressor *" "clinic_state()->bz2_decompressor_type"
232242
[clinic start generated code]*/
233-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=dc7d7992a79f9cb7]*/
243+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=92348121632b94c4]*/
234244

245+
#define clinic_state() (find_module_state_by_def(type))
235246
#include "clinic/_bz2module.c.h"
247+
#undef clinic_state
236248

237249
/*[clinic input]
238250
_bz2.BZ2Compressor.compress
@@ -308,24 +320,43 @@ BZ2_Free(void* ctx, void *ptr)
308320
PyMem_RawFree(ptr);
309321
}
310322

323+
/*[clinic input]
324+
@classmethod
325+
_bz2.BZ2Compressor.__new__
311326
312-
/* Argument Clinic is not used since the Argument Clinic always want to
313-
check the type which would be wrong here */
314-
static int
315-
_bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel)
327+
compresslevel: int = 9
328+
Compression level, as a number between 1 and 9.
329+
/
330+
331+
Create a compressor object for compressing data incrementally.
332+
333+
For one-shot compression, use the compress() function instead.
334+
[clinic start generated code]*/
335+
336+
static PyObject *
337+
_bz2_BZ2Compressor_impl(PyTypeObject *type, int compresslevel)
338+
/*[clinic end generated code: output=83346c96beaacad7 input=d4500d2a52c8b263]*/
316339
{
317340
int bzerror;
341+
BZ2Compressor *self;
318342

319343
if (!(1 <= compresslevel && compresslevel <= 9)) {
320344
PyErr_SetString(PyExc_ValueError,
321345
"compresslevel must be between 1 and 9");
322-
return -1;
346+
return NULL;
347+
}
348+
349+
assert(type != NULL && type->tp_alloc != NULL);
350+
self = (BZ2Compressor *)type->tp_alloc(type, 0);
351+
if (self == NULL) {
352+
return NULL;
323353
}
324354

325355
self->lock = PyThread_allocate_lock();
326356
if (self->lock == NULL) {
357+
Py_DECREF(self);
327358
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
328-
return -1;
359+
return NULL;
329360
}
330361

331362
self->bzs.opaque = NULL;
@@ -335,49 +366,11 @@ _bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel)
335366
if (catch_bz2_error(bzerror))
336367
goto error;
337368

338-
return 0;
369+
return (PyObject *)self;
339370

340371
error:
341-
PyThread_free_lock(self->lock);
342-
self->lock = NULL;
343-
return -1;
344-
}
345-
346-
PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__,
347-
"BZ2Compressor(compresslevel=9, /)\n"
348-
"--\n"
349-
"\n"
350-
"Create a compressor object for compressing data incrementally.\n"
351-
"\n"
352-
" compresslevel\n"
353-
" Compression level, as a number between 1 and 9.\n"
354-
"\n"
355-
"For one-shot compression, use the compress() function instead.");
356-
357-
static int
358-
_bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
359-
{
360-
int return_value = -1;
361-
int compresslevel = 9;
362-
363-
if (!_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
364-
goto exit;
365-
}
366-
if (!_PyArg_CheckPositional("BZ2Compressor", PyTuple_GET_SIZE(args), 0, 1)) {
367-
goto exit;
368-
}
369-
if (PyTuple_GET_SIZE(args) < 1) {
370-
goto skip_optional;
371-
}
372-
compresslevel = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
373-
if (compresslevel == -1 && PyErr_Occurred()) {
374-
goto exit;
375-
}
376-
skip_optional:
377-
return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel);
378-
379-
exit:
380-
return return_value;
372+
Py_DECREF(self);
373+
return NULL;
381374
}
382375

383376
static void
@@ -408,9 +401,8 @@ static PyMethodDef BZ2Compressor_methods[] = {
408401
static PyType_Slot bz2_compressor_type_slots[] = {
409402
{Py_tp_dealloc, BZ2Compressor_dealloc},
410403
{Py_tp_methods, BZ2Compressor_methods},
411-
{Py_tp_init, _bz2_BZ2Compressor___init__},
412-
{Py_tp_new, PyType_GenericNew},
413-
{Py_tp_doc, (char *)_bz2_BZ2Compressor___init____doc__},
404+
{Py_tp_new, _bz2_BZ2Compressor},
405+
{Py_tp_doc, (char *)_bz2_BZ2Compressor__doc__},
414406
{Py_tp_traverse, BZ2Compressor_traverse},
415407
{0, 0}
416408
};
@@ -637,69 +629,54 @@ _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
637629
return result;
638630
}
639631

640-
/* Argument Clinic is not used since the Argument Clinic always want to
641-
check the type which would be wrong here */
642-
static int
643-
_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self)
632+
/*[clinic input]
633+
@classmethod
634+
_bz2.BZ2Decompressor.__new__
635+
636+
Create a decompressor object for decompressing data incrementally.
637+
638+
For one-shot decompression, use the decompress() function instead.
639+
[clinic start generated code]*/
640+
641+
static PyObject *
642+
_bz2_BZ2Decompressor_impl(PyTypeObject *type)
643+
/*[clinic end generated code: output=5150d51ccaab220e input=b87413ce51853528]*/
644644
{
645+
BZ2Decompressor *self;
645646
int bzerror;
646647

647-
PyThread_type_lock lock = PyThread_allocate_lock();
648-
if (lock == NULL) {
649-
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
650-
return -1;
648+
assert(type != NULL && type->tp_alloc != NULL);
649+
self = (BZ2Decompressor *)type->tp_alloc(type, 0);
650+
if (self == NULL) {
651+
return NULL;
651652
}
652-
if (self->lock != NULL) {
653-
PyThread_free_lock(self->lock);
653+
654+
self->lock = PyThread_allocate_lock();
655+
if (self->lock == NULL) {
656+
Py_DECREF(self);
657+
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
658+
return NULL;
654659
}
655-
self->lock = lock;
656660

657661
self->needs_input = 1;
658662
self->bzs_avail_in_real = 0;
659663
self->input_buffer = NULL;
660664
self->input_buffer_size = 0;
661-
Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0));
665+
self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
662666
if (self->unused_data == NULL)
663667
goto error;
664668

665669
bzerror = BZ2_bzDecompressInit(&self->bzs, 0, 0);
666670
if (catch_bz2_error(bzerror))
667671
goto error;
668672

669-
return 0;
673+
return (PyObject *)self;
670674

671675
error:
672-
Py_CLEAR(self->unused_data);
673-
PyThread_free_lock(self->lock);
674-
self->lock = NULL;
675-
return -1;
676-
}
677-
678-
static int
679-
_bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
680-
{
681-
int return_value = -1;
682-
683-
if (!_PyArg_NoPositional("BZ2Decompressor", args)) {
684-
goto exit;
685-
}
686-
if (!_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
687-
goto exit;
688-
}
689-
return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
690-
691-
exit:
692-
return return_value;
676+
Py_DECREF(self);
677+
return NULL;
693678
}
694679

695-
PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__,
696-
"BZ2Decompressor()\n"
697-
"--\n"
698-
"\n"
699-
"Create a decompressor object for decompressing data incrementally.\n"
700-
"\n"
701-
"For one-shot decompression, use the decompress() function instead.");
702-
703680
static void
704681
BZ2Decompressor_dealloc(BZ2Decompressor *self)
705682
{
@@ -751,10 +728,9 @@ static PyMemberDef BZ2Decompressor_members[] = {
751728
static PyType_Slot bz2_decompressor_type_slots[] = {
752729
{Py_tp_dealloc, BZ2Decompressor_dealloc},
753730
{Py_tp_methods, BZ2Decompressor_methods},
754-
{Py_tp_init, _bz2_BZ2Decompressor___init__},
755-
{Py_tp_doc, (char *)_bz2_BZ2Decompressor___init____doc__},
731+
{Py_tp_doc, (char *)_bz2_BZ2Decompressor__doc__},
756732
{Py_tp_members, BZ2Decompressor_members},
757-
{Py_tp_new, PyType_GenericNew},
733+
{Py_tp_new, _bz2_BZ2Decompressor},
758734
{Py_tp_traverse, BZ2Decompressor_traverse},
759735
{0, 0}
760736
};
@@ -775,7 +751,7 @@ static PyType_Spec bz2_decompressor_type_spec = {
775751
static int
776752
_bz2_exec(PyObject *module)
777753
{
778-
_bz2_state *state = get_bz2_state(module);
754+
_bz2_state *state = get_module_state(module);
779755
state->bz2_compressor_type = (PyTypeObject *)PyType_FromModuleAndSpec(module,
780756
&bz2_compressor_type_spec, NULL);
781757
if (state->bz2_compressor_type == NULL) {
@@ -800,7 +776,7 @@ _bz2_exec(PyObject *module)
800776
static int
801777
_bz2_traverse(PyObject *module, visitproc visit, void *arg)
802778
{
803-
_bz2_state *state = get_bz2_state(module);
779+
_bz2_state *state = get_module_state(module);
804780
Py_VISIT(state->bz2_compressor_type);
805781
Py_VISIT(state->bz2_decompressor_type);
806782
return 0;
@@ -809,7 +785,7 @@ _bz2_traverse(PyObject *module, visitproc visit, void *arg)
809785
static int
810786
_bz2_clear(PyObject *module)
811787
{
812-
_bz2_state *state = get_bz2_state(module);
788+
_bz2_state *state = get_module_state(module);
813789
Py_CLEAR(state->bz2_compressor_type);
814790
Py_CLEAR(state->bz2_decompressor_type);
815791
return 0;
@@ -818,22 +794,23 @@ _bz2_clear(PyObject *module)
818794
static void
819795
_bz2_free(void *module)
820796
{
821-
_bz2_clear((PyObject *)module);
797+
(void)_bz2_clear((PyObject *)module);
822798
}
823799

824800
static struct PyModuleDef_Slot _bz2_slots[] = {
825801
{Py_mod_exec, _bz2_exec},
802+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
826803
{0, NULL}
827804
};
828805

829806
static struct PyModuleDef _bz2module = {
830-
PyModuleDef_HEAD_INIT,
807+
.m_base = PyModuleDef_HEAD_INIT,
831808
.m_name = "_bz2",
832809
.m_size = sizeof(_bz2_state),
833-
.m_slots = _bz2_slots,
834810
.m_traverse = _bz2_traverse,
835811
.m_clear = _bz2_clear,
836812
.m_free = _bz2_free,
813+
.m_slots = _bz2_slots,
837814
};
838815

839816
PyMODINIT_FUNC

0 commit comments

Comments
 (0)