]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Allow any object supporting the buffer protocol to be written as a binary object.
authorMark Hammond <mhammond@skippinet.com.au>
Fri, 28 Jul 2000 03:44:41 +0000 (03:44 +0000)
committerMark Hammond <mhammond@skippinet.com.au>
Fri, 28 Jul 2000 03:44:41 +0000 (03:44 +0000)
PC/_winreg.c

index 84bf3c48765c1d2f2c99892668cb563c9092a6ff..edfadac77ca4ae2e9882e7cf5edeae8824e9b524 100644 (file)
@@ -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;
        }