Skip to content

Commit b1f28f5

Browse files
committed
clinic argument for socket.ntohl
1 parent a533180 commit b1f28f5

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

Modules/clinic/socketmodule.c.h

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/socketmodule.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6360,15 +6360,18 @@ _socket_socket_ntohs_impl(PySocketSockObject *self, int x)
63606360
}
63616361

63626362

6363+
/*[clinic input]
6364+
_socket.socket.ntohl
6365+
x: unsigned_long(bitwise=True)
6366+
/
6367+
6368+
Convert a 32-bit integer from network to host byte order.
6369+
[clinic start generated code]*/
6370+
63636371
static PyObject *
6364-
socket_ntohl(PyObject *self, PyObject *arg)
6372+
_socket_socket_ntohl_impl(PySocketSockObject *self, unsigned long x)
6373+
/*[clinic end generated code: output=88e46cad3e45c65c input=02a9a0c0ad14a079]*/
63656374
{
6366-
unsigned long x;
6367-
6368-
if (PyLong_Check(arg)) {
6369-
x = PyLong_AsUnsignedLong(arg);
6370-
if (x == (unsigned long) -1 && PyErr_Occurred())
6371-
return NULL;
63726375
#if SIZEOF_LONG > 4
63736376
{
63746377
unsigned long y;
@@ -6380,19 +6383,9 @@ socket_ntohl(PyObject *self, PyObject *arg)
63806383
x = y;
63816384
}
63826385
#endif
6383-
}
6384-
else
6385-
return PyErr_Format(PyExc_TypeError,
6386-
"expected int, %s found",
6387-
Py_TYPE(arg)->tp_name);
63886386
return PyLong_FromUnsignedLong(ntohl(x));
63896387
}
63906388

6391-
PyDoc_STRVAR(ntohl_doc,
6392-
"ntohl(integer) -> integer\n\
6393-
\n\
6394-
Convert a 32-bit integer from network to host byte order.");
6395-
63966389

63976390
/*[clinic input]
63986391
_socket.socket.htons
@@ -7212,8 +7205,7 @@ static PyMethodDef socket_methods[] = {
72127205
METH_VARARGS, socketpair_doc},
72137206
#endif
72147207
_SOCKET_SOCKET_NTOHS_METHODDEF
7215-
{"ntohl", socket_ntohl,
7216-
METH_O, ntohl_doc},
7208+
_SOCKET_SOCKET_NTOHL_METHODDEF
72177209
_SOCKET_SOCKET_HTONS_METHODDEF
72187210
{"htonl", socket_htonl,
72197211
METH_O, htonl_doc},

0 commit comments

Comments
 (0)