gh-111178: Fix function signatures for test_socket (#131667)

Add unicode_fsdecode() wrapper for PyUnicode_DecodeFSDefault() to use
the correct API for Py_BuildValue() converter API.
This commit is contained in:
Victor Stinner 2025-03-24 15:51:32 +01:00 committed by GitHub
parent 4efe397d8e
commit 69e94e0a1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1380,6 +1380,11 @@ makebdaddr(bdaddr_t *bdaddr)
} }
#endif #endif
PyObject*
unicode_fsdecode(void *arg)
{
return PyUnicode_DecodeFSDefault((const char*)arg);
}
/* Create an object representing the given socket address, /* Create an object representing the given socket address,
suitable for passing it back to bind(), connect() etc. suitable for passing it back to bind(), connect() etc.
@ -1616,26 +1621,25 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
#ifdef CAN_ISOTP #ifdef CAN_ISOTP
case CAN_ISOTP: case CAN_ISOTP:
{ {
return Py_BuildValue("O&kk", PyUnicode_DecodeFSDefault, return Py_BuildValue("O&kk", unicode_fsdecode,
ifname, ifname,
a->can_addr.tp.rx_id, a->can_addr.tp.rx_id,
a->can_addr.tp.tx_id); a->can_addr.tp.tx_id);
} }
#endif /* CAN_ISOTP */ #endif /* CAN_ISOTP */
#ifdef CAN_J1939 #ifdef CAN_J1939
case CAN_J1939: case CAN_J1939:
{ {
return Py_BuildValue("O&KIB", PyUnicode_DecodeFSDefault, return Py_BuildValue("O&KIB", unicode_fsdecode,
ifname, ifname,
(unsigned long long)a->can_addr.j1939.name, (unsigned long long)a->can_addr.j1939.name,
(unsigned int)a->can_addr.j1939.pgn, (unsigned int)a->can_addr.j1939.pgn,
a->can_addr.j1939.addr); a->can_addr.j1939.addr);
} }
#endif /* CAN_J1939 */ #endif /* CAN_J1939 */
default: default:
{ {
return Py_BuildValue("(O&)", PyUnicode_DecodeFSDefault, return Py_BuildValue("(O&)", unicode_fsdecode, ifname);
ifname);
} }
} }
} }
@ -7161,7 +7165,7 @@ socket_if_nameindex(PyObject *self, PyObject *arg)
} }
#endif #endif
PyObject *ni_tuple = Py_BuildValue("IO&", PyObject *ni_tuple = Py_BuildValue("IO&",
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name); ni[i].if_index, unicode_fsdecode, ni[i].if_name);
if (ni_tuple == NULL || PyList_Append(list, ni_tuple) == -1) { if (ni_tuple == NULL || PyList_Append(list, ni_tuple) == -1) {
Py_XDECREF(ni_tuple); Py_XDECREF(ni_tuple);