10000 gh-111662: Update socket module to use AC for optimizing performance by wrongnull · Pull Request #111661 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111662: Update socket module to use AC for optimizing performance #111661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clinic argument for socket.htons
  • Loading branch information
wrongnull committed Nov 3, 2023
commit 0f3ca4740e3604fd9847ef1ccf04a2d6602b4394
30 changes: 29 additions & 1 deletion Modules/clinic/socketmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 11 additions & 21 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6395,22 +6395,18 @@ PyDoc_STRVAR(ntohl_doc,
Convert a 32-bit integer from network to host byte order.");


static PyObject *
socket_htons(PyObject *self, PyObject *arg)
{
int x;

if (!PyLong_Check(arg)) {
return PyErr_Format(PyExc_TypeError,
"expected int, %s found",
Py_TYPE(arg)->tp_name);
}
/*[clinic input]
_socket.socket.htons
x: int
/

x = PyLong_AsInt(arg);
Convert a 16-bit unsigned integer from host to network byte order.
[clinic start generated code]*/

if (x == -1 && PyErr_Occurred()) {
return NULL;
}
static PyObject *
_socket_socket_htons_impl(PySocketSockObject *self, int x)
/*[clinic end generated code: output=d785ee692312da47 input=053252d8416f4337]*/
{
if (x < 0) {
PyErr_SetString(PyExc_OverflowError,
"htons: can't convert negative Python int to C "
Expand All @@ -6426,11 +6422,6 @@ socket_htons(PyObject *self, PyObject *arg)
return PyLong_FromUnsignedLong(htons((unsigned short)x));
}

PyDoc_STRVAR(htons_doc,
"htons(integer) -> integer\n\
\n\
Convert a 16-bit unsigned integer from host to network byte order.");


static PyObject *
socket_htonl(PyObject *self, PyObject *arg)
Expand Down Expand Up @@ -7227,8 +7218,7 @@ static PyMethodDef socket_methods[] = {
METH_VARARGS, ntohs_doc},
{"ntohl", socket_ntohl,
METH_O, ntohl_doc},
{"htons", socket_htons,
METH_O, htons_doc},
_SOCKET_SOCKET_HTONS_METHODDEF
{"htonl", socket_htonl,
METH_O, htonl_doc},
{"inet_aton", socket_inet_aton,
Expand Down
0