[Python-checkins] CVS: python/dist/src/Include pyerrors.h,2.45,2.46

M.-A. Lemburg lemburg@users.sourceforge.net
Tue, 31 Jul 2001 06:24:46 -0700


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

Modified Files:
	pyerrors.h 
Log Message:
This patch turns the Python API mismatch notice into a standard
Python warning which can be catched by means of the Python warning
framework.

It also adds two new APIs which hopefully make it easier for Python
to switch to buffer overflow safe [v]snprintf() APIs for error
reporting et al. The two new APIs are PyOS_snprintf() and 
PyOS_vsnprintf() and work just like the standard ones in many
C libs. On platforms which have snprintf(), the native APIs are used,
on all other an emulation with snprintf() tries to do its best.



Index: pyerrors.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pyerrors.h,v
retrieving revision 2.45
retrieving revision 2.46
diff -C2 -d -r2.45 -r2.46
*** pyerrors.h	2001/04/20 19:13:01	2.45
--- pyerrors.h	2001/07/31 13:24:44	2.46
***************
*** 107,110 ****
--- 107,126 ----
  extern DL_IMPORT(PyObject *) PyErr_ProgramText(char *, int);
  	
+ /* These APIs aren't really part of the error implementation, but
+    often needed to format error messages; the native C lib APIs are
+    not available on all platforms, which is why we provide emulations
+    for those platforms in Python/mysnprintf.c */
+ #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
+ # define HAVE_SNPRINTF
+ # define snprintf _snprintf
+ # define vsnprintf _vsnprintf
+ #endif
+ #ifndef HAVE_SNPRINTF
+ extern DL_IMPORT(int) PyOS_snprintf(char *str, size_t size, const char  *format, ...);
+ extern DL_IMPORT(int) PyOS_vsnprintf(char *str, size_t size, const char  *format, va_list va);
+ #else
+ # define PyOS_vsnprintf	vsnprintf
+ # define PyOS_snprintf	snprintf
+ #endif
  
  #ifdef __cplusplus