1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9
10
11 static int
12 sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
13 PyObject *fdobj);
14
15 static int
16 sock_initobj(PyObject *self, PyObject *args, PyObject *kwargs)
17 {
18 int return_value = -1;
19 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
20
21 #define NUM_KEYWORDS 4
22 static struct {
23 PyGC_Head _this_is_not_used;
24 PyObject_VAR_HEAD
25 PyObject *ob_item[NUM_KEYWORDS];
26 } _kwtuple = {
27 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
28 .ob_item = { &_Py_ID(family), &_Py_ID(type), &_Py_ID(proto), &_Py_ID(fileno), },
29 };
30 #undef NUM_KEYWORDS
31 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
32
33 #else // !Py_BUILD_CORE
34 # define KWTUPLE NULL
35 #endif // !Py_BUILD_CORE
36
37 static const char * const _keywords[] = {"family", "type", "proto", "fileno", NULL};
38 static _PyArg_Parser _parser = {
39 .keywords = _keywords,
40 .fname = "socket",
41 .kwtuple = KWTUPLE,
42 };
43 #undef KWTUPLE
44 PyObject *argsbuf[4];
45 PyObject * const *fastargs;
46 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
47 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
48 int family = -1;
49 int type = -1;
50 int proto = -1;
51 PyObject *fdobj = NULL;
52
53 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 4, 0, argsbuf);
54 if (!fastargs) {
55 goto exit;
56 }
57 if (!noptargs) {
58 goto skip_optional_pos;
59 }
60 if (fastargs[0]) {
61 family = _PyLong_AsInt(fastargs[0]);
62 if (family == -1 && PyErr_Occurred()) {
63 goto exit;
64 }
65 if (!--noptargs) {
66 goto skip_optional_pos;
67 }
68 }
69 if (fastargs[1]) {
70 type = _PyLong_AsInt(fastargs[1]);
71 if (type == -1 && PyErr_Occurred()) {
72 goto exit;
73 }
74 if (!--noptargs) {
75 goto skip_optional_pos;
76 }
77 }
78 if (fastargs[2]) {
79 proto = _PyLong_AsInt(fastargs[2]);
80 if (proto == -1 && PyErr_Occurred()) {
81 goto exit;
82 }
83 if (!--noptargs) {
84 goto skip_optional_pos;
85 }
86 }
87 fdobj = fastargs[3];
88 skip_optional_pos:
89 return_value = sock_initobj_impl((PySocketSockObject *)self, family, type, proto, fdobj);
90
91 exit:
92 return return_value;
93 }
94 /*[clinic end generated code: output=987155ac4b48a198 input=a9049054013a1b77]*/