annotate Modules/_testcapimodule.c @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents 7fcdeeb16ec0
children 871da703e4c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1 /*
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
2 * C Extension module to test Python interpreter C APIs.
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
3 *
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
4 * The 'test_*' functions exported by this module are run as part of the
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
5 * standard Python regression test, via Lib/test/test_capi.py.
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
6 */
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
7
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
8 #include "Python.h"
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
9
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
10 static PyObject *TestError; /* set to exception object in init */
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
11
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
12 /* Raise TestError with test_name + ": " + msg, and return NULL. */
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
13
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
14 static PyObject *
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
15 raiseTestError(const char* test_name, const char* msg)
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
16 {
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
17 char buf[2048];
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
18
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
19 if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
20 PyErr_SetString(TestError, "internal error msg too large");
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
21 else {
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21066
diff changeset
22 PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
23 PyErr_SetString(TestError, buf);
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
24 }
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
25 return NULL;
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
26 }
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
27
18835
2dea40e40d9d Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents: 18294
diff changeset
28 /* Test #defines from pyconfig.h (particularly the SIZEOF_* defines).
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
29
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
30 The ones derived from autoconf on the UNIX-like OSes can be relied
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
31 upon (in the absence of sloppy cross-compiling), but the Windows
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
32 platforms have these hardcoded. Better safe than sorry.
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
33 */
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
34 static PyObject*
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
35 sizeof_error(const char* fatname, const char* typename,
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
36 int expected, int got)
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
37 {
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
38 char buf[1024];
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
39 PyOS_snprintf(buf, sizeof(buf),
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21066
diff changeset
40 "%.200s #define == %d but sizeof(%.200s) == %d",
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
41 fatname, expected, typename, got);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
42 PyErr_SetString(TestError, buf);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
43 return (PyObject*)NULL;
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
44 }
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
45
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
46 static PyObject*
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
47 test_config(PyObject *self)
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
48 {
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
49 #define CHECK_SIZEOF(FATNAME, TYPE) \
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
50 if (FATNAME != sizeof(TYPE)) \
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
51 return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
52
18294
b14521fd8e39 Windows build broke from recent Unicode changes -- need to #define
Tim Peters <tim.peters@gmail.com>
parents: 18132
diff changeset
53 CHECK_SIZEOF(SIZEOF_SHORT, short);
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
54 CHECK_SIZEOF(SIZEOF_INT, int);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
55 CHECK_SIZEOF(SIZEOF_LONG, long);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
56 CHECK_SIZEOF(SIZEOF_VOID_P, void*);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
57 CHECK_SIZEOF(SIZEOF_TIME_T, time_t);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
58 #ifdef HAVE_LONG_LONG
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
59 CHECK_SIZEOF(SIZEOF_LONG_LONG, LONG_LONG);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
60 #endif
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
61
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
62 #undef CHECK_SIZEOF
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
63
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
64 Py_INCREF(Py_None);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
65 return Py_None;
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
66 }
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
67
16582
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
68 static PyObject*
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
69 test_list_api(PyObject *self)
16582
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
70 {
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
71 PyObject* list;
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
72 int i;
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
73
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
74 /* SF bug 132008: PyList_Reverse segfaults */
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
75 #define NLIST 30
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
76 list = PyList_New(NLIST);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
77 if (list == (PyObject*)NULL)
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
78 return (PyObject*)NULL;
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
79 /* list = range(NLIST) */
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
80 for (i = 0; i < NLIST; ++i) {
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
81 PyObject* anint = PyInt_FromLong(i);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
82 if (anint == (PyObject*)NULL) {
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
83 Py_DECREF(list);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
84 return (PyObject*)NULL;
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
85 }
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
86 PyList_SET_ITEM(list, i, anint);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
87 }
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
88 /* list.reverse(), via PyList_Reverse() */
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
89 i = PyList_Reverse(list); /* should not blow up! */
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
90 if (i != 0) {
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
91 Py_DECREF(list);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
92 return (PyObject*)NULL;
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
93 }
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
94 /* Check that list == range(29, -1, -1) now */
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
95 for (i = 0; i < NLIST; ++i) {
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
96 PyObject* anint = PyList_GET_ITEM(list, i);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
97 if (PyInt_AS_LONG(anint) != NLIST-1-i) {
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
98 PyErr_SetString(TestError,
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
99 "test_list_api: reverse screwed up");
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
100 Py_DECREF(list);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
101 return (PyObject*)NULL;
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
102 }
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
103 }
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
104 Py_DECREF(list);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
105 #undef NLIST
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
106
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
107 Py_INCREF(Py_None);
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
108 return Py_None;
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
109 }
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
110
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
111 static int
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
112 test_dict_inner(int count)
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
113 {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
114 int pos = 0, iterations = 0, i;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
115 PyObject *dict = PyDict_New();
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
116 PyObject *v, *k;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
117
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
118 if (dict == NULL)
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
119 return -1;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
120
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
121 for (i = 0; i < count; i++) {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
122 v = PyInt_FromLong(i);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
123 PyDict_SetItem(dict, v, v);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
124 Py_DECREF(v);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
125 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
126
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
127 while (PyDict_Next(dict, &pos, &k, &v)) {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
128 PyObject *o;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
129 iterations++;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
130
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
131 i = PyInt_AS_LONG(v) + 1;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
132 o = PyInt_FromLong(i);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
133 if (o == NULL)
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
134 return -1;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
135 if (PyDict_SetItem(dict, k, o) < 0) {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
136 Py_DECREF(o);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
137 return -1;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
138 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
139 Py_DECREF(o);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
140 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
141
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
142 Py_DECREF(dict);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
143
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
144 if (iterations != count) {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
145 PyErr_SetString(
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
146 TestError,
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
147 "test_dict_iteration: dict iteration went wrong ");
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
148 return -1;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
149 } else {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
150 return 0;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
151 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
152 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
153
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
154 static PyObject*
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
155 test_dict_iteration(PyObject* self)
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
156 {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
157 int i;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
158
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
159 for (i = 0; i < 200; i++) {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
160 if (test_dict_inner(i) < 0) {
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
161 return NULL;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
162 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
163 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
164
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
165 Py_INCREF(Py_None);
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
166 return Py_None;
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
167 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
168
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
169
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
170 /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG)
18113
a4763bfed9f0 Fixed typo in comment.
Tim Peters <tim.peters@gmail.com>
parents: 18112
diff changeset
171 PyLong_{As, From}{Unsigned,}LongLong().
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
172
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
173 Note that the meat of the test is contained in testcapi_long.h.
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
174 This is revolting, but delicate code duplication is worse: "almost
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
175 exactly the same" code is needed to test LONG_LONG, but the ubiquitous
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
176 dependence on type names makes it impossible to use a parameterized
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
177 function. A giant macro would be even worse than this. A C++ template
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
178 would be perfect.
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
179
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
180 The "report an error" functions are deliberately not part of the #include
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
181 file: if the test fails, you can set a breakpoint in the appropriate
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
182 error function directly, and crawl back from there in the debugger.
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
183 */
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
184
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
185 #define UNBIND(X) Py_DECREF(X); (X) = NULL
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
186
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
187 static PyObject *
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
188 raise_test_long_error(const char* msg)
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
189 {
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
190 return raiseTestError("test_long_api", msg);
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
191 }
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
192
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
193 #define TESTNAME test_long_api_inner
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
194 #define TYPENAME long
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
195 #define F_S_TO_PY PyLong_FromLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
196 #define F_PY_TO_S PyLong_AsLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
197 #define F_U_TO_PY PyLong_FromUnsignedLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
198 #define F_PY_TO_U PyLong_AsUnsignedLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
199
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
200 #include "testcapi_long.h"
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
201
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
202 static PyObject *
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
203 test_long_api(PyObject* self)
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
204 {
18132
e887d6862f77 Fix error in comment, and in test_long_api and test_longlong_api remove
Tim Peters <tim.peters@gmail.com>
parents: 18113
diff changeset
205 return TESTNAME(raise_test_long_error);
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
206 }
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
207
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
208 #undef TESTNAME
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
209 #undef TYPENAME
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
210 #undef F_S_TO_PY
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
211 #undef F_PY_TO_S
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
212 #undef F_U_TO_PY
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
213 #undef F_PY_TO_U
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
214
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
215 #ifdef HAVE_LONG_LONG
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
216
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
217 static PyObject *
18093
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
218 raise_test_longlong_error(const char* msg)
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
219 {
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
220 return raiseTestError("test_longlong_api", msg);
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
221 }
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
222
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
223 #define TESTNAME test_longlong_api_inner
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
224 #define TYPENAME LONG_LONG
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
225 #define F_S_TO_PY PyLong_FromLongLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
226 #define F_PY_TO_S PyLong_AsLongLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
227 #define F_U_TO_PY PyLong_FromUnsignedLongLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
228 #define F_PY_TO_U PyLong_AsUnsignedLongLong
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
229
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
230 #include "testcapi_long.h"
18093
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
231
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
232 static PyObject *
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
233 test_longlong_api(PyObject* self)
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
234 {
18132
e887d6862f77 Fix error in comment, and in test_long_api and test_longlong_api remove
Tim Peters <tim.peters@gmail.com>
parents: 18113
diff changeset
235 return TESTNAME(raise_test_longlong_error);
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
236 }
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
237
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
238 #undef TESTNAME
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
239 #undef TYPENAME
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
240 #undef F_S_TO_PY
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
241 #undef F_PY_TO_S
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
242 #undef F_U_TO_PY
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
243 #undef F_PY_TO_U
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
244
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
245 /* Test the L code for PyArg_ParseTuple. This should deliver a LONG_LONG
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
246 for both long and int arguments. The test may leak a little memory if
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
247 it fails.
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
248 */
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
249 static PyObject *
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
250 test_L_code(PyObject *self)
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
251 {
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
252 PyObject *tuple, *num;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
253 LONG_LONG value;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
254
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
255 tuple = PyTuple_New(1);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
256 if (tuple == NULL)
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
257 return NULL;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
258
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
259 num = PyLong_FromLong(42);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
260 if (num == NULL)
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
261 return NULL;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
262
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
263 PyTuple_SET_ITEM(tuple, 0, num);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
264
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
265 value = -1;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
266 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
267 return NULL;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
268 if (value != 42)
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
269 return raiseTestError("test_L_code",
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
270 "L code returned wrong value for long 42");
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
271
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
272 Py_DECREF(num);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
273 num = PyInt_FromLong(42);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
274 if (num == NULL)
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
275 return NULL;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
276
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
277 PyTuple_SET_ITEM(tuple, 0, num);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
278
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
279 value = -1;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
280 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
281 return NULL;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
282 if (value != 42)
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
283 return raiseTestError("test_L_code",
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
284 "L code returned wrong value for int 42");
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
285
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
286 Py_DECREF(tuple);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
287 Py_INCREF(Py_None);
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
288 return Py_None;
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
289 }
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
290
18112
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
291 #endif /* ifdef HAVE_LONG_LONG */
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
292
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
293 #ifdef Py_USING_UNICODE
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
294
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
295 /* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
296 of an error.
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
297 */
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
298 static PyObject *
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
299 test_u_code(PyObject *self)
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
300 {
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
301 PyObject *tuple, *obj;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
302 Py_UNICODE *value;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
303 int len;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
304
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
305 tuple = PyTuple_New(1);
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
306 if (tuple == NULL)
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
307 return NULL;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
308
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
309 obj = PyUnicode_Decode("test", strlen("test"),
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
310 "ascii", NULL);
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
311 if (obj == NULL)
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
312 return NULL;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
313
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
314 PyTuple_SET_ITEM(tuple, 0, obj);
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
315
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
316 value = 0;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
317 if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
318 return NULL;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
319 if (value != PyUnicode_AS_UNICODE(obj))
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
320 return raiseTestError("test_u_code",
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
321 "u code returned wrong value for u'test'");
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
322 value = 0;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
323 if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
324 return NULL;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
325 if (value != PyUnicode_AS_UNICODE(obj) ||
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
326 len != PyUnicode_GET_SIZE(obj))
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
327 return raiseTestError("test_u_code",
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
328 "u# code returned wrong values for u'test'");
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
329
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
330 Py_DECREF(tuple);
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
331 Py_INCREF(Py_None);
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
332 return Py_None;
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
333 }
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
334
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
335 #endif
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
336
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
337 /* Simple test of _PyLong_NumBits and _PyLong_Sign. */
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
338 static PyObject *
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
339 test_long_numbits(PyObject *self)
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
340 {
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
341 struct triple {
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
342 long input;
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
343 size_t nbits;
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
344 int sign;
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
345 } testcases[] = {{0, 0, 0},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
346 {1L, 1, 1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
347 {-1L, 1, -1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
348 {2L, 2, 1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
349 {-2L, 2, -1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
350 {3L, 2, 1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
351 {-3L, 2, -1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
352 {4L, 3, 1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
353 {-4L, 3, -1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
354 {0x7fffL, 15, 1}, /* one Python long digit */
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
355 {-0x7fffL, 15, -1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
356 {0xffffL, 16, 1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
357 {-0xffffL, 16, -1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
358 {0xfffffffL, 28, 1},
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
359 {-0xfffffffL, 28, -1}};
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
360 int i;
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
361
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
362 for (i = 0; i < sizeof(testcases) / sizeof(struct triple); ++i) {
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
363 PyObject *plong = PyLong_FromLong(testcases[i].input);
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
364 size_t nbits = _PyLong_NumBits(plong);
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
365 int sign = _PyLong_Sign(plong);
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
366
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
367 Py_DECREF(plong);
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
368 if (nbits != testcases[i].nbits)
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
369 return raiseTestError("test_long_numbits",
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
370 "wrong result for _PyLong_NumBits");
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
371 if (sign != testcases[i].sign)
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
372 return raiseTestError("test_long_numbits",
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
373 "wrong result for _PyLong_Sign");
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
374 }
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
375 Py_INCREF(Py_None);
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
376 return Py_None;
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
377 }
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
378
20117
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
379 static PyObject *
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
380 raise_exception(PyObject *self, PyObject *args)
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
381 {
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
382 PyObject *exc;
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
383 PyObject *exc_args, *v;
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
384 int num_args, i;
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
385
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
386 if (!PyArg_ParseTuple(args, "Oi:raise_exception",
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
387 &exc, &num_args))
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
388 return NULL;
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
389
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
390 exc_args = PyTuple_New(num_args);
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
391 if (exc_args == NULL)
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
392 return NULL;
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
393 for (i = 0; i < num_args; ++i) {
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
394 v = PyInt_FromLong(i);
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
395 if (v == NULL) {
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
396 Py_DECREF(exc_args);
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
397 return NULL;
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
398 }
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
399 PyTuple_SET_ITEM(exc_args, i, v);
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
400 }
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
401 PyErr_SetObject(exc, exc_args);
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
402 return NULL;
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
403 }
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
404
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
405 static PyMethodDef TestMethods[] = {
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
406 {"raise_exception", raise_exception, METH_VARARGS},
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
407 {"test_config", (PyCFunction)test_config, METH_NOARGS},
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
408 {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
409 {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
410 {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
27487
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
411 {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS},
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
412 #ifdef HAVE_LONG_LONG
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
413 {"test_longlong_api", (PyCFunction)test_longlong_api, METH_NOARGS},
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
414 {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
18092
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
415 #endif
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
416 #ifdef Py_USING_UNICODE
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
417 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
418 #endif
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
419 {NULL, NULL} /* sentinel */
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
420 };
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
421
24363
979ff5d0ae07 Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents: 22726
diff changeset
422 PyMODINIT_FUNC
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
423 init_testcapi(void)
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
424 {
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
425 PyObject *m;
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
426
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
427 m = Py_InitModule("_testcapi", TestMethods);
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
428
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
429 TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
430 Py_INCREF(TestError);
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
431 PyModule_AddObject(m, "error", TestError);
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
432 }