annotate Modules/_testcapimodule.c @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents fd25030223b0
children b36cb4602e21
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"
40180
015f89a73929 Get DBL_MAX from float.h not values.h. Will backport.
Martin v. Löwis <martin@v.loewis.de>
parents: 40178
diff changeset
9 #include <float.h>
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
10 #include "structmember.h"
57722
40f3b8b83cc6 add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents: 57277
diff changeset
11 #include "datetime.h"
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
12
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
13 #ifdef WITH_THREAD
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
14 #include "pythread.h"
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
15 #endif /* WITH_THREAD */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
16 static PyObject *TestError; /* set to exception object in init */
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
17
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
18 /* 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
19
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 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
21 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
22 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
23 char buf[2048];
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
24
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
25 if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
26 PyErr_SetString(TestError, "internal error msg too large");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
27 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
28 PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
29 PyErr_SetString(TestError, buf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
30 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
31 return NULL;
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
32 }
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
33
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
34 /* 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
35
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
36 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
37 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
38 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
39 */
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
40 static PyObject*
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
41 sizeof_error(const char* fatname, const char* typname,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
42 int expected, int got)
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
43 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
44 char buf[1024];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
45 PyOS_snprintf(buf, sizeof(buf),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
46 "%.200s #define == %d but sizeof(%.200s) == %d",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
47 fatname, expected, typname, got);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
48 PyErr_SetString(TestError, buf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
49 return (PyObject*)NULL;
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
50 }
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
51
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
52 static PyObject*
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
53 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
54 {
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
55 #define CHECK_SIZEOF(FATNAME, TYPE) \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
56 if (FATNAME != sizeof(TYPE)) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
57 return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
58
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
59 CHECK_SIZEOF(SIZEOF_SHORT, short);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
60 CHECK_SIZEOF(SIZEOF_INT, int);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
61 CHECK_SIZEOF(SIZEOF_LONG, long);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
62 CHECK_SIZEOF(SIZEOF_VOID_P, void*);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
63 CHECK_SIZEOF(SIZEOF_TIME_T, time_t);
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
64 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
65 CHECK_SIZEOF(SIZEOF_LONG_LONG, PY_LONG_LONG);
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
66 #endif
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
67
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
68 #undef CHECK_SIZEOF
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
69
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
70 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
71 return Py_None;
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
72 }
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
73
16582
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
74 static PyObject*
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
75 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
76 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
77 PyObject* list;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
78 int i;
16582
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
79
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
80 /* SF bug 132008: PyList_Reverse segfaults */
16582
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
81 #define NLIST 30
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
82 list = PyList_New(NLIST);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
83 if (list == (PyObject*)NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
84 return (PyObject*)NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
85 /* list = range(NLIST) */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
86 for (i = 0; i < NLIST; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
87 PyObject* anint = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
88 if (anint == (PyObject*)NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
89 Py_DECREF(list);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
90 return (PyObject*)NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
91 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
92 PyList_SET_ITEM(list, i, anint);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
93 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
94 /* list.reverse(), via PyList_Reverse() */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
95 i = PyList_Reverse(list); /* should not blow up! */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
96 if (i != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
97 Py_DECREF(list);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
98 return (PyObject*)NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
99 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
100 /* Check that list == range(29, -1, -1) now */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
101 for (i = 0; i < NLIST; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
102 PyObject* anint = PyList_GET_ITEM(list, i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
103 if (PyInt_AS_LONG(anint) != NLIST-1-i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
104 PyErr_SetString(TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
105 "test_list_api: reverse screwed up");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
106 Py_DECREF(list);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
107 return (PyObject*)NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
108 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
109 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
110 Py_DECREF(list);
16582
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
111 #undef NLIST
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
112
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
113 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
114 return Py_None;
16582
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
115 }
9a8e961b505f Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents: 16447
diff changeset
116
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
117 static int
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
118 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
119 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
120 Py_ssize_t pos = 0, iterations = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
121 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
122 PyObject *dict = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
123 PyObject *v, *k;
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
124
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
125 if (dict == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
126 return -1;
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
127
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
128 for (i = 0; i < count; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
129 v = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
130 PyDict_SetItem(dict, v, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
131 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
132 }
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
133
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
134 while (PyDict_Next(dict, &pos, &k, &v)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
135 PyObject *o;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
136 iterations++;
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
137
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
138 i = PyInt_AS_LONG(v) + 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
139 o = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
140 if (o == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
141 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
142 if (PyDict_SetItem(dict, k, o) < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
143 Py_DECREF(o);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
144 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
145 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
146 Py_DECREF(o);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
147 }
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
148
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
149 Py_DECREF(dict);
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
150
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
151 if (iterations != count) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
152 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
153 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
154 "test_dict_iteration: dict iteration went wrong ");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
155 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
156 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
157 return 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
158 }
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
159 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
160
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
161 static PyObject*
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
162 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
163 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
164 int i;
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
165
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
166 for (i = 0; i < 200; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
167 if (test_dict_inner(i) < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
168 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
169 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
170 }
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
171
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
172 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
173 return Py_None;
17496
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
174 }
0b060cf762ce Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents: 16582
diff changeset
175
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
176
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
177 /* Issue #4701: Check that PyObject_Hash implicitly calls
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
178 * PyType_Ready if it hasn't already been called
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
179 */
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
180 static PyTypeObject _HashInheritanceTester_Type = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
181 PyObject_HEAD_INIT(NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
182 0, /* Number of items for varobject */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
183 "hashinheritancetester", /* Name of this type */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
184 sizeof(PyObject), /* Basic object size */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
185 0, /* Item size for varobject */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
186 (destructor)PyObject_Del, /* tp_dealloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
187 0, /* tp_print */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
188 0, /* tp_getattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
189 0, /* tp_setattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
190 0, /* tp_compare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
191 0, /* tp_repr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
192 0, /* tp_as_number */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
193 0, /* tp_as_sequence */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
194 0, /* tp_as_mapping */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
195 0, /* tp_hash */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
196 0, /* tp_call */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
197 0, /* tp_str */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
198 PyObject_GenericGetAttr, /* tp_getattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
199 0, /* tp_setattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
200 0, /* tp_as_buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
201 Py_TPFLAGS_DEFAULT, /* tp_flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
202 0, /* tp_doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
203 0, /* tp_traverse */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
204 0, /* tp_clear */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
205 0, /* tp_richcompare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
206 0, /* tp_weaklistoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
207 0, /* tp_iter */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
208 0, /* tp_iternext */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
209 0, /* tp_methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
210 0, /* tp_members */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
211 0, /* tp_getset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
212 0, /* tp_base */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
213 0, /* tp_dict */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
214 0, /* tp_descr_get */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
215 0, /* tp_descr_set */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
216 0, /* tp_dictoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
217 0, /* tp_init */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
218 0, /* tp_alloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
219 PyType_GenericNew, /* tp_new */
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
220 };
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
221
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
222 static PyObject*
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
223 test_lazy_hash_inheritance(PyObject* self)
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
224 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
225 PyTypeObject *type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
226 PyObject *obj;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
227 long hash;
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
228
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
229 type = &_HashInheritanceTester_Type;
53810
8f7cf5cb21bb fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents: 52210
diff changeset
230
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
231 if (type->tp_dict != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
232 /* The type has already been initialized. This probably means
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
233 -R is being used. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
234 Py_RETURN_NONE;
53810
8f7cf5cb21bb fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents: 52210
diff changeset
235
8f7cf5cb21bb fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents: 52210
diff changeset
236
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
237 obj = PyObject_New(PyObject, type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
238 if (obj == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
239 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
240 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
241 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
242 "test_lazy_hash_inheritance: failed to create object");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
243 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
244 }
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
245
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
246 if (type->tp_dict != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
247 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
248 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
249 "test_lazy_hash_inheritance: type initialised too soon");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
250 Py_DECREF(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
251 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
252 }
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
253
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
254 hash = PyObject_Hash(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
255 if ((hash == -1) && PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
256 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
257 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
258 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
259 "test_lazy_hash_inheritance: could not hash object");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
260 Py_DECREF(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
261 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
262 }
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
263
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
264 if (type->tp_dict == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
265 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
266 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
267 "test_lazy_hash_inheritance: type not initialised by hash()");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
268 Py_DECREF(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
269 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
270 }
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
271
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
272 if (type->tp_hash != PyType_Type.tp_hash) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
273 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
274 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
275 "test_lazy_hash_inheritance: unexpected hash function");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
276 Py_DECREF(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
277 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
278 }
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
279
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
280 Py_DECREF(obj);
53810
8f7cf5cb21bb fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents: 52210
diff changeset
281
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
282 Py_RETURN_NONE;
50369
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
283 }
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
284
7aaef4d5f880 Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents: 50277
diff changeset
285
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
286 /* Issue #7385: Check that memoryview() does not crash
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
287 * when bf_getbuffer returns an error
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
288 */
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
289
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
290 static int
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
291 broken_buffer_getbuffer(PyObject *self, Py_buffer *view, int flags)
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
292 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
293 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
294 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
295 "test_broken_memoryview: expected error in bf_getbuffer");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
296 return -1;
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
297 }
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
298
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
299 static PyBufferProcs memoryviewtester_as_buffer = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
300 0, /* bf_getreadbuffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
301 0, /* bf_getwritebuffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
302 0, /* bf_getsegcount */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
303 0, /* bf_getcharbuffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
304 (getbufferproc)broken_buffer_getbuffer, /* bf_getbuffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
305 0, /* bf_releasebuffer */
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
306 };
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
307
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
308 static PyTypeObject _MemoryViewTester_Type = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
309 PyObject_HEAD_INIT(NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
310 0, /* Number of items for varobject */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
311 "memoryviewtester", /* Name of this type */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
312 sizeof(PyObject), /* Basic object size */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
313 0, /* Item size for varobject */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
314 (destructor)PyObject_Del, /* tp_dealloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
315 0, /* tp_print */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
316 0, /* tp_getattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
317 0, /* tp_setattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
318 0, /* tp_compare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
319 0, /* tp_repr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
320 0, /* tp_as_number */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
321 0, /* tp_as_sequence */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
322 0, /* tp_as_mapping */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
323 0, /* tp_hash */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
324 0, /* tp_call */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
325 0, /* tp_str */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
326 PyObject_GenericGetAttr, /* tp_getattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
327 0, /* tp_setattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
328 &memoryviewtester_as_buffer, /* tp_as_buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
329 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_NEWBUFFER, /* tp_flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
330 0, /* tp_doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
331 0, /* tp_traverse */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
332 0, /* tp_clear */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
333 0, /* tp_richcompare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
334 0, /* tp_weaklistoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
335 0, /* tp_iter */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
336 0, /* tp_iternext */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
337 0, /* tp_methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
338 0, /* tp_members */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
339 0, /* tp_getset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
340 0, /* tp_base */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
341 0, /* tp_dict */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
342 0, /* tp_descr_get */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
343 0, /* tp_descr_set */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
344 0, /* tp_dictoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
345 0, /* tp_init */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
346 0, /* tp_alloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
347 PyType_GenericNew, /* tp_new */
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
348 };
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
349
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
350 static PyObject*
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
351 test_broken_memoryview(PyObject* self)
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
352 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
353 PyObject *obj = PyObject_New(PyObject, &_MemoryViewTester_Type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
354 PyObject *res;
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
355
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
356 if (obj == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
357 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
358 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
359 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
360 "test_broken_memoryview: failed to create object");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
361 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
362 }
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
363
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
364 res = PyMemoryView_FromObject(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
365 if (res || !PyErr_Occurred()){
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
366 PyErr_SetString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
367 TestError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
368 "test_broken_memoryview: memoryview() didn't raise an Exception");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
369 Py_XDECREF(res);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
370 Py_DECREF(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
371 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
372 }
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
373
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
374 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
375 Py_DECREF(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
376 Py_RETURN_NONE;
58643
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
377 }
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
378
c37f99b54d7c Issue #7385: Fix a crash in `MemoryView_FromObject` when
Antoine Pitrou <solipsis@pitrou.net>
parents: 58604
diff changeset
379
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
380 /* 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
381 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
382
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
383 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
384 This is revolting, but delicate code duplication is worse: "almost
28437
871da703e4c0 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents: 27549
diff changeset
385 exactly the same" code is needed to test PY_LONG_LONG, but the ubiquitous
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
386 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
387 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
388 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
389
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
390 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
391 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
392 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
393 */
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
394
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
395 #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
396
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
397 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
398 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
399 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
400 return raiseTestError("test_long_api", msg);
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
401 }
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
402
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
403 #define TESTNAME test_long_api_inner
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
404 #define TYPENAME long
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
405 #define F_S_TO_PY PyLong_FromLong
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
406 #define F_PY_TO_S PyLong_AsLong
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
407 #define F_U_TO_PY PyLong_FromUnsignedLong
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
408 #define F_PY_TO_U PyLong_AsUnsignedLong
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
409
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
410 #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
411
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
412 static PyObject *
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
413 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
414 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
415 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
416 }
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
417
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
418 #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
419 #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
420 #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
421 #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
422 #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
423 #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
424
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
425 #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
426
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
427 static PyObject *
18093
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
428 raise_test_longlong_error(const char* msg)
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
429 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
430 return raiseTestError("test_longlong_api", msg);
18093
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
431 }
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
432
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
433 #define TESTNAME test_longlong_api_inner
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
434 #define TYPENAME PY_LONG_LONG
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
435 #define F_S_TO_PY PyLong_FromLongLong
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
436 #define F_PY_TO_S PyLong_AsLongLong
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
437 #define F_U_TO_PY PyLong_FromUnsignedLongLong
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
438 #define F_PY_TO_U PyLong_AsUnsignedLongLong
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
439
9eb469a43144 Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents: 18093
diff changeset
440 #include "testcapi_long.h"
18093
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
441
6ea366a2b2a6 longobject.c:
Tim Peters <tim.peters@gmail.com>
parents: 18092
diff changeset
442 static PyObject *
37822
3ede175ead37 correct function signature
Skip Montanaro <skip@pobox.com>
parents: 37674
diff changeset
443 test_longlong_api(PyObject* self, PyObject *args)
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
444 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
445 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
446 }
bd0056ee1a6e The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents: 17496
diff changeset
447
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
448 #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
449 #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
450 #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
451 #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
452 #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
453 #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
454
57851
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
455 /* Test the PyLong_AsLongAndOverflow API. General conversion to PY_LONG
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
456 is tested by test_long_api_inner. This test will concentrate on proper
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
457 handling of overflow.
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
458 */
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
459
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
460 static PyObject *
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
461 test_long_and_overflow(PyObject *self)
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
462 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
463 PyObject *num, *one, *temp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
464 long value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
465 int overflow;
57851
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
466
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
467 /* Test that overflow is set properly for a large value. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
468 /* num is a number larger than LONG_MAX even on 64-bit platforms */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
469 num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
470 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
471 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
472 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
473 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
474 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
475 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
476 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
477 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
478 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
479 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
480 if (overflow != 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
481 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
482 "overflow was not set to 1");
57855
6d09e3fdf840 Additional edge-case tests for test_long_and_overflow.
Mark Dickinson <dickinsm@gmail.com>
parents: 57854
diff changeset
483
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
484 /* Same again, with num = LONG_MAX + 1 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
485 num = PyLong_FromLong(LONG_MAX);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
486 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
487 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
488 one = PyLong_FromLong(1L);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
489 if (one == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
490 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
491 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
492 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
493 temp = PyNumber_Add(num, one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
494 Py_DECREF(one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
495 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
496 num = temp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
497 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
498 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
499 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
500 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
501 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
502 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
503 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
504 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
505 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
506 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
507 if (overflow != 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
508 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
509 "overflow was not set to 1");
57851
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
510
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
511 /* Test that overflow is set properly for a large negative value. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
512 /* num is a number smaller than LONG_MIN even on 64-bit platforms */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
513 num = PyLong_FromString("-FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
514 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
515 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
516 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
517 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
518 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
519 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
520 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
521 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
522 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
523 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
524 if (overflow != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
525 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
526 "overflow was not set to -1");
57855
6d09e3fdf840 Additional edge-case tests for test_long_and_overflow.
Mark Dickinson <dickinsm@gmail.com>
parents: 57854
diff changeset
527
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
528 /* Same again, with num = LONG_MIN - 1 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
529 num = PyLong_FromLong(LONG_MIN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
530 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
531 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
532 one = PyLong_FromLong(1L);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
533 if (one == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
534 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
535 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
536 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
537 temp = PyNumber_Subtract(num, one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
538 Py_DECREF(one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
539 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
540 num = temp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
541 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
542 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
543 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
544 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
545 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
546 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
547 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
548 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
549 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
550 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
551 if (overflow != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
552 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
553 "overflow was not set to -1");
57851
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
554
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
555 /* Test that overflow is cleared properly for small values. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
556 num = PyLong_FromString("FF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
557 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
558 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
559 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
560 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
561 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
562 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
563 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
564 if (value != 0xFF)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
565 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
566 "expected return value 0xFF");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
567 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
568 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
569 "overflow was not cleared");
57851
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
570
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
571 num = PyLong_FromString("-FF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
572 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
573 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
574 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
575 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
576 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
577 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
578 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
579 if (value != -0xFF)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
580 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
581 "expected return value 0xFF");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
582 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
583 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
584 "overflow was set incorrectly");
57851
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
585
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
586 num = PyLong_FromLong(LONG_MAX);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
587 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
588 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
589 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
590 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
591 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
592 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
593 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
594 if (value != LONG_MAX)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
595 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
596 "expected return value LONG_MAX");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
597 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
598 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
599 "overflow was not cleared");
57855
6d09e3fdf840 Additional edge-case tests for test_long_and_overflow.
Mark Dickinson <dickinsm@gmail.com>
parents: 57854
diff changeset
600
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
601 num = PyLong_FromLong(LONG_MIN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
602 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
603 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
604 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
605 value = PyLong_AsLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
606 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
607 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
608 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
609 if (value != LONG_MIN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
610 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
611 "expected return value LONG_MIN");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
612 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
613 return raiseTestError("test_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
614 "overflow was not cleared");
57854
7b2eaa34b86b Fix reference counts for test_long_and_overflow.
Mark Dickinson <dickinsm@gmail.com>
parents: 57851
diff changeset
615
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
616 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
617 return Py_None;
57851
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
618 }
28de83f17d08 Issue #7528: Backport PyLong_AsLongAndOverflow from py3k to trunk.
Mark Dickinson <dickinsm@gmail.com>
parents: 57821
diff changeset
619
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
620 /* Test the PyLong_AsLongLongAndOverflow API. General conversion to
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
621 PY_LONG_LONG is tested by test_long_api_inner. This test will
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
622 concentrate on proper handling of overflow.
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
623 */
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
624
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
625 static PyObject *
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
626 test_long_long_and_overflow(PyObject *self)
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
627 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
628 PyObject *num, *one, *temp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
629 PY_LONG_LONG value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
630 int overflow;
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
631
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
632 /* Test that overflow is set properly for a large value. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
633 /* num is a number larger than PY_LLONG_MAX on a typical machine. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
634 num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
635 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
636 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
637 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
638 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
639 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
640 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
641 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
642 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
643 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
644 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
645 if (overflow != 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
646 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
647 "overflow was not set to 1");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
648
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
649 /* Same again, with num = PY_LLONG_MAX + 1 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
650 num = PyLong_FromLongLong(PY_LLONG_MAX);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
651 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
652 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
653 one = PyLong_FromLong(1L);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
654 if (one == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
655 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
656 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
657 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
658 temp = PyNumber_Add(num, one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
659 Py_DECREF(one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
660 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
661 num = temp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
662 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
663 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
664 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
665 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
666 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
667 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
668 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
669 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
670 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
671 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
672 if (overflow != 1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
673 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
674 "overflow was not set to 1");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
675
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
676 /* Test that overflow is set properly for a large negative value. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
677 /* num is a number smaller than PY_LLONG_MIN on a typical platform */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
678 num = PyLong_FromString("-FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
679 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
680 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
681 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
682 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
683 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
684 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
685 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
686 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
687 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
688 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
689 if (overflow != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
690 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
691 "overflow was not set to -1");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
692
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
693 /* Same again, with num = PY_LLONG_MIN - 1 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
694 num = PyLong_FromLongLong(PY_LLONG_MIN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
695 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
696 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
697 one = PyLong_FromLong(1L);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
698 if (one == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
699 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
700 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
701 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
702 temp = PyNumber_Subtract(num, one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
703 Py_DECREF(one);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
704 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
705 num = temp;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
706 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
707 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
708 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
709 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
710 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
711 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
712 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
713 if (value != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
714 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
715 "return value was not set to -1");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
716 if (overflow != -1)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
717 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
718 "overflow was not set to -1");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
719
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
720 /* Test that overflow is cleared properly for small values. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
721 num = PyLong_FromString("FF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
722 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
723 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
724 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
725 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
726 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
727 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
728 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
729 if (value != 0xFF)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
730 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
731 "expected return value 0xFF");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
732 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
733 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
734 "overflow was not cleared");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
735
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
736 num = PyLong_FromString("-FF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
737 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
738 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
739 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
740 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
741 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
742 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
743 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
744 if (value != -0xFF)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
745 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
746 "expected return value 0xFF");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
747 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
748 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
749 "overflow was set incorrectly");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
750
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
751 num = PyLong_FromLongLong(PY_LLONG_MAX);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
752 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
753 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
754 overflow = 1234;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
755 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
756 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
757 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
758 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
759 if (value != PY_LLONG_MAX)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
760 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
761 "expected return value PY_LLONG_MAX");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
762 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
763 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
764 "overflow was not cleared");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
765
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
766 num = PyLong_FromLongLong(PY_LLONG_MIN);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
767 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
768 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
769 overflow = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
770 value = PyLong_AsLongLongAndOverflow(num, &overflow);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
771 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
772 if (value == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
773 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
774 if (value != PY_LLONG_MIN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
775 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
776 "expected return value PY_LLONG_MIN");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
777 if (overflow != 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
778 return raiseTestError("test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
779 "overflow was not cleared");
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
780
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
781 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
782 return Py_None;
58581
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
783 }
6295e16303a7 Issue #7767: Add new C-API function PyLong_AsLongLongAndOverflow, a
Mark Dickinson <dickinsm@gmail.com>
parents: 57961
diff changeset
784
28437
871da703e4c0 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents: 27549
diff changeset
785 /* Test the L code for PyArg_ParseTuple. This should deliver a PY_LONG_LONG
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
786 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
787 it fails.
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
788 */
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
789 static PyObject *
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
790 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
791 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
792 PyObject *tuple, *num;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
793 PY_LONG_LONG value;
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
794
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
795 tuple = PyTuple_New(1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
796 if (tuple == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
797 return NULL;
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
798
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
799 num = PyLong_FromLong(42);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
800 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
801 return NULL;
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
802
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
803 PyTuple_SET_ITEM(tuple, 0, num);
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
804
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
805 value = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
806 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
807 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
808 if (value != 42)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
809 return raiseTestError("test_L_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
810 "L code returned wrong value for long 42");
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
811
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
812 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
813 num = PyInt_FromLong(42);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
814 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
815 return NULL;
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
816
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
817 PyTuple_SET_ITEM(tuple, 0, num);
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
818
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
819 value = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
820 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
821 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
822 if (value != 42)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
823 return raiseTestError("test_L_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
824 "L code returned wrong value for int 42");
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
825
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
826 Py_DECREF(tuple);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
827 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
828 return Py_None;
20182
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
829 }
6d73b54d9205 SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents: 20117
diff changeset
830
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
831 #endif /* ifdef HAVE_LONG_LONG */
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
832
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 38175
diff changeset
833 /* Test tuple argument processing */
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 38175
diff changeset
834 static PyObject *
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 38175
diff changeset
835 getargs_tuple(PyObject *self, PyObject *args)
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 38175
diff changeset
836 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
837 int a, b, c;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
838 if (!PyArg_ParseTuple(args, "i(ii)", &a, &b, &c))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
839 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
840 return Py_BuildValue("iii", a, b, c);
39189
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 38175
diff changeset
841 }
17d5671fffcc Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents: 38175
diff changeset
842
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 44864
diff changeset
843 /* test PyArg_ParseTupleAndKeywords */
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 44864
diff changeset
844 static PyObject *getargs_keywords(PyObject *self, PyObject *args, PyObject *kwargs)
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 44864
diff changeset
845 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
846 static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
847 static char *fmt="(ii)i|(i(ii))(iii)i";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
848 int int_args[10]={-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 44864
diff changeset
849
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
850 if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
851 &int_args[0], &int_args[1], &int_args[2], &int_args[3], &int_args[4],
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
852 &int_args[5], &int_args[6], &int_args[7], &int_args[8], &int_args[9]))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
853 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
854 return Py_BuildValue("iiiiiiiiii",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
855 int_args[0], int_args[1], int_args[2], int_args[3], int_args[4],
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
856 int_args[5], int_args[6], int_args[7], int_args[8], int_args[9]);
45537
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 44864
diff changeset
857 }
f33f66a2082f Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents: 44864
diff changeset
858
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
859 /* Functions to call PyArg_ParseTuple with integer format codes,
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
860 and return the result.
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
861 */
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
862 static PyObject *
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
863 getargs_b(PyObject *self, PyObject *args)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
864 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
865 unsigned char value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
866 if (!PyArg_ParseTuple(args, "b", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
867 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
868 return PyLong_FromUnsignedLong((unsigned long)value);
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
869 }
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
870
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
871 static PyObject *
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
872 getargs_B(PyObject *self, PyObject *args)
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
873 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
874 unsigned char value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
875 if (!PyArg_ParseTuple(args, "B", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
876 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
877 return PyLong_FromUnsignedLong((unsigned long)value);
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
878 }
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
879
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
880 static PyObject *
57821
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 57722
diff changeset
881 getargs_h(PyObject *self, PyObject *args)
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 57722
diff changeset
882 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
883 short value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
884 if (!PyArg_ParseTuple(args, "h", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
885 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
886 return PyLong_FromLong((long)value);
57821
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 57722
diff changeset
887 }
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 57722
diff changeset
888
7941a9f865c2 Add missing tests for PyArg_Parse* with format 'h'
Mark Dickinson <dickinsm@gmail.com>
parents: 57722
diff changeset
889 static PyObject *
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
890 getargs_H(PyObject *self, PyObject *args)
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
891 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
892 unsigned short value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
893 if (!PyArg_ParseTuple(args, "H", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
894 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
895 return PyLong_FromUnsignedLong((unsigned long)value);
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
896 }
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
897
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
898 static PyObject *
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
899 getargs_I(PyObject *self, PyObject *args)
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
900 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
901 unsigned int value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
902 if (!PyArg_ParseTuple(args, "I", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
903 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
904 return PyLong_FromUnsignedLong((unsigned long)value);
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
905 }
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
906
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
907 static PyObject *
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
908 getargs_k(PyObject *self, PyObject *args)
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
909 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
910 unsigned long value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
911 if (!PyArg_ParseTuple(args, "k", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
912 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
913 return PyLong_FromUnsignedLong(value);
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
914 }
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
915
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
916 static PyObject *
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
917 getargs_i(PyObject *self, PyObject *args)
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
918 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
919 int value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
920 if (!PyArg_ParseTuple(args, "i", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
921 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
922 return PyLong_FromLong((long)value);
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
923 }
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
924
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
925 static PyObject *
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
926 getargs_l(PyObject *self, PyObject *args)
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
927 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
928 long value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
929 if (!PyArg_ParseTuple(args, "l", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
930 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
931 return PyLong_FromLong(value);
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
932 }
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
933
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 37670
diff changeset
934 static PyObject *
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 37670
diff changeset
935 getargs_n(PyObject *self, PyObject *args)
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 37670
diff changeset
936 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
937 Py_ssize_t value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
938 if (!PyArg_ParseTuple(args, "n", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
939 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
940 return PyInt_FromSsize_t(value);
37674
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 37670
diff changeset
941 }
a4231aa3201a Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents: 37670
diff changeset
942
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
943 #ifdef HAVE_LONG_LONG
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
944 static PyObject *
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
945 getargs_L(PyObject *self, PyObject *args)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
946 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
947 PY_LONG_LONG value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
948 if (!PyArg_ParseTuple(args, "L", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
949 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
950 return PyLong_FromLongLong(value);
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
951 }
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
952
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
953 static PyObject *
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
954 getargs_K(PyObject *self, PyObject *args)
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
955 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
956 unsigned PY_LONG_LONG value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
957 if (!PyArg_ParseTuple(args, "K", &value))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
958 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
959 return PyLong_FromUnsignedLongLong(value);
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
960 }
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
961 #endif
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
962
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
963 /* This function not only tests the 'k' getargs code, but also the
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
964 PyInt_AsUnsignedLongMask() and PyInt_AsUnsignedLongMask() functions. */
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
965 static PyObject *
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
966 test_k_code(PyObject *self)
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
967 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
968 PyObject *tuple, *num;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
969 unsigned long value;
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
970
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
971 tuple = PyTuple_New(1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
972 if (tuple == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
973 return NULL;
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
974
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
975 /* a number larger than ULONG_MAX even on 64-bit platforms */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
976 num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
977 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
978 return NULL;
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
979
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
980 value = PyInt_AsUnsignedLongMask(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
981 if (value != ULONG_MAX)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
982 return raiseTestError("test_k_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
983 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
984
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
985 PyTuple_SET_ITEM(tuple, 0, num);
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
986
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
987 value = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
988 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
989 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
990 if (value != ULONG_MAX)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
991 return raiseTestError("test_k_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
992 "k code returned wrong value for long 0xFFF...FFF");
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
993
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
994 Py_DECREF(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
995 num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
996 if (num == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
997 return NULL;
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
998
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
999 value = PyInt_AsUnsignedLongMask(num);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1000 if (value != (unsigned long)-0x42)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1001 return raiseTestError("test_k_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1002 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1003
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1004 PyTuple_SET_ITEM(tuple, 0, num);
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1005
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1006 value = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1007 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1008 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1009 if (value != (unsigned long)-0x42)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1010 return raiseTestError("test_k_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1011 "k code returned wrong value for long -0xFFF..000042");
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1012
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1013 Py_DECREF(tuple);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1014 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1015 return Py_None;
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1016 }
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1017
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1018 #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
1019
50277
10097bd65564 make global static
Benjamin Peterson <benjamin@python.org>
parents: 50276
diff changeset
1020 static volatile int x;
50276
8751288ddd96 use a global variable, so the compiler doesn't optimize the assignment out
Benjamin Peterson <benjamin@python.org>
parents: 50264
diff changeset
1021
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1022 /* 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
1023 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
1024 */
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1025 static PyObject *
22726
c84110f05dc3 Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents: 21667
diff changeset
1026 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
1027 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1028 PyObject *tuple, *obj;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1029 Py_UNICODE *value;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1030 int len;
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1031
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1032 /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1033 /* Just use the macro and check that it compiles */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1034 x = Py_UNICODE_ISSPACE(25);
49502
e1a88e8b9649 Merged revisions 66891 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48841
diff changeset
1035
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1036 tuple = PyTuple_New(1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1037 if (tuple == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1038 return NULL;
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1039
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1040 obj = PyUnicode_Decode("test", strlen("test"),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1041 "ascii", NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1042 if (obj == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1043 return NULL;
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1044
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1045 PyTuple_SET_ITEM(tuple, 0, obj);
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1046
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1047 value = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1048 if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1049 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1050 if (value != PyUnicode_AS_UNICODE(obj))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1051 return raiseTestError("test_u_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1052 "u code returned wrong value for u'test'");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1053 value = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1054 if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1055 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1056 if (value != PyUnicode_AS_UNICODE(obj) ||
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1057 len != PyUnicode_GET_SIZE(obj))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1058 return raiseTestError("test_u_code",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1059 "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
1060
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1061 Py_DECREF(tuple);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1062 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1063 return Py_None;
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1064 }
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1065
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1066 static PyObject *
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1067 test_widechar(PyObject *self)
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1068 {
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1069 #if defined(SIZEOF_WCHAR_T) && (SIZEOF_WCHAR_T == 4)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1070 const wchar_t wtext[2] = {(wchar_t)0x10ABCDu};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1071 size_t wtextlen = 1;
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1072 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1073 const wchar_t wtext[3] = {(wchar_t)0xDBEAu, (wchar_t)0xDFCDu};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1074 size_t wtextlen = 2;
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1075 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1076 PyObject *wide, *utf8;
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1077
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1078 wide = PyUnicode_FromWideChar(wtext, wtextlen);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1079 if (wide == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1080 return NULL;
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1081
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1082 utf8 = PyUnicode_FromString("\xf4\x8a\xaf\x8d");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1083 if (utf8 == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1084 Py_DECREF(wide);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1085 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1086 }
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1087
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1088 if (PyUnicode_GET_SIZE(wide) != PyUnicode_GET_SIZE(utf8)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1089 Py_DECREF(wide);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1090 Py_DECREF(utf8);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1091 return raiseTestError("test_widechar",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1092 "wide string and utf8 string have different length");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1093 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1094 if (PyUnicode_Compare(wide, utf8)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1095 Py_DECREF(wide);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1096 Py_DECREF(utf8);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1097 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1098 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1099 return raiseTestError("test_widechar",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1100 "wide string and utf8 string are differents");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1101 }
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1102
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1103 Py_DECREF(wide);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1104 Py_DECREF(utf8);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1105 Py_RETURN_NONE;
52210
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1106 }
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1107
c73dd25c01c1 Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents: 50675
diff changeset
1108 static PyObject *
50262
bd3c5de4cc54 fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents: 49502
diff changeset
1109 test_empty_argparse(PyObject *self)
bd3c5de4cc54 fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents: 49502
diff changeset
1110 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1111 /* Test that formats can begin with '|'. See issue #4720. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1112 PyObject *tuple, *dict = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1113 static char *kwlist[] = {NULL};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1114 int result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1115 tuple = PyTuple_New(0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1116 if (!tuple)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1117 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1118 if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1119 goto done;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1120 dict = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1121 if (!dict)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1122 goto done;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1123 result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist);
50262
bd3c5de4cc54 fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents: 49502
diff changeset
1124 done:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1125 Py_DECREF(tuple);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1126 Py_XDECREF(dict);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1127 if (result < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1128 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1129 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1130 Py_RETURN_NONE;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1131 }
50262
bd3c5de4cc54 fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents: 49502
diff changeset
1132 }
bd3c5de4cc54 fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents: 49502
diff changeset
1133
bd3c5de4cc54 fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents: 49502
diff changeset
1134 static PyObject *
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1135 codec_incrementalencoder(PyObject *self, PyObject *args)
37077
38400b662404 Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents: 36989
diff changeset
1136 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1137 const char *encoding, *errors = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1138 if (!PyArg_ParseTuple(args, "s|s:test_incrementalencoder",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1139 &encoding, &errors))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1140 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1141 return PyCodec_IncrementalEncoder(encoding, errors);
37077
38400b662404 Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents: 36989
diff changeset
1142 }
38400b662404 Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents: 36989
diff changeset
1143
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1144 static PyObject *
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1145 codec_incrementaldecoder(PyObject *self, PyObject *args)
37077
38400b662404 Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents: 36989
diff changeset
1146 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1147 const char *encoding, *errors = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1148 if (!PyArg_ParseTuple(args, "s|s:test_incrementaldecoder",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1149 &encoding, &errors))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1150 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1151 return PyCodec_IncrementalDecoder(encoding, errors);
37077
38400b662404 Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents: 36989
diff changeset
1152 }
38400b662404 Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents: 36989
diff changeset
1153
21667
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1154 #endif
0d3bb68e3a28 Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents: 21073
diff changeset
1155
27549
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
1156 /* 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
1157 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
1158 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
1159 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1160 struct triple {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1161 long input;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1162 size_t nbits;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1163 int sign;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1164 } testcases[] = {{0, 0, 0},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1165 {1L, 1, 1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1166 {-1L, 1, -1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1167 {2L, 2, 1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1168 {-2L, 2, -1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1169 {3L, 2, 1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1170 {-3L, 2, -1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1171 {4L, 3, 1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1172 {-4L, 3, -1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1173 {0x7fffL, 15, 1}, /* one Python long digit */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1174 {-0x7fffL, 15, -1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1175 {0xffffL, 16, 1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1176 {-0xffffL, 16, -1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1177 {0xfffffffL, 28, 1},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1178 {-0xfffffffL, 28, -1}};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1179 int i;
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
1180
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1181 for (i = 0; i < sizeof(testcases) / sizeof(struct triple); ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1182 PyObject *plong = PyLong_FromLong(testcases[i].input);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1183 size_t nbits = _PyLong_NumBits(plong);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1184 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
1185
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1186 Py_DECREF(plong);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1187 if (nbits != testcases[i].nbits)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1188 return raiseTestError("test_long_numbits",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1189 "wrong result for _PyLong_NumBits");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1190 if (sign != testcases[i].sign)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1191 return raiseTestError("test_long_numbits",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1192 "wrong result for _PyLong_Sign");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1193 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1194 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1195 return Py_None;
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
1196 }
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24363
diff changeset
1197
36989
aba814aa4c6a Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1198 /* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */
aba814aa4c6a Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1199
aba814aa4c6a Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1200 static PyObject *
aba814aa4c6a Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1201 test_null_strings(PyObject *self)
aba814aa4c6a Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1202 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1203 PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1204 PyObject *tuple = PyTuple_Pack(2, o1, o2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1205 Py_XDECREF(o1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1206 Py_XDECREF(o2);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1207 return tuple;
36989
aba814aa4c6a Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1208 }
aba814aa4c6a Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1209
20117
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
1210 static PyObject *
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
1211 raise_exception(PyObject *self, PyObject *args)
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
1212 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1213 PyObject *exc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1214 PyObject *exc_args, *v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1215 int num_args, i;
20117
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
1216
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1217 if (!PyArg_ParseTuple(args, "Oi:raise_exception",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1218 &exc, &num_args))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1219 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1220 if (!PyExceptionClass_Check(exc)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1221 PyErr_Format(PyExc_TypeError, "an exception class is required");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1222 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1223 }
20117
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
1224
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1225 exc_args = PyTuple_New(num_args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1226 if (exc_args == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1227 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1228 for (i = 0; i < num_args; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1229 v = PyInt_FromLong(i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1230 if (v == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1231 Py_DECREF(exc_args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1232 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1233 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1234 PyTuple_SET_ITEM(exc_args, i, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1235 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1236 PyErr_SetObject(exc, exc_args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1237 Py_DECREF(exc_args);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1238 return NULL;
20117
e026f517f655 Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 18835
diff changeset
1239 }
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
1240
58604
68c56c4b8631 be robust against test being run over and over (such as -R)
Benjamin Peterson <benjamin@python.org>
parents: 58603
diff changeset
1241
68c56c4b8631 be robust against test being run over and over (such as -R)
Benjamin Peterson <benjamin@python.org>
parents: 58603
diff changeset
1242 static int test_run_counter = 0;
68c56c4b8631 be robust against test being run over and over (such as -R)
Benjamin Peterson <benjamin@python.org>
parents: 58603
diff changeset
1243
57722
40f3b8b83cc6 add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents: 57277
diff changeset
1244 static PyObject *
40f3b8b83cc6 add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents: 57277
diff changeset
1245 test_datetime_capi(PyObject *self, PyObject *args) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1246 if (PyDateTimeAPI) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1247 if (test_run_counter) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1248 /* Probably regrtest.py -R */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1249 Py_RETURN_NONE;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1250 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1251 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1252 PyErr_SetString(PyExc_AssertionError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1253 "PyDateTime_CAPI somehow initialized");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1254 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1255 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1256 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1257 test_run_counter++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1258 PyDateTime_IMPORT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1259 if (PyDateTimeAPI)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1260 Py_RETURN_NONE;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1261 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1262 return NULL;
57722
40f3b8b83cc6 add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents: 57277
diff changeset
1263 }
40f3b8b83cc6 add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents: 57277
diff changeset
1264
58603
fe086abb4aeb move test outside WITH_THREAD section
Benjamin Peterson <benjamin@python.org>
parents: 58581
diff changeset
1265
fe086abb4aeb move test outside WITH_THREAD section
Benjamin Peterson <benjamin@python.org>
parents: 58581
diff changeset
1266 #ifdef WITH_THREAD
fe086abb4aeb move test outside WITH_THREAD section
Benjamin Peterson <benjamin@python.org>
parents: 58581
diff changeset
1267
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1268 /* test_thread_state spawns a thread of its own, and that thread releases
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1269 * `thread_done` when it's finished. The driver code has to know when the
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1270 * thread finishes, because the thread uses a PyObject (the callable) that
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1271 * may go away when the driver finishes. The former lack of this explicit
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1272 * synchronization caused rare segfaults, so rare that they were seen only
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1273 * on a Mac buildbot (although they were possible on any box).
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1274 */
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1275 static PyThread_type_lock thread_done = NULL;
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1276
48841
76e71cecc4d3 #3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents: 47925
diff changeset
1277 static int
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1278 _make_call(void *callable)
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1279 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1280 PyObject *rc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1281 int success;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1282 PyGILState_STATE s = PyGILState_Ensure();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1283 rc = PyObject_CallFunction((PyObject *)callable, "");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1284 success = (rc != NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1285 Py_XDECREF(rc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1286 PyGILState_Release(s);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1287 return success;
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1288 }
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1289
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1290 /* Same thing, but releases `thread_done` when it returns. This variant
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1291 * should be called only from threads spawned by test_thread_state().
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1292 */
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1293 static void
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1294 _make_call_from_thread(void *callable)
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1295 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1296 _make_call(callable);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1297 PyThread_release_lock(thread_done);
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1298 }
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1299
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1300 static PyObject *
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1301 test_thread_state(PyObject *self, PyObject *args)
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1302 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1303 PyObject *fn;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1304 int success = 1;
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1305
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1306 if (!PyArg_ParseTuple(args, "O:test_thread_state", &fn))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1307 return NULL;
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1308
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1309 if (!PyCallable_Check(fn)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1310 PyErr_Format(PyExc_TypeError, "'%s' object is not callable",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1311 fn->ob_type->tp_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1312 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1313 }
48841
76e71cecc4d3 #3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents: 47925
diff changeset
1314
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1315 /* Ensure Python is set up for threading */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1316 PyEval_InitThreads();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1317 thread_done = PyThread_allocate_lock();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1318 if (thread_done == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1319 return PyErr_NoMemory();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1320 PyThread_acquire_lock(thread_done, 1);
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1321
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1322 /* Start a new thread with our callback. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1323 PyThread_start_new_thread(_make_call_from_thread, fn);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1324 /* Make the callback with the thread lock held by this thread */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1325 success &= _make_call(fn);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1326 /* Do it all again, but this time with the thread-lock released */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1327 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1328 success &= _make_call(fn);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1329 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1330 Py_END_ALLOW_THREADS
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1331
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1332 /* And once more with and without a thread
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1333 XXX - should use a lock and work out exactly what we are trying
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1334 to test <wink>
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1335 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1336 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1337 PyThread_start_new_thread(_make_call_from_thread, fn);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1338 success &= _make_call(fn);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1339 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1340 Py_END_ALLOW_THREADS
37117
f7993dc6bf26 Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents: 37077
diff changeset
1341
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1342 /* Release lock we acquired above. This is required on HP-UX. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1343 PyThread_release_lock(thread_done);
40226
61e4b59ada0c Fix crash in test on HP-UX. Apparently, it's not possible to delete a lock if
Neal Norwitz <nnorwitz@gmail.com>
parents: 40180
diff changeset
1344
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1345 PyThread_free_lock(thread_done);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1346 if (!success)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1347 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1348 Py_RETURN_NONE;
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1349 }
50675
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1350
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1351 /* test Py_AddPendingCalls using threads */
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1352 static int _pending_callback(void *arg)
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1353 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1354 /* we assume the argument is callable object to which we own a reference */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1355 PyObject *callable = (PyObject *)arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1356 PyObject *r = PyObject_CallObject(callable, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1357 Py_DECREF(callable);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1358 Py_XDECREF(r);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1359 return r != NULL ? 0 : -1;
50675
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1360 }
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1361
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1362 /* The following requests n callbacks to _pending_callback. It can be
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1363 * run from any python thread.
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1364 */
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1365 PyObject *pending_threadfunc(PyObject *self, PyObject *arg)
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1366 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1367 PyObject *callable;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1368 int r;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1369 if (PyArg_ParseTuple(arg, "O", &callable) == 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1370 return NULL;
50675
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1371
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1372 /* create the reference for the callbackwhile we hold the lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1373 Py_INCREF(callable);
50675
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1374
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1375 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1376 r = Py_AddPendingCall(&_pending_callback, callable);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1377 Py_END_ALLOW_THREADS
50675
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1378
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1379 if (r<0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1380 Py_DECREF(callable); /* unsuccessful add, destroy the extra reference */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1381 Py_INCREF(Py_False);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1382 return Py_False;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1383 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1384 Py_INCREF(Py_True);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1385 return Py_True;
50675
e6f55c9ec3d0 Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 50396
diff changeset
1386 }
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1387 #endif
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1388
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1389 /* Some tests of PyString_FromFormat(). This needs more tests. */
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1390 static PyObject *
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1391 test_string_from_format(PyObject *self, PyObject *args)
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1392 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1393 PyObject *result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1394 char *msg;
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1395
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1396 #define CHECK_1_FORMAT(FORMAT, TYPE) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1397 result = PyString_FromFormat(FORMAT, (TYPE)1); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1398 if (result == NULL) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1399 return NULL; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1400 if (strcmp(PyString_AsString(result), "1")) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1401 msg = FORMAT " failed at 1"; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1402 goto Fail; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1403 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1404 Py_DECREF(result)
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1405
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1406 CHECK_1_FORMAT("%d", int);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1407 CHECK_1_FORMAT("%ld", long);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1408 /* The z width modifier was added in Python 2.5. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1409 CHECK_1_FORMAT("%zd", Py_ssize_t);
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1410
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1411 /* The u type code was added in Python 2.5. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1412 CHECK_1_FORMAT("%u", unsigned int);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1413 CHECK_1_FORMAT("%lu", unsigned long);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1414 CHECK_1_FORMAT("%zu", size_t);
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1415
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1416 /* "%lld" and "%llu" support added in Python 2.7. */
57277
51028709abc3 Issue #7228: Add '%lld' and '%llu' support to PyFormat_FromString,
Mark Dickinson <dickinsm@gmail.com>
parents: 53930
diff changeset
1417 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1418 CHECK_1_FORMAT("%llu", unsigned PY_LONG_LONG);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1419 CHECK_1_FORMAT("%lld", PY_LONG_LONG);
57277
51028709abc3 Issue #7228: Add '%lld' and '%llu' support to PyFormat_FromString,
Mark Dickinson <dickinsm@gmail.com>
parents: 53930
diff changeset
1420 #endif
51028709abc3 Issue #7228: Add '%lld' and '%llu' support to PyFormat_FromString,
Mark Dickinson <dickinsm@gmail.com>
parents: 53930
diff changeset
1421
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1422 Py_RETURN_NONE;
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1423
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1424 Fail:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1425 Py_XDECREF(result);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1426 return raiseTestError("test_string_from_format", msg);
38173
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1427
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1428 #undef CHECK_1_FORMAT
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1429 }
380dad395599 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents: 37822
diff changeset
1430
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1431 /* Coverage testing of capsule objects. */
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1432
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1433 static const char *capsule_name = "capsule name";
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1434 static char *capsule_pointer = "capsule pointer";
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1435 static char *capsule_context = "capsule context";
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1436 static const char *capsule_error = NULL;
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1437 static int
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1438 capsule_destructor_call_count = 0;
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1439
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1440 static void
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1441 capsule_destructor(PyObject *o) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1442 capsule_destructor_call_count++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1443 if (PyCapsule_GetContext(o) != capsule_context) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1444 capsule_error = "context did not match in destructor!";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1445 } else if (PyCapsule_GetDestructor(o) != capsule_destructor) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1446 capsule_error = "destructor did not match in destructor! (woah!)";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1447 } else if (PyCapsule_GetName(o) != capsule_name) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1448 capsule_error = "name did not match in destructor!";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1449 } else if (PyCapsule_GetPointer(o, capsule_name) != capsule_pointer) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1450 capsule_error = "pointer did not match in destructor!";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1451 }
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1452 }
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1453
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1454 typedef struct {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1455 char *name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1456 char *module;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1457 char *attribute;
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1458 } known_capsule;
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1459
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1460 static PyObject *
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1461 test_capsule(PyObject *self, PyObject *args)
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1462 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1463 PyObject *object;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1464 const char *error = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1465 void *pointer;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1466 void *pointer2;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1467 known_capsule known_capsules[] = {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1468 #define KNOWN_CAPSULE(module, name) { module "." name, module, name }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1469 KNOWN_CAPSULE("_socket", "CAPI"),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1470 KNOWN_CAPSULE("_curses", "_C_API"),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1471 KNOWN_CAPSULE("datetime", "datetime_CAPI"),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1472 { NULL, NULL },
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1473 };
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1474 known_capsule *known = &known_capsules[0];
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1475
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1476 #define FAIL(x) { error = (x); goto exit; }
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1477
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1478 #define CHECK_DESTRUCTOR \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1479 if (capsule_error) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1480 FAIL(capsule_error); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1481 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1482 else if (!capsule_destructor_call_count) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1483 FAIL("destructor not called!"); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1484 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1485 capsule_destructor_call_count = 0; \
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1486
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1487 object = PyCapsule_New(capsule_pointer, capsule_name, capsule_destructor);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1488 PyCapsule_SetContext(object, capsule_context);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1489 capsule_destructor(object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1490 CHECK_DESTRUCTOR;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1491 Py_DECREF(object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1492 CHECK_DESTRUCTOR;
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1493
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1494 object = PyCapsule_New(known, "ignored", NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1495 PyCapsule_SetPointer(object, capsule_pointer);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1496 PyCapsule_SetName(object, capsule_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1497 PyCapsule_SetDestructor(object, capsule_destructor);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1498 PyCapsule_SetContext(object, capsule_context);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1499 capsule_destructor(object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1500 CHECK_DESTRUCTOR;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1501 /* intentionally access using the wrong name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1502 pointer2 = PyCapsule_GetPointer(object, "the wrong name");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1503 if (!PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1504 FAIL("PyCapsule_GetPointer should have failed but did not!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1505 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1506 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1507 if (pointer2) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1508 if (pointer2 == capsule_pointer) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1509 FAIL("PyCapsule_GetPointer should not have"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1510 " returned the internal pointer!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1511 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1512 FAIL("PyCapsule_GetPointer should have "
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1513 "returned NULL pointer but did not!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1514 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1515 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1516 PyCapsule_SetDestructor(object, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1517 Py_DECREF(object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1518 if (capsule_destructor_call_count) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1519 FAIL("destructor called when it should not have been!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1520 }
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1521
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1522 for (known = &known_capsules[0]; known->module != NULL; known++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1523 /* yeah, ordinarily I wouldn't do this either,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1524 but it's fine for this test harness.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1525 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1526 static char buffer[256];
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1527 #undef FAIL
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1528 #define FAIL(x) \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1529 { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1530 sprintf(buffer, "%s module: \"%s\" attribute: \"%s\"", \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1531 x, known->module, known->attribute); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1532 error = buffer; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1533 goto exit; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1534 } \
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1535
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1536 PyObject *module = PyImport_ImportModule(known->module);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1537 if (module) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1538 pointer = PyCapsule_Import(known->name, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1539 if (!pointer) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1540 Py_DECREF(module);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1541 FAIL("PyCapsule_GetPointer returned NULL unexpectedly!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1542 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1543 object = PyObject_GetAttrString(module, known->attribute);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1544 if (!object) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1545 Py_DECREF(module);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1546 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1547 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1548 pointer2 = PyCapsule_GetPointer(object,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1549 "weebles wobble but they don't fall down");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1550 if (!PyErr_Occurred()) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1551 Py_DECREF(object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1552 Py_DECREF(module);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1553 FAIL("PyCapsule_GetPointer should have failed but did not!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1554 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1555 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1556 if (pointer2) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1557 Py_DECREF(module);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1558 Py_DECREF(object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1559 if (pointer2 == pointer) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1560 FAIL("PyCapsule_GetPointer should not have"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1561 " returned its internal pointer!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1562 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1563 FAIL("PyCapsule_GetPointer should have"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1564 " returned NULL pointer but did not!");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1565 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1566 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1567 Py_DECREF(object);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1568 Py_DECREF(module);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1569 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1570 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1571 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1572 }
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1573
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1574 exit:
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1575 if (error) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1576 return raiseTestError("test_capsule", error);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1577 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1578 Py_RETURN_NONE;
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1579 #undef FAIL
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1580 }
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 58643
diff changeset
1581
39371
a9c742d6c888 Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents: 39189
diff changeset
1582 /* This is here to provide a docstring for test_descr. */
a9c742d6c888 Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents: 39189
diff changeset
1583 static PyObject *
a9c742d6c888 Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents: 39189
diff changeset
1584 test_with_docstring(PyObject *self)
a9c742d6c888 Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents: 39189
diff changeset
1585 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1586 Py_RETURN_NONE;
39371
a9c742d6c888 Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents: 39189
diff changeset
1587 }
a9c742d6c888 Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents: 39189
diff changeset
1588
46589
07a4e1710262 Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents: 45537
diff changeset
1589 /* To test the format of tracebacks as printed out. */
07a4e1710262 Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents: 45537
diff changeset
1590 static PyObject *
46592
4e47548edd36 Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents: 46589
diff changeset
1591 traceback_print(PyObject *self, PyObject *args)
46589
07a4e1710262 Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents: 45537
diff changeset
1592 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1593 PyObject *file;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1594 PyObject *traceback;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1595 int result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1596
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1597 if (!PyArg_ParseTuple(args, "OO:traceback_print",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1598 &traceback, &file))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1599 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1600
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1601 result = PyTraceBack_Print(traceback, file);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1602 if (result < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1603 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1604 Py_RETURN_NONE;
46589
07a4e1710262 Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents: 45537
diff changeset
1605 }
07a4e1710262 Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents: 45537
diff changeset
1606
53930
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1607 /* To test that the result of PyCode_NewEmpty has the right members. */
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1608 static PyObject *
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1609 code_newempty(PyObject *self, PyObject *args)
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1610 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1611 const char *filename;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1612 const char *funcname;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1613 int firstlineno;
53930
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1614
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1615 if (!PyArg_ParseTuple(args, "ssi:code_newempty",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1616 &filename, &funcname, &firstlineno))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1617 return NULL;
53930
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1618
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1619 return (PyObject *)PyCode_NewEmpty(filename, funcname, firstlineno);
53930
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1620 }
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 53820
diff changeset
1621
57961
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1622 /* Test PyErr_NewExceptionWithDoc (also exercise PyErr_NewException).
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1623 Run via Lib/test/test_exceptions.py */
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1624 static PyObject *
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1625 make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs)
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1626 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1627 char *name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1628 char *doc = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1629 PyObject *base = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1630 PyObject *dict = NULL;
57961
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1631
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1632 static char *kwlist[] = {"name", "doc", "base", "dict", NULL};
57961
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1633
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1634 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1635 "s|sOO:make_exception_with_doc", kwlist,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1636 &name, &doc, &base, &dict))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1637 return NULL;
57961
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1638
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1639 return PyErr_NewExceptionWithDoc(name, doc, base, dict);
57961
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1640 }
cf39c5e462f9 #7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents: 57855
diff changeset
1641
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1642 static PyMethodDef TestMethods[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1643 {"raise_exception", raise_exception, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1644 {"test_config", (PyCFunction)test_config, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1645 {"test_datetime_capi", test_datetime_capi, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1646 {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1647 {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1648 {"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1649 {"test_broken_memoryview", (PyCFunction)test_broken_memoryview,METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1650 {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1651 {"test_long_and_overflow", (PyCFunction)test_long_and_overflow,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1652 METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1653 {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1654 {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1655 {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1656 {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1657 {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1658 {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1659 PyDoc_STR("This is a pretty normal docstring.")},
28775
bc4231eb2758 New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents: 28714
diff changeset
1660
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1661 {"getargs_tuple", getargs_tuple, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1662 {"getargs_keywords", (PyCFunction)getargs_keywords,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1663 METH_VARARGS|METH_KEYWORDS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1664 {"getargs_b", getargs_b, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1665 {"getargs_B", getargs_B, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1666 {"getargs_h", getargs_h, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1667 {"getargs_H", getargs_H, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1668 {"getargs_I", getargs_I, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1669 {"getargs_k", getargs_k, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1670 {"getargs_i", getargs_i, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1671 {"getargs_l", getargs_l, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1672 {"getargs_n", getargs_n, METH_VARARGS},
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
1673 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1674 {"getargs_L", getargs_L, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1675 {"getargs_K", getargs_K, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1676 {"test_longlong_api", test_longlong_api, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1677 {"test_long_long_and_overflow",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1678 (PyCFunction)test_long_long_and_overflow, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1679 {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1680 {"codec_incrementalencoder",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1681 (PyCFunction)codec_incrementalencoder, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1682 {"codec_incrementaldecoder",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1683 (PyCFunction)codec_incrementaldecoder, METH_VARARGS},
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
1684 #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
1685 #ifdef Py_USING_UNICODE
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1686 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1687 {"test_widechar", (PyCFunction)test_widechar, 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
1688 #endif
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1689 #ifdef WITH_THREAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1690 {"_test_thread_state", test_thread_state, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1691 {"_pending_threadfunc", pending_threadfunc, METH_VARARGS},
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28652
diff changeset
1692 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1693 {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1694 {"traceback_print", traceback_print, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1695 {"code_newempty", code_newempty, METH_VARARGS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1696 {"make_exception_with_doc", (PyCFunction)make_exception_with_doc,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1697 METH_VARARGS | METH_KEYWORDS},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1698 {NULL, NULL} /* sentinel */
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1699 };
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1700
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1701 #define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);}
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1702
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1703 typedef struct {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1704 char bool_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1705 char byte_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1706 unsigned char ubyte_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1707 short short_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1708 unsigned short ushort_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1709 int int_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1710 unsigned int uint_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1711 long long_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1712 unsigned long ulong_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1713 float float_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1714 double double_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1715 char inplace_member[6];
42007
e8413971212d Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents: 40226
diff changeset
1716 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1717 PY_LONG_LONG longlong_member;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1718 unsigned PY_LONG_LONG ulonglong_member;
42007
e8413971212d Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents: 40226
diff changeset
1719 #endif
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1720 } all_structmembers;
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1721
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1722 typedef struct {
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1723 PyObject_HEAD
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1724 all_structmembers structmembers;
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1725 } test_structmembers;
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1726
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1727 static struct PyMemberDef test_members[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1728 {"T_BOOL", T_BOOL, offsetof(test_structmembers, structmembers.bool_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1729 {"T_BYTE", T_BYTE, offsetof(test_structmembers, structmembers.byte_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1730 {"T_UBYTE", T_UBYTE, offsetof(test_structmembers, structmembers.ubyte_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1731 {"T_SHORT", T_SHORT, offsetof(test_structmembers, structmembers.short_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1732 {"T_USHORT", T_USHORT, offsetof(test_structmembers, structmembers.ushort_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1733 {"T_INT", T_INT, offsetof(test_structmembers, structmembers.int_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1734 {"T_UINT", T_UINT, offsetof(test_structmembers, structmembers.uint_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1735 {"T_LONG", T_LONG, offsetof(test_structmembers, structmembers.long_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1736 {"T_ULONG", T_ULONG, offsetof(test_structmembers, structmembers.ulong_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1737 {"T_FLOAT", T_FLOAT, offsetof(test_structmembers, structmembers.float_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1738 {"T_DOUBLE", T_DOUBLE, offsetof(test_structmembers, structmembers.double_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1739 {"T_STRING_INPLACE", T_STRING_INPLACE, offsetof(test_structmembers, structmembers.inplace_member), 0, NULL},
42007
e8413971212d Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents: 40226
diff changeset
1740 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1741 {"T_LONGLONG", T_LONGLONG, offsetof(test_structmembers, structmembers.longlong_member), 0, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1742 {"T_ULONGLONG", T_ULONGLONG, offsetof(test_structmembers, structmembers.ulonglong_member), 0, NULL},
42007
e8413971212d Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents: 40226
diff changeset
1743 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1744 {NULL}
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1745 };
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1746
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1747
44864
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1748 static PyObject *
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1749 test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1750 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1751 static char *keywords[] = {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1752 "T_BOOL", "T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1753 "T_INT", "T_UINT", "T_LONG", "T_ULONG",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1754 "T_FLOAT", "T_DOUBLE", "T_STRING_INPLACE",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1755 #ifdef HAVE_LONG_LONG
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1756 "T_LONGLONG", "T_ULONGLONG",
44864
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1757 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1758 NULL};
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1759 static char *fmt = "|bbBhHiIlkfds#"
44864
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1760 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1761 "LK"
44864
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1762 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1763 ;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1764 test_structmembers *ob;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1765 const char *s = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1766 Py_ssize_t string_len = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1767 ob = PyObject_New(test_structmembers, type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1768 if (ob == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1769 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1770 memset(&ob->structmembers, 0, sizeof(all_structmembers));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1771 if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1772 &ob->structmembers.bool_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1773 &ob->structmembers.byte_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1774 &ob->structmembers.ubyte_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1775 &ob->structmembers.short_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1776 &ob->structmembers.ushort_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1777 &ob->structmembers.int_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1778 &ob->structmembers.uint_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1779 &ob->structmembers.long_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1780 &ob->structmembers.ulong_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1781 &ob->structmembers.float_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1782 &ob->structmembers.double_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1783 &s, &string_len
44864
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1784 #ifdef HAVE_LONG_LONG
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1785 , &ob->structmembers.longlong_member,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1786 &ob->structmembers.ulonglong_member
44864
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1787 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1788 )) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1789 Py_DECREF(ob);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1790 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1791 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1792 if (s != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1793 if (string_len > 5) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1794 Py_DECREF(ob);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1795 PyErr_SetString(PyExc_ValueError, "string too long");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1796 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1797 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1798 strcpy(ob->structmembers.inplace_member, s);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1799 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1800 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1801 strcpy(ob->structmembers.inplace_member, "");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1802 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1803 return (PyObject *)ob;
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1804 }
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1805
44864
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1806 static void
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1807 test_structmembers_free(PyObject *ob)
3107fdb9081e Reformat some ugly code.
Georg Brandl <georg@python.org>
parents: 44863
diff changeset
1808 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1809 PyObject_FREE(ob);
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1810 }
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1811
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1812 static PyTypeObject test_structmembersType = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 42007
diff changeset
1813 PyVarObject_HEAD_INIT(NULL, 0)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1814 "test_structmembersType",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1815 sizeof(test_structmembers), /* tp_basicsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1816 0, /* tp_itemsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1817 test_structmembers_free, /* destructor tp_dealloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1818 0, /* tp_print */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1819 0, /* tp_getattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1820 0, /* tp_setattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1821 0, /* tp_compare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1822 0, /* tp_repr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1823 0, /* tp_as_number */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1824 0, /* tp_as_sequence */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1825 0, /* tp_as_mapping */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1826 0, /* tp_hash */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1827 0, /* tp_call */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1828 0, /* tp_str */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1829 PyObject_GenericGetAttr, /* tp_getattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1830 PyObject_GenericSetAttr, /* tp_setattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1831 0, /* tp_as_buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1832 0, /* tp_flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1833 "Type containing all structmember types",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1834 0, /* traverseproc tp_traverse */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1835 0, /* tp_clear */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1836 0, /* tp_richcompare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1837 0, /* tp_weaklistoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1838 0, /* tp_iter */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1839 0, /* tp_iternext */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1840 0, /* tp_methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1841 test_members, /* tp_members */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1842 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1843 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1844 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1845 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1846 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1847 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1848 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1849 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1850 test_structmembers_new, /* tp_new */
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1851 };
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1852
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1853
24363
979ff5d0ae07 Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents: 22726
diff changeset
1854 PyMODINIT_FUNC
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1855 init_testcapi(void)
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1856 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1857 PyObject *m;
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1858
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1859 m = Py_InitModule("_testcapi", TestMethods);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1860 if (m == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1861 return;
16447
ac52d3727867 Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
1862
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1863 Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type;
50396
1c5d942128b6 Just inserted blank line.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 50394
diff changeset
1864
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1865 Py_TYPE(&test_structmembersType)=&PyType_Type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1866 Py_INCREF(&test_structmembersType);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1867 /* don't use a name starting with "test", since we don't want
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1868 test_capi to automatically call this */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1869 PyModule_AddObject(m, "_test_structmembersType", (PyObject *)&test_structmembersType);
40176
0c1cb92dac97 Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents: 39371
diff changeset
1870
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1871 PyModule_AddObject(m, "CHAR_MAX", PyInt_FromLong(CHAR_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1872 PyModule_AddObject(m, "CHAR_MIN", PyInt_FromLong(CHAR_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1873 PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1874 PyModule_AddObject(m, "SHRT_MAX", PyInt_FromLong(SHRT_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1875 PyModule_AddObject(m, "SHRT_MIN", PyInt_FromLong(SHRT_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1876 PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1877 PyModule_AddObject(m, "INT_MAX", PyLong_FromLong(INT_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1878 PyModule_AddObject(m, "INT_MIN", PyLong_FromLong(INT_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1879 PyModule_AddObject(m, "UINT_MAX", PyLong_FromUnsignedLong(UINT_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1880 PyModule_AddObject(m, "LONG_MAX", PyInt_FromLong(LONG_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1881 PyModule_AddObject(m, "LONG_MIN", PyInt_FromLong(LONG_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1882 PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1883 PyModule_AddObject(m, "FLT_MAX", PyFloat_FromDouble(FLT_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1884 PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1885 PyModule_AddObject(m, "DBL_MAX", PyFloat_FromDouble(DBL_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1886 PyModule_AddObject(m, "DBL_MIN", PyFloat_FromDouble(DBL_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1887 PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1888 PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1889 PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1890 PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1891 PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1892 PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyInt_FromSsize_t(sizeof(PyGC_Head)));
28652
28a2975514cd SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents: 28437
diff changeset
1893
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1894 TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1895 Py_INCREF(TestError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60225
diff changeset
1896 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
1897 }