[Python-checkins] CVS: python/dist/src/Modules newmodule.c,2.32,2.33

Tim Peters tim_one@users.sourceforge.net
Sat, 18 Aug 2001 13:18:51 -0700


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

Modified Files:
	newmodule.c 
Log Message:
Expose the CO_xxx flags via the "new" module (re-solving a problem "the
right way").  Fiddle __future__.py to use them.

Jeremy's pyassem.py may also want to use them (by-hand duplication of
magic numbers is brittle), but leaving that to his judgment.

Beef up __future__'s test to verify the exported feature names appear
correct.


Index: newmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/newmodule.c,v
retrieving revision 2.32
retrieving revision 2.33
diff -C2 -d -r2.32 -r2.33
*** newmodule.c	2001/02/01 19:50:28	2.32
--- newmodule.c	2001/08/18 20:18:49	2.33
***************
*** 221,228 ****
  You need to know a great deal about the interpreter to use this!";
  
  DL_EXPORT(void)
  initnew(void)
  {
! 	Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
! 		       PYTHON_API_VERSION);
  }
--- 221,257 ----
  You need to know a great deal about the interpreter to use this!";
  
+ static void
+ insertint(PyObject *d, char *name, int value)
+ {
+ 	PyObject *v = PyInt_FromLong((long) value);
+ 	if (v == NULL) {
+ 		/* Don't bother reporting this error */
+ 		PyErr_Clear();
+ 	}
+ 	else {
+ 		PyDict_SetItemString(d, name, v);
+ 		Py_DECREF(v);
+ 	}
+ }
+ 
  DL_EXPORT(void)
  initnew(void)
  {
! 	PyObject *m;
! 	PyObject *d;
! 
! 	m = Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
! 		            PYTHON_API_VERSION);
! 	d = PyModule_GetDict(m);
! 
! #define ADDSYM(TOKEN) insertint(d, #TOKEN, TOKEN)
! 	ADDSYM(CO_OPTIMIZED);
! 	ADDSYM(CO_NEWLOCALS);
! 	ADDSYM(CO_VARARGS);
! 	ADDSYM(CO_VARKEYWORDS);
! 	ADDSYM(CO_NESTED);
! 	ADDSYM(CO_GENERATOR);
! 	ADDSYM(CO_GENERATOR_ALLOWED);
! 	ADDSYM(CO_FUTURE_DIVISION);
! #undef ADDSYM
  }