Skip to content

Commit 8f3b1a2

Browse files
committed
check return codes in auto-generated functions
1 parent f0a5548 commit 8f3b1a2

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

Modules/_cursesmodule.c

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,12 +3016,15 @@ static PyType_Spec PyCursesWindow_Type_spec = {
30163016
*
30173017
* These macros should only be used for generating the body of
30183018
* the module's methods since they need a module reference.
3019+
*
3020+
* The Python function name must be the same as the curses function name (X).
30193021
*/
30203022

3021-
#define NoArgNoReturnFunctionBody(X) \
3022-
{ \
3023-
PyCursesStatefulInitialised(module); \
3024-
return curses_check_err(module, X(), # X, NULL); }
3023+
#define NoArgNoReturnFunctionBody(X) \
3024+
{ \
3025+
PyCursesStatefulInitialised(module); \
3026+
return curses_check_err(module, X(), # X, NULL); \
3027+
}
30253028

30263029
#define NoArgOrFlagNoReturnFunctionBody(X, FLAG) \
30273030
{ \
@@ -3039,26 +3042,40 @@ static PyType_Spec PyCursesWindow_Type_spec = {
30393042
return curses_check_err(module, rtn, funcname, # X); \
30403043
}
30413044

3042-
#define NoArgReturnIntFunctionBody(X) \
3043-
{ \
3044-
PyCursesStatefulInitialised(module); \
3045-
return PyLong_FromLong((long) X()); }
3045+
#define NoArgReturnIntFunctionBody(X) \
3046+
{ \
3047+
PyCursesStatefulInitialised(module); \
3048+
int rtn = X(); \
3049+
if (rtn == ERR) { \
3050+
curses_set_error(module, # X, NULL); \
3051+
return NULL; \
3052+
} \
3053+
return PyLong_FromLong(rtn); \
3054+
}
30463055

3047-
#define NoArgReturnStringFunctionBody(X) \
3048-
{ \
3049-
PyCursesStatefulInitialised(module); \
3050-
return PyBytes_FromString(X()); }
3056+
#define NoArgReturnStringFunctionBody(X) \
3057+
{ \
3058+
PyCursesStatefulInitialised(module); \
3059+
const char *res = X(); \
3060+
if (res == NULL) { \
3061+
curses_set_null_error(module, # X, NULL); \
3062+
return NULL; \
3063+
} \
3064+
return PyBytes_FromString(res); \
3065+
}
30513066

3052-
#define NoArgTrueFalseFunctionBody(X) \
3053-
{ \
3054-
PyCursesStatefulInitialised(module); \
3055-
return PyBool_FromLong(X()); }
3067+
#define NoArgTrueFalseFunctionBody(X) \
3068+
{ \
3069+
PyCursesStatefulInitialised(module); \
3070+
return PyBool_FromLong(X()); \
3071+
}
30563072

3057-
#define NoArgNoReturnVoidFunctionBody(X) \
3058-
{ \
3059-
PyCursesStatefulInitialised(module); \
3060-
X(); \
3061-
Py_RETURN_NONE; }
3073+
#define NoArgNoReturnVoidFunctionBody(X) \
3074+
{ \
3075+
PyCursesStatefulInitialised(module); \
3076+
X(); \
3077+
Py_RETURN_NONE; \
3078+
}
30623079

30633080
/*********************************************************************
30643081
Global Functions

0 commit comments

Comments
 (0)