Bug 386610 - "pyxpcom fails to build against python 2.5 (api changed)" [p=asac@jwsdot.com (Alexander Sack) r=mhammond (NPOTB)]

This commit is contained in:
reed@reedloden.com 2008-01-04 22:32:35 -08:00
Родитель 1a3e4ccbd7
Коммит dc44233b92
3 изменённых файлов: 35 добавлений и 11 удалений

Просмотреть файл

@ -103,18 +103,23 @@ PyG_nsIInputStream::Read(char * buf, PRUint32 count, PRUint32 *_retval)
const char *methodName = "read";
nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "i", count);
if (NS_SUCCEEDED(nr)) {
PRUint32 py_size;
Py_ssize_t py_size;
const void *py_buf;
if (PyObject_AsReadBuffer(ret, &py_buf, (int *)&py_size)!=0) {
if (PyObject_AsReadBuffer(ret, &py_buf, &py_size)!=0) {
PyErr_Format(PyExc_TypeError, "nsIInputStream::read() method must return a buffer object - not a '%s' object", ret->ob_type->tp_name);
nr = HandleNativeGatewayError(methodName);
} else {
if (py_size > count) {
PyXPCOM_LogWarning("nsIInputStream::read() was asked for %d bytes, but the string returned is %d bytes - truncating!\n", count, py_size);
py_size = count;
if ( (py_size & 0xFFFFFFFF) != py_size) {
PyErr_SetString(PyExc_RuntimeError, "Python Buffer length overflows 32-bit in PyObject_AsWriteBuffer");
nr = HandleNativeGatewayError(methodName);
} else {
if (py_size > count) {
PyXPCOM_LogWarning("nsIInputStream::read() was asked for %d bytes, but the string returned is %d bytes - truncating!\n", count, py_size);
py_size = count;
}
memcpy(buf, py_buf, py_size);
*_retval = py_size;
}
memcpy(buf, py_buf, py_size);
*_retval = py_size;
}
}
return nr;

Просмотреть файл

@ -65,12 +65,19 @@ static PyObject *DoPyRead_Buffer(nsIInputStream *pI, PyObject *obBuffer, PRUint3
{
PRUint32 nread;
void *buf;
PRUint32 buf_len;
if (PyObject_AsWriteBuffer(obBuffer, &buf, (int *)&buf_len) != 0) {
Py_ssize_t buf_len;
if (PyObject_AsWriteBuffer(obBuffer, &buf, &buf_len) != 0) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "The buffer object does not have a write buffer!");
return NULL;
}
if ( (buf_len & 0xFFFFFFFF) != buf_len) {
PyErr_Clear();
PyErr_SetString(PyExc_RuntimeError, "Python Buffer length overflows 32-bit in PyObject_AsWriteBuffer");
return NULL;
}
if (n==(PRUint32)-1) {
n = buf_len;
} else {
@ -116,11 +123,17 @@ static PyObject *DoPyRead_Size(nsIInputStream *pI, PRUint32 n)
rc = PyBuffer_New(nread);
if (rc != NULL) {
void *ob_buf;
PRUint32 buf_len;
if (PyObject_AsWriteBuffer(rc, &ob_buf, (int *)&buf_len) != 0) {
Py_ssize_t buf_len;
if (PyObject_AsWriteBuffer(rc, &ob_buf, &buf_len) != 0) {
// should never fail - we just created it!
return NULL;
}
if ( (buf_len & 0xFFFFFFFF) != buf_len) {
PyErr_SetString(PyExc_RuntimeError, "Python Buffer length overflows 32-bit in PyObject_AsWriteBuffer");
return NULL;
}
if (buf_len != nread) {
PyErr_SetString(PyExc_RuntimeError, "New buffer isn't the size we created it!");
return NULL;

Просмотреть файл

@ -78,6 +78,12 @@
#include <Python.h>
// python 2.4 doesn't have Py_ssize_t
// => fallback to int
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
#endif
// PYXPCOM_EXPORT means 'exported from the pyxpcom core lib' - which changes
// spelling depending on whether pyxpcom is being built or just referenced.
#ifdef BUILD_PYXPCOM