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

Skip to content

Commit 1385b89

Browse files
committed
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.
1 parent 0117ffc commit 1385b89

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

PC/_winreg.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,23 +814,28 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
814814
if (value == Py_None)
815815
*retDataSize = 0;
816816
else {
817-
void *src_buf;
818-
PyBufferProcs *pb = value->ob_type->tp_as_buffer;
819-
if (pb==NULL) {
817+
PyBuffer view;
818+
819+
if (!PyObject_CheckBuffer(value)) {
820820
PyErr_Format(PyExc_TypeError,
821821
"Objects of type '%s' can not "
822822
"be used as binary registry values",
823823
value->ob_type->tp_name);
824824
return FALSE;
825825
}
826-
*retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
827-
*retDataBuf = (BYTE *)PyMem_NEW(char,
828-
*retDataSize);
826+
827+
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
828+
return FALSE;
829+
830+
*retDataBuf = (BYTE *)PyMem_NEW(char, view.len);
829831
if (*retDataBuf==NULL){
832+
PyObject_ReleaseBuffer(value, &view);
830833
PyErr_NoMemory();
831834
return FALSE;
832835
}
833-
memcpy(*retDataBuf, src_buf, *retDataSize);
836+
*retDataSize = view.len;
837+
memcpy(*retDataBuf, view.buf, view.len);
838+
PyObject_ReleaseBuffer(value, &view);
834839
}
835840
break;
836841
}

0 commit comments

Comments
 (0)