[Python-3000-checkins] r57528 - python/branches/py3k/PC/_winreg.c
neal.norwitz
python-3000-checkins at python.org
Mon Aug 27 01:07:13 CEST 2007
Author: neal.norwitz
Date: Mon Aug 27 01:07:13 2007
New Revision: 57528
Modified:
python/branches/py3k/PC/_winreg.c
Log:
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.
Modified: python/branches/py3k/PC/_winreg.c
==============================================================================
--- python/branches/py3k/PC/_winreg.c (original)
+++ python/branches/py3k/PC/_winreg.c Mon Aug 27 01:07:13 2007
@@ -814,23 +814,28 @@
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;
}
More information about the Python-3000-checkins
mailing list