2 * C Extension module to test Python interpreter C APIs.
4 * The 'test_*' functions exported by this module are run as part of the
5 * standard Python regression test, via Lib/test/test_capi.py.
10 #include "structmember.h"
14 #endif /* WITH_THREAD */
15 static PyObject
*TestError
; /* set to exception object in init */
17 /* Raise TestError with test_name + ": " + msg, and return NULL. */
20 raiseTestError(const char* test_name
, const char* msg
)
24 if (strlen(test_name
) + strlen(msg
) > sizeof(buf
) - 50)
25 PyErr_SetString(TestError
, "internal error msg too large");
27 PyOS_snprintf(buf
, sizeof(buf
), "%s: %s", test_name
, msg
);
28 PyErr_SetString(TestError
, buf
);
33 /* Test #defines from pyconfig.h (particularly the SIZEOF_* defines).
35 The ones derived from autoconf on the UNIX-like OSes can be relied
36 upon (in the absence of sloppy cross-compiling), but the Windows
37 platforms have these hardcoded. Better safe than sorry.
40 sizeof_error(const char* fatname
, const char* typname
,
41 int expected
, int got
)
44 PyOS_snprintf(buf
, sizeof(buf
),
45 "%.200s #define == %d but sizeof(%.200s) == %d",
46 fatname
, expected
, typname
, got
);
47 PyErr_SetString(TestError
, buf
);
48 return (PyObject
*)NULL
;
52 test_config(PyObject
*self
)
54 #define CHECK_SIZEOF(FATNAME, TYPE) \
55 if (FATNAME != sizeof(TYPE)) \
56 return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
58 CHECK_SIZEOF(SIZEOF_SHORT
, short);
59 CHECK_SIZEOF(SIZEOF_INT
, int);
60 CHECK_SIZEOF(SIZEOF_LONG
, long);
61 CHECK_SIZEOF(SIZEOF_VOID_P
, void*);
62 CHECK_SIZEOF(SIZEOF_TIME_T
, time_t);
64 CHECK_SIZEOF(SIZEOF_LONG_LONG
, PY_LONG_LONG
);
74 test_list_api(PyObject
*self
)
79 /* SF bug 132008: PyList_Reverse segfaults */
81 list
= PyList_New(NLIST
);
82 if (list
== (PyObject
*)NULL
)
83 return (PyObject
*)NULL
;
84 /* list = range(NLIST) */
85 for (i
= 0; i
< NLIST
; ++i
) {
86 PyObject
* anint
= PyInt_FromLong(i
);
87 if (anint
== (PyObject
*)NULL
) {
89 return (PyObject
*)NULL
;
91 PyList_SET_ITEM(list
, i
, anint
);
93 /* list.reverse(), via PyList_Reverse() */
94 i
= PyList_Reverse(list
); /* should not blow up! */
97 return (PyObject
*)NULL
;
99 /* Check that list == range(29, -1, -1) now */
100 for (i
= 0; i
< NLIST
; ++i
) {
101 PyObject
* anint
= PyList_GET_ITEM(list
, i
);
102 if (PyInt_AS_LONG(anint
) != NLIST
-1-i
) {
103 PyErr_SetString(TestError
,
104 "test_list_api: reverse screwed up");
106 return (PyObject
*)NULL
;
117 test_dict_inner(int count
)
119 Py_ssize_t pos
= 0, iterations
= 0;
121 PyObject
*dict
= PyDict_New();
127 for (i
= 0; i
< count
; i
++) {
128 v
= PyInt_FromLong(i
);
129 PyDict_SetItem(dict
, v
, v
);
133 while (PyDict_Next(dict
, &pos
, &k
, &v
)) {
137 i
= PyInt_AS_LONG(v
) + 1;
138 o
= PyInt_FromLong(i
);
141 if (PyDict_SetItem(dict
, k
, o
) < 0) {
150 if (iterations
!= count
) {
153 "test_dict_iteration: dict iteration went wrong ");
161 test_dict_iteration(PyObject
* self
)
165 for (i
= 0; i
< 200; i
++) {
166 if (test_dict_inner(i
) < 0) {
176 /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG)
177 PyLong_{As, From}{Unsigned,}LongLong().
179 Note that the meat of the test is contained in testcapi_long.h.
180 This is revolting, but delicate code duplication is worse: "almost
181 exactly the same" code is needed to test PY_LONG_LONG, but the ubiquitous
182 dependence on type names makes it impossible to use a parameterized
183 function. A giant macro would be even worse than this. A C++ template
186 The "report an error" functions are deliberately not part of the #include
187 file: if the test fails, you can set a breakpoint in the appropriate
188 error function directly, and crawl back from there in the debugger.
191 #define UNBIND(X) Py_DECREF(X); (X) = NULL
194 raise_test_long_error(const char* msg
)
196 return raiseTestError("test_long_api", msg
);
199 #define TESTNAME test_long_api_inner
200 #define TYPENAME long
201 #define F_S_TO_PY PyLong_FromLong
202 #define F_PY_TO_S PyLong_AsLong
203 #define F_U_TO_PY PyLong_FromUnsignedLong
204 #define F_PY_TO_U PyLong_AsUnsignedLong
206 #include "testcapi_long.h"
209 test_long_api(PyObject
* self
)
211 return TESTNAME(raise_test_long_error
);
221 #ifdef HAVE_LONG_LONG
224 raise_test_longlong_error(const char* msg
)
226 return raiseTestError("test_longlong_api", msg
);
229 #define TESTNAME test_longlong_api_inner
230 #define TYPENAME PY_LONG_LONG
231 #define F_S_TO_PY PyLong_FromLongLong
232 #define F_PY_TO_S PyLong_AsLongLong
233 #define F_U_TO_PY PyLong_FromUnsignedLongLong
234 #define F_PY_TO_U PyLong_AsUnsignedLongLong
236 #include "testcapi_long.h"
239 test_longlong_api(PyObject
* self
, PyObject
*args
)
241 return TESTNAME(raise_test_longlong_error
);
251 /* Test the L code for PyArg_ParseTuple. This should deliver a PY_LONG_LONG
252 for both long and int arguments. The test may leak a little memory if
256 test_L_code(PyObject
*self
)
258 PyObject
*tuple
, *num
;
261 tuple
= PyTuple_New(1);
265 num
= PyLong_FromLong(42);
269 PyTuple_SET_ITEM(tuple
, 0, num
);
272 if (PyArg_ParseTuple(tuple
, "L:test_L_code", &value
) < 0)
275 return raiseTestError("test_L_code",
276 "L code returned wrong value for long 42");
279 num
= PyInt_FromLong(42);
283 PyTuple_SET_ITEM(tuple
, 0, num
);
286 if (PyArg_ParseTuple(tuple
, "L:test_L_code", &value
) < 0)
289 return raiseTestError("test_L_code",
290 "L code returned wrong value for int 42");
297 #endif /* ifdef HAVE_LONG_LONG */
299 /* Test tuple argument processing */
301 getargs_tuple(PyObject
*self
, PyObject
*args
)
304 if (!PyArg_ParseTuple(args
, "i(ii)", &a
, &b
, &c
))
306 return Py_BuildValue("iii", a
, b
, c
);
309 /* Functions to call PyArg_ParseTuple with integer format codes,
310 and return the result.
313 getargs_b(PyObject
*self
, PyObject
*args
)
316 if (!PyArg_ParseTuple(args
, "b", &value
))
318 return PyLong_FromUnsignedLong((unsigned long)value
);
322 getargs_B(PyObject
*self
, PyObject
*args
)
325 if (!PyArg_ParseTuple(args
, "B", &value
))
327 return PyLong_FromUnsignedLong((unsigned long)value
);
331 getargs_H(PyObject
*self
, PyObject
*args
)
333 unsigned short value
;
334 if (!PyArg_ParseTuple(args
, "H", &value
))
336 return PyLong_FromUnsignedLong((unsigned long)value
);
340 getargs_I(PyObject
*self
, PyObject
*args
)
343 if (!PyArg_ParseTuple(args
, "I", &value
))
345 return PyLong_FromUnsignedLong((unsigned long)value
);
349 getargs_k(PyObject
*self
, PyObject
*args
)
352 if (!PyArg_ParseTuple(args
, "k", &value
))
354 return PyLong_FromUnsignedLong(value
);
358 getargs_i(PyObject
*self
, PyObject
*args
)
361 if (!PyArg_ParseTuple(args
, "i", &value
))
363 return PyLong_FromLong((long)value
);
367 getargs_l(PyObject
*self
, PyObject
*args
)
370 if (!PyArg_ParseTuple(args
, "l", &value
))
372 return PyLong_FromLong(value
);
376 getargs_n(PyObject
*self
, PyObject
*args
)
379 if (!PyArg_ParseTuple(args
, "n", &value
))
381 return PyInt_FromSsize_t(value
);
384 #ifdef HAVE_LONG_LONG
386 getargs_L(PyObject
*self
, PyObject
*args
)
389 if (!PyArg_ParseTuple(args
, "L", &value
))
391 return PyLong_FromLongLong(value
);
395 getargs_K(PyObject
*self
, PyObject
*args
)
397 unsigned PY_LONG_LONG value
;
398 if (!PyArg_ParseTuple(args
, "K", &value
))
400 return PyLong_FromUnsignedLongLong(value
);
404 /* This function not only tests the 'k' getargs code, but also the
405 PyInt_AsUnsignedLongMask() and PyInt_AsUnsignedLongMask() functions. */
407 test_k_code(PyObject
*self
)
409 PyObject
*tuple
, *num
;
412 tuple
= PyTuple_New(1);
416 /* a number larger than ULONG_MAX even on 64-bit platforms */
417 num
= PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL
, 16);
421 value
= PyInt_AsUnsignedLongMask(num
);
422 if (value
!= ULONG_MAX
)
423 return raiseTestError("test_k_code",
424 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
426 PyTuple_SET_ITEM(tuple
, 0, num
);
429 if (PyArg_ParseTuple(tuple
, "k:test_k_code", &value
) < 0)
431 if (value
!= ULONG_MAX
)
432 return raiseTestError("test_k_code",
433 "k code returned wrong value for long 0xFFF...FFF");
436 num
= PyLong_FromString("-FFFFFFFF000000000000000042", NULL
, 16);
440 value
= PyInt_AsUnsignedLongMask(num
);
441 if (value
!= (unsigned long)-0x42)
442 return raiseTestError("test_k_code",
443 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
445 PyTuple_SET_ITEM(tuple
, 0, num
);
448 if (PyArg_ParseTuple(tuple
, "k:test_k_code", &value
) < 0)
450 if (value
!= (unsigned long)-0x42)
451 return raiseTestError("test_k_code",
452 "k code returned wrong value for long -0xFFF..000042");
459 #ifdef Py_USING_UNICODE
461 /* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
465 test_u_code(PyObject
*self
)
467 PyObject
*tuple
, *obj
;
471 tuple
= PyTuple_New(1);
475 obj
= PyUnicode_Decode("test", strlen("test"),
480 PyTuple_SET_ITEM(tuple
, 0, obj
);
483 if (PyArg_ParseTuple(tuple
, "u:test_u_code", &value
) < 0)
485 if (value
!= PyUnicode_AS_UNICODE(obj
))
486 return raiseTestError("test_u_code",
487 "u code returned wrong value for u'test'");
489 if (PyArg_ParseTuple(tuple
, "u#:test_u_code", &value
, &len
) < 0)
491 if (value
!= PyUnicode_AS_UNICODE(obj
) ||
492 len
!= PyUnicode_GET_SIZE(obj
))
493 return raiseTestError("test_u_code",
494 "u# code returned wrong values for u'test'");
502 codec_incrementalencoder(PyObject
*self
, PyObject
*args
)
504 const char *encoding
, *errors
= NULL
;
505 if (!PyArg_ParseTuple(args
, "s|s:test_incrementalencoder",
508 return PyCodec_IncrementalEncoder(encoding
, errors
);
512 codec_incrementaldecoder(PyObject
*self
, PyObject
*args
)
514 const char *encoding
, *errors
= NULL
;
515 if (!PyArg_ParseTuple(args
, "s|s:test_incrementaldecoder",
518 return PyCodec_IncrementalDecoder(encoding
, errors
);
523 /* Simple test of _PyLong_NumBits and _PyLong_Sign. */
525 test_long_numbits(PyObject
*self
)
531 } testcases
[] = {{0, 0, 0},
540 {0x7fffL
, 15, 1}, /* one Python long digit */
545 {-0xfffffffL
, 28, -1}};
548 for (i
= 0; i
< sizeof(testcases
) / sizeof(struct triple
); ++i
) {
549 PyObject
*plong
= PyLong_FromLong(testcases
[i
].input
);
550 size_t nbits
= _PyLong_NumBits(plong
);
551 int sign
= _PyLong_Sign(plong
);
554 if (nbits
!= testcases
[i
].nbits
)
555 return raiseTestError("test_long_numbits",
556 "wrong result for _PyLong_NumBits");
557 if (sign
!= testcases
[i
].sign
)
558 return raiseTestError("test_long_numbits",
559 "wrong result for _PyLong_Sign");
565 /* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */
568 test_null_strings(PyObject
*self
)
570 PyObject
*o1
= PyObject_Str(NULL
), *o2
= PyObject_Unicode(NULL
);
571 PyObject
*tuple
= PyTuple_Pack(2, o1
, o2
);
578 raise_exception(PyObject
*self
, PyObject
*args
)
581 PyObject
*exc_args
, *v
;
584 if (!PyArg_ParseTuple(args
, "Oi:raise_exception",
588 exc_args
= PyTuple_New(num_args
);
589 if (exc_args
== NULL
)
591 for (i
= 0; i
< num_args
; ++i
) {
592 v
= PyInt_FromLong(i
);
597 PyTuple_SET_ITEM(exc_args
, i
, v
);
599 PyErr_SetObject(exc
, exc_args
);
606 /* test_thread_state spawns a thread of its own, and that thread releases
607 * `thread_done` when it's finished. The driver code has to know when the
608 * thread finishes, because the thread uses a PyObject (the callable) that
609 * may go away when the driver finishes. The former lack of this explicit
610 * synchronization caused rare segfaults, so rare that they were seen only
611 * on a Mac buildbot (although they were possible on any box).
613 static PyThread_type_lock thread_done
= NULL
;
616 _make_call(void *callable
)
619 PyGILState_STATE s
= PyGILState_Ensure();
620 rc
= PyObject_CallFunction((PyObject
*)callable
, "");
622 PyGILState_Release(s
);
625 /* Same thing, but releases `thread_done` when it returns. This variant
626 * should be called only from threads spawned by test_thread_state().
629 _make_call_from_thread(void *callable
)
631 _make_call(callable
);
632 PyThread_release_lock(thread_done
);
636 test_thread_state(PyObject
*self
, PyObject
*args
)
640 if (!PyArg_ParseTuple(args
, "O:test_thread_state", &fn
))
643 /* Ensure Python is set up for threading */
644 PyEval_InitThreads();
645 thread_done
= PyThread_allocate_lock();
646 if (thread_done
== NULL
)
647 return PyErr_NoMemory();
648 PyThread_acquire_lock(thread_done
, 1);
650 /* Start a new thread with our callback. */
651 PyThread_start_new_thread(_make_call_from_thread
, fn
);
652 /* Make the callback with the thread lock held by this thread */
654 /* Do it all again, but this time with the thread-lock released */
655 Py_BEGIN_ALLOW_THREADS
657 PyThread_acquire_lock(thread_done
, 1); /* wait for thread to finish */
660 /* And once more with and without a thread
661 XXX - should use a lock and work out exactly what we are trying
664 Py_BEGIN_ALLOW_THREADS
665 PyThread_start_new_thread(_make_call_from_thread
, fn
);
667 PyThread_acquire_lock(thread_done
, 1); /* wait for thread to finish */
670 /* Release lock we acquired above. This is required on HP-UX. */
671 PyThread_release_lock(thread_done
);
673 PyThread_free_lock(thread_done
);
678 /* Some tests of PyString_FromFormat(). This needs more tests. */
680 test_string_from_format(PyObject
*self
, PyObject
*args
)
685 #define CHECK_1_FORMAT(FORMAT, TYPE) \
686 result = PyString_FromFormat(FORMAT, (TYPE)1); \
687 if (result == NULL) \
689 if (strcmp(PyString_AsString(result), "1")) { \
690 msg = FORMAT " failed at 1"; \
695 CHECK_1_FORMAT("%d", int);
696 CHECK_1_FORMAT("%ld", long);
697 /* The z width modifier was added in Python 2.5. */
698 CHECK_1_FORMAT("%zd", Py_ssize_t
);
700 /* The u type code was added in Python 2.5. */
701 CHECK_1_FORMAT("%u", unsigned int);
702 CHECK_1_FORMAT("%lu", unsigned long);
703 CHECK_1_FORMAT("%zu", size_t);
709 return raiseTestError("test_string_from_format", msg
);
711 #undef CHECK_1_FORMAT
714 /* This is here to provide a docstring for test_descr. */
716 test_with_docstring(PyObject
*self
)
721 static PyMethodDef TestMethods
[] = {
722 {"raise_exception", raise_exception
, METH_VARARGS
},
723 {"test_config", (PyCFunction
)test_config
, METH_NOARGS
},
724 {"test_list_api", (PyCFunction
)test_list_api
, METH_NOARGS
},
725 {"test_dict_iteration", (PyCFunction
)test_dict_iteration
,METH_NOARGS
},
726 {"test_long_api", (PyCFunction
)test_long_api
, METH_NOARGS
},
727 {"test_long_numbits", (PyCFunction
)test_long_numbits
, METH_NOARGS
},
728 {"test_k_code", (PyCFunction
)test_k_code
, METH_NOARGS
},
729 {"test_null_strings", (PyCFunction
)test_null_strings
, METH_NOARGS
},
730 {"test_string_from_format", (PyCFunction
)test_string_from_format
, METH_NOARGS
},
731 {"test_with_docstring", (PyCFunction
)test_with_docstring
, METH_NOARGS
,
732 PyDoc_STR("This is a pretty normal docstring.")},
734 {"getargs_tuple", getargs_tuple
, METH_VARARGS
},
735 {"getargs_b", getargs_b
, METH_VARARGS
},
736 {"getargs_B", getargs_B
, METH_VARARGS
},
737 {"getargs_H", getargs_H
, METH_VARARGS
},
738 {"getargs_I", getargs_I
, METH_VARARGS
},
739 {"getargs_k", getargs_k
, METH_VARARGS
},
740 {"getargs_i", getargs_i
, METH_VARARGS
},
741 {"getargs_l", getargs_l
, METH_VARARGS
},
742 {"getargs_n", getargs_n
, METH_VARARGS
},
743 #ifdef HAVE_LONG_LONG
744 {"getargs_L", getargs_L
, METH_VARARGS
},
745 {"getargs_K", getargs_K
, METH_VARARGS
},
746 {"test_longlong_api", test_longlong_api
, METH_NOARGS
},
747 {"test_L_code", (PyCFunction
)test_L_code
, METH_NOARGS
},
748 {"codec_incrementalencoder",
749 (PyCFunction
)codec_incrementalencoder
, METH_VARARGS
},
750 {"codec_incrementaldecoder",
751 (PyCFunction
)codec_incrementaldecoder
, METH_VARARGS
},
753 #ifdef Py_USING_UNICODE
754 {"test_u_code", (PyCFunction
)test_u_code
, METH_NOARGS
},
757 {"_test_thread_state", test_thread_state
, METH_VARARGS
},
759 {NULL
, NULL
} /* sentinel */
762 #define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);}
766 unsigned char ubyte_member
;
768 unsigned short ushort_member
;
770 unsigned int uint_member
;
772 unsigned long ulong_member
;
774 double double_member
;
775 #ifdef HAVE_LONG_LONG
776 PY_LONG_LONG longlong_member
;
777 unsigned PY_LONG_LONG ulonglong_member
;
783 all_structmembers structmembers
;
784 } test_structmembers
;
786 static struct PyMemberDef test_members
[] = {
787 {"T_BYTE", T_BYTE
, offsetof(test_structmembers
, structmembers
.byte_member
), 0, NULL
},
788 {"T_UBYTE", T_UBYTE
, offsetof(test_structmembers
, structmembers
.ubyte_member
), 0, NULL
},
789 {"T_SHORT", T_SHORT
, offsetof(test_structmembers
, structmembers
.short_member
), 0, NULL
},
790 {"T_USHORT", T_USHORT
, offsetof(test_structmembers
, structmembers
.ushort_member
), 0, NULL
},
791 {"T_INT", T_INT
, offsetof(test_structmembers
, structmembers
.int_member
), 0, NULL
},
792 {"T_UINT", T_UINT
, offsetof(test_structmembers
, structmembers
.uint_member
), 0, NULL
},
793 {"T_LONG", T_LONG
, offsetof(test_structmembers
, structmembers
.long_member
), 0, NULL
},
794 {"T_ULONG", T_ULONG
, offsetof(test_structmembers
, structmembers
.ulong_member
), 0, NULL
},
795 {"T_FLOAT", T_FLOAT
, offsetof(test_structmembers
, structmembers
.float_member
), 0, NULL
},
796 {"T_DOUBLE", T_DOUBLE
, offsetof(test_structmembers
, structmembers
.double_member
), 0, NULL
},
797 #ifdef HAVE_LONG_LONG
798 {"T_LONGLONG", T_LONGLONG
, offsetof(test_structmembers
, structmembers
.longlong_member
), 0, NULL
},
799 {"T_ULONGLONG", T_ULONGLONG
, offsetof(test_structmembers
, structmembers
.ulonglong_member
), 0, NULL
},
805 static PyObject
*test_structmembers_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
){
806 static char *keywords
[]={"T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", "T_INT", "T_UINT",
807 "T_LONG", "T_ULONG", "T_FLOAT", "T_DOUBLE",
808 #ifdef HAVE_LONG_LONG
809 "T_LONGLONG", "T_ULONGLONG",
812 static char *fmt
="|bBhHiIlkfd"
813 #ifdef HAVE_LONG_LONG
817 test_structmembers
*ob
=PyObject_New(test_structmembers
, type
);
820 memset(&ob
->structmembers
, 0, sizeof(all_structmembers
));
821 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, fmt
, keywords
,
822 &ob
->structmembers
.byte_member
, &ob
->structmembers
.ubyte_member
,
823 &ob
->structmembers
.short_member
, &ob
->structmembers
.ushort_member
,
824 &ob
->structmembers
.int_member
, &ob
->structmembers
.uint_member
,
825 &ob
->structmembers
.long_member
, &ob
->structmembers
.ulong_member
,
826 &ob
->structmembers
.float_member
, &ob
->structmembers
.double_member
827 #ifdef HAVE_LONG_LONG
828 ,&ob
->structmembers
.longlong_member
, &ob
->structmembers
.ulonglong_member
834 return (PyObject
*)ob
;
837 static void test_structmembers_free(PyObject
*ob
){
841 static PyTypeObject test_structmembersType
= {
842 PyObject_HEAD_INIT(NULL
)
844 "test_structmembersType",
845 sizeof(test_structmembers
), /* tp_basicsize */
847 test_structmembers_free
, /* destructor tp_dealloc */
853 0, /* tp_as_number */
854 0, /* tp_as_sequence */
855 0, /* tp_as_mapping */
859 PyObject_GenericGetAttr
,
860 PyObject_GenericSetAttr
,
861 0, /* tp_as_buffer */
863 "Type containing all structmember types",
864 0, /* traverseproc tp_traverse */
866 0, /* tp_richcompare */
867 0, /* tp_weaklistoffset */
871 test_members
, /* tp_members */
880 test_structmembers_new
, /* tp_new */
889 m
= Py_InitModule("_testcapi", TestMethods
);
893 test_structmembersType
.ob_type
=&PyType_Type
;
894 Py_INCREF(&test_structmembersType
);
895 PyModule_AddObject(m
, "test_structmembersType", (PyObject
*)&test_structmembersType
);
897 PyModule_AddObject(m
, "CHAR_MAX", PyInt_FromLong(CHAR_MAX
));
898 PyModule_AddObject(m
, "CHAR_MIN", PyInt_FromLong(CHAR_MIN
));
899 PyModule_AddObject(m
, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX
));
900 PyModule_AddObject(m
, "SHRT_MAX", PyInt_FromLong(SHRT_MAX
));
901 PyModule_AddObject(m
, "SHRT_MIN", PyInt_FromLong(SHRT_MIN
));
902 PyModule_AddObject(m
, "USHRT_MAX", PyInt_FromLong(USHRT_MAX
));
903 PyModule_AddObject(m
, "INT_MAX", PyLong_FromLong(INT_MAX
));
904 PyModule_AddObject(m
, "INT_MIN", PyLong_FromLong(INT_MIN
));
905 PyModule_AddObject(m
, "UINT_MAX", PyLong_FromUnsignedLong(UINT_MAX
));
906 PyModule_AddObject(m
, "LONG_MAX", PyInt_FromLong(LONG_MAX
));
907 PyModule_AddObject(m
, "LONG_MIN", PyInt_FromLong(LONG_MIN
));
908 PyModule_AddObject(m
, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX
));
909 PyModule_AddObject(m
, "FLT_MAX", PyFloat_FromDouble(FLT_MAX
));
910 PyModule_AddObject(m
, "FLT_MIN", PyFloat_FromDouble(FLT_MIN
));
911 PyModule_AddObject(m
, "DBL_MAX", PyFloat_FromDouble(DBL_MAX
));
912 PyModule_AddObject(m
, "DBL_MIN", PyFloat_FromDouble(DBL_MIN
));
913 PyModule_AddObject(m
, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX
));
914 PyModule_AddObject(m
, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN
));
915 PyModule_AddObject(m
, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX
));
916 PyModule_AddObject(m
, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX
));
917 PyModule_AddObject(m
, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN
));
919 TestError
= PyErr_NewException("_testcapi.error", NULL
, NULL
);
920 Py_INCREF(TestError
);
921 PyModule_AddObject(m
, "error", TestError
);