xref: /third_party/python/Modules/_testclinic.c (revision 7db96d56)
1#ifndef Py_BUILD_CORE_BUILTIN
2#  define Py_BUILD_CORE_MODULE 1
3#endif
4
5/* Always enable assertions */
6#undef NDEBUG
7
8#define PY_SSIZE_T_CLEAN
9
10#include "Python.h"
11
12#include "clinic/_testclinic.c.h"
13
14
15/* Pack arguments to a tuple, implicitly increase all the arguments' refcount.
16 * NULL arguments will be replaced to Py_None. */
17static PyObject *
18pack_arguments_newref(int argc, ...)
19{
20    assert(!PyErr_Occurred());
21    PyObject *tuple = PyTuple_New(argc);
22    if (!tuple) {
23        return NULL;
24    }
25
26    va_list vargs;
27    va_start(vargs, argc);
28    for (int i = 0; i < argc; i++) {
29        PyObject *arg = va_arg(vargs, PyObject *);
30        if (arg) {
31            if (_PyObject_IsFreed(arg)) {
32                PyErr_Format(PyExc_AssertionError,
33                             "argument %d at %p is freed or corrupted!",
34                             i, arg);
35                va_end(vargs);
36                Py_DECREF(tuple);
37                return NULL;
38            }
39        }
40        else {
41            arg = Py_None;
42        }
43        PyTuple_SET_ITEM(tuple, i, Py_NewRef(arg));
44    }
45    va_end(vargs);
46    return tuple;
47}
48
49/* Pack arguments to a tuple.
50 * `wrapper` is function which converts primitive type to PyObject.
51 * `arg_type` is type that arguments should be converted to before wrapped. */
52#define RETURN_PACKED_ARGS(argc, wrapper, arg_type, ...) do { \
53        assert(!PyErr_Occurred()); \
54        arg_type in[argc] = {__VA_ARGS__}; \
55        PyObject *out[argc] = {NULL,}; \
56        for (int _i = 0; _i < argc; _i++) { \
57            out[_i] = wrapper(in[_i]); \
58            assert(out[_i] || PyErr_Occurred()); \
59            if (!out[_i]) { \
60                for (int _j = 0; _j < _i; _j++) { \
61                    Py_DECREF(out[_j]); \
62                } \
63                return NULL; \
64            } \
65        } \
66        PyObject *tuple = PyTuple_New(argc); \
67        if (!tuple) { \
68            for (int _i = 0; _i < argc; _i++) { \
69                Py_DECREF(out[_i]); \
70            } \
71            return NULL; \
72        } \
73        for (int _i = 0; _i < argc; _i++) { \
74            PyTuple_SET_ITEM(tuple, _i, out[_i]); \
75        } \
76        return tuple; \
77    } while (0)
78
79
80/*[clinic input]
81module  _testclinic
82[clinic start generated code]*/
83/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d4981b80d6efdb12]*/
84
85
86/*[clinic input]
87test_empty_function
88
89[clinic start generated code]*/
90
91static PyObject *
92test_empty_function_impl(PyObject *module)
93/*[clinic end generated code: output=0f8aeb3ddced55cb input=0dd7048651ad4ae4]*/
94{
95    Py_RETURN_NONE;
96}
97
98
99/*[clinic input]
100objects_converter
101
102    a: object
103    b: object = NULL
104    /
105
106[clinic start generated code]*/
107
108static PyObject *
109objects_converter_impl(PyObject *module, PyObject *a, PyObject *b)
110/*[clinic end generated code: output=3f9c9415ec86c695 input=1533b1bd94187de4]*/
111{
112    return pack_arguments_newref(2, a, b);
113}
114
115
116/*[clinic input]
117bytes_object_converter
118
119    a: PyBytesObject
120    /
121
122[clinic start generated code]*/
123
124static PyObject *
125bytes_object_converter_impl(PyObject *module, PyBytesObject *a)
126/*[clinic end generated code: output=7732da869d74b784 input=94211751e7996236]*/
127{
128    if (!PyBytes_Check(a)) {
129        PyErr_SetString(PyExc_AssertionError,
130                        "argument a is not a PyBytesObject");
131        return NULL;
132    }
133    return pack_arguments_newref(1, a);
134}
135
136
137/*[clinic input]
138byte_array_object_converter
139
140    a: PyByteArrayObject
141    /
142
143[clinic start generated code]*/
144
145static PyObject *
146byte_array_object_converter_impl(PyObject *module, PyByteArrayObject *a)
147/*[clinic end generated code: output=51f15c76f302b1f7 input=b04d253db51c6f56]*/
148{
149    if (!PyByteArray_Check(a)) {
150        PyErr_SetString(PyExc_AssertionError,
151                        "argument a is not a PyByteArrayObject");
152        return NULL;
153    }
154    return pack_arguments_newref(1, a);
155}
156
157
158/*[clinic input]
159unicode_converter
160
161    a: unicode
162    /
163
164[clinic start generated code]*/
165
166static PyObject *
167unicode_converter_impl(PyObject *module, PyObject *a)
168/*[clinic end generated code: output=1b4a4adbb6ac6e34 input=de7b5adbf07435ba]*/
169{
170    if (!PyUnicode_Check(a)) {
171        PyErr_SetString(PyExc_AssertionError,
172                        "argument a is not a unicode object");
173        return NULL;
174    }
175    return pack_arguments_newref(1, a);
176}
177
178
179/*[clinic input]
180bool_converter
181
182    a: bool = True
183    b: bool(accept={object}) = True
184    c: bool(accept={int}) = True
185    /
186
187[clinic start generated code]*/
188
189static PyObject *
190bool_converter_impl(PyObject *module, int a, int b, int c)
191/*[clinic end generated code: output=17005b0c29afd590 input=7f6537705b2f32f4]*/
192{
193    PyObject *obj_a = a ? Py_True : Py_False;
194    PyObject *obj_b = b ? Py_True : Py_False;
195    PyObject *obj_c = c ? Py_True : Py_False;
196    return pack_arguments_newref(3, obj_a, obj_b, obj_c);
197}
198
199
200/*[clinic input]
201char_converter
202
203    a: char = b'A'
204    b: char = b'\a'
205    c: char = b'\b'
206    d: char = b'\t'
207    e: char = b'\n'
208    f: char = b'\v'
209    g: char = b'\f'
210    h: char = b'\r'
211    i: char = b'"'
212    j: char = b"'"
213    k: char = b'?'
214    l: char = b'\\'
215    m: char = b'\000'
216    n: char = b'\377'
217    /
218
219[clinic start generated code]*/
220
221static PyObject *
222char_converter_impl(PyObject *module, char a, char b, char c, char d, char e,
223                    char f, char g, char h, char i, char j, char k, char l,
224                    char m, char n)
225/*[clinic end generated code: output=f929dbd2e55a9871 input=b601bc5bc7fe85e3]*/
226{
227    RETURN_PACKED_ARGS(14, PyLong_FromUnsignedLong, unsigned char,
228                       a, b, c, d, e, f, g, h, i, j, k, l, m, n);
229}
230
231
232/*[clinic input]
233unsigned_char_converter
234
235    a: unsigned_char = 12
236    b: unsigned_char(bitwise=False) = 34
237    c: unsigned_char(bitwise=True) = 56
238    /
239
240[clinic start generated code]*/
241
242static PyObject *
243unsigned_char_converter_impl(PyObject *module, unsigned char a,
244                             unsigned char b, unsigned char c)
245/*[clinic end generated code: output=490af3b39ce0b199 input=e859502fbe0b3185]*/
246{
247    RETURN_PACKED_ARGS(3, PyLong_FromUnsignedLong, unsigned char, a, b, c);
248}
249
250
251/*[clinic input]
252short_converter
253
254    a: short = 12
255    /
256
257[clinic start generated code]*/
258
259static PyObject *
260short_converter_impl(PyObject *module, short a)
261/*[clinic end generated code: output=1ebb7ddb64248988 input=b4e2309a66f650ae]*/
262{
263    RETURN_PACKED_ARGS(1, PyLong_FromLong, long, a);
264}
265
266
267/*[clinic input]
268unsigned_short_converter
269
270    a: unsigned_short = 12
271    b: unsigned_short(bitwise=False) = 34
272    c: unsigned_short(bitwise=True) = 56
273    /
274
275[clinic start generated code]*/
276
277static PyObject *
278unsigned_short_converter_impl(PyObject *module, unsigned short a,
279                              unsigned short b, unsigned short c)
280/*[clinic end generated code: output=5f92cc72fc8707a7 input=9d15cd11e741d0c6]*/
281{
282    RETURN_PACKED_ARGS(3, PyLong_FromUnsignedLong, unsigned long, a, b, c);
283}
284
285
286/*[clinic input]
287int_converter
288
289    a: int = 12
290    b: int(accept={int}) = 34
291    c: int(accept={str}) = 45
292    /
293
294[clinic start generated code]*/
295
296static PyObject *
297int_converter_impl(PyObject *module, int a, int b, int c)
298/*[clinic end generated code: output=8e56b59be7d0c306 input=a1dbc6344853db7a]*/
299{
300    RETURN_PACKED_ARGS(3, PyLong_FromLong, long, a, b, c);
301}
302
303
304/*[clinic input]
305unsigned_int_converter
306
307    a: unsigned_int = 12
308    b: unsigned_int(bitwise=False) = 34
309    c: unsigned_int(bitwise=True) = 56
310    /
311
312[clinic start generated code]*/
313
314static PyObject *
315unsigned_int_converter_impl(PyObject *module, unsigned int a, unsigned int b,
316                            unsigned int c)
317/*[clinic end generated code: output=399a57a05c494cc7 input=8427ed9a3f96272d]*/
318{
319    RETURN_PACKED_ARGS(3, PyLong_FromUnsignedLong, unsigned long, a, b, c);
320}
321
322
323/*[clinic input]
324long_converter
325
326    a: long = 12
327    /
328
329[clinic start generated code]*/
330
331static PyObject *
332long_converter_impl(PyObject *module, long a)
333/*[clinic end generated code: output=9663d936a652707a input=84ad0ef28f24bd85]*/
334{
335    RETURN_PACKED_ARGS(1, PyLong_FromLong, long, a);
336}
337
338
339/*[clinic input]
340unsigned_long_converter
341
342    a: unsigned_long = 12
343    b: unsigned_long(bitwise=False) = 34
344    c: unsigned_long(bitwise=True) = 56
345    /
346
347[clinic start generated code]*/
348
349static PyObject *
350unsigned_long_converter_impl(PyObject *module, unsigned long a,
351                             unsigned long b, unsigned long c)
352/*[clinic end generated code: output=120b82ea9ebd93a8 input=440dd6f1817f5d91]*/
353{
354    RETURN_PACKED_ARGS(3, PyLong_FromUnsignedLong, unsigned long, a, b, c);
355}
356
357
358/*[clinic input]
359long_long_converter
360
361    a: long_long = 12
362    /
363
364[clinic start generated code]*/
365
366static PyObject *
367long_long_converter_impl(PyObject *module, long long a)
368/*[clinic end generated code: output=5fb5f2220770c3e1 input=730fcb3eecf4d993]*/
369{
370    RETURN_PACKED_ARGS(1, PyLong_FromLongLong, long long, a);
371}
372
373
374/*[clinic input]
375unsigned_long_long_converter
376
377    a: unsigned_long_long = 12
378    b: unsigned_long_long(bitwise=False) = 34
379    c: unsigned_long_long(bitwise=True) = 56
380    /
381
382[clinic start generated code]*/
383
384static PyObject *
385unsigned_long_long_converter_impl(PyObject *module, unsigned long long a,
386                                  unsigned long long b, unsigned long long c)
387/*[clinic end generated code: output=65b7273e63501762 input=300737b0bdb230e9]*/
388{
389    RETURN_PACKED_ARGS(3, PyLong_FromUnsignedLongLong, unsigned long long,
390                       a, b, c);
391}
392
393
394/*[clinic input]
395py_ssize_t_converter
396
397    a: Py_ssize_t = 12
398    b: Py_ssize_t(accept={int}) = 34
399    c: Py_ssize_t(accept={int, NoneType}) = 56
400    /
401
402[clinic start generated code]*/
403
404static PyObject *
405py_ssize_t_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b,
406                          Py_ssize_t c)
407/*[clinic end generated code: output=ce252143e0ed0372 input=76d0f342e9317a1f]*/
408{
409    RETURN_PACKED_ARGS(3, PyLong_FromSsize_t, Py_ssize_t, a, b, c);
410}
411
412
413/*[clinic input]
414slice_index_converter
415
416    a: slice_index = 12
417    b: slice_index(accept={int}) = 34
418    c: slice_index(accept={int, NoneType}) = 56
419    /
420
421[clinic start generated code]*/
422
423static PyObject *
424slice_index_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b,
425                           Py_ssize_t c)
426/*[clinic end generated code: output=923c6cac77666a6b input=64f99f3f83265e47]*/
427{
428    RETURN_PACKED_ARGS(3, PyLong_FromSsize_t, Py_ssize_t, a, b, c);
429}
430
431
432/*[clinic input]
433size_t_converter
434
435    a: size_t = 12
436    /
437
438[clinic start generated code]*/
439
440static PyObject *
441size_t_converter_impl(PyObject *module, size_t a)
442/*[clinic end generated code: output=412b5b7334ab444d input=83ae7d9171fbf208]*/
443{
444    RETURN_PACKED_ARGS(1, PyLong_FromSize_t, size_t, a);
445}
446
447
448/*[clinic input]
449float_converter
450
451    a: float = 12.5
452    /
453
454[clinic start generated code]*/
455
456static PyObject *
457float_converter_impl(PyObject *module, float a)
458/*[clinic end generated code: output=1c98f64f2cf1d55c input=a625b59ad68047d8]*/
459{
460    RETURN_PACKED_ARGS(1, PyFloat_FromDouble, double, a);
461}
462
463
464/*[clinic input]
465double_converter
466
467    a: double = 12.5
468    /
469
470[clinic start generated code]*/
471
472static PyObject *
473double_converter_impl(PyObject *module, double a)
474/*[clinic end generated code: output=a4e8532d284d035d input=098df188f24e7c62]*/
475{
476    RETURN_PACKED_ARGS(1, PyFloat_FromDouble, double, a);
477}
478
479
480/*[clinic input]
481py_complex_converter
482
483    a: Py_complex
484    /
485
486[clinic start generated code]*/
487
488static PyObject *
489py_complex_converter_impl(PyObject *module, Py_complex a)
490/*[clinic end generated code: output=9e6ca2eb53b14846 input=e9148a8ca1dbf195]*/
491{
492    RETURN_PACKED_ARGS(1, PyComplex_FromCComplex, Py_complex, a);
493}
494
495
496/*[clinic input]
497str_converter
498
499    a: str = "a"
500    b: str(accept={robuffer}) = "b"
501    c: str(accept={robuffer, str}, zeroes=True) = "c"
502    /
503
504[clinic start generated code]*/
505
506static PyObject *
507str_converter_impl(PyObject *module, const char *a, const char *b,
508                   const char *c, Py_ssize_t c_length)
509/*[clinic end generated code: output=475bea40548c8cd6 input=bff2656c92ee25de]*/
510{
511    assert(!PyErr_Occurred());
512    PyObject *out[3] = {NULL,};
513    int i = 0;
514    PyObject *arg;
515
516    arg = PyUnicode_FromString(a);
517    assert(arg || PyErr_Occurred());
518    if (!arg) {
519        goto error;
520    }
521    out[i++] = arg;
522
523    arg = PyUnicode_FromString(b);
524    assert(arg || PyErr_Occurred());
525    if (!arg) {
526        goto error;
527    }
528    out[i++] = arg;
529
530    arg = PyUnicode_FromStringAndSize(c, c_length);
531    assert(arg || PyErr_Occurred());
532    if (!arg) {
533        goto error;
534    }
535    out[i++] = arg;
536
537    PyObject *tuple = PyTuple_New(3);
538    if (!tuple) {
539        goto error;
540    }
541    for (int j = 0; j < 3; j++) {
542        PyTuple_SET_ITEM(tuple, j, out[j]);
543    }
544    return tuple;
545
546error:
547    for (int j = 0; j < i; j++) {
548        Py_DECREF(out[j]);
549    }
550    return NULL;
551}
552
553
554/*[clinic input]
555str_converter_encoding
556
557    a: str(encoding="idna")
558    b: str(encoding="idna", accept={bytes, bytearray, str})
559    c: str(encoding="idna", accept={bytes, bytearray, str}, zeroes=True)
560    /
561
562[clinic start generated code]*/
563
564static PyObject *
565str_converter_encoding_impl(PyObject *module, char *a, char *b, char *c,
566                            Py_ssize_t c_length)
567/*[clinic end generated code: output=af68766049248a1c input=0c5cf5159d0e870d]*/
568{
569    assert(!PyErr_Occurred());
570    PyObject *out[3] = {NULL,};
571    int i = 0;
572    PyObject *arg;
573
574    arg = PyUnicode_FromString(a);
575    assert(arg || PyErr_Occurred());
576    if (!arg) {
577        goto error;
578    }
579    out[i++] = arg;
580
581    arg = PyUnicode_FromString(b);
582    assert(arg || PyErr_Occurred());
583    if (!arg) {
584        goto error;
585    }
586    out[i++] = arg;
587
588    arg = PyUnicode_FromStringAndSize(c, c_length);
589    assert(arg || PyErr_Occurred());
590    if (!arg) {
591        goto error;
592    }
593    out[i++] = arg;
594
595    PyObject *tuple = PyTuple_New(3);
596    if (!tuple) {
597        goto error;
598    }
599    for (int j = 0; j < 3; j++) {
600        PyTuple_SET_ITEM(tuple, j, out[j]);
601    }
602    return tuple;
603
604error:
605    for (int j = 0; j < i; j++) {
606        Py_DECREF(out[j]);
607    }
608    return NULL;
609}
610
611
612static PyObject *
613bytes_from_buffer(Py_buffer *buf)
614{
615    PyObject *bytes_obj = PyBytes_FromStringAndSize(NULL, buf->len);
616    if (!bytes_obj) {
617        return NULL;
618    }
619    void *bytes_obj_buf = ((PyBytesObject *)bytes_obj)->ob_sval;
620    if (PyBuffer_ToContiguous(bytes_obj_buf, buf, buf->len, 'C') < 0) {
621        Py_DECREF(bytes_obj);
622        return NULL;
623    }
624    return bytes_obj;
625}
626
627/*[clinic input]
628py_buffer_converter
629
630    a: Py_buffer(accept={str, buffer, NoneType})
631    b: Py_buffer(accept={rwbuffer})
632    /
633
634[clinic start generated code]*/
635
636static PyObject *
637py_buffer_converter_impl(PyObject *module, Py_buffer *a, Py_buffer *b)
638/*[clinic end generated code: output=52fb13311e3d6d03 input=775de727de5c7421]*/
639{
640    RETURN_PACKED_ARGS(2, bytes_from_buffer, Py_buffer *, a, b);
641}
642
643
644/*[clinic input]
645keywords
646
647    a: object
648    b: object
649
650[clinic start generated code]*/
651
652static PyObject *
653keywords_impl(PyObject *module, PyObject *a, PyObject *b)
654/*[clinic end generated code: output=850aaed53e26729e input=f44b89e718c1a93b]*/
655{
656    return pack_arguments_newref(2, a, b);
657}
658
659
660/*[clinic input]
661keywords_kwonly
662
663    a: object
664    *
665    b: object
666
667[clinic start generated code]*/
668
669static PyObject *
670keywords_kwonly_impl(PyObject *module, PyObject *a, PyObject *b)
671/*[clinic end generated code: output=a45c48241da584dc input=1f08e39c3312b015]*/
672{
673    return pack_arguments_newref(2, a, b);
674}
675
676
677/*[clinic input]
678keywords_opt
679
680    a: object
681    b: object = None
682    c: object = None
683
684[clinic start generated code]*/
685
686static PyObject *
687keywords_opt_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c)
688/*[clinic end generated code: output=25e4b67d91c76a66 input=b0ba0e4f04904556]*/
689{
690    return pack_arguments_newref(3, a, b, c);
691}
692
693
694/*[clinic input]
695keywords_opt_kwonly
696
697    a: object
698    b: object = None
699    *
700    c: object = None
701    d: object = None
702
703[clinic start generated code]*/
704
705static PyObject *
706keywords_opt_kwonly_impl(PyObject *module, PyObject *a, PyObject *b,
707                         PyObject *c, PyObject *d)
708/*[clinic end generated code: output=6aa5b655a6e9aeb0 input=f79da689d6c51076]*/
709{
710    return pack_arguments_newref(4, a, b, c, d);
711}
712
713
714/*[clinic input]
715keywords_kwonly_opt
716
717    a: object
718    *
719    b: object = None
720    c: object = None
721
722[clinic start generated code]*/
723
724static PyObject *
725keywords_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
726                         PyObject *c)
727/*[clinic end generated code: output=707f78eb0f55c2b1 input=e0fa1a0e46dca791]*/
728{
729    return pack_arguments_newref(3, a, b, c);
730}
731
732
733/*[clinic input]
734posonly_keywords
735
736    a: object
737    /
738    b: object
739
740[clinic start generated code]*/
741
742static PyObject *
743posonly_keywords_impl(PyObject *module, PyObject *a, PyObject *b)
744/*[clinic end generated code: output=6ac88f4a5f0bfc8d input=fde0a2f79fe82b06]*/
745{
746    return pack_arguments_newref(2, a, b);
747}
748
749
750/*[clinic input]
751posonly_kwonly
752
753    a: object
754    /
755    *
756    b: object
757
758[clinic start generated code]*/
759
760static PyObject *
761posonly_kwonly_impl(PyObject *module, PyObject *a, PyObject *b)
762/*[clinic end generated code: output=483e6790d3482185 input=78b3712768da9a19]*/
763{
764    return pack_arguments_newref(2, a, b);
765}
766
767
768/*[clinic input]
769posonly_keywords_kwonly
770
771    a: object
772    /
773    b: object
774    *
775    c: object
776
777[clinic start generated code]*/
778
779static PyObject *
780posonly_keywords_kwonly_impl(PyObject *module, PyObject *a, PyObject *b,
781                             PyObject *c)
782/*[clinic end generated code: output=2fae573e8cc3fad8 input=a1ad5d2295eb803c]*/
783{
784    return pack_arguments_newref(3, a, b, c);
785}
786
787
788/*[clinic input]
789posonly_keywords_opt
790
791    a: object
792    /
793    b: object
794    c: object = None
795    d: object = None
796
797[clinic start generated code]*/
798
799static PyObject *
800posonly_keywords_opt_impl(PyObject *module, PyObject *a, PyObject *b,
801                          PyObject *c, PyObject *d)
802/*[clinic end generated code: output=f5eb66241bcf68fb input=51c10de2a120e279]*/
803{
804    return pack_arguments_newref(4, a, b, c, d);
805}
806
807
808/*[clinic input]
809posonly_opt_keywords_opt
810
811    a: object
812    b: object = None
813    /
814    c: object = None
815    d: object = None
816
817[clinic start generated code]*/
818
819static PyObject *
820posonly_opt_keywords_opt_impl(PyObject *module, PyObject *a, PyObject *b,
821                              PyObject *c, PyObject *d)
822/*[clinic end generated code: output=d54a30e549296ffd input=f408a1de7dfaf31f]*/
823{
824    return pack_arguments_newref(4, a, b, c, d);
825}
826
827
828/*[clinic input]
829posonly_kwonly_opt
830
831    a: object
832    /
833    *
834    b: object
835    c: object = None
836    d: object = None
837
838[clinic start generated code]*/
839
840static PyObject *
841posonly_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
842                        PyObject *c, PyObject *d)
843/*[clinic end generated code: output=a20503fe36b4fd62 input=3494253975272f52]*/
844{
845    return pack_arguments_newref(4, a, b, c, d);
846}
847
848
849/*[clinic input]
850posonly_opt_kwonly_opt
851
852    a: object
853    b: object = None
854    /
855    *
856    c: object = None
857    d: object = None
858
859[clinic start generated code]*/
860
861static PyObject *
862posonly_opt_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
863                            PyObject *c, PyObject *d)
864/*[clinic end generated code: output=64f3204a3a0413b6 input=d17516581e478412]*/
865{
866    return pack_arguments_newref(4, a, b, c, d);
867}
868
869
870/*[clinic input]
871posonly_keywords_kwonly_opt
872
873    a: object
874    /
875    b: object
876    *
877    c: object
878    d: object = None
879    e: object = None
880
881[clinic start generated code]*/
882
883static PyObject *
884posonly_keywords_kwonly_opt_impl(PyObject *module, PyObject *a, PyObject *b,
885                                 PyObject *c, PyObject *d, PyObject *e)
886/*[clinic end generated code: output=dbd7e7ddd6257fa0 input=33529f29e97e5adb]*/
887{
888    return pack_arguments_newref(5, a, b, c, d, e);
889}
890
891
892/*[clinic input]
893posonly_keywords_opt_kwonly_opt
894
895    a: object
896    /
897    b: object
898    c: object = None
899    *
900    d: object = None
901    e: object = None
902
903[clinic start generated code]*/
904
905static PyObject *
906posonly_keywords_opt_kwonly_opt_impl(PyObject *module, PyObject *a,
907                                     PyObject *b, PyObject *c, PyObject *d,
908                                     PyObject *e)
909/*[clinic end generated code: output=775d12ae44653045 input=4d4cc62f11441301]*/
910{
911    return pack_arguments_newref(5, a, b, c, d, e);
912}
913
914
915/*[clinic input]
916posonly_opt_keywords_opt_kwonly_opt
917
918    a: object
919    b: object = None
920    /
921    c: object = None
922    *
923    d: object = None
924
925[clinic start generated code]*/
926
927static PyObject *
928posonly_opt_keywords_opt_kwonly_opt_impl(PyObject *module, PyObject *a,
929                                         PyObject *b, PyObject *c,
930                                         PyObject *d)
931/*[clinic end generated code: output=40c6dc422591eade input=3964960a68622431]*/
932{
933    return pack_arguments_newref(4, a, b, c, d);
934}
935
936
937/*[clinic input]
938keyword_only_parameter
939
940    *
941    a: object
942
943[clinic start generated code]*/
944
945static PyObject *
946keyword_only_parameter_impl(PyObject *module, PyObject *a)
947/*[clinic end generated code: output=c454b6ce98232787 input=8d2868b8d0b27bdb]*/
948{
949    return pack_arguments_newref(1, a);
950}
951
952
953/*[clinic input]
954posonly_vararg
955
956    a: object
957    /
958    b: object
959    *args: object
960
961[clinic start generated code]*/
962
963static PyObject *
964posonly_vararg_impl(PyObject *module, PyObject *a, PyObject *b,
965                    PyObject *args)
966/*[clinic end generated code: output=ee6713acda6b954e input=783427fe7ec2b67a]*/
967{
968    return pack_arguments_newref(3, a, b, args);
969}
970
971
972/*[clinic input]
973vararg_and_posonly
974
975    a: object
976    *args: object
977    /
978
979[clinic start generated code]*/
980
981static PyObject *
982vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
983/*[clinic end generated code: output=42792f799465a14d input=defe017b19ba52e8]*/
984{
985    return pack_arguments_newref(2, a, args);
986}
987
988
989/*[clinic input]
990vararg
991
992    a: object
993    *args: object
994
995[clinic start generated code]*/
996
997static PyObject *
998vararg_impl(PyObject *module, PyObject *a, PyObject *args)
999/*[clinic end generated code: output=91ab7a0efc52dd5e input=02c0f772d05f591e]*/
1000{
1001    return pack_arguments_newref(2, a, args);
1002}
1003
1004
1005/*[clinic input]
1006vararg_with_default
1007
1008    a: object
1009    *args: object
1010    b: bool = False
1011
1012[clinic start generated code]*/
1013
1014static PyObject *
1015vararg_with_default_impl(PyObject *module, PyObject *a, PyObject *args,
1016                         int b)
1017/*[clinic end generated code: output=182c01035958ce92 input=68cafa6a79f89e36]*/
1018{
1019    PyObject *obj_b = b ? Py_True : Py_False;
1020    return pack_arguments_newref(3, a, args, obj_b);
1021}
1022
1023
1024/*[clinic input]
1025vararg_with_only_defaults
1026
1027    *args: object
1028    b: object = None
1029
1030[clinic start generated code]*/
1031
1032static PyObject *
1033vararg_with_only_defaults_impl(PyObject *module, PyObject *args, PyObject *b)
1034/*[clinic end generated code: output=c06b1826d91f2f7b input=678c069bc67550e1]*/
1035{
1036    return pack_arguments_newref(2, args, b);
1037}
1038
1039
1040
1041/*[clinic input]
1042gh_32092_oob
1043
1044    pos1: object
1045    pos2: object
1046    *varargs: object
1047    kw1: object = None
1048    kw2: object = None
1049
1050Proof-of-concept of GH-32092 OOB bug.
1051
1052[clinic start generated code]*/
1053
1054static PyObject *
1055gh_32092_oob_impl(PyObject *module, PyObject *pos1, PyObject *pos2,
1056                  PyObject *varargs, PyObject *kw1, PyObject *kw2)
1057/*[clinic end generated code: output=ee259c130054653f input=46d15c881608f8ff]*/
1058{
1059    Py_RETURN_NONE;
1060}
1061
1062
1063/*[clinic input]
1064gh_32092_kw_pass
1065
1066    pos: object
1067    *args: object
1068    kw: object = None
1069
1070Proof-of-concept of GH-32092 keyword args passing bug.
1071
1072[clinic start generated code]*/
1073
1074static PyObject *
1075gh_32092_kw_pass_impl(PyObject *module, PyObject *pos, PyObject *args,
1076                      PyObject *kw)
1077/*[clinic end generated code: output=4a2bbe4f7c8604e9 input=5c0bd5b9079a0cce]*/
1078{
1079    Py_RETURN_NONE;
1080}
1081
1082
1083/*[clinic input]
1084gh_99233_refcount
1085
1086    *args: object
1087    /
1088
1089Proof-of-concept of GH-99233 refcount error bug.
1090
1091[clinic start generated code]*/
1092
1093static PyObject *
1094gh_99233_refcount_impl(PyObject *module, PyObject *args)
1095/*[clinic end generated code: output=585855abfbca9a7f input=85f5fb47ac91a626]*/
1096{
1097    Py_RETURN_NONE;
1098}
1099
1100
1101/*[clinic input]
1102gh_99240_double_free
1103
1104    a: str(encoding="idna")
1105    b: str(encoding="idna")
1106    /
1107
1108Proof-of-concept of GH-99240 double-free bug.
1109
1110[clinic start generated code]*/
1111
1112static PyObject *
1113gh_99240_double_free_impl(PyObject *module, char *a, char *b)
1114/*[clinic end generated code: output=586dc714992fe2ed input=23db44aa91870fc7]*/
1115{
1116    Py_RETURN_NONE;
1117}
1118
1119
1120static PyMethodDef tester_methods[] = {
1121    TEST_EMPTY_FUNCTION_METHODDEF
1122    OBJECTS_CONVERTER_METHODDEF
1123    BYTES_OBJECT_CONVERTER_METHODDEF
1124    BYTE_ARRAY_OBJECT_CONVERTER_METHODDEF
1125    UNICODE_CONVERTER_METHODDEF
1126    BOOL_CONVERTER_METHODDEF
1127    CHAR_CONVERTER_METHODDEF
1128    UNSIGNED_CHAR_CONVERTER_METHODDEF
1129    SHORT_CONVERTER_METHODDEF
1130    UNSIGNED_SHORT_CONVERTER_METHODDEF
1131    INT_CONVERTER_METHODDEF
1132    UNSIGNED_INT_CONVERTER_METHODDEF
1133    LONG_CONVERTER_METHODDEF
1134    UNSIGNED_LONG_CONVERTER_METHODDEF
1135    LONG_LONG_CONVERTER_METHODDEF
1136    UNSIGNED_LONG_LONG_CONVERTER_METHODDEF
1137    PY_SSIZE_T_CONVERTER_METHODDEF
1138    SLICE_INDEX_CONVERTER_METHODDEF
1139    SIZE_T_CONVERTER_METHODDEF
1140    FLOAT_CONVERTER_METHODDEF
1141    DOUBLE_CONVERTER_METHODDEF
1142    PY_COMPLEX_CONVERTER_METHODDEF
1143    STR_CONVERTER_METHODDEF
1144    STR_CONVERTER_ENCODING_METHODDEF
1145    PY_BUFFER_CONVERTER_METHODDEF
1146    KEYWORDS_METHODDEF
1147    KEYWORDS_KWONLY_METHODDEF
1148    KEYWORDS_OPT_METHODDEF
1149    KEYWORDS_OPT_KWONLY_METHODDEF
1150    KEYWORDS_KWONLY_OPT_METHODDEF
1151    POSONLY_KEYWORDS_METHODDEF
1152    POSONLY_KWONLY_METHODDEF
1153    POSONLY_KEYWORDS_KWONLY_METHODDEF
1154    POSONLY_KEYWORDS_OPT_METHODDEF
1155    POSONLY_OPT_KEYWORDS_OPT_METHODDEF
1156    POSONLY_KWONLY_OPT_METHODDEF
1157    POSONLY_OPT_KWONLY_OPT_METHODDEF
1158    POSONLY_KEYWORDS_KWONLY_OPT_METHODDEF
1159    POSONLY_KEYWORDS_OPT_KWONLY_OPT_METHODDEF
1160    POSONLY_OPT_KEYWORDS_OPT_KWONLY_OPT_METHODDEF
1161    KEYWORD_ONLY_PARAMETER_METHODDEF
1162    POSONLY_VARARG_METHODDEF
1163    VARARG_AND_POSONLY_METHODDEF
1164    VARARG_METHODDEF
1165    VARARG_WITH_DEFAULT_METHODDEF
1166    VARARG_WITH_ONLY_DEFAULTS_METHODDEF
1167    GH_32092_OOB_METHODDEF
1168    GH_32092_KW_PASS_METHODDEF
1169    GH_99233_REFCOUNT_METHODDEF
1170    GH_99240_DOUBLE_FREE_METHODDEF
1171    {NULL, NULL}
1172};
1173
1174static struct PyModuleDef _testclinic_module = {
1175    PyModuleDef_HEAD_INIT,
1176    .m_name = "_testclinic",
1177    .m_size = 0,
1178    .m_methods = tester_methods,
1179};
1180
1181PyMODINIT_FUNC
1182PyInit__testclinic(void)
1183{
1184    return PyModule_Create(&_testclinic_module);
1185}
1186
1187#undef RETURN_PACKED_ARGS
1188