From 6fc9589fa13c5544975f4587c7a209f1c069218e Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Thu, 2 Apr 2020 23:20:01 +0800 Subject: [PATCH 1/2] Use ADD_INT macro to replace PyModule_AddIntMacro macro --- Modules/_localemodule.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 0ce5dc5e7777e6..9c7b3341325a93 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -726,40 +726,48 @@ static struct PyMethodDef PyLocale_Methods[] = { }; static int -_locale_exec(PyObject *m) +_locale_exec(PyObject *module) { #ifdef HAVE_LANGINFO_H int i; #endif +#define ADD_INT(module, value) \ + do { \ + if (PyModule_AddIntConstant(module, #value, value) < 0) { \ + return -1; \ + } \ + } while (0) - PyModule_AddIntMacro(m, LC_CTYPE); - PyModule_AddIntMacro(m, LC_TIME); - PyModule_AddIntMacro(m, LC_COLLATE); - PyModule_AddIntMacro(m, LC_MONETARY); + ADD_INT(module, LC_CTYPE); + ADD_INT(module, LC_TIME); + ADD_INT(module, LC_COLLATE); + ADD_INT(module, LC_MONETARY); #ifdef LC_MESSAGES - PyModule_AddIntMacro(m, LC_MESSAGES); + ADD_INT(module, LC_MESSAGES); #endif /* LC_MESSAGES */ - PyModule_AddIntMacro(m, LC_NUMERIC); - PyModule_AddIntMacro(m, LC_ALL); - PyModule_AddIntMacro(m, CHAR_MAX); + ADD_INT(module, LC_NUMERIC); + ADD_INT(module, LC_ALL); + ADD_INT(module, CHAR_MAX); - _locale_state *state = get_locale_state(m); + _locale_state *state = get_locale_state(module); state->Error = PyErr_NewException("locale.Error", NULL, NULL); if (state->Error == NULL) { return -1; } - Py_INCREF(get_locale_state(m)->Error); - if (PyModule_AddObject(m, "Error", get_locale_state(m)->Error) < 0) { - Py_DECREF(get_locale_state(m)->Error); + Py_INCREF(get_locale_state(module)->Error); + if (PyModule_AddObject(module, "Error", get_locale_state(module)->Error) < 0) { + Py_DECREF(get_locale_state(module)->Error); return -1; } #ifdef HAVE_LANGINFO_H for (i = 0; langinfo_constants[i].name; i++) { - PyModule_AddIntConstant(m, langinfo_constants[i].name, - langinfo_constants[i].value); + if (PyModule_AddIntConstant(module, langinfo_constants[i].name, + langinfo_constants[i].value) < 0) { + return -1; + } } #endif @@ -767,6 +775,8 @@ _locale_exec(PyObject *m) return -1; } return 0; + +#undef ADD_INT } static struct PyModuleDef_Slot _locale_slots[] = { From 0b378de13c3c78fa9180871bf70a1fb38e033ef3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 2 Apr 2020 19:26:49 +0200 Subject: [PATCH 2/2] Update Modules/_localemodule.c --- Modules/_localemodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 9c7b3341325a93..5bf6638ed2a643 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -764,7 +764,8 @@ _locale_exec(PyObject *module) #ifdef HAVE_LANGINFO_H for (i = 0; langinfo_constants[i].name; i++) { - if (PyModule_AddIntConstant(module, langinfo_constants[i].name, + if (PyModule_AddIntConstant(module, + langinfo_constants[i].name, langinfo_constants[i].value) < 0) { return -1; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy