Added duplicate call to fileConfig() to ensure that it cleans up after itself correctly.
[python.git] / Modules / _testcapimodule.c
blob6b9dffde464356700e6cb8bb246c2609c1237c8e
1 /*
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.
6 */
8 #include "Python.h"
10 #ifdef WITH_THREAD
11 #include "pythread.h"
12 #endif /* WITH_THREAD */
13 static PyObject *TestError; /* set to exception object in init */
15 /* Raise TestError with test_name + ": " + msg, and return NULL. */
17 static PyObject *
18 raiseTestError(const char* test_name, const char* msg)
20 char buf[2048];
22 if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
23 PyErr_SetString(TestError, "internal error msg too large");
24 else {
25 PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
26 PyErr_SetString(TestError, buf);
28 return NULL;
31 /* Test #defines from pyconfig.h (particularly the SIZEOF_* defines).
33 The ones derived from autoconf on the UNIX-like OSes can be relied
34 upon (in the absence of sloppy cross-compiling), but the Windows
35 platforms have these hardcoded. Better safe than sorry.
37 static PyObject*
38 sizeof_error(const char* fatname, const char* typename,
39 int expected, int got)
41 char buf[1024];
42 PyOS_snprintf(buf, sizeof(buf),
43 "%.200s #define == %d but sizeof(%.200s) == %d",
44 fatname, expected, typename, got);
45 PyErr_SetString(TestError, buf);
46 return (PyObject*)NULL;
49 static PyObject*
50 test_config(PyObject *self)
52 #define CHECK_SIZEOF(FATNAME, TYPE) \
53 if (FATNAME != sizeof(TYPE)) \
54 return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
56 CHECK_SIZEOF(SIZEOF_SHORT, short);
57 CHECK_SIZEOF(SIZEOF_INT, int);
58 CHECK_SIZEOF(SIZEOF_LONG, long);
59 CHECK_SIZEOF(SIZEOF_VOID_P, void*);
60 CHECK_SIZEOF(SIZEOF_TIME_T, time_t);
61 #ifdef HAVE_LONG_LONG
62 CHECK_SIZEOF(SIZEOF_LONG_LONG, PY_LONG_LONG);
63 #endif
65 #undef CHECK_SIZEOF
67 Py_INCREF(Py_None);
68 return Py_None;
71 static PyObject*
72 test_list_api(PyObject *self)
74 PyObject* list;
75 int i;
77 /* SF bug 132008: PyList_Reverse segfaults */
78 #define NLIST 30
79 list = PyList_New(NLIST);
80 if (list == (PyObject*)NULL)
81 return (PyObject*)NULL;
82 /* list = range(NLIST) */
83 for (i = 0; i < NLIST; ++i) {
84 PyObject* anint = PyInt_FromLong(i);
85 if (anint == (PyObject*)NULL) {
86 Py_DECREF(list);
87 return (PyObject*)NULL;
89 PyList_SET_ITEM(list, i, anint);
91 /* list.reverse(), via PyList_Reverse() */
92 i = PyList_Reverse(list); /* should not blow up! */
93 if (i != 0) {
94 Py_DECREF(list);
95 return (PyObject*)NULL;
97 /* Check that list == range(29, -1, -1) now */
98 for (i = 0; i < NLIST; ++i) {
99 PyObject* anint = PyList_GET_ITEM(list, i);
100 if (PyInt_AS_LONG(anint) != NLIST-1-i) {
101 PyErr_SetString(TestError,
102 "test_list_api: reverse screwed up");
103 Py_DECREF(list);
104 return (PyObject*)NULL;
107 Py_DECREF(list);
108 #undef NLIST
110 Py_INCREF(Py_None);
111 return Py_None;
114 static int
115 test_dict_inner(int count)
117 Py_ssize_t pos = 0, iterations = 0;
118 int i;
119 PyObject *dict = PyDict_New();
120 PyObject *v, *k;
122 if (dict == NULL)
123 return -1;
125 for (i = 0; i < count; i++) {
126 v = PyInt_FromLong(i);
127 PyDict_SetItem(dict, v, v);
128 Py_DECREF(v);
131 while (PyDict_Next(dict, &pos, &k, &v)) {
132 PyObject *o;
133 iterations++;
135 i = PyInt_AS_LONG(v) + 1;
136 o = PyInt_FromLong(i);
137 if (o == NULL)
138 return -1;
139 if (PyDict_SetItem(dict, k, o) < 0) {
140 Py_DECREF(o);
141 return -1;
143 Py_DECREF(o);
146 Py_DECREF(dict);
148 if (iterations != count) {
149 PyErr_SetString(
150 TestError,
151 "test_dict_iteration: dict iteration went wrong ");
152 return -1;
153 } else {
154 return 0;
158 static PyObject*
159 test_dict_iteration(PyObject* self)
161 int i;
163 for (i = 0; i < 200; i++) {
164 if (test_dict_inner(i) < 0) {
165 return NULL;
169 Py_INCREF(Py_None);
170 return Py_None;
174 /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG)
175 PyLong_{As, From}{Unsigned,}LongLong().
177 Note that the meat of the test is contained in testcapi_long.h.
178 This is revolting, but delicate code duplication is worse: "almost
179 exactly the same" code is needed to test PY_LONG_LONG, but the ubiquitous
180 dependence on type names makes it impossible to use a parameterized
181 function. A giant macro would be even worse than this. A C++ template
182 would be perfect.
184 The "report an error" functions are deliberately not part of the #include
185 file: if the test fails, you can set a breakpoint in the appropriate
186 error function directly, and crawl back from there in the debugger.
189 #define UNBIND(X) Py_DECREF(X); (X) = NULL
191 static PyObject *
192 raise_test_long_error(const char* msg)
194 return raiseTestError("test_long_api", msg);
197 #define TESTNAME test_long_api_inner
198 #define TYPENAME long
199 #define F_S_TO_PY PyLong_FromLong
200 #define F_PY_TO_S PyLong_AsLong
201 #define F_U_TO_PY PyLong_FromUnsignedLong
202 #define F_PY_TO_U PyLong_AsUnsignedLong
204 #include "testcapi_long.h"
206 static PyObject *
207 test_long_api(PyObject* self)
209 return TESTNAME(raise_test_long_error);
212 #undef TESTNAME
213 #undef TYPENAME
214 #undef F_S_TO_PY
215 #undef F_PY_TO_S
216 #undef F_U_TO_PY
217 #undef F_PY_TO_U
219 #ifdef HAVE_LONG_LONG
221 static PyObject *
222 raise_test_longlong_error(const char* msg)
224 return raiseTestError("test_longlong_api", msg);
227 #define TESTNAME test_longlong_api_inner
228 #define TYPENAME PY_LONG_LONG
229 #define F_S_TO_PY PyLong_FromLongLong
230 #define F_PY_TO_S PyLong_AsLongLong
231 #define F_U_TO_PY PyLong_FromUnsignedLongLong
232 #define F_PY_TO_U PyLong_AsUnsignedLongLong
234 #include "testcapi_long.h"
236 static PyObject *
237 test_longlong_api(PyObject* self, PyObject *args)
239 return TESTNAME(raise_test_longlong_error);
242 #undef TESTNAME
243 #undef TYPENAME
244 #undef F_S_TO_PY
245 #undef F_PY_TO_S
246 #undef F_U_TO_PY
247 #undef F_PY_TO_U
249 /* Test the L code for PyArg_ParseTuple. This should deliver a PY_LONG_LONG
250 for both long and int arguments. The test may leak a little memory if
251 it fails.
253 static PyObject *
254 test_L_code(PyObject *self)
256 PyObject *tuple, *num;
257 PY_LONG_LONG value;
259 tuple = PyTuple_New(1);
260 if (tuple == NULL)
261 return NULL;
263 num = PyLong_FromLong(42);
264 if (num == NULL)
265 return NULL;
267 PyTuple_SET_ITEM(tuple, 0, num);
269 value = -1;
270 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
271 return NULL;
272 if (value != 42)
273 return raiseTestError("test_L_code",
274 "L code returned wrong value for long 42");
276 Py_DECREF(num);
277 num = PyInt_FromLong(42);
278 if (num == NULL)
279 return NULL;
281 PyTuple_SET_ITEM(tuple, 0, num);
283 value = -1;
284 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
285 return NULL;
286 if (value != 42)
287 return raiseTestError("test_L_code",
288 "L code returned wrong value for int 42");
290 Py_DECREF(tuple);
291 Py_INCREF(Py_None);
292 return Py_None;
295 #endif /* ifdef HAVE_LONG_LONG */
297 /* Functions to call PyArg_ParseTuple with integer format codes,
298 and return the result.
300 static PyObject *
301 getargs_b(PyObject *self, PyObject *args)
303 unsigned char value;
304 if (!PyArg_ParseTuple(args, "b", &value))
305 return NULL;
306 return PyLong_FromUnsignedLong((unsigned long)value);
309 static PyObject *
310 getargs_B(PyObject *self, PyObject *args)
312 unsigned char value;
313 if (!PyArg_ParseTuple(args, "B", &value))
314 return NULL;
315 return PyLong_FromUnsignedLong((unsigned long)value);
318 static PyObject *
319 getargs_H(PyObject *self, PyObject *args)
321 unsigned short value;
322 if (!PyArg_ParseTuple(args, "H", &value))
323 return NULL;
324 return PyLong_FromUnsignedLong((unsigned long)value);
327 static PyObject *
328 getargs_I(PyObject *self, PyObject *args)
330 unsigned int value;
331 if (!PyArg_ParseTuple(args, "I", &value))
332 return NULL;
333 return PyLong_FromUnsignedLong((unsigned long)value);
336 static PyObject *
337 getargs_k(PyObject *self, PyObject *args)
339 unsigned long value;
340 if (!PyArg_ParseTuple(args, "k", &value))
341 return NULL;
342 return PyLong_FromUnsignedLong(value);
345 static PyObject *
346 getargs_i(PyObject *self, PyObject *args)
348 int value;
349 if (!PyArg_ParseTuple(args, "i", &value))
350 return NULL;
351 return PyLong_FromLong((long)value);
354 static PyObject *
355 getargs_l(PyObject *self, PyObject *args)
357 long value;
358 if (!PyArg_ParseTuple(args, "l", &value))
359 return NULL;
360 return PyLong_FromLong(value);
363 static PyObject *
364 getargs_n(PyObject *self, PyObject *args)
366 Py_ssize_t value;
367 if (!PyArg_ParseTuple(args, "n", &value))
368 return NULL;
369 return PyInt_FromSsize_t(value);
372 #ifdef HAVE_LONG_LONG
373 static PyObject *
374 getargs_L(PyObject *self, PyObject *args)
376 PY_LONG_LONG value;
377 if (!PyArg_ParseTuple(args, "L", &value))
378 return NULL;
379 return PyLong_FromLongLong(value);
382 static PyObject *
383 getargs_K(PyObject *self, PyObject *args)
385 unsigned PY_LONG_LONG value;
386 if (!PyArg_ParseTuple(args, "K", &value))
387 return NULL;
388 return PyLong_FromUnsignedLongLong(value);
390 #endif
392 /* This function not only tests the 'k' getargs code, but also the
393 PyInt_AsUnsignedLongMask() and PyInt_AsUnsignedLongMask() functions. */
394 static PyObject *
395 test_k_code(PyObject *self)
397 PyObject *tuple, *num;
398 unsigned long value;
400 tuple = PyTuple_New(1);
401 if (tuple == NULL)
402 return NULL;
404 /* a number larger than ULONG_MAX even on 64-bit platforms */
405 num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
406 if (num == NULL)
407 return NULL;
409 value = PyInt_AsUnsignedLongMask(num);
410 if (value != ULONG_MAX)
411 return raiseTestError("test_k_code",
412 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
414 PyTuple_SET_ITEM(tuple, 0, num);
416 value = 0;
417 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
418 return NULL;
419 if (value != ULONG_MAX)
420 return raiseTestError("test_k_code",
421 "k code returned wrong value for long 0xFFF...FFF");
423 Py_DECREF(num);
424 num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16);
425 if (num == NULL)
426 return NULL;
428 value = PyInt_AsUnsignedLongMask(num);
429 if (value != (unsigned long)-0x42)
430 return raiseTestError("test_k_code",
431 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
433 PyTuple_SET_ITEM(tuple, 0, num);
435 value = 0;
436 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
437 return NULL;
438 if (value != (unsigned long)-0x42)
439 return raiseTestError("test_k_code",
440 "k code returned wrong value for long -0xFFF..000042");
442 Py_DECREF(tuple);
443 Py_INCREF(Py_None);
444 return Py_None;
447 #ifdef Py_USING_UNICODE
449 /* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
450 of an error.
452 static PyObject *
453 test_u_code(PyObject *self)
455 PyObject *tuple, *obj;
456 Py_UNICODE *value;
457 int len;
459 tuple = PyTuple_New(1);
460 if (tuple == NULL)
461 return NULL;
463 obj = PyUnicode_Decode("test", strlen("test"),
464 "ascii", NULL);
465 if (obj == NULL)
466 return NULL;
468 PyTuple_SET_ITEM(tuple, 0, obj);
470 value = 0;
471 if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
472 return NULL;
473 if (value != PyUnicode_AS_UNICODE(obj))
474 return raiseTestError("test_u_code",
475 "u code returned wrong value for u'test'");
476 value = 0;
477 if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
478 return NULL;
479 if (value != PyUnicode_AS_UNICODE(obj) ||
480 len != PyUnicode_GET_SIZE(obj))
481 return raiseTestError("test_u_code",
482 "u# code returned wrong values for u'test'");
484 Py_DECREF(tuple);
485 Py_INCREF(Py_None);
486 return Py_None;
489 static PyObject *
490 codec_incrementalencoder(PyObject *self, PyObject *args)
492 const char *encoding, *errors = NULL;
493 if (!PyArg_ParseTuple(args, "s|s:test_incrementalencoder",
494 &encoding, &errors))
495 return NULL;
496 return PyCodec_IncrementalEncoder(encoding, errors);
499 static PyObject *
500 codec_incrementaldecoder(PyObject *self, PyObject *args)
502 const char *encoding, *errors = NULL;
503 if (!PyArg_ParseTuple(args, "s|s:test_incrementaldecoder",
504 &encoding, &errors))
505 return NULL;
506 return PyCodec_IncrementalDecoder(encoding, errors);
509 #endif
511 /* Simple test of _PyLong_NumBits and _PyLong_Sign. */
512 static PyObject *
513 test_long_numbits(PyObject *self)
515 struct triple {
516 long input;
517 size_t nbits;
518 int sign;
519 } testcases[] = {{0, 0, 0},
520 {1L, 1, 1},
521 {-1L, 1, -1},
522 {2L, 2, 1},
523 {-2L, 2, -1},
524 {3L, 2, 1},
525 {-3L, 2, -1},
526 {4L, 3, 1},
527 {-4L, 3, -1},
528 {0x7fffL, 15, 1}, /* one Python long digit */
529 {-0x7fffL, 15, -1},
530 {0xffffL, 16, 1},
531 {-0xffffL, 16, -1},
532 {0xfffffffL, 28, 1},
533 {-0xfffffffL, 28, -1}};
534 int i;
536 for (i = 0; i < sizeof(testcases) / sizeof(struct triple); ++i) {
537 PyObject *plong = PyLong_FromLong(testcases[i].input);
538 size_t nbits = _PyLong_NumBits(plong);
539 int sign = _PyLong_Sign(plong);
541 Py_DECREF(plong);
542 if (nbits != testcases[i].nbits)
543 return raiseTestError("test_long_numbits",
544 "wrong result for _PyLong_NumBits");
545 if (sign != testcases[i].sign)
546 return raiseTestError("test_long_numbits",
547 "wrong result for _PyLong_Sign");
549 Py_INCREF(Py_None);
550 return Py_None;
553 /* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */
555 static PyObject *
556 test_null_strings(PyObject *self)
558 PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL);
559 PyObject *tuple = PyTuple_Pack(2, o1, o2);
560 Py_XDECREF(o1);
561 Py_XDECREF(o2);
562 return tuple;
565 static PyObject *
566 raise_exception(PyObject *self, PyObject *args)
568 PyObject *exc;
569 PyObject *exc_args, *v;
570 int num_args, i;
572 if (!PyArg_ParseTuple(args, "Oi:raise_exception",
573 &exc, &num_args))
574 return NULL;
576 exc_args = PyTuple_New(num_args);
577 if (exc_args == NULL)
578 return NULL;
579 for (i = 0; i < num_args; ++i) {
580 v = PyInt_FromLong(i);
581 if (v == NULL) {
582 Py_DECREF(exc_args);
583 return NULL;
585 PyTuple_SET_ITEM(exc_args, i, v);
587 PyErr_SetObject(exc, exc_args);
588 Py_DECREF(exc_args);
589 return NULL;
592 #ifdef WITH_THREAD
594 /* test_thread_state spawns a thread of its own, and that thread releases
595 * `thread_done` when it's finished. The driver code has to know when the
596 * thread finishes, because the thread uses a PyObject (the callable) that
597 * may go away when the driver finishes. The former lack of this explicit
598 * synchronization caused rare segfaults, so rare that they were seen only
599 * on a Mac buildbot (although they were possible on any box).
601 static PyThread_type_lock thread_done = NULL;
603 static void
604 _make_call(void *callable)
606 PyObject *rc;
607 PyGILState_STATE s = PyGILState_Ensure();
608 rc = PyObject_CallFunction(callable, "");
609 Py_XDECREF(rc);
610 PyGILState_Release(s);
613 /* Same thing, but releases `thread_done` when it returns. This variant
614 * should be called only from threads spawned by test_thread_state().
616 static void
617 _make_call_from_thread(void *callable)
619 _make_call(callable);
620 PyThread_release_lock(thread_done);
623 static PyObject *
624 test_thread_state(PyObject *self, PyObject *args)
626 PyObject *fn;
628 if (!PyArg_ParseTuple(args, "O:test_thread_state", &fn))
629 return NULL;
631 /* Ensure Python is set up for threading */
632 PyEval_InitThreads();
633 thread_done = PyThread_allocate_lock();
634 if (thread_done == NULL)
635 return PyErr_NoMemory();
636 PyThread_acquire_lock(thread_done, 1);
638 /* Start a new thread with our callback. */
639 PyThread_start_new_thread(_make_call_from_thread, fn);
640 /* Make the callback with the thread lock held by this thread */
641 _make_call(fn);
642 /* Do it all again, but this time with the thread-lock released */
643 Py_BEGIN_ALLOW_THREADS
644 _make_call(fn);
645 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */
646 Py_END_ALLOW_THREADS
648 /* And once more with and without a thread
649 XXX - should use a lock and work out exactly what we are trying
650 to test <wink>
652 Py_BEGIN_ALLOW_THREADS
653 PyThread_start_new_thread(_make_call_from_thread, fn);
654 _make_call(fn);
655 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */
656 Py_END_ALLOW_THREADS
658 PyThread_free_lock(thread_done);
659 Py_RETURN_NONE;
661 #endif
663 /* Some tests of PyString_FromFormat(). This needs more tests. */
664 static PyObject *
665 test_string_from_format(PyObject *self, PyObject *args)
667 PyObject *result;
668 char *msg;
670 #define CHECK_1_FORMAT(FORMAT, TYPE) \
671 result = PyString_FromFormat(FORMAT, (TYPE)1); \
672 if (result == NULL) \
673 return NULL; \
674 if (strcmp(PyString_AsString(result), "1")) { \
675 msg = FORMAT " failed at 1"; \
676 goto Fail; \
678 Py_DECREF(result)
680 CHECK_1_FORMAT("%d", int);
681 CHECK_1_FORMAT("%ld", long);
682 /* The z width modifier was added in Python 2.5. */
683 CHECK_1_FORMAT("%zd", Py_ssize_t);
685 /* The u type code was added in Python 2.5. */
686 CHECK_1_FORMAT("%u", unsigned int);
687 CHECK_1_FORMAT("%lu", unsigned long);
688 CHECK_1_FORMAT("%zu", size_t);
690 Py_RETURN_NONE;
692 Fail:
693 Py_XDECREF(result);
694 return raiseTestError("test_string_from_format", msg);
696 #undef CHECK_1_FORMAT
699 static PyMethodDef TestMethods[] = {
700 {"raise_exception", raise_exception, METH_VARARGS},
701 {"test_config", (PyCFunction)test_config, METH_NOARGS},
702 {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
703 {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
704 {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
705 {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS},
706 {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS},
707 {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS},
708 {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},
710 {"getargs_b", getargs_b, METH_VARARGS},
711 {"getargs_B", getargs_B, METH_VARARGS},
712 {"getargs_H", getargs_H, METH_VARARGS},
713 {"getargs_I", getargs_I, METH_VARARGS},
714 {"getargs_k", getargs_k, METH_VARARGS},
715 {"getargs_i", getargs_i, METH_VARARGS},
716 {"getargs_l", getargs_l, METH_VARARGS},
717 {"getargs_n", getargs_n, METH_VARARGS},
718 #ifdef HAVE_LONG_LONG
719 {"getargs_L", getargs_L, METH_VARARGS},
720 {"getargs_K", getargs_K, METH_VARARGS},
721 {"test_longlong_api", test_longlong_api, METH_NOARGS},
722 {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
723 {"codec_incrementalencoder",
724 (PyCFunction)codec_incrementalencoder, METH_VARARGS},
725 {"codec_incrementaldecoder",
726 (PyCFunction)codec_incrementaldecoder, METH_VARARGS},
727 #endif
728 #ifdef Py_USING_UNICODE
729 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
730 #endif
731 #ifdef WITH_THREAD
732 {"_test_thread_state", test_thread_state, METH_VARARGS},
733 #endif
734 {NULL, NULL} /* sentinel */
737 #define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);}
739 PyMODINIT_FUNC
740 init_testcapi(void)
742 PyObject *m;
744 m = Py_InitModule("_testcapi", TestMethods);
745 if (m == NULL)
746 return;
748 PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX));
749 PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX));
750 PyModule_AddObject(m, "UINT_MAX", PyLong_FromUnsignedLong(UINT_MAX));
751 PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX));
752 PyModule_AddObject(m, "INT_MIN", PyInt_FromLong(INT_MIN));
753 PyModule_AddObject(m, "LONG_MIN", PyInt_FromLong(LONG_MIN));
754 PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN));
755 PyModule_AddObject(m, "INT_MAX", PyInt_FromLong(INT_MAX));
756 PyModule_AddObject(m, "LONG_MAX", PyInt_FromLong(LONG_MAX));
757 PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX));
759 TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
760 Py_INCREF(TestError);
761 PyModule_AddObject(m, "error", TestError);