tonysimpson / nanomsg-python

nanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy
MIT License
382 stars 85 forks source link

Socket options should be integer, not long #69

Closed wtfuzz closed 3 years ago

wtfuzz commented 5 years ago

Using anaconda3 Python 3.7 on OSX at least, the 'l' format using pack produces a 64bit result. The nanomsg C API callsnn_[set|get]sockopt() expect a pointer to an int according to the documentation.

Python 3.7.0 (default, Jun 28 2018, 07:39:16)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from struct import *
>>> pack('l', 1)
b'\x01\x00\x00\x00\x00\x00\x00\x00'
>>> pack('i', 1)
b'\x01\x00\x00\x00'
>>>

We can verify that int is in fact 4 bytes using the default clang compilter on OSX:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  printf("%lu\n", sizeof(int));
  return EXIT_SUCCESS;
}
$ gcc -o test test.c
$ ./test
4
radiocane commented 5 years ago

Yes, pulling this would fix the bug introduced in commit:aed1521for #64

physercoe commented 5 years ago

Yes, after fix it the set_int_option works, otherswise it raise NanoMsgAPIError()