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