[Python-checkins] CVS: python/dist/src/Python getargs.c,2.72,2.73

Tim Peters tim_one@users.sourceforge.net
2001年10月26日 21:26:59 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv3534/python/Python
Modified Files:
	getargs.c 
Log Message:
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
introduced this bug just a little while ago, when *adding* internal error
checks).
vgetargskeywords: Rewrote the section that crawls over the format string.
+ Added block comment so it won't take the next person 15 minutes to
 reverse-engineer what it's doing.
+ Lined up the "else" clauses.
+ Rearranged the ifs in decreasing order of likelihood (for speed).
Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.72
retrieving revision 2.73
diff -C2 -d -r2.72 -r2.73
*** getargs.c	2001年10月27日 03:58:40	2.72
--- getargs.c	2001年10月27日 04:26:57	2.73
***************
*** 998,1001 ****
--- 998,1002 ----
 Geoff Philbrick <philbric@delphi.hks.com> */
 
+ /* Return false (0) for error, else true. */
 int
 PyArg_ParseTupleAndKeywords(PyObject *args,
***************
*** 1013,1017 ****
 	{
 		PyErr_BadInternalCall();
! 		return -1;
 	}
 
--- 1014,1018 ----
 	{
 		PyErr_BadInternalCall();
! 		return 0;
 	}
 
***************
*** 1029,1036 ****
 	char msgbuf[256];
 	int levels[32];
! 	char *fname = NULL;
! 	char *message = NULL;
! 	int min = -1;
! 	int max = 0;
 	char *formatsave = format;
 	int i, len, tplen, kwlen;
--- 1030,1035 ----
 	char msgbuf[256];
 	int levels[32];
! 	char *fname, *message;
! 	int min, max;
 	char *formatsave = format;
 	int i, len, tplen, kwlen;
***************
*** 1044,1078 ****
 	assert(kwlist != NULL);
 	assert(p_va != NULL);
- 
- 	/* nested tuples cannot be parsed when using keyword arguments */
 
! 	for (;;) {
! 		int c = *format++;
! 		if (c == '(') {
! 			PyErr_SetString(PyExc_SystemError,
! 		 "tuple found in format when using keyword arguments");
! 			return 0;
! 		}
! 		else if (c == '0円')
! 			break;
! 		else if (c == ':') {
 			fname = format;
 			break;
! 		} else if (c == ';') {
 			message = format;
 			break;
! 		} else if (c == 'e')
! 			; /* Pass */
! 		else if (isalpha(c))
! 			max++;
! 		else if (c == '|')
! 			min = max;
 	}	
! 	
! 	if (min < 0)
 		min = max;
! 	
 	format = formatsave;
! 	
 	if (!PyTuple_Check(args)) {
 		PyErr_SetString(PyExc_SystemError,
--- 1043,1082 ----
 	assert(kwlist != NULL);
 	assert(p_va != NULL);
 
! 	/* Search the format:
! 	 message <- error msg, if any (else NULL).
! 	 name <- routine name, if any (else NULL).
! 	 min <- # of required arguments, or -1 if all are required.
! 	 max <- most arguments (required + optional).
! 	 Raise error if a tuple arg spec is found.
! 	*/
! 	fname = message = NULL;
! 	min = -1;
! 	max = 0;
! 	while ((i = *format++) != '0円') {
! 		if (isalpha(i) && i != 'e')
! 			max++;
! 		else if (i == '|')
! 			min = max;
! 		else if (i == ':') {
 			fname = format;
 			break;
! 		}
! 		else if (i == ';') {
 			message = format;
 			break;
! 		}
! 		else if (i == '(') {
! 			PyErr_SetString(PyExc_SystemError,
! 		 "tuple found in format when using keyword arguments");
! 			return 0;
! 		}
 	}	
! 	if (min < 0) {
! 		/* All arguments are required. */
 		min = max;
! 	}
 	format = formatsave;
! 
 	if (!PyTuple_Check(args)) {
 		PyErr_SetString(PyExc_SystemError,
***************
*** 1080,1086 ****
 		return 0;
 	}	
! 	
 	tplen = PyTuple_GET_SIZE(args);
! 	
 	/* do a cursory check of the keywords just to see how many we got */
 
--- 1084,1090 ----
 		return 0;
 	}	
! 
 	tplen = PyTuple_GET_SIZE(args);
! 
 	/* do a cursory check of the keywords just to see how many we got */
 

AltStyle によって変換されたページ (->オリジナル) /