unix/modsocket: Use type-checking mp_obj_get_int.

MP_OBJ_SMALL_INT_VALUE would give erroneous results, such as assertion
failures in the coverage build and other oddities like:

    >>> s = socket.socket()
    >>> s.recv(3.14)
    MemoryError: memory allocation failed, allocating 4235896656 bytes

Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
Jeff Epler
2025-08-03 10:11:49 -05:00
committed by Damien George
parent 6d640a15ab
commit e9da4c9c98
2 changed files with 37 additions and 18 deletions

View File

@@ -0,0 +1,22 @@
# Test passing in bad values to socket.socket constructor.
try:
import socket
except:
print("SKIP")
raise SystemExit
try:
s = socket.socket(None)
except TypeError:
print("TypeError")
try:
s = socket.socket(socket.AF_INET, None)
except TypeError:
print("TypeError")
try:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, None)
except TypeError:
print("TypeError")