Skip to content

Commit

Permalink
Use get_binascii_state instead of PyModule_GetState (GH-26069)
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed May 12, 2021
1 parent 2b458c1 commit 9b06e4b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Modules/binascii.c
Expand Up @@ -66,7 +66,7 @@ typedef struct binascii_state {
PyObject *Incomplete;
} binascii_state;

static binascii_state *
static inline binascii_state *
get_binascii_state(PyObject *module)
{
return (binascii_state *)PyModule_GetState(module);
Expand Down Expand Up @@ -312,7 +312,7 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data)
** '`' as zero instead of space.
*/
if ( this_ch < ' ' || this_ch > (' ' + 64)) {
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand Down Expand Up @@ -344,7 +344,7 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data)
/* Extra '`' may be written as padding in some cases */
if ( this_ch != ' ' && this_ch != ' '+64 &&
this_ch != '\n' && this_ch != '\r' ) {
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand Down Expand Up @@ -385,7 +385,7 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick)
bin_len = data->len;
if ( bin_len > 45 ) {
/* The 45 is a limit that appears in all uuencode's */
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand Down Expand Up @@ -505,9 +505,9 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data)
}

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

if ( bin_len > BASE64_MAXBIN ) {
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand Down Expand Up @@ -657,7 +657,7 @@ binascii_a2b_hqx_impl(PyObject *module, Py_buffer *data)
if ( this_ch == SKIP )
continue;
if ( this_ch == FAIL ) {
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand All @@ -682,7 +682,7 @@ binascii_a2b_hqx_impl(PyObject *module, Py_buffer *data)
}

if ( leftbits && !done ) {
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand Down Expand Up @@ -878,7 +878,7 @@ binascii_rledecode_hqx_impl(PyObject *module, Py_buffer *data)
#define INBYTE(b) \
do { \
if ( --in_len < 0 ) { \
state = PyModule_GetState(module); \
state = get_binascii_state(module); \
if (state == NULL) { \
return NULL; \
} \
Expand All @@ -904,7 +904,7 @@ binascii_rledecode_hqx_impl(PyObject *module, Py_buffer *data)
/* Note Error, not Incomplete (which is at the end
** of the string only). This is a programmer error.
*/
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand Down Expand Up @@ -1235,7 +1235,7 @@ binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr)
* raise an exception.
*/
if (arglen % 2) {
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand All @@ -1252,7 +1252,7 @@ binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr)
unsigned int top = _PyLong_DigitValue[Py_CHARMASK(argbuf[i])];
unsigned int bot = _PyLong_DigitValue[Py_CHARMASK(argbuf[i+1])];
if (top >= 16 || bot >= 16) {
state = PyModule_GetState(module);
state = get_binascii_state(module);
if (state == NULL) {
return NULL;
}
Expand Down

0 comments on commit 9b06e4b

Please sign in to comment.