Serhiy Storchaka | 18b250f | 2017-03-19 08:51:07 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(complex_new__doc__, |
| 6 | "complex(real=0, imag=0)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Create a complex number from a real part and an optional imaginary part.\n" |
| 10 | "\n" |
| 11 | "This is equivalent to (real + imag*1j) where imag defaults to 0."); |
| 12 | |
| 13 | static PyObject * |
| 14 | complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i); |
| 15 | |
| 16 | static PyObject * |
| 17 | complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 18 | { |
| 19 | PyObject *return_value = NULL; |
| 20 | static const char * const _keywords[] = {"real", "imag", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 21 | static _PyArg_Parser _parser = {NULL, _keywords, "complex", 0}; |
| 22 | PyObject *argsbuf[2]; |
| 23 | PyObject * const *fastargs; |
| 24 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 25 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
Serhiy Storchaka | bae6881 | 2017-04-05 12:00:42 +0300 | [diff] [blame] | 26 | PyObject *r = _PyLong_Zero; |
Serhiy Storchaka | 18b250f | 2017-03-19 08:51:07 +0200 | [diff] [blame] | 27 | PyObject *i = NULL; |
| 28 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 29 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); |
| 30 | if (!fastargs) { |
Serhiy Storchaka | 18b250f | 2017-03-19 08:51:07 +0200 | [diff] [blame] | 31 | goto exit; |
| 32 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 33 | if (!noptargs) { |
| 34 | goto skip_optional_pos; |
| 35 | } |
| 36 | if (fastargs[0]) { |
| 37 | r = fastargs[0]; |
| 38 | if (!--noptargs) { |
| 39 | goto skip_optional_pos; |
| 40 | } |
| 41 | } |
| 42 | i = fastargs[1]; |
| 43 | skip_optional_pos: |
Serhiy Storchaka | 18b250f | 2017-03-19 08:51:07 +0200 | [diff] [blame] | 44 | return_value = complex_new_impl(type, r, i); |
| 45 | |
| 46 | exit: |
| 47 | return return_value; |
| 48 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 49 | /*[clinic end generated code: output=a0fe23fdbdc9b06b input=a9049054013a1b77]*/ |