[Python-checkins] CVS: python/dist/src/Python getargs.c,2.30,2.31

Fred Drake python-dev@python.org
Wed, 3 May 2000 11:16:00 -0400


Update of /projects/cvsroot/python/dist/src/Python
In directory seahag.cnri.reston.va.us:/home/fdrake/projects/python/Python

Modified Files:
	getargs.c 
Log Message:

Brian Hooper <brian_takashi@hotmail.com>:

Added 'u' and 'u#' tags for PyArg_ParseTuple - these turn a
PyUnicodeObject argument into a Py_UNICODE * buffer, or a Py_UNICODE *
buffer plus a length with the '#'.  Also added an analog to 'U'
for Py_BuildValue.


Index: getargs.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/getargs.c,v
retrieving revision 2.30
retrieving revision 2.31
diff -C2 -r2.30 -r2.31
*** getargs.c	2000/04/27 20:13:18	2.30
--- getargs.c	2000/05/03 15:15:57	2.31
***************
*** 778,781 ****
--- 778,813 ----
  		}
  
+ 	case 'u': /* raw unicode buffer (Py_UNICODE *) */
+ 		{
+ 			if (*format == '#') { /* any buffer-like object */
+ 			        void **p = (void **)va_arg(*p_va, char **);
+ 			        PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
+ 				int *q = va_arg(*p_va, int *);
+ 				int count;
+ 
+ 				if ( pb == NULL ||
+ 				     pb->bf_getreadbuffer == NULL ||
+ 				     pb->bf_getsegcount == NULL )
+ 				  return "read-only buffer";
+ 				if ( (*pb->bf_getsegcount)(arg, NULL) != 1 )
+ 				  return "single-segment read-only buffer";
+ 				if ( (count =
+ 				      (*pb->bf_getreadbuffer)(arg, 0, p)) < 0 )
+ 				  return "(unspecified)";
+ 				/* buffer interface returns bytes, we want
+ 				   length in characters */
+ 				*q = count/(sizeof(Py_UNICODE)); 
+ 				format++;
+ 			} else {
+ 			        Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
+ 			
+ 			        if (PyUnicode_Check(arg))
+ 				    *p = PyUnicode_AS_UNICODE(arg);
+ 				else
+ 				  return "unicode";
+ 			}
+ 			break;
+ 		}
+ 
  	case 'S': /* string object */
  		{