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).
This commit is contained in:
Jack Jansen 2000-08-05 21:29:58 +00:00
parent ab3a0f36ed
commit cc22fbe3db

View File

@ -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;