summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-26 23:07:13 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-26 23:07:13 (GMT)
commit1385b8940a449c0a7ef693e5bbb1b39d30e58270 (patch)
treef1b2fb1e1d46b304dc61f06c5aa91657a0f0ce8f /PC
parent0117ffca637595687f0ea9acd75653e932806e7c (diff)
downloadcpython-1385b8940a449c0a7ef693e5bbb1b39d30e58270.zip
cpython-1385b8940a449c0a7ef693e5bbb1b39d30e58270.tar.gz
cpython-1385b8940a449c0a7ef693e5bbb1b39d30e58270.tar.bz2
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.
Diffstat (limited to 'PC')
-rw-r--r--PC/_winreg.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/PC/_winreg.c b/PC/_winreg.c
index 135be32..7386ea1 100644
--- a/PC/_winreg.c
+++ b/PC/_winreg.c
@@ -814,23 +814,28 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
if (value == Py_None)
*retDataSize = 0;
else {
- void *src_buf;
- PyBufferProcs *pb = value->ob_type->tp_as_buffer;
- if (pb==NULL) {
+ PyBuffer view;
+
+ if (!PyObject_CheckBuffer(value)) {
PyErr_Format(PyExc_TypeError,
"Objects of type '%s' can not "
"be used as binary registry values",
value->ob_type->tp_name);
return FALSE;
}
- *retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
- *retDataBuf = (BYTE *)PyMem_NEW(char,
- *retDataSize);
+
+ if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
+ return FALSE;
+
+ *retDataBuf = (BYTE *)PyMem_NEW(char, view.len);
if (*retDataBuf==NULL){
+ PyObject_ReleaseBuffer(value, &view);
PyErr_NoMemory();
return FALSE;
}
- memcpy(*retDataBuf, src_buf, *retDataSize);
+ *retDataSize = view.len;
+ memcpy(*retDataBuf, view.buf, view.len);
+ PyObject_ReleaseBuffer(value, &view);
}
break;
}