diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2000-07-28 03:44:41 (GMT) |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2000-07-28 03:44:41 (GMT) |
commit | 4e80bb551e0df7e22ceeca51e93e9bb87a56b9a3 (patch) | |
tree | 7bcc7351532b1efbe39b080a916950c9b8b91cd1 /PC | |
parent | abfeff7f44fcc9451d7f4588bda53adebd2d4ea4 (diff) | |
download | cpython-4e80bb551e0df7e22ceeca51e93e9bb87a56b9a3.zip cpython-4e80bb551e0df7e22ceeca51e93e9bb87a56b9a3.tar.gz cpython-4e80bb551e0df7e22ceeca51e93e9bb87a56b9a3.tar.bz2 |
Allow any object supporting the buffer protocol to be written as a binary object.
Diffstat (limited to 'PC')
-rw-r--r-- | PC/_winreg.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/PC/_winreg.c b/PC/_winreg.c index 84bf3c4..edfadac 100644 --- a/PC/_winreg.c +++ b/PC/_winreg.c @@ -830,19 +830,23 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) if (value == Py_None) *retDataSize = 0; else { - if (!PyString_Check(value)) - return 0; - *retDataSize = PyString_Size(value); + void *src_buf; + PyBufferProcs *pb = value->ob_type->tp_as_buffer; + if (pb==NULL) { + 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 (*retDataBuf==NULL){ PyErr_NoMemory(); return FALSE; } - memcpy(*retDataBuf, - PyString_AS_STRING( - (PyStringObject *)value), - *retDataSize); + memcpy(*retDataBuf, src_buf, *retDataSize); } break; } |