vmarkovtsev / udt4py

libudt4 Python wrapper written with Cython

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Cannot convert 'sockaddr_in' to Python object

bchretien opened this issue · comments

While trying to compile udt4py on Arch Linux, I get:

$ python3 setup.py build_ext --inplace
missing cimport in module 'pair': /usr/lib/python3.3/site-packages/Cython/Includes/libcpp/set.pxd
Compiling src/udt4py.pyx because it changed.
Cythonizing src/udt4py.pyx

Error compiling Cython file:
------------------------------------------------------------
...
        memset(&addrv4, 0, sizeof(sockaddr_in))
        addrv4.sin_family = self._family
        addrv4.sin_port = htons(int(str_port))
        if inet_aton(str_host, &addrv4.sin_addr) == 0:
            raise ValueError("Could not parse IPv4 address \"%s\"" % str_host)
        return addrv4
                    ^
------------------------------------------------------------

src/udt4py.pyx:607:21: Cannot convert 'sockaddr_in' to Python object

etc.

In /usr/include/netinet/in.h, we indeed have:

/* Structure describing an Internet socket address.  */
struct sockaddr_in
  {
    __SOCKADDR_COMMON (sin_);
    in_port_t sin_port;         /* Port number.  */
    struct in_addr sin_addr;        /* Internet address.  */

    /* Pad to size of `struct sockaddr'.  */
    unsigned char sin_zero[sizeof (struct sockaddr) -
               __SOCKADDR_COMMON_SIZE -
               sizeof (in_port_t) -
               sizeof (struct in_addr)];
  };

which is reflected in udt4py.pyx:

cdef extern from "netinet/in.h":
    struct in_addr:
        uint32_t s_addr

    struct sockaddr_in:
        unsigned short int sin_family
        uint16_t sin_port
        in_addr sin_addr

    uint16_t htons(uint16_t)
    uint16_t ntohs(uint16_t)

    int AF_INET6
    int AF_INET

Could this be due to the missing padding? (cf. https://github.com/ironport/shrapnel/blob/master/coro/socket.pxd#L13)

$ python3 --version
Python 3.3.5
$ cython --version
Cython version 0.20.1

@vmarkovtsev thanks! The sockaddr_in errors disappeared, now there is one new error left:

Error compiling Cython file:
------------------------------------------------------------
...
        """
        UDTSocket.perfmon() call result. Corresponds to libudt4's
        UDT::TRACEINFO struct.
        """

        def __init__(self, _TRACEINFO ti):
                          ^
------------------------------------------------------------

src/udt4py.pyx:514:27: Cannot convert Python object argument to type '_TRACEINFO'

Indeed, Cython 0.20 fails to build the extension, whereas Cython 0.19 produces a perfectly valid binary. I am trying to fix it now.

I fixed all issues with Cython 0.20 in pypi-1.1 release.

@vmarkovtsev thanks, it works ;-)