Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/socketmodule.h

    r2 r388  
    1818/* VC6 is shipped with old platform headers, and does not have MSTcpIP.h
    1919 * Separate SDKs have all the functions we want, but older ones don't have
    20  * any version information. 
     20 * any version information.
    2121 * I use SIO_GET_MULTICAST_FILTER to detect a decent SDK.
    2222 */
     
    7777
    7878/* Python module and C API name */
    79 #define PySocket_MODULE_NAME    "_socket"
    80 #define PySocket_CAPI_NAME      "CAPI"
     79#define PySocket_MODULE_NAME    "_socket"
     80#define PySocket_CAPI_NAME      "CAPI"
     81#define PySocket_CAPSULE_NAME  (PySocket_MODULE_NAME "." PySocket_CAPI_NAME)
    8182
    8283/* Abstract the socket file descriptor type */
    8384#ifdef MS_WINDOWS
    8485typedef SOCKET SOCKET_T;
    85 #       ifdef MS_WIN64
    86 #               define SIZEOF_SOCKET_T 8
    87 #       else
    88 #               define SIZEOF_SOCKET_T 4
    89 #       endif
     86#       ifdef MS_WIN64
     87#               define SIZEOF_SOCKET_T 8
     88#       else
     89#               define SIZEOF_SOCKET_T 4
     90#       endif
    9091#else
    9192typedef int SOCKET_T;
    92 #       define SIZEOF_SOCKET_T SIZEOF_INT
     93#       define SIZEOF_SOCKET_T SIZEOF_INT
    9394#endif
    9495
    9596/* Socket address */
    9697typedef union sock_addr {
    97         struct sockaddr_in in;
     98    struct sockaddr_in in;
    9899#ifdef AF_UNIX
    99         struct sockaddr_un un;
     100    struct sockaddr_un un;
    100101#endif
    101102#ifdef AF_NETLINK
    102         struct sockaddr_nl nl;
     103    struct sockaddr_nl nl;
    103104#endif
    104105#ifdef ENABLE_IPV6
    105         struct sockaddr_in6 in6;
    106         struct sockaddr_storage storage;
     106    struct sockaddr_in6 in6;
     107    struct sockaddr_storage storage;
    107108#endif
    108109#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    109         struct sockaddr_l2 bt_l2;
    110         struct sockaddr_rc bt_rc;
    111         struct sockaddr_sco bt_sco;
    112         struct sockaddr_hci bt_hci;
     110    struct sockaddr_l2 bt_l2;
     111    struct sockaddr_rc bt_rc;
     112    struct sockaddr_sco bt_sco;
     113    struct sockaddr_hci bt_hci;
    113114#endif
    114115#ifdef HAVE_NETPACKET_PACKET_H
    115         struct sockaddr_ll ll;
     116    struct sockaddr_ll ll;
    116117#endif
    117118} sock_addr_t;
     
    122123
    123124typedef struct {
    124         PyObject_HEAD
    125         SOCKET_T sock_fd;       /* Socket file descriptor */
    126         int sock_family;        /* Address family, e.g., AF_INET */
    127         int sock_type;          /* Socket type, e.g., SOCK_STREAM */
    128         int sock_proto;         /* Protocol type, usually 0 */
    129         PyObject *(*errorhandler)(void); /* Error handler; checks
    130                                             errno, returns NULL and
    131                                             sets a Python exception */
    132         double sock_timeout;            /* Operation timeout in seconds;
    133                                             0.0 means non-blocking */
     125    PyObject_HEAD
     126    SOCKET_T sock_fd;           /* Socket file descriptor */
     127    int sock_family;            /* Address family, e.g., AF_INET */
     128    int sock_type;              /* Socket type, e.g., SOCK_STREAM */
     129    int sock_proto;             /* Protocol type, usually 0 */
     130    PyObject *(*errorhandler)(void); /* Error handler; checks
     131                                        errno, returns NULL and
     132                                        sets a Python exception */
     133    double sock_timeout;                /* Operation timeout in seconds;
     134                                        0.0 means non-blocking */
    134135} PySocketSockObject;
    135136
     
    139140   and how it works:
    140141
    141     The _ssl module needs access to the type object defined in 
     142    The _ssl module needs access to the type object defined in
    142143    the _socket module. Since cross-DLL linking introduces a lot of
    143144    problems on many platforms, the "trick" is to wrap the
    144145    C API of a module in a struct which then gets exported to
    145     other modules via a PyCObject.
     146    other modules via a PyCapsule.
    146147
    147148    The code in socketmodule.c defines this struct (which currently
    148149    only contains the type object reference, but could very
    149150    well also include other C APIs needed by other modules)
    150     and exports it as PyCObject via the module dictionary
     151    and exports it as PyCapsule via the module dictionary
    151152    under the name "CAPI".
    152153
     
    161162    Load _socket module and its C API; this sets up the global
    162163    PySocketModule:
    163    
    164         if (PySocketModule_ImportModuleAndAPI())
    165             return;
     164
     165    if (PySocketModule_ImportModuleAndAPI())
     166        return;
    166167
    167168
     
    169170    module:
    170171
    171         if (!PyArg_ParseTuple(args, "O!|zz:ssl",
    172 
    173                               PySocketModule.Sock_Type,
    174 
    175                               (PyObject*)&Sock,
    176                               &key_file, &cert_file))
    177             return NULL;
     172    if (!PyArg_ParseTuple(args, "O!|zz:ssl",
     173
     174                          PySocketModule.Sock_Type,
     175
     176                          (PyObject*)&Sock,
     177                          &key_file, &cert_file))
     178        return NULL;
    178179
    179180    Support could easily be extended to export more C APIs/symbols
    180     this way. Currently, only the type object is exported, 
     181    this way. Currently, only the type object is exported,
    181182    other candidates would be socket constructors and socket
    182183    access functions.
     
    186187/* C API for usage by other Python modules */
    187188typedef struct {
    188         PyTypeObject *Sock_Type;
    189         PyObject *error;
     189    PyTypeObject *Sock_Type;
     190    PyObject *error;
    190191} PySocketModule_APIObject;
    191192
    192193/* XXX The net effect of the following appears to be to define a function
    193194   XXX named PySocketModule_APIObject in _ssl.c.  It's unclear why it isn't
    194    XXX defined there directly. 
     195   XXX defined there directly.
    195196
    196197   >>> It's defined here because other modules might also want to use
     
    208209   if (!PyArg_ParseTuple(args, "O!|zz:ssl",
    209210                         &PySocketModule.Sock_Type, (PyObject*)&Sock,
    210                         &key_file, &cert_file))
    211          return NULL;
     211                        &key_file, &cert_file))
     212     return NULL;
    212213   ...
    213214*/
     
    227228int PySocketModule_ImportModuleAndAPI(void)
    228229{
    229         PyObject *mod = 0, *v = 0;
    230         char *apimodule = PySocket_MODULE_NAME;
    231         char *apiname = PySocket_CAPI_NAME;
    232         void *api;
    233 
    234         DPRINTF("Importing the %s C API...\n", apimodule);
    235         mod = PyImport_ImportModuleNoBlock(apimodule);
    236         if (mod == NULL)
    237                 goto onError;
    238         DPRINTF(" %s package found\n", apimodule);
    239         v = PyObject_GetAttrString(mod, apiname);
    240         if (v == NULL)
    241                 goto onError;
    242         Py_DECREF(mod);
    243         DPRINTF(" API object %s found\n", apiname);
    244         api = PyCObject_AsVoidPtr(v);
    245         if (api == NULL)
    246                 goto onError;
    247         Py_DECREF(v);
    248         memcpy(&PySocketModule, api, sizeof(PySocketModule));
    249         DPRINTF(" API object loaded and initialized.\n");
    250         return 0;
     230    void *api;
     231
     232  DPRINTF(" Loading capsule %s\n", PySocket_CAPSULE_NAME);
     233  api = PyCapsule_Import(PySocket_CAPSULE_NAME, 1);
     234    if (api == NULL)
     235        goto onError;
     236    memcpy(&PySocketModule, api, sizeof(PySocketModule));
     237    DPRINTF(" API object loaded and initialized.\n");
     238    return 0;
    251239
    252240 onError:
    253         DPRINTF(" not found.\n");
    254         Py_XDECREF(mod);
    255         Py_XDECREF(v);
    256         return -1;
     241    DPRINTF(" not found.\n");
     242    return -1;
    257243}
    258244
Note: See TracChangeset for help on using the changeset viewer.