Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d076228

Browse files
author
Thomas Heller
committed
Change the StgDictObject's proto member to a PyUnicode_Object (was a
PyStringObject before).
1 parent 2c5e964 commit d076228

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

Modules/_ctypes/_ctypes.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
414414
return -1;
415415

416416
if (value && PyUnicode_Check(key) &&
417+
/* XXX struni PyUnicode_AsString can fail (also in other places)! */
417418
0 == strcmp(PyUnicode_AsString(key), "_fields_"))
418419
return StructUnionType_update_stgdict(self, value, 1);
419420
return 0;
@@ -1339,10 +1340,10 @@ c_void_p_from_param(PyObject *type, PyObject *value)
13391340
}
13401341
/* c_char_p, c_wchar_p */
13411342
stgd = PyObject_stgdict(value);
1342-
if (stgd && CDataObject_Check(value) && stgd->proto && PyString_Check(stgd->proto)) {
1343+
if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) {
13431344
PyCArgObject *parg;
13441345

1345-
switch (PyString_AS_STRING(stgd->proto)[0]) {
1346+
switch (PyUnicode_AsString(stgd->proto)[0]) {
13461347
case 'z': /* c_char_p */
13471348
case 'Z': /* c_wchar_p */
13481349
parg = new_CArgObject();
@@ -1511,16 +1512,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
15111512
goto error;
15121513
proto_str = PyString_AS_STRING(v);
15131514
proto_len = PyString_GET_SIZE(v);
1514-
}
1515-
else if (PyString_Check(proto)) {
1516-
proto_str = PyString_AS_STRING(proto);
1517-
proto_len = PyString_GET_SIZE(proto);
1518-
}
1519-
else if (PyBytes_Check(proto)) {
1520-
proto_str = PyBytes_AS_STRING(proto);
1521-
proto_len = PyBytes_GET_SIZE(proto);
1522-
}
1523-
else {
1515+
} else {
15241516
PyErr_SetString(PyExc_TypeError,
15251517
"class must define a '_type_' string attribute");
15261518
goto error;
@@ -2681,9 +2673,9 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
26812673
dict = PyType_stgdict(arg);
26822674
if (dict
26832675
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
2684-
&& PyString_Check(dict->proto)
2676+
&& PyUnicode_Check(dict->proto)
26852677
/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */
2686-
&& (strchr("PzZ", PyString_AS_STRING(dict->proto)[0]))) {
2678+
&& (strchr("PzZ", PyUnicode_AsString(dict->proto)[0]))) {
26872679
return 1;
26882680
}
26892681

@@ -3183,7 +3175,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
31833175
"NULL stgdict unexpected");
31843176
goto error;
31853177
}
3186-
if (PyString_Check(dict->proto)) {
3178+
if (PyUnicode_Check(dict->proto)) {
31873179
PyErr_Format(
31883180
PyExc_TypeError,
31893181
"%s 'out' parameter must be passed as default value",
@@ -4594,8 +4586,8 @@ cast_check_pointertype(PyObject *arg)
45944586
return 1;
45954587
dict = PyType_stgdict(arg);
45964588
if (dict) {
4597-
if (PyString_Check(dict->proto)
4598-
&& (strchr("sPzUZXO", PyString_AS_STRING(dict->proto)[0]))) {
4589+
if (PyUnicode_Check(dict->proto)
4590+
&& (strchr("sPzUZXO", PyUnicode_AsString(dict->proto)[0]))) {
45994591
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
46004592
return 1;
46014593
}

0 commit comments

Comments
 (0)