summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-10-08 02:21:21 (GMT)
committerGuido van Rossum <guido@python.org>1998-10-08 02:21:21 (GMT)
commitb317f8aa0d1387f30c72df47bf18cb7517f45f2a (patch)
treefaae9851759463e2584eab93c13deecca6af09af
parent1db7070217d80f0889aed44ceb1f11a82265b3f0 (diff)
downloadcpython-b317f8aa0d1387f30c72df47bf18cb7517f45f2a.zip
cpython-b317f8aa0d1387f30c72df47bf18cb7517f45f2a.tar.gz
cpython-b317f8aa0d1387f30c72df47bf18cb7517f45f2a.tar.bz2
Implement new format character 't#'. This is like s#, accepting an
object that implements the buffer interface, but requires a buffer that contains 8-bit character data. Greg Stein.
-rw-r--r--Python/getargs.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 86fd471..9fcfb9f 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -712,6 +712,31 @@ convertsimple1(arg, p_format, p_va)
break;
}
+ case 't': /* 8-bit character buffer, read-only access */
+ {
+ const char **p = va_arg(*p_va, const char **);
+ PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
+ int count;
+
+ if ( *format++ != '#' )
+ return "invalid use of 't' format character";
+ if ( !PyType_HasFeature(
+ arg->ob_type,
+ Py_TPFLAGS_HAVE_GETCHARBUFFER) ||
+ pb == NULL ||
+ pb->bf_getcharbuffer == NULL ||
+ pb->bf_getsegcount == NULL )
+ return "read-only character buffer";
+ if ( (*pb->bf_getsegcount)(arg, NULL) != 1 )
+ return "single-segment read-only buffer";
+ if ( (count = pb->bf_getcharbuffer(arg, 0, p)) < 0 )
+ return "(unspecified)";
+
+ *va_arg(*p_va, int *) = count;
+
+ break;
+ }
+
default:
return "impossible<bad format char>";