VirtualBox

Ignore:
Timestamp:
Sep 28, 2020 8:01:18 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140619
Message:

xpcom/python: Initial Py_LIMITED_API support. bugref:9840

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/src/PyGInputStream.cpp

    r11746 r86333  
    104104        nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "i", count);
    105105        if (NS_SUCCEEDED(nr)) {
    106 #ifndef VBOX /* unsafe cast on 64-bit hosts. */
     106#if 0 /* VBox: new buffer protocol (though I could use it for Py_LIMITED_API and ditch the warning, but cpython specific) */
     107                Py_buffer py_view;
     108                if (PyObject_GetBuffer(ret, &py_view, PyBUF_SIMPLE) == 0) {
     109                        if (py_view.len <= count) {
     110                                count = py_view.len;
     111                        } else {
     112                                PyXPCOM_LogWarning("nsIInputStream::read() was asked for %d bytes, but the string returned is %d bytes - truncating!\n", count, py_size);
     113                        }
     114                        memcpy(buf, py_view.py_buf, count);
     115                        PyBuffer_Release(&py_view);
     116                        *_retval = count;
     117                } else {
     118                        PyErr_Format(PyExc_TypeError, "nsIInputStream::read() method must return a buffer object - not a '%s' object", PyXPCOM_ObTypeName(ret));
     119                        nr = HandleNativeGatewayError(methodName);
     120                }
     121#else  /* Old protocol: */
     122# ifndef VBOX /* unsafe cast on 64-bit hosts. */
    107123                PRUint32 py_size;
    108124                const void *py_buf;
    109125                if (PyObject_AsReadBuffer(ret, &py_buf, (Py_ssize_t*)&py_size)!=0) {
    110 #else  /* VBOX */
     126# else  /* VBOX */
    111127                const void *py_buf;
    112 # if PY_VERSION_HEX >= 0x02050000 || defined(PY_SSIZE_T_MIN)
     128#  if PY_VERSION_HEX >= 0x02050000 || defined(PY_SSIZE_T_MIN)
    113129                Py_ssize_t py_size;
    114 # else
     130#  else
    115131                int py_size;
     132#  endif
     133                if (PyObject_AsReadBuffer(ret, &py_buf, &py_size)!=0) {
    116134# endif /* VBOX */
    117                 if (PyObject_AsReadBuffer(ret, &py_buf, &py_size)!=0) {
    118 #endif /* VBOX */
    119                         PyErr_Format(PyExc_TypeError, "nsIInputStream::read() method must return a buffer object - not a '%s' object", ret->ob_type->tp_name);
     135                        PyErr_Format(PyExc_TypeError, "nsIInputStream::read() method must return a buffer object - not a '%s' object", PyXPCOM_ObTypeName(ret));
    120136                        nr = HandleNativeGatewayError(methodName);
    121137                } else {
     
    127143                        *_retval = py_size;
    128144                }
     145#endif
    129146        }
    130147        return nr;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette