[Python-checkins] CVS: python/dist/src/Python exceptions.c,1.13,1.14

Fred L. Drake python-dev@python.org
Tue, 15 Aug 2000 09:20:38 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv3942

Modified Files:
	exceptions.c 
Log Message:

my_basename():  Removes the leading path components from a path name,
	returning a pointer to the start of the file's "base" name;
	similar to os.path.basename().

SyntaxError__str__():  Use my_basename() to keep the length of the
	file name included in the exception message short.


Index: exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** exceptions.c	2000/08/15 15:46:16	1.13
--- exceptions.c	2000/08/15 16:20:36	1.14
***************
*** 20,23 ****
--- 20,24 ----
  
  #include "Python.h"
+ #include "osdefs.h"
  
  /* Caution:  MS Visual C++ 6 errors if a single string literal exceeds
***************
*** 730,733 ****
--- 731,754 ----
  
  
+ /* This is called "my_basename" instead of just "basename" to avoid name
+    conflicts with glibc; basename is already prototyped if _GNU_SOURCE is
+    defined, and Python does define that. */
+ static char *
+ my_basename(char *name)
+ {
+ 	char *cp = name;
+ 	char *result = name;
+ 
+ 	if (name == NULL)
+ 		return "???";
+ 	while (*cp != '\0') {
+ 		if (*cp == SEP)
+ 			result = cp + 1;
+ 		++cp;
+ 	}
+ 	return result;
+ }
+ 
+ 
  static PyObject *
  SyntaxError__str__(PyObject *self, PyObject *args)
***************
*** 773,782 ****
  		    sprintf(buffer, "%s (%s, line %d)",
  			    PyString_AS_STRING(str),
! 			    PyString_AS_STRING(filename),
  			    PyInt_AsLong(lineno));
  		else if (have_filename)
  		    sprintf(buffer, "%s (%s)",
  			    PyString_AS_STRING(str),
! 			    PyString_AS_STRING(filename));
  		else if (have_lineno)
  		    sprintf(buffer, "%s (line %d)",
--- 794,803 ----
  		    sprintf(buffer, "%s (%s, line %d)",
  			    PyString_AS_STRING(str),
! 			    my_basename(PyString_AS_STRING(filename)),
  			    PyInt_AsLong(lineno));
  		else if (have_filename)
  		    sprintf(buffer, "%s (%s)",
  			    PyString_AS_STRING(str),
! 			    my_basename(PyString_AS_STRING(filename)));
  		else if (have_lineno)
  		    sprintf(buffer, "%s (line %d)",