mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
bpo-16576: Add checks for bitfields passed by value to functions. (GH-17097)
This commit is contained in:
parent
c8b53dc3d8
commit
106271568c
3 changed files with 141 additions and 3 deletions
|
|
@ -2400,11 +2400,18 @@ converters_from_argtypes(PyObject *ob)
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
if (stgdict->flags & TYPEFLAG_HASBITFIELD) {
|
||||
printf("found stgdict with bitfield\n");
|
||||
Py_DECREF(converters);
|
||||
Py_DECREF(ob);
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"item %zd in _argtypes_ passes a struct/"
|
||||
"union with a bitfield by value, which is "
|
||||
"unsupported.",
|
||||
i + 1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttrId(tp, &PyId_from_param, &cnv) <= 0) {
|
||||
|
|
|
|||
|
|
@ -194,6 +194,56 @@ _testfunc_union_by_reference3(Test5 *in) {
|
|||
return result;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
signed int A: 1, B:2, C:3, D:2;
|
||||
} Test6;
|
||||
|
||||
EXPORT(long)
|
||||
_testfunc_bitfield_by_value1(Test6 in) {
|
||||
long result = in.A + in.B + in.C + in.D;
|
||||
|
||||
/* As the struct is passed by value, changes to it shouldn't be
|
||||
* reflected in the caller.
|
||||
*/
|
||||
memset(&in, 0, sizeof(in));
|
||||
return result;
|
||||
}
|
||||
|
||||
EXPORT(long)
|
||||
_testfunc_bitfield_by_reference1(Test6 *in) {
|
||||
long result = in->A + in->B + in->C + in->D;
|
||||
|
||||
memset(in, 0, sizeof(Test6));
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned int A: 1, B:2, C:3, D:2;
|
||||
} Test7;
|
||||
|
||||
EXPORT(long)
|
||||
_testfunc_bitfield_by_reference2(Test7 *in) {
|
||||
long result = in->A + in->B + in->C + in->D;
|
||||
|
||||
memset(in, 0, sizeof(Test7));
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef union {
|
||||
signed int A: 1, B:2, C:3, D:2;
|
||||
} Test8;
|
||||
|
||||
EXPORT(long)
|
||||
_testfunc_bitfield_by_value2(Test8 in) {
|
||||
long result = in.A + in.B + in.C + in.D;
|
||||
|
||||
/* As the struct is passed by value, changes to it shouldn't be
|
||||
* reflected in the caller.
|
||||
*/
|
||||
memset(&in, 0, sizeof(in));
|
||||
return result;
|
||||
}
|
||||
|
||||
EXPORT(void)testfunc_array(int values[4])
|
||||
{
|
||||
printf("testfunc_array %d %d %d %d\n",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue