summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2000-08-05 21:29:58 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2000-08-05 21:29:58 (GMT)
commitcc22fbe3dbf3374de0827fc52f6765de0af2a7d8 (patch)
tree951918a14220a92548f1c7493927ca44dd546268 /Python
parentab3a0f36eded60acede255bb286688fcc17c5b01 (diff)
downloadcpython-cc22fbe3dbf3374de0827fc52f6765de0af2a7d8.zip
cpython-cc22fbe3dbf3374de0827fc52f6765de0af2a7d8.tar.gz
cpython-cc22fbe3dbf3374de0827fc52f6765de0af2a7d8.tar.bz2
Changed H specifier to mean "bitfield", i.e. any value from
-32768..65535 is acceptable. Added B specifier (with values from -128..255). No L added (which would have completed the set) because l already accepts any value (and the letter L is taken for quadwords).
Diffstat (limited to 'Python')
-rw-r--r--Python/getargs.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index ceaf6cb..359e3bd 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -409,6 +409,27 @@ convertsimple1(PyObject *arg, char **p_format, va_list *p_va)
break;
}
+ case 'B': /* byte sized bitfield - both signed and unsigned values allowed */
+ {
+ char *p = va_arg(*p_va, char *);
+ long ival = PyInt_AsLong(arg);
+ if (ival == -1 && PyErr_Occurred())
+ return "integer<b>";
+ else if (ival < SCHAR_MIN) {
+ PyErr_SetString(PyExc_OverflowError,
+ "byte-sized integer bitfield is less than minimum");
+ return "integer<B>";
+ }
+ else if (ival > UCHAR_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "byte-sized integer bitfield is greater than maximum");
+ return "integer<B>";
+ }
+ else
+ *p = (unsigned char) ival;
+ break;
+ }
+
case 'h': /* signed short int */
{
short *p = va_arg(*p_va, short *);
@@ -430,20 +451,20 @@ convertsimple1(PyObject *arg, char **p_format, va_list *p_va)
break;
}
- case 'H': /* unsigned short int */
+ case 'H': /* short int sized bitfield, both signed and unsigned allowed */
{
unsigned short *p = va_arg(*p_va, unsigned short *);
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<H>";
- else if (ival < 0) {
+ else if (ival < SHRT_MIN) {
PyErr_SetString(PyExc_OverflowError,
- "unsigned short integer is less than minimum");
+ "short integer bitfield is less than minimum");
return "integer<H>";
}
else if (ival > USHRT_MAX) {
PyErr_SetString(PyExc_OverflowError,
- "unsigned short integer is greater than maximum");
+ "short integer bitfield is greater than maximum");
return "integer<H>";
}
else
@@ -1133,6 +1154,7 @@ skipitem(char **p_format, va_list *p_va)
switch (c) {
case 'b': /* byte -- very short int */
+ case 'B': /* byte as bitfield */
{
(void) va_arg(*p_va, char *);
break;
@@ -1144,7 +1166,7 @@ skipitem(char **p_format, va_list *p_va)
break;
}
- case 'H': /* unsigned short int */
+ case 'H': /* short int as bitfield */
{
(void) va_arg(*p_va, unsigned short *);
break;