From 9b06e4b535a3a0af495604778d4010a4677478cc Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 13 May 2021 00:09:30 +0900 Subject: [PATCH] Use get_binascii_state instead of PyModule_GetState (GH-26069) --- Modules/binascii.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Modules/binascii.c b/Modules/binascii.c index 1f3248b6049..59e4b0a4a78 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -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); @@ -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; } @@ -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; } @@ -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; } @@ -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. @@ -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; } @@ -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; } @@ -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; } @@ -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; \ } \ @@ -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; } @@ -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; } @@ -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; }