socketmodule.c.h 2.6 KB

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