[Python-checkins] CVS: python/dist/src/Modules _cursesmodule.c,2.44,2.45

A.M. Kuchling python-dev@python.org
Fri, 22 Dec 2000 13:52:30 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv19738

Modified Files:
	_cursesmodule.c 
Log Message:
Export C API from this module.
Remove several macros and #includes; py_curses.h contains them now.


Index: _cursesmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_cursesmodule.c,v
retrieving revision 2.44
retrieving revision 2.45
diff -C2 -r2.44 -r2.45
*** _cursesmodule.c	2000/12/21 16:22:22	2.44
--- _cursesmodule.c	2000/12/22 21:52:27	2.45
***************
*** 96,104 ****
  /* Release Number */
  
! char *PyCursesVersion = "1.6";
  
  /* Includes */
  
  #include "Python.h"
  
  #ifdef __osf__
--- 96,106 ----
  /* Release Number */
  
! char *PyCursesVersion = "2.1";
  
  /* Includes */
  
  #include "Python.h"
+ #define CURSES_MODULE
+ #include "py_curses.h"
  
  #ifdef __osf__
***************
*** 107,116 ****
  #endif
  
- #ifdef HAVE_NCURSES_H
- #include <ncurses.h>
- #else
- #include <curses.h>
- #endif
- 
  /*  These prototypes are in <term.h>, but including this header 
      #defines many common symbols (such as "lines") which breaks the 
--- 109,112 ----
***************
*** 131,138 ****
  static PyObject *PyCursesError;
  
- /* general error messages */
- static char *catchall_ERR  = "curses function returned ERR";
- static char *catchall_NULL = "curses function returned NULL";
- 
  /* Tells whether setupterm() has been called to initialise terminfo.  */
  static int initialised_setupterm = FALSE;
--- 127,130 ----
***************
*** 141,156 ****
  static int initialised = FALSE;
  
! /* Tells whether start_color() has been called to initialise colorusage. */
  static int initialisedcolors = FALSE;
  
  /* Utility Macros */
- #define ARG_COUNT(X) \
- 	(((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
- 
  #define PyCursesSetupTermCalled \
    if (initialised_setupterm != TRUE) { \
                    PyErr_SetString(PyCursesError, \
                                    "must call (at least) setupterm() first"); \
!                   return NULL; }
  
  #define PyCursesInitialised \
--- 133,145 ----
  static int initialised = FALSE;
  
! /* Tells whether start_color() has been called to initialise color usage. */
  static int initialisedcolors = FALSE;
  
  /* Utility Macros */
  #define PyCursesSetupTermCalled \
    if (initialised_setupterm != TRUE) { \
                    PyErr_SetString(PyCursesError, \
                                    "must call (at least) setupterm() first"); \
!                   return 0; }
  
  #define PyCursesInitialised \
***************
*** 158,162 ****
                    PyErr_SetString(PyCursesError, \
                                    "must call initscr() first"); \
!                   return NULL; }
  
  #define PyCursesInitialisedColor \
--- 147,151 ----
                    PyErr_SetString(PyCursesError, \
                                    "must call initscr() first"); \
!                   return 0; }
  
  #define PyCursesInitialisedColor \
***************
*** 164,168 ****
                    PyErr_SetString(PyCursesError, \
                                    "must call start_color() first"); \
!                   return NULL; }
  
  /* Utility Functions */
--- 153,157 ----
                    PyErr_SetString(PyCursesError, \
                                    "must call start_color() first"); \
!                   return 0; }
  
  /* Utility Functions */
***************
*** 170,174 ****
  /*
   * Check the return code from a curses function and return None 
!  * or raise an exception as appropriate.
   */
  
--- 159,164 ----
  /*
   * Check the return code from a curses function and return None 
!  * or raise an exception as appropriate.  These are exported using the
!  * CObject API. 
   */
  
***************
*** 203,223 ****
  }
  
  /*****************************************************************************
   The Window Object
  ******************************************************************************/
- 
- /* Definition of the window object and window type */
  
! typedef struct {
! 	PyObject_HEAD
! 	WINDOW *win;
! } PyCursesWindowObject;
  
  PyTypeObject PyCursesWindow_Type;
  
! #define PyCursesWindow_Check(v)	 ((v)->ob_type == &PyCursesWindow_Type)
  
- /* Function Prototype Macros - They are ugly but very, very useful. ;-)
- 
     X - function name
     TYPE - parameter Type
--- 193,227 ----
  }
  
+ /* Function versions of the 3 functions for tested whether curses has been
+    initialised or not. */
+    
+ static int func_PyCursesSetupTermCalled(void)
+ {
+     PyCursesSetupTermCalled;
+     return 1;
+ }
+ 
+ static int func_PyCursesInitialised(void)
+ {
+     PyCursesInitialised;
+     return 1;
+ }
+ 
+ static int func_PyCursesInitialisedColor(void)
+ {
+     PyCursesInitialisedColor;
+     return 1;
+ }
+ 
  /*****************************************************************************
   The Window Object
  ******************************************************************************/
  
! /* Definition of the window type */
  
  PyTypeObject PyCursesWindow_Type;
  
! /* Function prototype macros for Window object
  
     X - function name
     TYPE - parameter Type
***************
*** 1459,1531 ****
  **********************************************************************/
  
- static PyObject *ModDict;
- 
- /* Function Prototype Macros - They are ugly but very, very useful. ;-)
- 
-    X - function name
-    TYPE - parameter Type
-    ERGSTR - format string for construction of the return value
-    PARSESTR - format string for argument parsing
-    */
- 
- #define NoArgNoReturnFunction(X) \
- static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
- { \
-   PyCursesInitialised \
-   if (!PyArg_NoArgs(args)) return NULL; \
-   return PyCursesCheckERR(X(), # X); }
- 
- #define NoArgOrFlagNoReturnFunction(X) \
- static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
- { \
-   int flag = 0; \
-   PyCursesInitialised \
-   switch(ARG_COUNT(args)) { \
-   case 0: \
-     return PyCursesCheckERR(X(), # X); \
-   case 1: \
-     if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL; \
-     if (flag) return PyCursesCheckERR(X(), # X); \
-     else return PyCursesCheckERR(no ## X (), # X); \
-   default: \
-     PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
-     return NULL; } }
- 
- #define NoArgReturnIntFunction(X) \
- static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
- { \
-  PyCursesInitialised \
-  if (!PyArg_NoArgs(args)) return NULL; \
-  return PyInt_FromLong((long) X()); }
- 
- 
- #define NoArgReturnStringFunction(X) \
- static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
- { \
-   PyCursesInitialised \
-   if (!PyArg_NoArgs(args)) return NULL; \
-   return PyString_FromString(X()); }
- 
- #define NoArgTrueFalseFunction(X) \
- static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
- { \
-   PyCursesInitialised \
-   if (!PyArg_NoArgs(args)) return NULL; \
-   if (X () == FALSE) { \
-     Py_INCREF(Py_False); \
-     return Py_False; \
-   } \
-   Py_INCREF(Py_True); \
-   return Py_True; }
- 
- #define NoArgNoReturnVoidFunction(X) \
- static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
- { \
-   PyCursesInitialised \
-   if (!PyArg_NoArgs(args)) return NULL; \
-   X(); \
-   Py_INCREF(Py_None); \
-   return Py_None; }
- 
  NoArgNoReturnFunction(beep)
  NoArgNoReturnFunction(def_prog_mode)
--- 1463,1466 ----
***************
*** 1806,1809 ****
--- 1741,1746 ----
  }
  
+ static PyObject *ModDict;
+ 
  static PyObject * 
  PyCurses_InitScr(PyObject *self, PyObject *args)
***************
*** 2498,2503 ****
  init_curses(void)
  {
! 	PyObject *m, *d, *v;
  
  	/* Create the module and add the functions */
  	m = Py_InitModule("_curses", PyCurses_methods);
--- 2435,2447 ----
  init_curses(void)
  {
! 	PyObject *m, *d, *v, *c_api_object;
! 	static void *PyCurses_API[PyCurses_API_pointers];
  
+ 	/* Initialize the C API pointer array */
+ 	PyCurses_API[0] = (void *)&PyCursesWindow_Type;
+ 	PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
+ 	PyCurses_API[2] = (void *)func_PyCursesInitialised;
+ 	PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
+ 
  	/* Create the module and add the functions */
  	m = Py_InitModule("_curses", PyCurses_methods);
***************
*** 2505,2509 ****
  	/* Add some symbolic constants to the module */
  	d = PyModule_GetDict(m);
! 	ModDict = d; /* For PyCurses_InitScr */
  
  	/* For exception curses.error */
--- 2449,2457 ----
  	/* Add some symbolic constants to the module */
  	d = PyModule_GetDict(m);
! 	ModDict = d; /* For PyCurses_InitScr to use later */
! 
! 	/* Add a CObject for the C API */
! 	c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL);
! 	PyDict_SetItemString(d, "_C_API", c_api_object);
  
  	/* For exception curses.error */