[Python-checkins] CVS: python/dist/src/Python getargs.c,2.58,2.59

Jeremy Hylton jhylton@users.sourceforge.net
Tue, 29 May 2001 10:37:07 -0700


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

Modified Files:
	getargs.c 
Log Message:
Internal refactoring of convertsimple() and friends.

Note that lots of code was re-indented.

Replace two-step of convertsimple() and convertsimple1() with
convertsimple() and helper converterr(), which is called to format
error messages when convertsimple() fails.  The old code did all the
real work in convertsimple1(), but deferred error message formatting
to conversimple().  The result was paying the price of a second
function call on every call just to format error messages in the
failure cases.

Factor out of the buffer-handling code in convertsimple() and package
it as convertbuffer().

Add two macros to ease readability of Unicode coversions,
UNICODE_DEFAULT_ENCODING() and CONV_UNICODE, an error string.

The convertsimple() routine had awful indentation problems, primarily
because there were two tabs between the case line and the body of the
case statements.  This patch reformats the entire function to have a
single tab between case line and case body, which makes the code
easier to read (and consistent with ceval).  The introduction of
converterr() exacerbated the problem and prompted this fix.

Also, eliminate non-standard whitespace after opening paren and before
closing paren in a few if statements.

(This checkin is part of SF patch 426072.)


Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.58
retrieving revision 2.59
diff -C2 -r2.58 -r2.59
*** getargs.c	2001/05/18 21:03:40	2.58
--- getargs.c	2001/05/29 17:37:05	2.59
***************
*** 26,30 ****
  			  int *, char *, int);
  static char *convertsimple(PyObject *, char **, va_list *, char *);
! static char *convertsimple1(PyObject *, char **, va_list *);
  
  static int vgetargskeywords(PyObject *, PyObject *,
--- 26,30 ----
  			  int *, char *, int);
  static char *convertsimple(PyObject *, char **, va_list *, char *);
! static int convertbuffer(PyObject *, void **p, char **);
  
[...1202 lines suppressed...]
+ {
+ 	PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
+ 	int count;
+ 	if (pb == NULL ||
+ 	    pb->bf_getreadbuffer == NULL ||
+ 	    pb->bf_getsegcount == NULL) {
+ 		*errmsg = "string or read-only buffer";
+ 		return -1;
+ 	}
+ 	if ((*pb->bf_getsegcount)(arg, NULL) != 1) {
+ 		*errmsg = "string or single-segment read-only buffer";
+ 		return -1;
+ 	}
+ 	if ((count = (*pb->bf_getreadbuffer)(arg, 0, p)) < 0) {
+ 		*errmsg = "(unspecified)";
+ 	}
+ 	return count;
+ }
  
  /* Support for keyword arguments donated by