Skip to content

Commit 9b06e4b

Browse files
authored
Use get_binascii_state instead of PyModule_GetState (GH-26069)
1 parent 2b458c1 commit 9b06e4b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Modules/binascii.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef struct binascii_state {
6666
PyObject *Incomplete;
6767
} binascii_state;
6868

69-
static binascii_state *
69+
static inline binascii_state *
7070
get_binascii_state(PyObject *module)
7171
{
7272
return (binascii_state *)PyModule_GetState(module);
@@ -312,7 +312,7 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data)
312312
** '`' as zero instead of space.
313313
*/
314314
if ( this_ch < ' ' || this_ch > (' ' + 64)) {
315-
state = PyModule_GetState(module);
315+
state = get_binascii_state(module);
316316
if (state == NULL) {
317317
return NULL;
318318
}
@@ -344,7 +344,7 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data)
344344
/* Extra '`' may be written as padding in some cases */
345345
if ( this_ch != ' ' && this_ch != ' '+64 &&
346346
this_ch != '\n' && this_ch != '\r' ) {
347-
state = PyModule_GetState(module);
347+
state = get_binascii_state(module);
348348
if (state == NULL) {
349349
return NULL;
350350
}
@@ -385,7 +385,7 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick)
385385
bin_len = data->len;
386386
if ( bin_len > 45 ) {
387387
/* The 45 is a limit that appears in all uuencode's */
388-
state = PyModule_GetState(module);
388+
state = get_binascii_state(module);
389389
if (state == NULL) {
390390
return NULL;
391391
}
@@ -505,9 +505,9 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data)
505505
}
506506

507507
if (quad_pos != 0) {
508-
binascii_state *state = PyModule_GetState(module);
508+
binascii_state *state = get_binascii_state(module);
509509
if (state == NULL) {
510-
/* error already set, from PyModule_GetState */
510+
/* error already set, from get_binascii_state */
511511
} else if (quad_pos == 1) {
512512
/*
513513
** There is exactly one extra valid, non-padding, base64 character.
@@ -562,7 +562,7 @@ binascii_b2a_base64_impl(PyObject *module, Py_buffer *data, int newline)
562562
assert(bin_len >= 0);
563563

564564
if ( bin_len > BASE64_MAXBIN ) {
565-
state = PyModule_GetState(module);
565+
state = get_binascii_state(module);
566566
if (state == NULL) {
567567
return NULL;
568568
}
@@ -657,7 +657,7 @@ binascii_a2b_hqx_impl(PyObject *module, Py_buffer *data)
657657
if ( this_ch == SKIP )
658658
continue;
659659
if ( this_ch == FAIL ) {
660-
state = PyModule_GetState(module);
660+
state = get_binascii_state(module);
661661
if (state == NULL) {
662662
return NULL;
663663
}
@@ -682,7 +682,7 @@ binascii_a2b_hqx_impl(PyObject *module, Py_buffer *data)
682682
}
683683

684684
if ( leftbits && !done ) {
685-
state = PyModule_GetState(module);
685+
state = get_binascii_state(module);
686686
if (state == NULL) {
687687
return NULL;
688688
}
@@ -878,7 +878,7 @@ binascii_rledecode_hqx_impl(PyObject *module, Py_buffer *data)
878878
#define INBYTE(b) \
879879
do { \
880880
if ( --in_len < 0 ) { \
881-
state = PyModule_GetState(module); \
881+
state = get_binascii_state(module); \
882882
if (state == NULL) { \
883883
return NULL; \
884884
} \
@@ -904,7 +904,7 @@ binascii_rledecode_hqx_impl(PyObject *module, Py_buffer *data)
904904
/* Note Error, not Incomplete (which is at the end
905905
** of the string only). This is a programmer error.
906906
*/
907-
state = PyModule_GetState(module);
907+
state = get_binascii_state(module);
908908
if (state == NULL) {
909909
return NULL;
910910
}
@@ -1235,7 +1235,7 @@ binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr)
12351235
* raise an exception.
12361236
*/
12371237
if (arglen % 2) {
1238-
state = PyModule_GetState(module);
1238+
state = get_binascii_state(module);
12391239
if (state == NULL) {
12401240
return NULL;
12411241
}
@@ -1252,7 +1252,7 @@ binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr)
12521252
unsigned int top = _PyLong_DigitValue[Py_CHARMASK(argbuf[i])];
12531253
unsigned int bot = _PyLong_DigitValue[Py_CHARMASK(argbuf[i+1])];
12541254
if (top >= 16 || bot >= 16) {
1255-
state = PyModule_GetState(module);
1255+
state = get_binascii_state(module);
12561256
if (state == NULL) {
12571257
return NULL;
12581258
}

0 commit comments

Comments
 (0)