Mercurial > cpython-lru_cache-weakref
annotate Modules/_testcapimodule.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 3ecddf168f1f |
| children | a199ec80c679 |
| 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 */ |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
25 if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
26 PyErr_SetString(TestError, "internal error msg too large"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
27 else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
28 PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
29 PyErr_SetString(TestError, buf); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
30 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
44 char buf[1024]; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
45 PyOS_snprintf(buf, sizeof(buf), |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
46 "%.200s #define == %d but sizeof(%.200s) == %d", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
47 fatname, expected, typname, got); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
48 PyErr_SetString(TestError, buf); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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) \ |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
56 if (FATNAME != sizeof(TYPE)) \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
59 CHECK_SIZEOF(SIZEOF_SHORT, short); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
60 CHECK_SIZEOF(SIZEOF_INT, int); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
61 CHECK_SIZEOF(SIZEOF_LONG, long); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
62 CHECK_SIZEOF(SIZEOF_VOID_P, void*); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
70 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
77 PyObject* list; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
82 list = PyList_New(NLIST); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
83 if (list == (PyObject*)NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
84 return (PyObject*)NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
85 /* list = range(NLIST) */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
86 for (i = 0; i < NLIST; ++i) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
87 PyObject* anint = PyInt_FromLong(i); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
88 if (anint == (PyObject*)NULL) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
89 Py_DECREF(list); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
90 return (PyObject*)NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
91 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
92 PyList_SET_ITEM(list, i, anint); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
93 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
94 /* list.reverse(), via PyList_Reverse() */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
95 i = PyList_Reverse(list); /* should not blow up! */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
96 if (i != 0) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
97 Py_DECREF(list); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
98 return (PyObject*)NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
99 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
100 /* Check that list == range(29, -1, -1) now */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
101 for (i = 0; i < NLIST; ++i) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
102 PyObject* anint = PyList_GET_ITEM(list, i); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
103 if (PyInt_AS_LONG(anint) != NLIST-1-i) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
104 PyErr_SetString(TestError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
105 "test_list_api: reverse screwed up"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
106 Py_DECREF(list); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
107 return (PyObject*)NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
108 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
109 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
113 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
120 Py_ssize_t pos = 0, iterations = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
121 int i; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
122 PyObject *dict = PyDict_New(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
125 if (dict == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
128 for (i = 0; i < count; i++) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
129 v = PyInt_FromLong(i); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
130 PyDict_SetItem(dict, v, v); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
131 Py_DECREF(v); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
134 while (PyDict_Next(dict, &pos, &k, &v)) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
135 PyObject *o; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
138 i = PyInt_AS_LONG(v) + 1; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
139 o = PyInt_FromLong(i); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
140 if (o == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
141 return -1; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
142 if (PyDict_SetItem(dict, k, o) < 0) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
143 Py_DECREF(o); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
144 return -1; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
145 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
146 Py_DECREF(o); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
151 if (iterations != count) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
152 PyErr_SetString( |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
153 TestError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
154 "test_dict_iteration: dict iteration went wrong "); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
155 return -1; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
156 } else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
157 return 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
166 for (i = 0; i < 200; i++) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
167 if (test_dict_inner(i) < 0) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
168 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
169 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
172 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
177 /* Issue #4701: Check that PyObject_Hash implicitly calls |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
178 * PyType_Ready if it hasn't already been called |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
179 */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
180 static PyTypeObject _HashInheritanceTester_Type = { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
181 PyObject_HEAD_INIT(NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
182 0, /* Number of items for varobject */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
183 "hashinheritancetester", /* Name of this type */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
184 sizeof(PyObject), /* Basic object size */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
185 0, /* Item size for varobject */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
186 (destructor)PyObject_Del, /* tp_dealloc */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
187 0, /* tp_print */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
188 0, /* tp_getattr */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
189 0, /* tp_setattr */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
190 0, /* tp_compare */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
191 0, /* tp_repr */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
192 0, /* tp_as_number */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
193 0, /* tp_as_sequence */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
194 0, /* tp_as_mapping */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
195 0, /* tp_hash */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
196 0, /* tp_call */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
197 0, /* tp_str */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
198 PyObject_GenericGetAttr, /* tp_getattro */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
199 0, /* tp_setattro */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
200 0, /* tp_as_buffer */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
201 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
202 0, /* tp_doc */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
203 0, /* tp_traverse */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
204 0, /* tp_clear */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
205 0, /* tp_richcompare */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
206 0, /* tp_weaklistoffset */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
207 0, /* tp_iter */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
208 0, /* tp_iternext */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
209 0, /* tp_methods */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
210 0, /* tp_members */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
211 0, /* tp_getset */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
212 0, /* tp_base */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
213 0, /* tp_dict */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
214 0, /* tp_descr_get */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
215 0, /* tp_descr_set */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
216 0, /* tp_dictoffset */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
217 0, /* tp_init */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
218 0, /* tp_alloc */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
219 PyType_GenericNew, /* tp_new */ |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
220 }; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
221 |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
222 static PyObject* |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
223 test_lazy_hash_inheritance(PyObject* self) |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
224 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
225 PyTypeObject *type; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
226 PyObject *obj; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
227 long hash; |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
228 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
229 type = &_HashInheritanceTester_Type; |
|
58680
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
230 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
231 if (type->tp_dict != NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
232 /* The type has already been initialized. This probably means |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
233 -R is being used. */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
234 Py_RETURN_NONE; |
|
58680
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
235 |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
236 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
237 obj = PyObject_New(PyObject, type); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
238 if (obj == NULL) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
239 PyErr_Clear(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
240 PyErr_SetString( |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
241 TestError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
242 "test_lazy_hash_inheritance: failed to create object"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
243 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
244 } |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
245 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
246 if (type->tp_dict != NULL) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
247 PyErr_SetString( |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
248 TestError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
249 "test_lazy_hash_inheritance: type initialised too soon"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
250 Py_DECREF(obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
251 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
252 } |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
253 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
254 hash = PyObject_Hash(obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
255 if ((hash == -1) && PyErr_Occurred()) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
256 PyErr_Clear(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
257 PyErr_SetString( |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
258 TestError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
259 "test_lazy_hash_inheritance: could not hash object"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
260 Py_DECREF(obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
261 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
262 } |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
263 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
264 if (type->tp_dict == NULL) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
265 PyErr_SetString( |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
266 TestError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
267 "test_lazy_hash_inheritance: type not initialised by hash()"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
268 Py_DECREF(obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
269 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
270 } |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
271 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
272 if (type->tp_hash != PyType_Type.tp_hash) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
273 PyErr_SetString( |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
274 TestError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
275 "test_lazy_hash_inheritance: unexpected hash function"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
276 Py_DECREF(obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
277 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
278 } |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
279 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
280 Py_DECREF(obj); |
|
58680
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
281 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
282 Py_RETURN_NONE; |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
283 } |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
284 |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
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 | 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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
403 #define TESTNAME test_long_api_inner |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
404 #define TYPENAME long |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
405 #define F_S_TO_PY PyLong_FromLong |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
406 #define F_PY_TO_S PyLong_AsLong |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
407 #define F_U_TO_PY PyLong_FromUnsignedLong |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 | 428 raise_test_longlong_error(const char* msg) |
| 429 { | |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
430 return raiseTestError("test_longlong_api", msg); |
| 18093 | 431 } |
| 432 | |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
433 #define TESTNAME test_longlong_api_inner |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
434 #define TYPENAME PY_LONG_LONG |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
435 #define F_S_TO_PY PyLong_FromLongLong |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
436 #define F_PY_TO_S PyLong_AsLongLong |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
437 #define F_U_TO_PY PyLong_FromUnsignedLongLong |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 | 441 |
| 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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
792 PyObject *tuple, *num; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
795 tuple = PyTuple_New(1); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
796 if (tuple == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
799 num = PyLong_FromLong(42); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
800 if (num == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
805 value = -1; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
806 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
807 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
808 if (value != 42) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
809 return raiseTestError("test_L_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
812 Py_DECREF(num); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
813 num = PyInt_FromLong(42); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
814 if (num == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
819 value = -1; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
820 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
821 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
822 if (value != 42) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
823 return raiseTestError("test_L_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
826 Py_DECREF(tuple); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
827 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
837 int a, b, c; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
838 if (!PyArg_ParseTuple(args, "i(ii)", &a, &b, &c)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
839 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
846 static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL}; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
847 static char *fmt="(ii)i|(i(ii))(iii)i"; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
850 if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
851 &int_args[0], &int_args[1], &int_args[2], &int_args[3], &int_args[4], |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
852 &int_args[5], &int_args[6], &int_args[7], &int_args[8], &int_args[9])) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
853 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
854 return Py_BuildValue("iiiiiiiiii", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
855 int_args[0], int_args[1], int_args[2], int_args[3], int_args[4], |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
865 unsigned char value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
866 if (!PyArg_ParseTuple(args, "b", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
867 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
874 unsigned char value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
875 if (!PyArg_ParseTuple(args, "B", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
876 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
892 unsigned short value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
893 if (!PyArg_ParseTuple(args, "H", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
894 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
901 unsigned int value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
902 if (!PyArg_ParseTuple(args, "I", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
903 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
910 unsigned long value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
911 if (!PyArg_ParseTuple(args, "k", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
912 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
919 int value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
920 if (!PyArg_ParseTuple(args, "i", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
921 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
928 long value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
929 if (!PyArg_ParseTuple(args, "l", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
930 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
937 Py_ssize_t value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
938 if (!PyArg_ParseTuple(args, "n", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
939 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
947 PY_LONG_LONG value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
948 if (!PyArg_ParseTuple(args, "L", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
949 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
956 unsigned PY_LONG_LONG value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
957 if (!PyArg_ParseTuple(args, "K", &value)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
958 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
968 PyObject *tuple, *num; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
971 tuple = PyTuple_New(1); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
972 if (tuple == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
975 /* a number larger than ULONG_MAX even on 64-bit platforms */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
976 num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
977 if (num == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
980 value = PyInt_AsUnsignedLongMask(num); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
981 if (value != ULONG_MAX) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
982 return raiseTestError("test_k_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
987 value = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
988 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
989 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
990 if (value != ULONG_MAX) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
991 return raiseTestError("test_k_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
994 Py_DECREF(num); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
995 num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
996 if (num == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
999 value = PyInt_AsUnsignedLongMask(num); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1000 if (value != (unsigned long)-0x42) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1001 return raiseTestError("test_k_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1006 value = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1007 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1008 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1009 if (value != (unsigned long)-0x42) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1010 return raiseTestError("test_k_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1013 Py_DECREF(tuple); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1014 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
50305
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1020 static volatile int x; |
|
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1028 PyObject *tuple, *obj; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1029 Py_UNICODE *value; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1032 /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1033 /* Just use the macro and check that it compiles */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1036 tuple = PyTuple_New(1); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1037 if (tuple == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1040 obj = PyUnicode_Decode("test", strlen("test"), |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1041 "ascii", NULL); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1042 if (obj == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1047 value = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1048 if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1049 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1050 if (value != PyUnicode_AS_UNICODE(obj)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1051 return raiseTestError("test_u_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1052 "u code returned wrong value for u'test'"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1053 value = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1054 if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1055 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1056 if (value != PyUnicode_AS_UNICODE(obj) || |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1057 len != PyUnicode_GET_SIZE(obj)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1058 return raiseTestError("test_u_code", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1061 Py_DECREF(tuple); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1062 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
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 * |
|
73682
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1109 unicode_encodedecimal(PyObject *self, PyObject *args) |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1110 { |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1111 Py_UNICODE *unicode; |
|
73783
3ecddf168f1f
Issue #13093: Fix _testcapi.unicode_encodedecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73682
diff
changeset
|
1112 int length; |
|
73682
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1113 char *errors = NULL; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1114 PyObject *decimal; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1115 Py_ssize_t decimal_length, new_length; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1116 int res; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1117 |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1118 if (!PyArg_ParseTuple(args, "u#|s", &unicode, &length, &errors)) |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1119 return NULL; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1120 |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1121 decimal_length = length * 7; /* len('€') */ |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1122 decimal = PyBytes_FromStringAndSize(NULL, decimal_length); |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1123 if (decimal == NULL) |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1124 return NULL; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1125 |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1126 res = PyUnicode_EncodeDecimal(unicode, length, |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1127 PyBytes_AS_STRING(decimal), |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1128 errors); |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1129 if (res < 0) { |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1130 Py_DECREF(decimal); |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1131 return NULL; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1132 } |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1133 |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1134 new_length = strlen(PyBytes_AS_STRING(decimal)); |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1135 assert(new_length <= decimal_length); |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1136 res = _PyBytes_Resize(&decimal, new_length); |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1137 if (res < 0) |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1138 return NULL; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1139 |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1140 return decimal; |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1141 } |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1142 |
|
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1143 static PyObject * |
|
50305
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1144 test_empty_argparse(PyObject *self) |
|
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1145 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1146 /* Test that formats can begin with '|'. See issue #4720. */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1147 PyObject *tuple, *dict = NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1148 static char *kwlist[] = {NULL}; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1149 int result; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1150 tuple = PyTuple_New(0); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1151 if (!tuple) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1152 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1153 if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1154 goto done; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1155 dict = PyDict_New(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1156 if (!dict) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1157 goto done; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1158 result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist); |
|
50305
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1159 done: |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1160 Py_DECREF(tuple); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1161 Py_XDECREF(dict); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1162 if (result < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1163 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1164 else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1165 Py_RETURN_NONE; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1166 } |
|
50305
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1167 } |
|
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1168 |
|
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1169 static PyObject * |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1170 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
|
1171 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1172 const char *encoding, *errors = NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1173 if (!PyArg_ParseTuple(args, "s|s:test_incrementalencoder", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1174 &encoding, &errors)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1175 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1176 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
|
1177 } |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
1178 |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1179 static PyObject * |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1180 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
|
1181 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1182 const char *encoding, *errors = NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1183 if (!PyArg_ParseTuple(args, "s|s:test_incrementaldecoder", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1184 &encoding, &errors)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1185 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1186 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
|
1187 } |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
1188 |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
1189 #endif |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
1190 |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
1191 /* 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
|
1192 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
|
1193 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
|
1194 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1195 struct triple { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1196 long input; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1197 size_t nbits; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1198 int sign; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1199 } testcases[] = {{0, 0, 0}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1200 {1L, 1, 1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1201 {-1L, 1, -1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1202 {2L, 2, 1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1203 {-2L, 2, -1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1204 {3L, 2, 1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1205 {-3L, 2, -1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1206 {4L, 3, 1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1207 {-4L, 3, -1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1208 {0x7fffL, 15, 1}, /* one Python long digit */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1209 {-0x7fffL, 15, -1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1210 {0xffffL, 16, 1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1211 {-0xffffL, 16, -1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1212 {0xfffffffL, 28, 1}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1213 {-0xfffffffL, 28, -1}}; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1214 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
|
1215 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1216 for (i = 0; i < sizeof(testcases) / sizeof(struct triple); ++i) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1217 PyObject *plong = PyLong_FromLong(testcases[i].input); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1218 size_t nbits = _PyLong_NumBits(plong); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1219 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
|
1220 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1221 Py_DECREF(plong); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1222 if (nbits != testcases[i].nbits) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1223 return raiseTestError("test_long_numbits", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1224 "wrong result for _PyLong_NumBits"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1225 if (sign != testcases[i].sign) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1226 return raiseTestError("test_long_numbits", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1227 "wrong result for _PyLong_Sign"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1228 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1229 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1230 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
|
1231 } |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
1232 |
|
36989
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
1233 /* 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
|
1234 |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
1235 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
|
1236 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
|
1237 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1238 PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1239 PyObject *tuple = PyTuple_Pack(2, o1, o2); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1240 Py_XDECREF(o1); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1241 Py_XDECREF(o2); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1242 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
|
1243 } |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
1244 |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
1245 static PyObject * |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
1246 raise_exception(PyObject *self, PyObject *args) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
1247 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1248 PyObject *exc; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1249 PyObject *exc_args, *v; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1250 int num_args, i; |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
1251 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1252 if (!PyArg_ParseTuple(args, "Oi:raise_exception", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1253 &exc, &num_args)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1254 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1255 if (!PyExceptionClass_Check(exc)) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1256 PyErr_Format(PyExc_TypeError, "an exception class is required"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1257 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1258 } |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
1259 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1260 exc_args = PyTuple_New(num_args); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1261 if (exc_args == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1262 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1263 for (i = 0; i < num_args; ++i) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1264 v = PyInt_FromLong(i); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1265 if (v == NULL) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1266 Py_DECREF(exc_args); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1267 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1268 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1269 PyTuple_SET_ITEM(exc_args, i, v); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1270 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1271 PyErr_SetObject(exc, exc_args); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1272 Py_DECREF(exc_args); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1273 return NULL; |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
1274 } |
|
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
|
1275 |
|
58604
68c56c4b8631
be robust against test being run over and over (such as -R)
Benjamin Peterson <benjamin@python.org>
parents:
58603
diff
changeset
|
1276 |
|
68c56c4b8631
be robust against test being run over and over (such as -R)
Benjamin Peterson <benjamin@python.org>
parents:
58603
diff
changeset
|
1277 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
|
1278 |
|
57722
40f3b8b83cc6
add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents:
57277
diff
changeset
|
1279 static PyObject * |
|
40f3b8b83cc6
add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents:
57277
diff
changeset
|
1280 test_datetime_capi(PyObject *self, PyObject *args) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1281 if (PyDateTimeAPI) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1282 if (test_run_counter) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1283 /* Probably regrtest.py -R */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1284 Py_RETURN_NONE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1285 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1286 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1287 PyErr_SetString(PyExc_AssertionError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1288 "PyDateTime_CAPI somehow initialized"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1289 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1290 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1291 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1292 test_run_counter++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1293 PyDateTime_IMPORT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1294 if (PyDateTimeAPI) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1295 Py_RETURN_NONE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1296 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1297 return NULL; |
|
57722
40f3b8b83cc6
add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents:
57277
diff
changeset
|
1298 } |
|
40f3b8b83cc6
add a test of loading the datetime capi
Benjamin Peterson <benjamin@python.org>
parents:
57277
diff
changeset
|
1299 |
|
58603
fe086abb4aeb
move test outside WITH_THREAD section
Benjamin Peterson <benjamin@python.org>
parents:
58581
diff
changeset
|
1300 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1301 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1302 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
1303 /* 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
|
1304 * `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
|
1305 * 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
|
1306 * 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
|
1307 * 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
|
1308 * 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
|
1309 */ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
1310 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
|
1311 |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
1312 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
|
1313 _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
|
1314 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1315 PyObject *rc; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1316 int success; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1317 PyGILState_STATE s = PyGILState_Ensure(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1318 rc = PyObject_CallFunction((PyObject *)callable, ""); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1319 success = (rc != NULL); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1320 Py_XDECREF(rc); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1321 PyGILState_Release(s); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1322 return success; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1323 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1324 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
1325 /* 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
|
1326 * 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
|
1327 */ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
1328 static void |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
1329 _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
|
1330 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1331 _make_call(callable); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1332 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
|
1333 } |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
1334 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1335 static PyObject * |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1336 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
|
1337 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1338 PyObject *fn; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1339 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
|
1340 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1341 if (!PyArg_ParseTuple(args, "O:test_thread_state", &fn)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1342 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
|
1343 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1344 if (!PyCallable_Check(fn)) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1345 PyErr_Format(PyExc_TypeError, "'%s' object is not callable", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1346 fn->ob_type->tp_name); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1347 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1348 } |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
1349 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1350 /* Ensure Python is set up for threading */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1351 PyEval_InitThreads(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1352 thread_done = PyThread_allocate_lock(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1353 if (thread_done == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1354 return PyErr_NoMemory(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1355 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
|
1356 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1357 /* Start a new thread with our callback. */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1358 PyThread_start_new_thread(_make_call_from_thread, fn); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1359 /* Make the callback with the thread lock held by this thread */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1360 success &= _make_call(fn); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1361 /* Do it all again, but this time with the thread-lock released */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1362 Py_BEGIN_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1363 success &= _make_call(fn); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1364 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1365 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
|
1366 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1367 /* And once more with and without a thread |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1368 XXX - should use a lock and work out exactly what we are trying |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1369 to test <wink> |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1370 */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1371 Py_BEGIN_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1372 PyThread_start_new_thread(_make_call_from_thread, fn); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1373 success &= _make_call(fn); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1374 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1375 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
|
1376 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1377 /* Release lock we acquired above. This is required on HP-UX. */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1378 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
|
1379 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1380 PyThread_free_lock(thread_done); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1381 if (!success) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1382 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1383 Py_RETURN_NONE; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1384 } |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1385 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1386 /* 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
|
1387 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
|
1388 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1389 /* 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
|
1390 PyObject *callable = (PyObject *)arg; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1391 PyObject *r = PyObject_CallObject(callable, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1392 Py_DECREF(callable); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1393 Py_XDECREF(r); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1394 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
|
1395 } |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1396 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1397 /* 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
|
1398 * 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
|
1399 */ |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1400 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
|
1401 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1402 PyObject *callable; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1403 int r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1404 if (PyArg_ParseTuple(arg, "O", &callable) == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1405 return NULL; |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1406 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1407 /* 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
|
1408 Py_INCREF(callable); |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1409 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1410 Py_BEGIN_ALLOW_THREADS |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1411 r = Py_AddPendingCall(&_pending_callback, callable); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1412 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
|
1413 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1414 if (r<0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1415 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
|
1416 Py_INCREF(Py_False); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1417 return Py_False; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1418 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1419 Py_INCREF(Py_True); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1420 return Py_True; |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1421 } |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1422 #endif |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1423 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1424 /* 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
|
1425 static PyObject * |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1426 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
|
1427 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1428 PyObject *result; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1429 char *msg; |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1430 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1431 #define CHECK_1_FORMAT(FORMAT, TYPE) \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1432 result = PyString_FromFormat(FORMAT, (TYPE)1); \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1433 if (result == NULL) \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1434 return NULL; \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1435 if (strcmp(PyString_AsString(result), "1")) { \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1436 msg = FORMAT " failed at 1"; \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1437 goto Fail; \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1438 } \ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1439 Py_DECREF(result) |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1440 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1441 CHECK_1_FORMAT("%d", int); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1442 CHECK_1_FORMAT("%ld", long); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1443 /* The z width modifier was added in Python 2.5. */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1444 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
|
1445 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1446 /* The u type code was added in Python 2.5. */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1447 CHECK_1_FORMAT("%u", unsigned int); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1448 CHECK_1_FORMAT("%lu", unsigned long); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1449 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
|
1450 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1451 /* "%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
|
1452 #ifdef HAVE_LONG_LONG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1453 CHECK_1_FORMAT("%llu", unsigned PY_LONG_LONG); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1454 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
|
1455 #endif |
|
51028709abc3
Issue #7228: Add '%lld' and '%llu' support to PyFormat_FromString,
Mark Dickinson <dickinsm@gmail.com>
parents:
53930
diff
changeset
|
1456 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1457 Py_RETURN_NONE; |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1458 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1459 Fail: |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1460 Py_XDECREF(result); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1461 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
|
1462 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1463 #undef CHECK_1_FORMAT |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1464 } |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
1465 |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1466 /* 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
|
1467 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1468 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
|
1469 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
|
1470 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
|
1471 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
|
1472 static int |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1473 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
|
1474 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1475 static void |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1476 capsule_destructor(PyObject *o) { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1477 capsule_destructor_call_count++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1478 if (PyCapsule_GetContext(o) != capsule_context) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1479 capsule_error = "context did not match in destructor!"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1480 } else if (PyCapsule_GetDestructor(o) != capsule_destructor) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1481 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
|
1482 } else if (PyCapsule_GetName(o) != capsule_name) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1483 capsule_error = "name did not match in destructor!"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1484 } 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
|
1485 capsule_error = "pointer did not match in destructor!"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1486 } |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1487 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1488 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1489 typedef struct { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1490 char *name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1491 char *module; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1492 char *attribute; |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1493 } known_capsule; |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1494 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1495 static PyObject * |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1496 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
|
1497 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1498 PyObject *object; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1499 const char *error = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1500 void *pointer; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1501 void *pointer2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1502 known_capsule known_capsules[] = { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1503 #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
|
1504 KNOWN_CAPSULE("_socket", "CAPI"), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1505 KNOWN_CAPSULE("_curses", "_C_API"), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1506 KNOWN_CAPSULE("datetime", "datetime_CAPI"), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1507 { NULL, NULL }, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1508 }; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1509 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
|
1510 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1511 #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
|
1512 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1513 #define CHECK_DESTRUCTOR \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1514 if (capsule_error) { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1515 FAIL(capsule_error); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1516 } \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1517 else if (!capsule_destructor_call_count) { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1518 FAIL("destructor not called!"); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1519 } \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1520 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
|
1521 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1522 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
|
1523 PyCapsule_SetContext(object, capsule_context); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1524 capsule_destructor(object); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1525 CHECK_DESTRUCTOR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1526 Py_DECREF(object); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1527 CHECK_DESTRUCTOR; |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1528 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1529 object = PyCapsule_New(known, "ignored", NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1530 PyCapsule_SetPointer(object, capsule_pointer); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1531 PyCapsule_SetName(object, capsule_name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1532 PyCapsule_SetDestructor(object, capsule_destructor); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1533 PyCapsule_SetContext(object, capsule_context); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1534 capsule_destructor(object); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1535 CHECK_DESTRUCTOR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1536 /* intentionally access using the wrong name */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1537 pointer2 = PyCapsule_GetPointer(object, "the wrong name"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1538 if (!PyErr_Occurred()) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1539 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
|
1540 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1541 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1542 if (pointer2) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1543 if (pointer2 == capsule_pointer) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1544 FAIL("PyCapsule_GetPointer should not have" |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1545 " returned the internal pointer!"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1546 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1547 FAIL("PyCapsule_GetPointer should have " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1548 "returned NULL pointer but did not!"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1549 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1550 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1551 PyCapsule_SetDestructor(object, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1552 Py_DECREF(object); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1553 if (capsule_destructor_call_count) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1554 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
|
1555 } |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1556 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1557 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
|
1558 /* yeah, ordinarily I wouldn't do this either, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1559 but it's fine for this test harness. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1560 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1561 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
|
1562 #undef FAIL |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1563 #define FAIL(x) \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1564 { \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1565 sprintf(buffer, "%s module: \"%s\" attribute: \"%s\"", \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1566 x, known->module, known->attribute); \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1567 error = buffer; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1568 goto exit; \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1569 } \ |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1570 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1571 PyObject *module = PyImport_ImportModule(known->module); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1572 if (module) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1573 pointer = PyCapsule_Import(known->name, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1574 if (!pointer) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1575 Py_DECREF(module); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1576 FAIL("PyCapsule_GetPointer returned NULL unexpectedly!"); |
|
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 object = PyObject_GetAttrString(module, known->attribute); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1579 if (!object) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1580 Py_DECREF(module); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1581 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1582 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1583 pointer2 = PyCapsule_GetPointer(object, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1584 "weebles wobble but they don't fall down"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1585 if (!PyErr_Occurred()) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1586 Py_DECREF(object); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1587 Py_DECREF(module); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1588 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
|
1589 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1590 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1591 if (pointer2) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1592 Py_DECREF(module); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1593 Py_DECREF(object); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1594 if (pointer2 == pointer) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1595 FAIL("PyCapsule_GetPointer should not have" |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1596 " returned its internal pointer!"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1597 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1598 FAIL("PyCapsule_GetPointer should have" |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1599 " returned NULL pointer but did not!"); |
|
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 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1602 Py_DECREF(object); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1603 Py_DECREF(module); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1604 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1605 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1606 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1607 } |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1608 |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1609 exit: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1610 if (error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1611 return raiseTestError("test_capsule", error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1612 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1613 Py_RETURN_NONE; |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1614 #undef FAIL |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1615 } |
|
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
58643
diff
changeset
|
1616 |
|
39371
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
1617 /* 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
|
1618 static PyObject * |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
1619 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
|
1620 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1621 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
|
1622 } |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
1623 |
|
46589
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
1624 /* 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
|
1625 static PyObject * |
|
46592
4e47548edd36
Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents:
46589
diff
changeset
|
1626 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
|
1627 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1628 PyObject *file; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1629 PyObject *traceback; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1630 int result; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1631 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1632 if (!PyArg_ParseTuple(args, "OO:traceback_print", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1633 &traceback, &file)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1634 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1635 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1636 result = PyTraceBack_Print(traceback, file); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1637 if (result < 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1638 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1639 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
|
1640 } |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
1641 |
| 53930 | 1642 /* To test that the result of PyCode_NewEmpty has the right members. */ |
| 1643 static PyObject * | |
| 1644 code_newempty(PyObject *self, PyObject *args) | |
| 1645 { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1646 const char *filename; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1647 const char *funcname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1648 int firstlineno; |
| 53930 | 1649 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1650 if (!PyArg_ParseTuple(args, "ssi:code_newempty", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1651 &filename, &funcname, &firstlineno)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1652 return NULL; |
| 53930 | 1653 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1654 return (PyObject *)PyCode_NewEmpty(filename, funcname, firstlineno); |
| 53930 | 1655 } |
| 1656 | |
|
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
|
1657 /* 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
|
1658 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
|
1659 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
|
1660 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
|
1661 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1662 char *name; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1663 char *doc = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1664 PyObject *base = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1665 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
|
1666 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1667 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
|
1668 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1669 if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1670 "s|sOO:make_exception_with_doc", kwlist, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1671 &name, &doc, &base, &dict)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1672 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
|
1673 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1674 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
|
1675 } |
|
cf39c5e462f9
#7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Georg Brandl <georg@python.org>
parents:
57855
diff
changeset
|
1676 |
|
72942
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1677 static PyObject * |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1678 sequence_delitem(PyObject *self, PyObject *args) |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1679 { |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1680 PyObject *seq; |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1681 Py_ssize_t i; |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1682 |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1683 if (!PyArg_ParseTuple(args, "On", &seq, &i)) |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1684 return NULL; |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1685 if (PySequence_DelItem(seq, i) < 0) |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1686 return NULL; |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1687 Py_RETURN_NONE; |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1688 } |
|
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1689 |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1690 static PyMethodDef TestMethods[] = { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1691 {"raise_exception", raise_exception, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1692 {"test_config", (PyCFunction)test_config, METH_NOARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1693 {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1694 {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1695 {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1696 {"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1697 {"test_broken_memoryview", (PyCFunction)test_broken_memoryview,METH_NOARGS}, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1698 {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1699 {"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
|
1700 METH_NOARGS}, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1701 {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1702 {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1703 {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1704 {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1705 {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1706 {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1707 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
|
1708 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1709 {"getargs_tuple", getargs_tuple, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1710 {"getargs_keywords", (PyCFunction)getargs_keywords, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1711 METH_VARARGS|METH_KEYWORDS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1712 {"getargs_b", getargs_b, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1713 {"getargs_B", getargs_B, METH_VARARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1714 {"getargs_h", getargs_h, METH_VARARGS}, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1715 {"getargs_H", getargs_H, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1716 {"getargs_I", getargs_I, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1717 {"getargs_k", getargs_k, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1718 {"getargs_i", getargs_i, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1719 {"getargs_l", getargs_l, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1720 {"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
|
1721 #ifdef HAVE_LONG_LONG |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1722 {"getargs_L", getargs_L, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1723 {"getargs_K", getargs_K, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1724 {"test_longlong_api", test_longlong_api, METH_NOARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1725 {"test_long_long_and_overflow", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1726 (PyCFunction)test_long_long_and_overflow, METH_NOARGS}, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1727 {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1728 {"codec_incrementalencoder", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1729 (PyCFunction)codec_incrementalencoder, METH_VARARGS}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1730 {"codec_incrementaldecoder", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1731 (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
|
1732 #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
|
1733 #ifdef Py_USING_UNICODE |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1734 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1735 {"test_widechar", (PyCFunction)test_widechar, METH_NOARGS}, |
|
73682
0cd197f13400
Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72942
diff
changeset
|
1736 {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
1737 #endif |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1738 #ifdef WITH_THREAD |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1739 {"_test_thread_state", test_thread_state, METH_VARARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1740 {"_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
|
1741 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1742 {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS}, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1743 {"traceback_print", traceback_print, METH_VARARGS}, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1744 {"code_newempty", code_newempty, METH_VARARGS}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60225
diff
changeset
|
1745 {"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
|
1746 METH_VARARGS | METH_KEYWORDS}, |
|
72942
418fbf1af875
PyEval_CallObject requires a tuple of args (closes #13186)
Benjamin Peterson <benjamin@python.org>
parents:
68256
diff
changeset
|
1747 {"sequence_delitem", (PyCFunction)sequence_delitem, METH_VARARGS}, |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1748 {NULL, NULL} /* sentinel */ |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1749 }; |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1750 |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
1751 #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
|
1752 |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1753 typedef struct { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1754 char bool_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1755 char byte_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1756 unsigned char ubyte_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1757 short short_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1758 unsigned short ushort_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1759 int int_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1760 unsigned int uint_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1761 long long_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1762 unsigned long ulong_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1763 float float_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1764 double double_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1765 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
|
1766 #ifdef HAVE_LONG_LONG |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1767 PY_LONG_LONG longlong_member; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1768 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
|
1769 #endif |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1770 } all_structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1771 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1772 typedef struct { |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1773 PyObject_HEAD |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1774 all_structmembers structmembers; |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1775 } test_structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1776 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1777 static struct PyMemberDef test_members[] = { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1778 {"T_BOOL", T_BOOL, offsetof(test_structmembers, structmembers.bool_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1779 {"T_BYTE", T_BYTE, offsetof(test_structmembers, structmembers.byte_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1780 {"T_UBYTE", T_UBYTE, offsetof(test_structmembers, structmembers.ubyte_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1781 {"T_SHORT", T_SHORT, offsetof(test_structmembers, structmembers.short_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1782 {"T_USHORT", T_USHORT, offsetof(test_structmembers, structmembers.ushort_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1783 {"T_INT", T_INT, offsetof(test_structmembers, structmembers.int_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1784 {"T_UINT", T_UINT, offsetof(test_structmembers, structmembers.uint_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1785 {"T_LONG", T_LONG, offsetof(test_structmembers, structmembers.long_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1786 {"T_ULONG", T_ULONG, offsetof(test_structmembers, structmembers.ulong_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1787 {"T_FLOAT", T_FLOAT, offsetof(test_structmembers, structmembers.float_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1788 {"T_DOUBLE", T_DOUBLE, offsetof(test_structmembers, structmembers.double_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1789 {"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
|
1790 #ifdef HAVE_LONG_LONG |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1791 {"T_LONGLONG", T_LONGLONG, offsetof(test_structmembers, structmembers.longlong_member), 0, NULL}, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1792 {"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
|
1793 #endif |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1794 {NULL} |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1795 }; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1796 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1797 |
| 44864 | 1798 static PyObject * |
| 1799 test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | |
| 1800 { | |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1801 static char *keywords[] = { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1802 "T_BOOL", "T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1803 "T_INT", "T_UINT", "T_LONG", "T_ULONG", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1804 "T_FLOAT", "T_DOUBLE", "T_STRING_INPLACE", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1805 #ifdef HAVE_LONG_LONG |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1806 "T_LONGLONG", "T_ULONGLONG", |
| 44864 | 1807 #endif |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1808 NULL}; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1809 static char *fmt = "|bbBhHiIlkfds#" |
| 44864 | 1810 #ifdef HAVE_LONG_LONG |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1811 "LK" |
| 44864 | 1812 #endif |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1813 ; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1814 test_structmembers *ob; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1815 const char *s = NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1816 Py_ssize_t string_len = 0; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1817 ob = PyObject_New(test_structmembers, type); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1818 if (ob == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1819 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1820 memset(&ob->structmembers, 0, sizeof(all_structmembers)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1821 if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1822 &ob->structmembers.bool_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1823 &ob->structmembers.byte_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1824 &ob->structmembers.ubyte_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1825 &ob->structmembers.short_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1826 &ob->structmembers.ushort_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1827 &ob->structmembers.int_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1828 &ob->structmembers.uint_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1829 &ob->structmembers.long_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1830 &ob->structmembers.ulong_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1831 &ob->structmembers.float_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1832 &ob->structmembers.double_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1833 &s, &string_len |
| 44864 | 1834 #ifdef HAVE_LONG_LONG |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1835 , &ob->structmembers.longlong_member, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1836 &ob->structmembers.ulonglong_member |
| 44864 | 1837 #endif |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1838 )) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1839 Py_DECREF(ob); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1840 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1841 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1842 if (s != NULL) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1843 if (string_len > 5) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1844 Py_DECREF(ob); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1845 PyErr_SetString(PyExc_ValueError, "string too long"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1846 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1847 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1848 strcpy(ob->structmembers.inplace_member, s); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1849 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1850 else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1851 strcpy(ob->structmembers.inplace_member, ""); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1852 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1853 return (PyObject *)ob; |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1854 } |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1855 |
| 44864 | 1856 static void |
| 1857 test_structmembers_free(PyObject *ob) | |
| 1858 { | |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1859 PyObject_FREE(ob); |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1860 } |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1861 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1862 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
|
1863 PyVarObject_HEAD_INIT(NULL, 0) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1864 "test_structmembersType", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1865 sizeof(test_structmembers), /* tp_basicsize */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1866 0, /* tp_itemsize */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1867 test_structmembers_free, /* destructor tp_dealloc */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1868 0, /* tp_print */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1869 0, /* tp_getattr */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1870 0, /* tp_setattr */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1871 0, /* tp_compare */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1872 0, /* tp_repr */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1873 0, /* tp_as_number */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1874 0, /* tp_as_sequence */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1875 0, /* tp_as_mapping */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1876 0, /* tp_hash */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1877 0, /* tp_call */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1878 0, /* tp_str */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1879 PyObject_GenericGetAttr, /* tp_getattro */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1880 PyObject_GenericSetAttr, /* tp_setattro */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1881 0, /* tp_as_buffer */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1882 0, /* tp_flags */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1883 "Type containing all structmember types", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1884 0, /* traverseproc tp_traverse */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1885 0, /* tp_clear */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1886 0, /* tp_richcompare */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1887 0, /* tp_weaklistoffset */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1888 0, /* tp_iter */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1889 0, /* tp_iternext */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1890 0, /* tp_methods */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1891 test_members, /* tp_members */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1892 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1893 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1894 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1895 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1896 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1897 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1898 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1899 0, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1900 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
|
1901 }; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1902 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1903 |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
22726
diff
changeset
|
1904 PyMODINIT_FUNC |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1905 init_testcapi(void) |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1906 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1907 PyObject *m; |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1908 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1909 m = Py_InitModule("_testcapi", TestMethods); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1910 if (m == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1911 return; |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1912 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1913 Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type; |
|
50397
c43226875bd4
Merged revisions 68099 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
50395
diff
changeset
|
1914 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1915 Py_TYPE(&test_structmembersType)=&PyType_Type; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1916 Py_INCREF(&test_structmembersType); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1917 /* don't use a name starting with "test", since we don't want |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1918 test_capi to automatically call this */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1919 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
|
1920 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1921 PyModule_AddObject(m, "CHAR_MAX", PyInt_FromLong(CHAR_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1922 PyModule_AddObject(m, "CHAR_MIN", PyInt_FromLong(CHAR_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1923 PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1924 PyModule_AddObject(m, "SHRT_MAX", PyInt_FromLong(SHRT_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1925 PyModule_AddObject(m, "SHRT_MIN", PyInt_FromLong(SHRT_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1926 PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1927 PyModule_AddObject(m, "INT_MAX", PyLong_FromLong(INT_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1928 PyModule_AddObject(m, "INT_MIN", PyLong_FromLong(INT_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1929 PyModule_AddObject(m, "UINT_MAX", PyLong_FromUnsignedLong(UINT_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1930 PyModule_AddObject(m, "LONG_MAX", PyInt_FromLong(LONG_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1931 PyModule_AddObject(m, "LONG_MIN", PyInt_FromLong(LONG_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1932 PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1933 PyModule_AddObject(m, "FLT_MAX", PyFloat_FromDouble(FLT_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1934 PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1935 PyModule_AddObject(m, "DBL_MAX", PyFloat_FromDouble(DBL_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1936 PyModule_AddObject(m, "DBL_MIN", PyFloat_FromDouble(DBL_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1937 PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1938 PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1939 PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1940 PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1941 PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1942 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
|
1943 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1944 TestError = PyErr_NewException("_testcapi.error", NULL, NULL); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1945 Py_INCREF(TestError); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
60228
diff
changeset
|
1946 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
|
1947 } |
