Changes to ctypes and Mac toolbox glue that fix test_threading and test_platform.
However, test_ctypes is still broken -- and apparently more than before.
This commit is contained in:
parent
9a63470fd7
commit
5e23d5732b
|
@ -1389,6 +1389,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
|
||||||
PyTypeObject *result;
|
PyTypeObject *result;
|
||||||
StgDictObject *stgdict;
|
StgDictObject *stgdict;
|
||||||
PyObject *name = PyTuple_GET_ITEM(args, 0);
|
PyObject *name = PyTuple_GET_ITEM(args, 0);
|
||||||
|
PyObject *newname;
|
||||||
PyObject *swapped_args;
|
PyObject *swapped_args;
|
||||||
static PyObject *suffix;
|
static PyObject *suffix;
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
|
@ -1399,17 +1400,17 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
|
||||||
|
|
||||||
if (suffix == NULL)
|
if (suffix == NULL)
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
suffix = PyString_FromString("_le");
|
suffix = PyUnicode_FromString("_le");
|
||||||
#else
|
#else
|
||||||
suffix = PyString_FromString("_be");
|
suffix = PyUnicode_FromString("_be");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Py_INCREF(name);
|
newname = PyUnicode_Concat(name, suffix);
|
||||||
PyString_Concat(&name, suffix);
|
if (newname == NULL) {
|
||||||
if (name == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
PyTuple_SET_ITEM(swapped_args, 0, name);
|
PyTuple_SET_ITEM(swapped_args, 0, newname);
|
||||||
for (i=1; i<PyTuple_GET_SIZE(args); ++i) {
|
for (i=1; i<PyTuple_GET_SIZE(args); ++i) {
|
||||||
PyObject *v = PyTuple_GET_ITEM(args, i);
|
PyObject *v = PyTuple_GET_ITEM(args, i);
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
|
@ -1484,6 +1485,8 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
PyTypeObject *result;
|
PyTypeObject *result;
|
||||||
StgDictObject *stgdict;
|
StgDictObject *stgdict;
|
||||||
PyObject *proto;
|
PyObject *proto;
|
||||||
|
const char *proto_str;
|
||||||
|
int proto_len;
|
||||||
PyMethodDef *ml;
|
PyMethodDef *ml;
|
||||||
struct fielddesc *fmt;
|
struct fielddesc *fmt;
|
||||||
|
|
||||||
|
@ -1494,24 +1497,52 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
proto = PyObject_GetAttrString((PyObject *)result, "_type_"); /* new ref */
|
proto = PyObject_GetAttrString((PyObject *)result, "_type_"); /* new ref */
|
||||||
if (!proto
|
if (!proto) {
|
||||||
|| !PyString_Check(proto)
|
PyErr_SetString(PyExc_AttributeError,
|
||||||
|| 1 != strlen(PyString_AS_STRING(proto))
|
"class must define a '_type_' attribute");
|
||||||
|| !strchr(SIMPLE_TYPE_CHARS, PyString_AS_STRING(proto)[0])) {
|
error:
|
||||||
|
Py_XDECREF(proto);
|
||||||
|
Py_XDECREF(result);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (PyUnicode_Check(proto)) {
|
||||||
|
PyObject *v = _PyUnicode_AsDefaultEncodedString(proto, NULL);
|
||||||
|
if (!v)
|
||||||
|
goto error;
|
||||||
|
proto_str = PyString_AS_STRING(v);
|
||||||
|
proto_len = PyString_GET_SIZE(v);
|
||||||
|
}
|
||||||
|
else if (PyString_Check(proto)) {
|
||||||
|
proto_str = PyString_AS_STRING(proto);
|
||||||
|
proto_len = PyString_GET_SIZE(proto);
|
||||||
|
}
|
||||||
|
else if (PyBytes_Check(proto)) {
|
||||||
|
proto_str = PyBytes_AS_STRING(proto);
|
||||||
|
proto_len = PyBytes_GET_SIZE(proto);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"class must define a '_type_' string attribute");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (proto_len != 1) {
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"class must define a '_type_' attribute "
|
||||||
|
"which must be a string of length 1");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (!strchr(SIMPLE_TYPE_CHARS, *proto_str)) {
|
||||||
PyErr_Format(PyExc_AttributeError,
|
PyErr_Format(PyExc_AttributeError,
|
||||||
"class must define a '_type_' attribute which must be\n"
|
"class must define a '_type_' attribute which must be\n"
|
||||||
"a single character string containing one of '%s'.",
|
"a single character string containing one of '%s'.",
|
||||||
SIMPLE_TYPE_CHARS);
|
SIMPLE_TYPE_CHARS);
|
||||||
Py_XDECREF(proto);
|
goto error;
|
||||||
Py_DECREF(result);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
fmt = getentry(PyString_AS_STRING(proto));
|
fmt = getentry(proto_str);
|
||||||
if (fmt == NULL) {
|
if (fmt == NULL) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"_type_ '%s' not supported",
|
"_type_ '%s' not supported", proto_str);
|
||||||
PyString_AS_STRING(proto));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1551,7 +1582,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
Overrides the SimpleType_from_param generic method.
|
Overrides the SimpleType_from_param generic method.
|
||||||
*/
|
*/
|
||||||
if (result->tp_base == &Simple_Type) {
|
if (result->tp_base == &Simple_Type) {
|
||||||
switch (PyString_AS_STRING(proto)[0]) {
|
switch (*proto_str) {
|
||||||
case 'z': /* c_char_p */
|
case 'z': /* c_char_p */
|
||||||
ml = &c_char_p_method;
|
ml = &c_char_p_method;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -159,12 +159,32 @@ int
|
||||||
PyMac_GetOSType(PyObject *v, OSType *pr)
|
PyMac_GetOSType(PyObject *v, OSType *pr)
|
||||||
{
|
{
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
if (!PyString_Check(v) || PyString_Size(v) != 4) {
|
const char *str;
|
||||||
|
int len;
|
||||||
|
if (PyUnicode_Check(v)) {
|
||||||
|
v = _PyUnicode_AsDefaultEncodedString(v, NULL);
|
||||||
|
if (v == NULL)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (PyString_Check(v)) {
|
||||||
|
str = PyString_AS_STRING(v);
|
||||||
|
len = PyString_GET_SIZE(v);
|
||||||
|
}
|
||||||
|
else if (PyBytes_Check(v)) {
|
||||||
|
str = PyBytes_AS_STRING(v);
|
||||||
|
len = PyBytes_GET_SIZE(v);
|
||||||
|
}
|
||||||
|
else {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"OSType arg must be string of 4 chars");
|
"OSType arg must be string (of 4 chars)");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy((char *)&tmp, PyString_AsString(v), 4);
|
if (len != 4) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"OSType arg must be (string of) 4 chars");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy((char *)&tmp, str, 4);
|
||||||
*pr = (OSType)ntohl(tmp);
|
*pr = (OSType)ntohl(tmp);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue