Skip to content

Commit 000a072

Browse files
zitterbewegungambvErlend Egeberg Aaslanderlend-aaslandJelleZijlstra
authored
gh-92210: Move socket.__init__ to argument clinic (#92237)
Co-authored-by: Łukasz Langa <[email protected]> Co-authored-by: Erlend Egeberg Aasland <[email protected]> Co-authored-by: Erlend Egeberg Aasland <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 090819e commit 000a072

File tree

3 files changed

+92
-14
lines changed

3 files changed

+92
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Port ``socket.__init__`` to Argument Clinic. Patch by Cinder.

Modules/clinic/socketmodule.c.h

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/socketmodule.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ static FlagRuntimeInfo win_runtime_flags[] = {
328328
{14393, "TCP_FASTOPEN"}
329329
};
330330

331+
/*[clinic input]
332+
module _socket
333+
class _socket.socket "PySocketSockObject *" "&sock_type"
334+
[clinic start generated code]*/
335+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=7a8313d9b7f51988]*/
336+
331337
static int
332338
remove_unusable_flags(PyObject *m)
333339
{
@@ -511,6 +517,8 @@ remove_unusable_flags(PyObject *m)
511517
#define INADDR_NONE (-1)
512518
#endif
513519

520+
#include "clinic/socketmodule.c.h"
521+
514522
/* XXX There's a problem here: *static* functions are not supposed to have
515523
a Py prefix (or use CapitalizedWords). Later... */
516524

@@ -1708,7 +1716,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
17081716
}
17091717
addr->sun_family = s->sock_family;
17101718
memcpy(addr->sun_path, path.buf, path.len);
1711-
1719+
17121720
retval = 1;
17131721
unix_out:
17141722
PyBuffer_Release(&path);
@@ -5103,14 +5111,23 @@ static int sock_cloexec_works = -1;
51035111
#endif
51045112

51055113
/*ARGSUSED*/
5114+
5115+
/*[clinic input]
5116+
_socket.socket.__init__ as sock_initobj
5117+
family: int = -1
5118+
type: int = -1
5119+
proto: int = -1
5120+
fileno as fdobj: object = NULL
5121+
[clinic start generated code]*/
5122+
51065123
static int
5107-
sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
5124+
sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
5125+
PyObject *fdobj)
5126+
/*[clinic end generated code: output=d114d026b9a9a810 input=04cfc32953f5cc25]*/
51085127
{
5109-
PySocketSockObject *s = (PySocketSockObject *)self;
5110-
PyObject *fdobj = NULL;
5128+
51115129
SOCKET_T fd = INVALID_SOCKET;
5112-
int family = -1, type = -1, proto = -1;
5113-
static char *keywords[] = {"family", "type", "proto", "fileno", 0};
5130+
51145131
#ifndef MS_WINDOWS
51155132
#ifdef SOCK_CLOEXEC
51165133
int *atomic_flag_works = &sock_cloexec_works;
@@ -5119,18 +5136,13 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
51195136
#endif
51205137
#endif
51215138

5122-
if (!PyArg_ParseTupleAndKeywords(args, kwds,
5123-
"|iiiO:socket", keywords,
5124-
&family, &type, &proto, &fdobj))
5125-
return -1;
5126-
51275139
#ifdef MS_WINDOWS
51285140
/* In this case, we don't use the family, type and proto args */
51295141
if (fdobj == NULL || fdobj == Py_None)
51305142
#endif
51315143
{
51325144
if (PySys_Audit("socket.__new__", "Oiii",
5133-
s, family, type, proto) < 0) {
5145+
self, family, type, proto) < 0) {
51345146
return -1;
51355147
}
51365148
}
@@ -5148,7 +5160,7 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
51485160
}
51495161
memcpy(&info, PyBytes_AS_STRING(fdobj), sizeof(info));
51505162

5151-
if (PySys_Audit("socket.__new__", "Oiii", s,
5163+
if (PySys_Audit("socket.__new__", "Oiii", self,
51525164
info.iAddressFamily, info.iSocketType,
51535165
info.iProtocol) < 0) {
51545166
return -1;
@@ -5318,7 +5330,7 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
53185330
}
53195331
#endif
53205332
}
5321-
if (init_sockobject(s, fd, family, type, proto) == -1) {
5333+
if (init_sockobject(self, fd, family, type, proto) == -1) {
53225334
SOCKETCLOSE(fd);
53235335
return -1;
53245336
}

0 commit comments

Comments
 (0)