-
-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
Describe the bug
I tried to listen with a host 127.0.0.1 but it turns out that socketify is listening to 0.0.0.0 instead, and the callback is having a mostly empty, sometimes random string as its host.
Tested with int port number without host, dict and AppListenOptions.
Desktop (please complete the following information):
- Device: MacBook Pro M1 Max (arm64)
- OS: macOS 15.3
- Version 0.0.31
- CPython 3.12.8
- cffi Version 1.17.1, 1.17.0, 1.16.0
Additional context
I'm feeling that it'd be either we are not using cffi in the right way, or there's some issues with the latest cffi.
A minimal reproducible example is here:
Python 3.12.8 (main, Jan 30 2025, 09:29:57) [Clang 16.0.0 (clang-1600.0.26.6)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.32.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import cffi
In [2]: ffi = cffi.FFI()
In [3]: ffi.cdef("""
...: typedef struct
...: {
...: int port;
...: const char *host;
...: int options;
...: } uws_app_listen_config_t;
...: """)
In [4]: native_options = ffi.new("uws_app_listen_config_t *")
In [5]: options = native_options[0]
In [6]: port = 3000
In [7]: host = "127.0.0.1"
In [8]: options.port = (
...: ffi.cast("int", port)
...: if isinstance(port, int)
...: else ffi.cast("int", 0)
...: )
In [9]: options.port
Out[9]: 3000
In [10]: options.host = (
...: ffi.new("char[]", host.encode("utf-8"))
...: )
In [11]: options.host
Out[11]: <cdata 'char *' 0x1259f6210>
In [12]: ffi.string(options.host).decode('utf-8')
Out[12]: ''
In [13]: foo = ffi.new("char[]", host.encode("utf-8"))
In [14]: foo
Out[14]: <cdata 'char[]' owning 10 bytes>
In [15]: options.host = foo
In [16]: options.host
Out[16]: <cdata 'char *' 0x145a34da0>
In [17]: ffi.string(options.host).decode('utf-8')
Out[17]: '127.0.0.1'Linked to: python-cffi/cffi#155
Metadata
Metadata
Assignees
Labels
No labels