mirror of https://github.com/python/cpython
Patch 1030, Adapt _winreg.c to the new buffer API.
Applying without testing since I don't have Windows. It seems to make sense from a cursory review.
This commit is contained in:
parent
0117ffca63
commit
1385b8940a
19
PC/_winreg.c
19
PC/_winreg.c
|
@ -814,23 +814,28 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
|
||||||
if (value == Py_None)
|
if (value == Py_None)
|
||||||
*retDataSize = 0;
|
*retDataSize = 0;
|
||||||
else {
|
else {
|
||||||
void *src_buf;
|
PyBuffer view;
|
||||||
PyBufferProcs *pb = value->ob_type->tp_as_buffer;
|
|
||||||
if (pb==NULL) {
|
if (!PyObject_CheckBuffer(value)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"Objects of type '%s' can not "
|
"Objects of type '%s' can not "
|
||||||
"be used as binary registry values",
|
"be used as binary registry values",
|
||||||
value->ob_type->tp_name);
|
value->ob_type->tp_name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
*retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
|
|
||||||
*retDataBuf = (BYTE *)PyMem_NEW(char,
|
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
|
||||||
*retDataSize);
|
return FALSE;
|
||||||
|
|
||||||
|
*retDataBuf = (BYTE *)PyMem_NEW(char, view.len);
|
||||||
if (*retDataBuf==NULL){
|
if (*retDataBuf==NULL){
|
||||||
|
PyObject_ReleaseBuffer(value, &view);
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
memcpy(*retDataBuf, src_buf, *retDataSize);
|
*retDataSize = view.len;
|
||||||
|
memcpy(*retDataBuf, view.buf, view.len);
|
||||||
|
PyObject_ReleaseBuffer(value, &view);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue