#define _CURSES_PAIR_CONTENT_FUNC pair_content
#endif /* _NCURSES_EXTENDED_COLOR_FUNCS */
+typedef struct _cursesmodule_state {
+ PyObject *error; // PyCursesError
+ PyTypeObject *window_type; // PyCursesWindow_Type
+} _cursesmodule_state;
+
+// For now, we keep a global state variable to prepare for PEP 489.
+static _cursesmodule_state curses_global_state;
+
+static inline _cursesmodule_state *
+get_cursesmodule_state(PyObject *Py_UNUSED(module))
+{
+ return &curses_global_state;
+}
+
+static inline _cursesmodule_state *
+get_cursesmodule_state_by_win(PyCursesWindowObject *Py_UNUSED(win))
+{
+ return &curses_global_state;
+}
+
/*[clinic input]
module _curses
class _curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=43265c372c2887d6]*/
-/* Definition of exception curses.error */
-
-static PyObject *PyCursesError;
-
/* Tells whether setupterm() has been called to initialise terminfo. */
static int curses_setupterm_called = FALSE;
static const char *curses_screen_encoding = NULL;
-/* Utility Macros */
-#define PyCursesSetupTermCalled \
+/* Utility Checking Procedures */
+
+/*
+ * Function to check that 'funcname' has been called by testing
+ * the 'called' boolean. If an error occurs, a PyCursesError is
+ * set and this returns 0. Otherwise, this returns 1.
+ *
+ * Since this function can be called in functions that do not
+ * have a direct access to the module's state, the exception
+ * type is directly taken from the global state for now.
+ */
+static inline int
+_PyCursesCheckFunction(int called, const char *funcname)
+{
+ if (called == TRUE) {
+ return 1;
+ }
+ PyErr_Format(curses_global_state.error, "must call %s() first", funcname);
+ return 0;
+}
+
+/*
+ * Function to check that 'funcname' has been called by testing
+ * the 'called'' boolean. If an error occurs, a PyCursesError is
+ * set and this returns 0. Otherwise this returns 1.
+ *
+ * The exception type is obtained from the 'module' state.
+ */
+static inline int
+_PyCursesStatefulCheckFunction(PyObject *module, int called, const char *funcname)
+{
+ if (called == TRUE) {
+ return 1;
+ }
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_Format(state->error, "must call %s() first", funcname);
+ return 0;
+}
+
+#define PyCursesStatefulSetupTermCalled(MODULE) \
do { \
- if (curses_setupterm_called != TRUE) { \
- PyErr_SetString(PyCursesError, \
- "must call (at least) setupterm() first"); \
+ if (!_PyCursesStatefulCheckFunction(MODULE, \
+ curses_setupterm_called, \
+ "setupterm")) \
+ { \
return 0; \
} \
} while (0)
-#define PyCursesInitialised \
- do { \
- if (curses_initscr_called != TRUE) { \
- PyErr_SetString(PyCursesError, \
- "must call initscr() first"); \
- return 0; \
- } \
+#define PyCursesStatefulInitialised(MODULE) \
+ do { \
+ if (!_PyCursesStatefulCheckFunction(MODULE, \
+ curses_initscr_called, \
+ "initscr")) \
+ { \
+ return 0; \
+ } \
} while (0)
-#define PyCursesInitialisedColor \
- do { \
- if (curses_start_color_called != TRUE) { \
- PyErr_SetString(PyCursesError, \
- "must call start_color() first"); \
- return 0; \
- } \
+#define PyCursesStatefulInitialisedColor(MODULE) \
+ do { \
+ if (!_PyCursesStatefulCheckFunction(MODULE, \
+ curses_start_color_called, \
+ "start_color")) \
+ { \
+ return 0; \
+ } \
} while (0)
/* Utility Functions */
+static inline void
+_PyCursesSetError(_cursesmodule_state *state, const char *funcname)
+{
+ if (funcname == NULL) {
+ PyErr_SetString(state->error, catchall_ERR);
+ }
+ else {
+ PyErr_Format(state->error, "%s() returned ERR", funcname);
+ }
+}
+
/*
* Check the return code from a curses function and return None
- * or raise an exception as appropriate. These are exported using the
- * capsule API.
+ * or raise an exception as appropriate.
*/
static PyObject *
-PyCursesCheckERR(int code, const char *fname)
+PyCursesCheckERR(PyObject *module, int code, const char *fname)
{
if (code != ERR) {
Py_RETURN_NONE;
} else {
- if (fname == NULL) {
- PyErr_SetString(PyCursesError, catchall_ERR);
- } else {
- PyErr_Format(PyCursesError, "%s() returned ERR", fname);
- }
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ _PyCursesSetError(state, fname);
+ return NULL;
+ }
+}
+
+static PyObject *
+PyCursesCheckERR_ForWin(PyCursesWindowObject *win, int code, const char *fname)
+{
+ if (code != ERR) {
+ Py_RETURN_NONE;
+ } else {
+ _cursesmodule_state *state = get_cursesmodule_state_by_win(win);
+ _PyCursesSetError(state, fname);
return NULL;
}
}
static int func_PyCursesSetupTermCalled(void)
{
- PyCursesSetupTermCalled;
- return 1;
+ return _PyCursesCheckFunction(curses_setupterm_called, "setupterm");
}
static int func_PyCursesInitialised(void)
{
- PyCursesInitialised;
- return 1;
+ return _PyCursesCheckFunction(curses_initscr_called, "initscr");
}
static int func_PyCursesInitialisedColor(void)
{
- PyCursesInitialisedColor;
- return 1;
+ return _PyCursesCheckFunction(curses_start_color_called, "start_color");
}
/*****************************************************************************
#define Window_NoArgNoReturnFunction(X) \
static PyObject *PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \
- { return PyCursesCheckERR(X(self->win), # X); }
+ { return PyCursesCheckERR_ForWin(self, X(self->win), # X); }
#define Window_NoArgTrueFalseFunction(X) \
static PyObject * PyCursesWindow_ ## X \
{ \
TYPE arg1; \
if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
- return PyCursesCheckERR(X(self->win, arg1), # X); }
+ return PyCursesCheckERR_ForWin(self, X(self->win, arg1), # X); }
#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X \
{ \
TYPE arg1, arg2; \
if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
- return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
+ return PyCursesCheckERR_ForWin(self, X(self->win, arg1, arg2), # X); }
/* ------------- WINDOW routines --------------- */
else {
return NULL;
}
- return PyCursesCheckERR(rtn, funcname);
+ return PyCursesCheckERR_ForWin(self, rtn, funcname);
}
/*[clinic input]
}
if (use_attr)
(void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, funcname);
+ return PyCursesCheckERR_ForWin(self, rtn, funcname);
}
/*[clinic input]
}
if (use_attr)
(void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, funcname);
+ return PyCursesCheckERR_ForWin(self, rtn, funcname);
}
/*[clinic input]
if (!PyCurses_ConvertToChtype(self, ch, &bkgd))
return NULL;
- return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
+ return PyCursesCheckERR_ForWin(self, wbkgd(self->win, bkgd | attr), "bkgd");
}
/*[clinic input]
_curses_window_attroff_impl(PyCursesWindowObject *self, long attr)
/*[clinic end generated code: output=8a2fcd4df682fc64 input=786beedf06a7befe]*/
{
- return PyCursesCheckERR(wattroff(self->win, (attr_t)attr), "attroff");
+ return PyCursesCheckERR_ForWin(self, wattroff(self->win, (attr_t)attr), "attroff");
}
/*[clinic input]
_curses_window_attron_impl(PyCursesWindowObject *self, long attr)
/*[clinic end generated code: output=7afea43b237fa870 input=5a88fba7b1524f32]*/
{
- return PyCursesCheckERR(wattron(self->win, (attr_t)attr), "attron");
+ return PyCursesCheckERR_ForWin(self, wattron(self->win, (attr_t)attr), "attron");
}
/*[clinic input]
_curses_window_attrset_impl(PyCursesWindowObject *self, long attr)
/*[clinic end generated code: output=84e379bff20c0433 input=42e400c0d0154ab5]*/
{
- return PyCursesCheckERR(wattrset(self->win, (attr_t)attr), "attrset");
+ return PyCursesCheckERR_ForWin(self, wattrset(self->win, (attr_t)attr), "attrset");
}
/*[clinic input]
return NULL;
wbkgdset(self->win, bkgd | attr);
- return PyCursesCheckERR(0, "bkgdset");
+ return PyCursesCheckERR_ForWin(self, 0, "bkgdset");
}
/*[clinic input]
rtn = wchgat(self->win,num,attr,color,NULL);
touchline(self->win,y,1);
}
- return PyCursesCheckERR(rtn, "chgat");
+ return PyCursesCheckERR_ForWin(self, rtn, "chgat");
}
#endif
/*[clinic end generated code: output=22e77bb9fa11b461 input=d2f79e630a4fc6d0]*/
{
if (!group_right_1) {
- return PyCursesCheckERR(wdelch(self->win), "wdelch");
+ return PyCursesCheckERR_ForWin(self, wdelch(self->win), "wdelch");
}
else {
- return PyCursesCheckERR(py_mvwdelch(self->win, y, x), "mvwdelch");
+ return PyCursesCheckERR_ForWin(self, py_mvwdelch(self->win, y, x), "mvwdelch");
}
}
win = derwin(self->win,nlines,ncols,begin_y,begin_x);
if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
+ _cursesmodule_state *state = get_cursesmodule_state_by_win(self);
+ PyErr_SetString(state->error, catchall_NULL);
return NULL;
}
#ifdef py_is_pad
if (py_is_pad(self->win)) {
- return PyCursesCheckERR(pechochar(self->win, ch_ | (attr_t)attr),
- "echochar");
+ return PyCursesCheckERR_ForWin(self,
+ pechochar(self->win, ch_ | (attr_t)attr),
+ "echochar");
}
else
#endif
- return PyCursesCheckERR(wechochar(self->win, ch_ | (attr_t)attr),
- "echochar");
+ return PyCursesCheckERR_ForWin(self,
+ wechochar(self->win, ch_ | (attr_t)attr),
+ "echochar");
}
#ifdef NCURSES_MOUSE_VERSION
if (rtn == ERR) {
/* getch() returns ERR in nodelay mode */
PyErr_CheckSignals();
- if (!PyErr_Occurred())
- PyErr_SetString(PyCursesError, "no input");
+ if (!PyErr_Occurred()) {
+ _cursesmodule_state *state = get_cursesmodule_state_by_win(self);
+ PyErr_SetString(state->error, "no input");
+ }
return NULL;
} else if (rtn <= 255) {
#ifdef NCURSES_VERSION_MAJOR
return NULL;
/* get_wch() returns ERR in nodelay mode */
- PyErr_SetString(PyCursesError, "no input");
+ _cursesmodule_state *state = get_cursesmodule_state_by_win(self);
+ PyErr_SetString(state->error, "no input");
return NULL;
}
if (ct == KEY_CODE_YES)
return NULL;
if (group_left_1) {
if (wmove(self->win, y, x) == ERR) {
- return PyCursesCheckERR(ERR, "wmove");
+ return PyCursesCheckERR_ForWin(self, ERR, "wmove");
}
}
- return PyCursesCheckERR(whline(self->win, ch_ | (attr_t)attr, n), "hline");
+ return PyCursesCheckERR_ForWin(self, whline(self->win, ch_ | (attr_t)attr, n), "hline");
}
/*[clinic input]
rtn = mvwinsch(self->win, y, x, ch_ | (attr_t)attr);
}
- return PyCursesCheckERR(rtn, "insch");
+ return PyCursesCheckERR_ForWin(self, rtn, "insch");
}
/*[clinic input]
}
if (use_attr)
(void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, funcname);
+ return PyCursesCheckERR_ForWin(self, rtn, funcname);
}
/*[clinic input]
}
if (use_attr)
(void)wattrset(self->win,attr_old);
- return PyCursesCheckERR(rtn, funcname);
+ return PyCursesCheckERR_ForWin(self, rtn, funcname);
}
/*[clinic input]
#ifdef py_is_pad
if (py_is_pad(self->win)) {
if (!group_right_1) {
- PyErr_SetString(PyCursesError,
+ _cursesmodule_state *state = get_cursesmodule_state_by_win(self);
+ PyErr_SetString(state->error,
"noutrefresh() called for a pad "
"requires 6 arguments");
return NULL;
rtn = pnoutrefresh(self->win, pminrow, pmincol,
sminrow, smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "pnoutrefresh");
+ return PyCursesCheckERR_ForWin(self, rtn, "pnoutrefresh");
}
if (group_right_1) {
PyErr_SetString(PyExc_TypeError,
Py_BEGIN_ALLOW_THREADS
rtn = wnoutrefresh(self->win);
Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "wnoutrefresh");
+ return PyCursesCheckERR_ForWin(self, rtn, "wnoutrefresh");
}
/*[clinic input]
if (group_right_1) {
rtn = copywin(self->win, destwin->win, sminrow, smincol,
dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
- return PyCursesCheckERR(rtn, "copywin");
+ return PyCursesCheckERR_ForWin(self, rtn, "copywin");
}
else {
rtn = overlay(self->win, destwin->win);
- return PyCursesCheckERR(rtn, "overlay");
+ return PyCursesCheckERR_ForWin(self, rtn, "overlay");
}
}
if (group_right_1) {
rtn = copywin(self->win, destwin->win, sminrow, smincol,
dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
- return PyCursesCheckERR(rtn, "copywin");
+ return PyCursesCheckERR_ForWin(self, rtn, "copywin");
}
else {
rtn = overwrite(self->win, destwin->win);
- return PyCursesCheckERR(rtn, "overwrite");
+ return PyCursesCheckERR_ForWin(self, rtn, "overwrite");
}
}
return PyErr_SetFromErrno(PyExc_OSError);
if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
goto exit;
- res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
+ res = PyCursesCheckERR_ForWin(self, putwin(self->win, fp), "putwin");
if (res == NULL)
goto exit;
fseek(fp, 0, 0);
_curses_window_redrawln_impl(PyCursesWindowObject *self, int beg, int num)
/*[clinic end generated code: output=ea216e334f9ce1b4 input=152155e258a77a7a]*/
{
- return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
+ return PyCursesCheckERR_ForWin(self, wredrawln(self->win,beg,num), "redrawln");
}
/*[clinic input]
#ifdef py_is_pad
if (py_is_pad(self->win)) {
if (!group_right_1) {
- PyErr_SetString(PyCursesError,
+ _cursesmodule_state *state = get_cursesmodule_state_by_win(self);
+ PyErr_SetString(state->error,
"refresh() for a pad requires 6 arguments");
return NULL;
}
rtn = prefresh(self->win, pminrow, pmincol,
sminrow, smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "prefresh");
+ return PyCursesCheckERR_ForWin(self, rtn, "prefresh");
}
#endif
if (group_right_1) {
Py_BEGIN_ALLOW_THREADS
rtn = wrefresh(self->win);
Py_END_ALLOW_THREADS
- return PyCursesCheckERR(rtn, "prefresh");
+ return PyCursesCheckERR_ForWin(self, rtn, "prefresh");
}
/*[clinic input]
int bottom)
/*[clinic end generated code: output=486ab5db218d2b1a input=1b517b986838bf0e]*/
{
- return PyCursesCheckERR(wsetscrreg(self->win, top, bottom), "wsetscrreg");
+ return PyCursesCheckERR_ForWin(self, wsetscrreg(self->win, top, bottom), "wsetscrreg");
}
/*[clinic input]
win = subwin(self->win, nlines, ncols, begin_y, begin_x);
if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
+ _cursesmodule_state *state = get_cursesmodule_state_by_win(self);
+ PyErr_SetString(state->error, catchall_NULL);
return NULL;
}
/*[clinic end generated code: output=4541a8a11852d360 input=c969ca0cfabbdbec]*/
{
if (!group_right_1) {
- return PyCursesCheckERR(scroll(self->win), "scroll");
+ return PyCursesCheckERR_ForWin(self, scroll(self->win), "scroll");
}
else {
- return PyCursesCheckERR(wscrl(self->win, lines), "scroll");
+ return PyCursesCheckERR_ForWin(self, wscrl(self->win, lines), "scroll");
}
}
/*[clinic end generated code: output=65d05b3f7438c61d input=a98aa4f79b6be845]*/
{
if (!group_right_1) {
- return PyCursesCheckERR(touchline(self->win, start, count), "touchline");
+ return PyCursesCheckERR_ForWin(self, touchline(self->win, start, count), "touchline");
}
else {
- return PyCursesCheckERR(wtouchln(self->win, start, count, changed), "touchline");
+ return PyCursesCheckERR_ForWin(self, wtouchln(self->win, start, count, changed), "touchline");
}
}
return NULL;
if (group_left_1) {
if (wmove(self->win, y, x) == ERR)
- return PyCursesCheckERR(ERR, "wmove");
+ return PyCursesCheckERR_ForWin(self, ERR, "wmove");
}
- return PyCursesCheckERR(wvline(self->win, ch_ | (attr_t)attr, n), "vline");
+ return PyCursesCheckERR_ForWin(self, wvline(self->win, ch_ | (attr_t)attr, n), "vline");
}
static PyObject *
PyCursesWindow_getsets, /* tp_getset */
};
-/* Function Prototype Macros - They are ugly but very, very useful. ;-)
+/* Function Body Macros - They are ugly but very, very useful. ;-)
X - function name
TYPE - parameter Type
#define NoArgNoReturnFunctionBody(X) \
{ \
- PyCursesInitialised; \
- return PyCursesCheckERR(X(), # X); }
+ PyCursesStatefulInitialised(module); \
+ return PyCursesCheckERR(module, X(), # X); }
#define NoArgOrFlagNoReturnFunctionBody(X, flag) \
{ \
- PyCursesInitialised; \
+ PyCursesStatefulInitialised(module); \
if (flag) \
- return PyCursesCheckERR(X(), # X); \
+ return PyCursesCheckERR(module, X(), # X); \
else \
- return PyCursesCheckERR(no ## X(), # X); \
+ return PyCursesCheckERR(module, no ## X(), # X); \
}
#define NoArgReturnIntFunctionBody(X) \
{ \
- PyCursesInitialised; \
+ PyCursesStatefulInitialised(module); \
return PyLong_FromLong((long) X()); }
#define NoArgReturnStringFunctionBody(X) \
{ \
- PyCursesInitialised; \
+ PyCursesStatefulInitialised(module); \
return PyBytes_FromString(X()); }
#define NoArgTrueFalseFunctionBody(X) \
{ \
- PyCursesInitialised; \
+ PyCursesStatefulInitialised(module); \
return PyBool_FromLong(X()); }
#define NoArgNoReturnVoidFunctionBody(X) \
{ \
- PyCursesInitialised; \
+ PyCursesStatefulInitialised(module); \
X(); \
Py_RETURN_NONE; }
{
_CURSES_COLOR_VAL_TYPE r,g,b;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesStatefulInitialised(module);
+ PyCursesStatefulInitialisedColor(module);
if (_COLOR_CONTENT_FUNC(color_number, &r, &g, &b) == ERR) {
- PyErr_Format(PyCursesError, "%s() returned ERR",
- Py_STRINGIFY(_COLOR_CONTENT_FUNC));
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_Format(state->error, "%s() returned ERR",
+ Py_STRINGIFY(_COLOR_CONTENT_FUNC));
return NULL;
}
_curses_color_pair_impl(PyObject *module, int pair_number)
/*[clinic end generated code: output=60718abb10ce9feb input=6034e9146f343802]*/
{
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesStatefulInitialised(module);
+ PyCursesStatefulInitialisedColor(module);
return PyLong_FromLong(COLOR_PAIR(pair_number));
}
{
int erg;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
erg = curs_set(visibility);
- if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
+ if (erg == ERR) return PyCursesCheckERR(module, erg, "curs_set");
return PyLong_FromLong((long) erg);
}
_curses_delay_output_impl(PyObject *module, int ms)
/*[clinic end generated code: output=b6613a67f17fa4f4 input=5316457f5f59196c]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- return PyCursesCheckERR(delay_output(ms), "delay_output");
+ return PyCursesCheckERR(module, delay_output(ms), "delay_output");
}
/*[clinic input]
{
char ch;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
ch = erasechar();
int x = 0;
int y = 0;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
getsyx(y, x);
int rtn;
MEVENT event;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
rtn = getmouse( &event );
if (rtn == ERR) {
- PyErr_SetString(PyCursesError, "getmouse() returned ERR");
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, "getmouse() returned ERR");
return NULL;
}
return Py_BuildValue("(hiiik)",
{
MEVENT event;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
event.id = id;
event.x = x;
event.y = y;
event.z = z;
event.bstate = bstate;
- return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
+ return PyCursesCheckERR(module, ungetmouse(&event), "ungetmouse");
}
#endif
WINDOW *win;
PyObject *res = NULL;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
fp = tmpfile();
if (fp == NULL)
fseek(fp, 0, 0);
win = getwin(fp);
if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, catchall_NULL);
goto error;
}
res = PyCursesWindow_New(win, NULL);
_curses_halfdelay_impl(PyObject *module, unsigned char tenths)
/*[clinic end generated code: output=e92cdf0ef33c0663 input=e42dce7259c15100]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
+ return PyCursesCheckERR(module, halfdelay(tenths), "halfdelay");
}
/*[clinic input]
_curses_has_key_impl(PyObject *module, int key)
/*[clinic end generated code: output=19ad48319414d0b1 input=78bd44acf1a4997c]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
return PyBool_FromLong(has_key(key));
}
short b)
/*[clinic end generated code: output=d7ed71b2d818cdf2 input=ae2b8bea0f152c80]*/
{
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesStatefulInitialised(module);
+ PyCursesStatefulInitialisedColor(module);
- return PyCursesCheckERR(_CURSES_INIT_COLOR_FUNC(color_number, r, g, b),
+ return PyCursesCheckERR(module,
+ _CURSES_INIT_COLOR_FUNC(color_number, r, g, b),
Py_STRINGIFY(_CURSES_INIT_COLOR_FUNC));
}
_curses_init_pair_impl(PyObject *module, int pair_number, int fg, int bg)
/*[clinic end generated code: output=a0bba03d2bbc3ee6 input=54b421b44c12c389]*/
{
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesStatefulInitialised(module);
+ PyCursesStatefulInitialisedColor(module);
if (_CURSES_INIT_PAIR_FUNC(pair_number, fg, bg) == ERR) {
if (pair_number >= COLOR_PAIRS) {
COLOR_PAIRS - 1);
}
else {
- PyErr_Format(PyCursesError, "%s() returned ERR",
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_Format(state->error, "%s() returned ERR",
Py_STRINGIFY(_CURSES_INIT_PAIR_FUNC));
}
return NULL;
win = initscr();
if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, catchall_NULL);
return NULL;
}
sys_stdout = PySys_GetObject("stdout");
if (sys_stdout == NULL || sys_stdout == Py_None) {
- PyErr_SetString(
- PyCursesError,
- "lost sys.stdout");
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, "lost sys.stdout");
return NULL;
}
s = "setupterm: could not find terminfo database";
}
- PyErr_SetString(PyCursesError,s);
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, s);
return NULL;
}
return NULL;
}
- return PyCursesCheckERR(set_escdelay(ms), "set_escdelay");
+ return PyCursesCheckERR(module, set_escdelay(ms), "set_escdelay");
}
/*[clinic input]
return NULL;
}
- return PyCursesCheckERR(set_tabsize(size), "set_tabsize");
+ return PyCursesCheckERR(module, set_tabsize(size), "set_tabsize");
}
#endif
_curses_intrflush_impl(PyObject *module, int flag)
/*[clinic end generated code: output=c1986df35e999a0f input=c65fe2ef973fe40a]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- return PyCursesCheckERR(intrflush(NULL, flag), "intrflush");
+ return PyCursesCheckERR(module, intrflush(NULL, flag), "intrflush");
}
/*[clinic input]
_curses_is_term_resized_impl(PyObject *module, int nlines, int ncols)
/*[clinic end generated code: output=aafe04afe50f1288 input=ca9c0bd0fb8ab444]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
return PyBool_FromLong(is_term_resized(nlines, ncols));
}
{
const char *knp;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
if (key < 0) {
PyErr_SetString(PyExc_ValueError, "invalid key number");
_curses_meta_impl(PyObject *module, int yes)
/*[clinic end generated code: output=22f5abda46a605d8 input=cfe7da79f51d0e30]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- return PyCursesCheckERR(meta(stdscr, yes), "meta");
+ return PyCursesCheckERR(module, meta(stdscr, yes), "meta");
}
#ifdef NCURSES_MOUSE_VERSION
_curses_mouseinterval_impl(PyObject *module, int interval)
/*[clinic end generated code: output=c4f5ff04354634c5 input=75aaa3f0db10ac4e]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
+ return PyCursesCheckERR(module, mouseinterval(interval), "mouseinterval");
}
/*[clinic input]
{
mmask_t oldmask, availmask;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
availmask = mousemask((mmask_t)newmask, &oldmask);
return Py_BuildValue("(kk)",
(unsigned long)availmask, (unsigned long)oldmask);
_curses_napms_impl(PyObject *module, int ms)
/*[clinic end generated code: output=5f292a6a724491bd input=c6d6e01f2f1df9f7]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
return napms(ms);
}
{
WINDOW *win;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
win = newpad(nlines, ncols);
if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, catchall_NULL);
return NULL;
}
{
WINDOW *win;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
win = newwin(nlines,ncols,begin_y,begin_x);
if (win == NULL) {
- PyErr_SetString(PyCursesError, catchall_NULL);
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, catchall_NULL);
return NULL;
}
{
_CURSES_COLOR_NUM_TYPE f, b;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesStatefulInitialised(module);
+ PyCursesStatefulInitialisedColor(module);
if (_CURSES_PAIR_CONTENT_FUNC(pair_number, &f, &b) == ERR) {
if (pair_number >= COLOR_PAIRS) {
COLOR_PAIRS - 1);
}
else {
- PyErr_Format(PyCursesError, "%s() returned ERR",
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_Format(state->error, "%s() returned ERR",
Py_STRINGIFY(_CURSES_PAIR_CONTENT_FUNC));
}
return NULL;
_curses_pair_number_impl(PyObject *module, int attr)
/*[clinic end generated code: output=85bce7d65c0aa3f4 input=d478548e33f5e61a]*/
{
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesStatefulInitialised(module);
+ PyCursesStatefulInitialisedColor(module);
return PyLong_FromLong(PAIR_NUMBER(attr));
}
_curses_putp_impl(PyObject *module, const char *string)
/*[clinic end generated code: output=e98081d1b8eb5816 input=1601faa828b44cb3]*/
{
- return PyCursesCheckERR(putp(string), "putp");
+ return PyCursesCheckERR(module, putp(string), "putp");
}
/*[clinic input]
_curses_qiflush_impl(PyObject *module, int flag)
/*[clinic end generated code: output=9167e862f760ea30 input=6ec8b3e2b717ec40]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
if (flag) {
qiflush();
{
PyObject *result;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");
+ result = PyCursesCheckERR(module, resizeterm(nlines, ncols), "resizeterm");
if (!result)
return NULL;
if (!update_lines_cols(module)) {
{
PyObject *result;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- result = PyCursesCheckERR(resize_term(nlines, ncols), "resize_term");
+ result = PyCursesCheckERR(module, resize_term(nlines, ncols), "resize_term");
if (!result)
return NULL;
if (!update_lines_cols(module)) {
_curses_setsyx_impl(PyObject *module, int y, int x)
/*[clinic end generated code: output=23dcf753511a2464 input=fa7f2b208e10a557]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
setsyx(y,x);
_curses_start_color_impl(PyObject *module)
/*[clinic end generated code: output=8b772b41d8090ede input=0ca0ecb2b77e1a12]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
if (start_color() == ERR) {
- PyErr_SetString(PyCursesError, "start_color() returned ERR");
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, "start_color() returned ERR");
return NULL;
}
_curses_tigetflag_impl(PyObject *module, const char *capname)
/*[clinic end generated code: output=8853c0e55542195b input=b0787af9e3e9a6ce]*/
{
- PyCursesSetupTermCalled;
+ PyCursesStatefulSetupTermCalled(module);
return PyLong_FromLong( (long) tigetflag( (char *)capname ) );
}
_curses_tigetnum_impl(PyObject *module, const char *capname)
/*[clinic end generated code: output=46f8b0a1b5dff42f input=5cdf2f410b109720]*/
{
- PyCursesSetupTermCalled;
+ PyCursesStatefulSetupTermCalled(module);
return PyLong_FromLong( (long) tigetnum( (char *)capname ) );
}
_curses_tigetstr_impl(PyObject *module, const char *capname)
/*[clinic end generated code: output=f22b576ad60248f3 input=36644df25c73c0a7]*/
{
- PyCursesSetupTermCalled;
+ PyCursesStatefulSetupTermCalled(module);
capname = tigetstr( (char *)capname );
if (capname == NULL || capname == (char*) -1) {
{
char* result = NULL;
- PyCursesSetupTermCalled;
+ PyCursesStatefulSetupTermCalled(module);
result = tparm((char *)str,i1,i2,i3,i4,i5,i6,i7,i8,i9);
if (!result) {
- PyErr_SetString(PyCursesError, "tparm() returned NULL");
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, "tparm() returned NULL");
return NULL;
}
_curses_typeahead_impl(PyObject *module, int fd)
/*[clinic end generated code: output=084bb649d7066583 input=f2968d8e1805051b]*/
{
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
- return PyCursesCheckERR(typeahead( fd ), "typeahead");
+ return PyCursesCheckERR(module, typeahead( fd ), "typeahead");
}
#endif
{
chtype ch_;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))
return NULL;
{
chtype ch_;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))
return NULL;
- return PyCursesCheckERR(ungetch(ch_), "ungetch");
+ return PyCursesCheckERR(module, ungetch(ch_), "ungetch");
}
#ifdef HAVE_NCURSESW
{
wchar_t wch;
- PyCursesInitialised;
+ PyCursesStatefulInitialised(module);
if (!PyCurses_ConvertToWchar_t(ch, &wch))
return NULL;
- return PyCursesCheckERR(unget_wch(wch), "unget_wch");
+ return PyCursesCheckERR(module, unget_wch(wch), "unget_wch");
}
#endif
{
int code;
- PyCursesInitialised;
- PyCursesInitialisedColor;
+ PyCursesStatefulInitialised(module);
+ PyCursesStatefulInitialisedColor(module);
code = use_default_colors();
if (code != ERR) {
Py_RETURN_NONE;
} else {
- PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
+ _cursesmodule_state *state = get_cursesmodule_state(module);
+ PyErr_SetString(state->error, "use_default_colors() returned ERR");
return NULL;
}
}
static int
cursesmodule_exec(PyObject *module)
{
+ _cursesmodule_state *state = get_cursesmodule_state(module);
/* Initialize object type */
if (PyType_Ready(&PyCursesWindow_Type) < 0) {
return -1;
if (PyModule_AddType(module, &PyCursesWindow_Type) < 0) {
return -1;
}
+ state->window_type = &PyCursesWindow_Type;
/* Add some symbolic constants to the module */
PyObject *module_dict = PyModule_GetDict(module);
}
/* For exception curses.error */
- PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
- if (PyCursesError == NULL) {
+ state->error = PyErr_NewException("_curses.error", NULL, NULL);
+ if (state->error == NULL) {
return -1;
}
- rc = PyDict_SetItemString(module_dict, "error", PyCursesError);
- Py_DECREF(PyCursesError);
+ rc = PyDict_SetItemString(module_dict, "error", state->error);
+ Py_DECREF(state->error);
if (rc < 0) {
return -1;
}