Index: Modules/_ctypes/_ctypes.c =================================================================== --- Modules/_ctypes/_ctypes.c (revision 77489) +++ Modules/_ctypes/_ctypes.c (working copy) @@ -1076,6 +1076,7 @@ { char *ptr; Py_ssize_t size; +#if (PY_VERSION_HEX < 0x02070000) if (PyBuffer_Check(value)) { size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr); if (size < 0) @@ -1083,15 +1084,30 @@ } else if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) { return -1; } +#else + Py_buffer view; + if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0) + return -1; + size = view.len; + ptr = view.buf; +#endif if (size > self->b_size) { PyErr_SetString(PyExc_ValueError, "string too long"); - return -1; + goto fail; } memcpy(self->b_ptr, ptr, size); +#if (PY_VERSION_HEX >= 0x02070000) + PyBuffer_Release(&view); +#endif return 0; + fail: +#if (PY_VERSION_HEX >= 0x02070000) + PyBuffer_Release(&view); +#endif + return -1; } static PyObject *