@@ -3255,8 +3255,6 @@ _curses_init_pair_impl(PyObject *module, int pair_number, int fg, int bg)
3255
3255
Py_RETURN_NONE ;
3256
3256
}
3257
3257
3258
- static PyObject * ModDict ;
3259
-
3260
3258
/*[clinic input]
3261
3259
_curses.initscr
3262
3260
@@ -3285,19 +3283,23 @@ _curses_initscr_impl(PyObject *module)
3285
3283
3286
3284
initialised = initialised_setupterm = TRUE;
3287
3285
3288
- /* This was moved from initcurses() because it core dumped on SGI,
3289
- where they're not defined until you've called initscr() */
3290
- #define SetDictInt (NAME , VALUE ) \
3291
- do { \
3292
- PyObject *value = PyLong_FromLong((long)(VALUE)); \
3293
- if (value == NULL) { \
3294
- return NULL; \
3295
- } \
3296
- int rc = PyDict_SetItemString(ModDict, (NAME), value); \
3297
- Py_DECREF(value); \
3298
- if (rc < 0) { \
3299
- return NULL; \
3300
- } \
3286
+ PyObject * module_dict = PyModule_GetDict (module ); // borrowed
3287
+ if (module_dict == NULL ) {
3288
+ return NULL ;
3289
+ }
3290
+ /* This was moved from initcurses() because it core dumped on SGI,
3291
+ where they're not defined until you've called initscr() */
3292
+ #define SetDictInt (NAME , VALUE ) \
3293
+ do { \
3294
+ PyObject *value = PyLong_FromLong((long)(VALUE)); \
3295
+ if (value == NULL) { \
3296
+ return NULL; \
3297
+ } \
3298
+ int rc = PyDict_SetItemString(module_dict, (NAME), value); \
3299
+ Py_DECREF(value); \
3300
+ if (rc < 0) { \
3301
+ return NULL; \
3302
+ } \
3301
3303
} while (0)
3302
3304
3303
3305
/* Here are some graphic symbols you can use */
@@ -3976,11 +3978,11 @@ _curses_qiflush_impl(PyObject *module, int flag)
3976
3978
Py_RETURN_NONE ;
3977
3979
}
3978
3980
3979
- /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
3980
- * and _curses.COLS */
3981
3981
#if defined(HAVE_CURSES_RESIZETERM ) || defined(HAVE_CURSES_RESIZE_TERM )
3982
+ /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
3983
+ * and _curses.COLS. Returns 1 on success and 0 on failure. */
3982
3984
static int
3983
- update_lines_cols (void )
3985
+ update_lines_cols (PyObject * private_module )
3984
3986
{
3985
3987
PyObject * exposed_module = NULL , * o = NULL ;
3986
3988
@@ -3992,6 +3994,10 @@ update_lines_cols(void)
3992
3994
if (exposed_module_dict == NULL ) {
3993
3995
goto error ;
3994
3996
}
3997
+ PyObject * private_module_dict = PyModule_GetDict (private_module ); // borrowed
3998
+ if (private_module_dict == NULL ) {
3999
+ goto error ;
4000
+ }
3995
4001
3996
4002
o = PyLong_FromLong (LINES );
3997
4003
if (o == NULL ) {
@@ -4000,7 +4006,7 @@ update_lines_cols(void)
4000
4006
if (PyDict_SetItemString (exposed_module_dict , "LINES" , o ) < 0 ) {
4001
4007
goto error ;
4002
4008
}
4003
- if (PyDict_SetItemString (ModDict , "LINES" , o ) < 0 ) {
4009
+ if (PyDict_SetItemString (private_module_dict , "LINES" , o ) < 0 ) {
4004
4010
goto error ;
4005
4011
}
4006
4012
Py_DECREF (o );
@@ -4012,7 +4018,7 @@ update_lines_cols(void)
4012
4018
if (PyDict_SetItemString (exposed_module_dict , "COLS" , o ) < 0 ) {
4013
4019
goto error ;
4014
4020
}
4015
- if (PyDict_SetItemString (ModDict , "COLS" , o ) < 0 ) {
4021
+ if (PyDict_SetItemString (private_module_dict , "COLS" , o ) < 0 ) {
4016
4022
goto error ;
4017
4023
}
4018
4024
Py_DECREF (o );
@@ -4034,7 +4040,7 @@ static PyObject *
4034
4040
_curses_update_lines_cols_impl (PyObject * module )
4035
4041
/*[clinic end generated code: output=423f2b1e63ed0f75 input=5f065ab7a28a5d90]*/
4036
4042
{
4037
- if (!update_lines_cols ()) {
4043
+ if (!update_lines_cols (module )) {
4038
4044
return NULL ;
4039
4045
}
4040
4046
Py_RETURN_NONE ;
@@ -4121,7 +4127,7 @@ _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
4121
4127
result = PyCursesCheckERR (resizeterm (nlines , ncols ), "resizeterm" );
4122
4128
if (!result )
4123
4129
return NULL ;
4124
- if (!update_lines_cols ()) {
4130
+ if (!update_lines_cols (module )) {
4125
4131
Py_DECREF (result );
4126
4132
return NULL ;
4127
4133
}
@@ -4160,7 +4166,7 @@ _curses_resize_term_impl(PyObject *module, int nlines, int ncols)
4160
4166
result = PyCursesCheckERR (resize_term (nlines , ncols ), "resize_term" );
4161
4167
if (!result )
4162
4168
return NULL ;
4163
- if (!update_lines_cols ()) {
4169
+ if (!update_lines_cols (module )) {
4164
4170
Py_DECREF (result );
4165
4171
return NULL ;
4166
4172
}
@@ -4232,17 +4238,21 @@ _curses_start_color_impl(PyObject *module)
4232
4238
4233
4239
initialisedcolors = TRUE;
4234
4240
4235
- #define DICT_ADD_INT_VALUE (NAME , VALUE ) \
4236
- do { \
4237
- PyObject *value = PyLong_FromLong((long)(VALUE)); \
4238
- if (value == NULL) { \
4239
- return NULL; \
4240
- } \
4241
- int rc = PyDict_SetItemString(ModDict, (NAME), value); \
4242
- Py_DECREF(value); \
4243
- if (rc < 0) { \
4244
- return NULL; \
4245
- } \
4241
+ PyObject * module_dict = PyModule_GetDict (module ); // borrowed
4242
+ if (module_dict == NULL ) {
4243
+ return NULL ;
4244
+ }
4245
+ #define DICT_ADD_INT_VALUE (NAME , VALUE ) \
4246
+ do { \
4247
+ PyObject *value = PyLong_FromLong((long)(VALUE)); \
4248
+ if (value == NULL) { \
4249
+ return NULL; \
4250
+ } \
4251
+ int rc = PyDict_SetItemString(module_dict, (NAME), value); \
4252
+ Py_DECREF(value); \
4253
+ if (rc < 0) { \
4254
+ return NULL; \
4255
+ } \
4246
4256
} while (0)
4247
4257
4248
4258
DICT_ADD_INT_VALUE ("COLORS" , COLORS );
@@ -4779,7 +4789,6 @@ cursesmodule_exec(PyObject *module)
4779
4789
if (module_dict == NULL ) {
4780
4790
return -1 ;
4781
4791
}
4782
- ModDict = module_dict ; /* For PyCurses_InitScr to use later */
4783
4792
4784
4793
void * * PyCurses_API = PyMem_Calloc (PyCurses_API_pointers , sizeof (void * ));
4785
4794
if (PyCurses_API == NULL ) {
0 commit comments