mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Issue #23765: Remove IsBadStringPtr calls in ctypes
Also renames a local to avoid warnings about shadowing
This commit is contained in:
parent
c98290b91b
commit
ef42dae7fa
1 changed files with 4 additions and 20 deletions
|
@ -1354,14 +1354,6 @@ z_get(void *ptr, Py_ssize_t size)
|
|||
{
|
||||
/* XXX What about invalid pointers ??? */
|
||||
if (*(void **)ptr) {
|
||||
#if defined(MS_WIN32) && !defined(_WIN32_WCE)
|
||||
if (IsBadStringPtrA(*(char **)ptr, -1)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"invalid string pointer %p",
|
||||
*(char **)ptr);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return PyBytes_FromStringAndSize(*(char **)ptr,
|
||||
strlen(*(char **)ptr));
|
||||
} else {
|
||||
|
@ -1418,14 +1410,6 @@ Z_get(void *ptr, Py_ssize_t size)
|
|||
wchar_t *p;
|
||||
p = *(wchar_t **)ptr;
|
||||
if (p) {
|
||||
#if defined(MS_WIN32) && !defined(_WIN32_WCE)
|
||||
if (IsBadStringPtrW(*(wchar_t **)ptr, -1)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"invalid string pointer %p",
|
||||
*(wchar_t **)ptr);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return PyUnicode_FromWideChar(p, wcslen(p));
|
||||
} else {
|
||||
Py_INCREF(Py_None);
|
||||
|
@ -1455,15 +1439,15 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
|
|||
/* create a BSTR from value */
|
||||
if (value) {
|
||||
wchar_t* wvalue;
|
||||
Py_ssize_t size;
|
||||
wvalue = PyUnicode_AsUnicodeAndSize(value, &size);
|
||||
Py_ssize_t wsize;
|
||||
wvalue = PyUnicode_AsUnicodeAndSize(value, &wsize);
|
||||
if (wvalue == NULL)
|
||||
return NULL;
|
||||
if ((unsigned) size != size) {
|
||||
if ((unsigned) wsize != wsize) {
|
||||
PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
|
||||
return NULL;
|
||||
}
|
||||
bstr = SysAllocStringLen(wvalue, (unsigned)size);
|
||||
bstr = SysAllocStringLen(wvalue, (unsigned)wsize);
|
||||
Py_DECREF(value);
|
||||
} else
|
||||
bstr = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue