8000 clinic argument for socket.htonl · wrongnull/cpython@387725b · GitHub
[go: up one dir, main page]

Skip to content

Commit 387725b

Browse files
committed
clinic argument for socket.htonl
1 parent b1f28f5 commit 387725b

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
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: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6415,15 +6415,18 @@ _socket_socket_htons_impl(PySocketSockObject *self, int x)
64156415
}
64166416

64176417

6418+
/*[clinic input]
6419+
_socket.socket.htonl
6420+
x: unsigned_long(bitwise=True)
6421+
/
6422+
6423+
Convert a 32-bit integer from host to network byte order.
6424+
[clinic start generated code]*/
6425+
64186426
static PyObject *
6419-
socket_htonl(PyObject *self, PyObject *arg)
6427+
_socket_socket_htonl_impl(PySocketSockObject *self, unsigned long x)
6428+
/*[clinic end generated code: output=04a88551f090913e input=e356f217ac56bef5]*/
64206429
{
6421-
unsigned long x;
6422-
6423-
if (PyLong_Check(arg)) {
6424-
x = PyLong_AsUnsignedLong(arg);
6425-
if (x == (unsigned long) -1 && PyErr_Occurred())
6426-
return NULL;
64276430
#if SIZEOF_LONG > 4
64286431
{
64296432
unsigned long y;
@@ -6435,19 +6438,9 @@ socket_htonl(PyObject *self, PyObject *arg)
64356438
x = y;
64366439
}
64376440
#endif
6438-
}
6439-
else
6440-
return PyErr_Format(PyExc_TypeError,
6441-
"expected int, %s found",
6442-
Py_TYPE(arg)->tp_name);
6443-
return PyLong_FromUnsignedLong(htonl((unsigned long)x));
6441+
return PyLong_FromUnsignedLong(htonl(x));
6 8000 4446442
}
64456443

6446-
PyDoc_STRVAR(htonl_doc,
6447-
"htonl(integer) -> integer\n\
6448-
\n\
6449-
Convert a 32-bit integer from host to network byte order.");
6450-
64516444
/* socket.inet_aton() and socket.inet_ntoa() functions. */
64526445

64536446
/*[clinic input]
@@ -7207,8 +7200,7 @@ static PyMethodDef socket_methods[] = {
72077200
_SOCKET_SOCKET_NTOHS_METHODDEF
72087201
_SOCKET_SOCKET_NTOHL_METHODDEF
72097202
_SOCKET_SOCKET_HTONS_METHODDEF
7210-
{"htonl", socket_htonl,
7211-
METH_O, htonl_doc},
7203+
_SOCKET_SOCKET_HTONL_METHODDEF
72127204
_SOCKET_SOCKET_INET_ATON_METHODDEF
72137205
#ifdef HAVE_INET_NTOA
72147206
_SOCKET_SOCKET_INET_NTOA_METHODDEF

0 commit comments

Comments
 (0)
0