Mercurial > cpython-lru_cache-weakref
annotate Modules/_testcapimodule.c @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | d75f887da772 |
| children | 66b60a6e8198 |
| 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" |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
11 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
12 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
13 #include "pythread.h" |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
14 #endif /* WITH_THREAD */ |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
15 static PyObject *TestError; /* set to exception object in init */ |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
16 |
|
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
|
17 /* 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
|
18 |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
19 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
|
20 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
|
21 { |
|
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 char buf[2048]; |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
23 |
|
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 if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50) |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
25 PyErr_SetString(TestError, "internal error msg too large"); |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
26 else { |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
27 PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg); |
|
18092
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
28 PyErr_SetString(TestError, buf); |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
29 } |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
30 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
|
31 } |
|
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 |
|
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
|
33 /* 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
|
34 |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 */ |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
39 static PyObject* |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
40 sizeof_error(const char* fatname, const char* typname, |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
41 int expected, int got) |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
42 { |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
43 char buf[1024]; |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
44 PyOS_snprintf(buf, sizeof(buf), |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
45 "%.200s #define == %d but sizeof(%.200s) == %d", |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
46 fatname, expected, typname, got); |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
47 PyErr_SetString(TestError, buf); |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
48 return (PyObject*)NULL; |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
49 } |
|
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 static PyObject* |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
52 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
|
53 { |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
54 #define CHECK_SIZEOF(FATNAME, TYPE) \ |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
55 if (FATNAME != sizeof(TYPE)) \ |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
56 return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE)) |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
57 |
|
18294
b14521fd8e39
Windows build broke from recent Unicode changes -- need to #define
Tim Peters <tim.peters@gmail.com>
parents:
18132
diff
changeset
|
58 CHECK_SIZEOF(SIZEOF_SHORT, short); |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
59 CHECK_SIZEOF(SIZEOF_INT, int); |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
60 CHECK_SIZEOF(SIZEOF_LONG, long); |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
61 CHECK_SIZEOF(SIZEOF_VOID_P, void*); |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
62 CHECK_SIZEOF(SIZEOF_TIME_T, time_t); |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
63 #ifdef HAVE_LONG_LONG |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
64 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
|
65 #endif |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
66 |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
67 #undef CHECK_SIZEOF |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
68 |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
69 Py_INCREF(Py_None); |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
70 return Py_None; |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
71 } |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
72 |
|
16582
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
73 static PyObject* |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
74 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
|
75 { |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
76 PyObject* list; |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
77 int i; |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
78 |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
79 /* SF bug 132008: PyList_Reverse segfaults */ |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
80 #define NLIST 30 |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
81 list = PyList_New(NLIST); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
82 if (list == (PyObject*)NULL) |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
83 return (PyObject*)NULL; |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
84 /* list = range(NLIST) */ |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
85 for (i = 0; i < NLIST; ++i) { |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
86 PyObject* anint = PyInt_FromLong(i); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
87 if (anint == (PyObject*)NULL) { |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
88 Py_DECREF(list); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
89 return (PyObject*)NULL; |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
90 } |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
91 PyList_SET_ITEM(list, i, anint); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
92 } |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
93 /* list.reverse(), via PyList_Reverse() */ |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
94 i = PyList_Reverse(list); /* should not blow up! */ |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
95 if (i != 0) { |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
96 Py_DECREF(list); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
97 return (PyObject*)NULL; |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
98 } |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
99 /* Check that list == range(29, -1, -1) now */ |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
100 for (i = 0; i < NLIST; ++i) { |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
101 PyObject* anint = PyList_GET_ITEM(list, i); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
102 if (PyInt_AS_LONG(anint) != NLIST-1-i) { |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
103 PyErr_SetString(TestError, |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
104 "test_list_api: reverse screwed up"); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
105 Py_DECREF(list); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
106 return (PyObject*)NULL; |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
107 } |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
108 } |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
109 Py_DECREF(list); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
110 #undef NLIST |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
111 |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
112 Py_INCREF(Py_None); |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
113 return Py_None; |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
114 } |
|
9a8e961b505f
Related to SF bug 132008 (PyList_Reverse blows up).
Tim Peters <tim.peters@gmail.com>
parents:
16447
diff
changeset
|
115 |
|
17496
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
116 static int |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
117 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
|
118 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
119 Py_ssize_t pos = 0, iterations = 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
120 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
|
121 PyObject *dict = PyDict_New(); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
122 PyObject *v, *k; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
123 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
124 if (dict == NULL) |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
125 return -1; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
126 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
127 for (i = 0; i < count; i++) { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
128 v = PyInt_FromLong(i); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
129 PyDict_SetItem(dict, v, v); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
130 Py_DECREF(v); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
131 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
132 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
133 while (PyDict_Next(dict, &pos, &k, &v)) { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
134 PyObject *o; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
135 iterations++; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
136 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
137 i = PyInt_AS_LONG(v) + 1; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
138 o = PyInt_FromLong(i); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
139 if (o == NULL) |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
140 return -1; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
141 if (PyDict_SetItem(dict, k, o) < 0) { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
142 Py_DECREF(o); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
143 return -1; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
144 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
145 Py_DECREF(o); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
146 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
147 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
148 Py_DECREF(dict); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
149 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
150 if (iterations != count) { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
151 PyErr_SetString( |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
152 TestError, |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
153 "test_dict_iteration: dict iteration went wrong "); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
154 return -1; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
155 } else { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
156 return 0; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
157 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
158 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
159 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
160 static PyObject* |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
161 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
|
162 { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
163 int i; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
164 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
165 for (i = 0; i < 200; i++) { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
166 if (test_dict_inner(i) < 0) { |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
167 return NULL; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
168 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
169 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
170 |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
171 Py_INCREF(Py_None); |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
172 return Py_None; |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
173 } |
|
0b060cf762ce
Slight adaptation of Michael Hudson's patch to test PyDict_Next()
Guido van Rossum <guido@python.org>
parents:
16582
diff
changeset
|
174 |
|
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
|
175 |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
176 /* Issue #4701: Check that PyObject_Hash implicitly calls |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
177 * 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
|
178 */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
179 static PyTypeObject _HashInheritanceTester_Type = { |
|
50395
dcbe99b0ce83
Merged revisions 68097 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
50370
diff
changeset
|
180 PyObject_HEAD_INIT(NULL) |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
181 0, /* Number of items for varobject */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
182 "hashinheritancetester", /* Name of this type */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
183 sizeof(PyObject), /* Basic object size */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
184 0, /* Item size for varobject */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
185 (destructor)PyObject_Del, /* tp_dealloc */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
186 0, /* tp_print */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
187 0, /* tp_getattr */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
188 0, /* tp_setattr */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
189 0, /* tp_compare */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
190 0, /* tp_repr */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
191 0, /* tp_as_number */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
192 0, /* tp_as_sequence */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
193 0, /* tp_as_mapping */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
194 0, /* tp_hash */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
195 0, /* tp_call */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
196 0, /* tp_str */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
197 PyObject_GenericGetAttr, /* tp_getattro */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
198 0, /* tp_setattro */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
199 0, /* tp_as_buffer */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
200 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
201 0, /* tp_doc */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
202 0, /* tp_traverse */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
203 0, /* tp_clear */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
204 0, /* tp_richcompare */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
205 0, /* tp_weaklistoffset */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
206 0, /* tp_iter */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
207 0, /* tp_iternext */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
208 0, /* tp_methods */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
209 0, /* tp_members */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
210 0, /* tp_getset */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
211 0, /* tp_base */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
212 0, /* tp_dict */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
213 0, /* tp_descr_get */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
214 0, /* tp_descr_set */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
215 0, /* tp_dictoffset */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
216 0, /* tp_init */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
217 0, /* tp_alloc */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
218 PyType_GenericNew, /* tp_new */ |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
219 }; |
|
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 static PyObject* |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
222 test_lazy_hash_inheritance(PyObject* self) |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
223 { |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
224 PyTypeObject *type; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
225 PyObject *obj; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
226 long hash; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
227 |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
228 type = &_HashInheritanceTester_Type; |
|
58680
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
229 |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
230 if (type->tp_dict != NULL) |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
231 /* The type has already been initialized. This probably means |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
232 -R is being used. */ |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
233 Py_RETURN_NONE; |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
234 |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
235 |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
236 obj = PyObject_New(PyObject, type); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
237 if (obj == NULL) { |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
238 PyErr_Clear(); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
239 PyErr_SetString( |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
240 TestError, |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
241 "test_lazy_hash_inheritance: failed to create object"); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
242 return NULL; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
243 } |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
244 |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
245 if (type->tp_dict != NULL) { |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
246 PyErr_SetString( |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
247 TestError, |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
248 "test_lazy_hash_inheritance: type initialised too soon"); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
249 Py_DECREF(obj); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
250 return NULL; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
251 } |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
252 |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
253 hash = PyObject_Hash(obj); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
254 if ((hash == -1) && PyErr_Occurred()) { |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
255 PyErr_Clear(); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
256 PyErr_SetString( |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
257 TestError, |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
258 "test_lazy_hash_inheritance: could not hash object"); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
259 Py_DECREF(obj); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
260 return NULL; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
261 } |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
262 |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
263 if (type->tp_dict == NULL) { |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
264 PyErr_SetString( |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
265 TestError, |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
266 "test_lazy_hash_inheritance: type not initialised by hash()"); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
267 Py_DECREF(obj); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
268 return NULL; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
269 } |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
270 |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
271 if (type->tp_hash != PyType_Type.tp_hash) { |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
272 PyErr_SetString( |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
273 TestError, |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
274 "test_lazy_hash_inheritance: unexpected hash function"); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
275 Py_DECREF(obj); |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
276 return NULL; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
277 } |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
278 |
|
58680
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
279 Py_DECREF(obj); |
|
d75f887da772
Merged revisions 72357,72367 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
50397
diff
changeset
|
280 |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
281 Py_RETURN_NONE; |
|
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
282 } |
|
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 |
|
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
|
285 /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG) |
| 18113 | 286 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
|
287 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 */ |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
299 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
300 #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
|
301 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
302 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
|
303 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
|
304 { |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
305 return raiseTestError("test_long_api", msg); |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
306 } |
|
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
|
307 |
|
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
|
308 #define TESTNAME test_long_api_inner |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
309 #define TYPENAME long |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
310 #define F_S_TO_PY PyLong_FromLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
311 #define F_PY_TO_S PyLong_AsLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
312 #define F_U_TO_PY PyLong_FromUnsignedLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
313 #define F_PY_TO_U PyLong_AsUnsignedLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
314 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
315 #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
|
316 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
317 static PyObject * |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
318 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
|
319 { |
|
18132
e887d6862f77
Fix error in comment, and in test_long_api and test_longlong_api remove
Tim Peters <tim.peters@gmail.com>
parents:
18113
diff
changeset
|
320 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
|
321 } |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
322 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
323 #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
|
324 #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
|
325 #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
|
326 #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
|
327 #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
|
328 #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
|
329 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
330 #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
|
331 |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
332 static PyObject * |
| 18093 | 333 raise_test_longlong_error(const char* msg) |
| 334 { | |
| 335 return raiseTestError("test_longlong_api", msg); | |
| 336 } | |
| 337 | |
|
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
|
338 #define TESTNAME test_longlong_api_inner |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
339 #define TYPENAME PY_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
|
340 #define F_S_TO_PY PyLong_FromLongLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
341 #define F_PY_TO_S PyLong_AsLongLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
342 #define F_U_TO_PY PyLong_FromUnsignedLongLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
343 #define F_PY_TO_U PyLong_AsUnsignedLongLong |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
344 |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
345 #include "testcapi_long.h" |
| 18093 | 346 |
| 347 static PyObject * | |
|
37822
3ede175ead37
correct function signature
Skip Montanaro <skip@pobox.com>
parents:
37674
diff
changeset
|
348 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
|
349 { |
|
18132
e887d6862f77
Fix error in comment, and in test_long_api and test_longlong_api remove
Tim Peters <tim.peters@gmail.com>
parents:
18113
diff
changeset
|
350 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
|
351 } |
|
bd0056ee1a6e
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
Tim Peters <tim.peters@gmail.com>
parents:
17496
diff
changeset
|
352 |
|
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
|
353 #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
|
354 #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
|
355 #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
|
356 #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
|
357 #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
|
358 #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
|
359 |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
360 /* 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
|
361 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
|
362 it fails. |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
363 */ |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
364 static PyObject * |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
365 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
|
366 { |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
367 PyObject *tuple, *num; |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
368 PY_LONG_LONG value; |
|
20182
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
369 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
370 tuple = PyTuple_New(1); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
371 if (tuple == NULL) |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
372 return NULL; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
373 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
374 num = PyLong_FromLong(42); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
375 if (num == NULL) |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
376 return NULL; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
377 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
378 PyTuple_SET_ITEM(tuple, 0, num); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
379 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
380 value = -1; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
381 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0) |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
382 return NULL; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
383 if (value != 42) |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
384 return raiseTestError("test_L_code", |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
385 "L code returned wrong value for long 42"); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
386 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
387 Py_DECREF(num); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
388 num = PyInt_FromLong(42); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
389 if (num == NULL) |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
390 return NULL; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
391 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
392 PyTuple_SET_ITEM(tuple, 0, num); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
393 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
394 value = -1; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
395 if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0) |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
396 return NULL; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
397 if (value != 42) |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
398 return raiseTestError("test_L_code", |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
399 "L code returned wrong value for int 42"); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
400 |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
401 Py_DECREF(tuple); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
402 Py_INCREF(Py_None); |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
403 return Py_None; |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
404 } |
|
6d73b54d9205
SF [#466125] PyLong_AsLongLong works for any integer.
Tim Peters <tim.peters@gmail.com>
parents:
20117
diff
changeset
|
405 |
|
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
|
406 #endif /* ifdef HAVE_LONG_LONG */ |
|
9eb469a43144
Add tests of PyLong_{As,From}{Unsigned,}Long. These are very much like
Tim Peters <tim.peters@gmail.com>
parents:
18093
diff
changeset
|
407 |
|
39189
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
408 /* Test tuple argument processing */ |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
409 static PyObject * |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
410 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
|
411 { |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
412 int a, b, c; |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
413 if (!PyArg_ParseTuple(args, "i(ii)", &a, &b, &c)) |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
414 return NULL; |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
415 return Py_BuildValue("iii", a, b, c); |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
416 } |
|
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
417 |
|
45537
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
418 /* 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
|
419 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
|
420 { |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
421 static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL}; |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
422 static char *fmt="(ii)i|(i(ii))(iii)i"; |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
423 int int_args[10]={-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
424 |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
425 if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
426 &int_args[0], &int_args[1], &int_args[2], &int_args[3], &int_args[4], |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
427 &int_args[5], &int_args[6], &int_args[7], &int_args[8], &int_args[9])) |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
428 return NULL; |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
429 return Py_BuildValue("iiiiiiiiii", |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
430 int_args[0], int_args[1], int_args[2], int_args[3], int_args[4], |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
431 int_args[5], int_args[6], int_args[7], int_args[8], int_args[9]); |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
432 } |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
433 |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
434 /* 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
|
435 and return the result. |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
436 */ |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
437 static PyObject * |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
438 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
|
439 { |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
440 unsigned char value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
441 if (!PyArg_ParseTuple(args, "b", &value)) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
442 return NULL; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
443 return PyLong_FromUnsignedLong((unsigned long)value); |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
444 } |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
445 |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
446 static PyObject * |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
447 getargs_B(PyObject *self, PyObject *args) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
448 { |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
449 unsigned char value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
450 if (!PyArg_ParseTuple(args, "B", &value)) |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
451 return NULL; |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
452 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
|
453 } |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
454 |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
455 static PyObject * |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
456 getargs_H(PyObject *self, PyObject *args) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
457 { |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
458 unsigned short value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
459 if (!PyArg_ParseTuple(args, "H", &value)) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
460 return NULL; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
461 return PyLong_FromUnsignedLong((unsigned long)value); |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
462 } |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
463 |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
464 static PyObject * |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
465 getargs_I(PyObject *self, PyObject *args) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
466 { |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
467 unsigned int value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
468 if (!PyArg_ParseTuple(args, "I", &value)) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
469 return NULL; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
470 return PyLong_FromUnsignedLong((unsigned long)value); |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
471 } |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
472 |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
473 static PyObject * |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
474 getargs_k(PyObject *self, PyObject *args) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
475 { |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
476 unsigned long value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
477 if (!PyArg_ParseTuple(args, "k", &value)) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
478 return NULL; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
479 return PyLong_FromUnsignedLong(value); |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
480 } |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
481 |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
482 static PyObject * |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
483 getargs_i(PyObject *self, PyObject *args) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
484 { |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
485 int value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
486 if (!PyArg_ParseTuple(args, "i", &value)) |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
487 return NULL; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
488 return PyLong_FromLong((long)value); |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
489 } |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
490 |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
491 static PyObject * |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
492 getargs_l(PyObject *self, PyObject *args) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
493 { |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
494 long value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
495 if (!PyArg_ParseTuple(args, "l", &value)) |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
496 return NULL; |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
497 return PyLong_FromLong(value); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
498 } |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
499 |
|
37674
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
500 static PyObject * |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
501 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
|
502 { |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
503 Py_ssize_t value; |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
504 if (!PyArg_ParseTuple(args, "n", &value)) |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
505 return NULL; |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
506 return PyInt_FromSsize_t(value); |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
507 } |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
508 |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
509 #ifdef HAVE_LONG_LONG |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
510 static PyObject * |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
511 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
|
512 { |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
513 PY_LONG_LONG value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
514 if (!PyArg_ParseTuple(args, "L", &value)) |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
515 return NULL; |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
516 return PyLong_FromLongLong(value); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
517 } |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
518 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
519 static PyObject * |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
520 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
|
521 { |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
522 unsigned PY_LONG_LONG value; |
|
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
523 if (!PyArg_ParseTuple(args, "K", &value)) |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
524 return NULL; |
|
28775
bc4231eb2758
New support functions for test_getargs2.
Thomas Heller <theller@ctypes.org>
parents:
28714
diff
changeset
|
525 return PyLong_FromUnsignedLongLong(value); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
526 } |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
527 #endif |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
528 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
529 /* 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
|
530 PyInt_AsUnsignedLongMask() and PyInt_AsUnsignedLongMask() functions. */ |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
531 static PyObject * |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
532 test_k_code(PyObject *self) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
533 { |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
534 PyObject *tuple, *num; |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
535 unsigned long value; |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
536 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
537 tuple = PyTuple_New(1); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
538 if (tuple == NULL) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
539 return NULL; |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
540 |
|
28714
ec2a0f15c14c
Get test_capi & test_getargs2 to pass on alphas
Neal Norwitz <nnorwitz@gmail.com>
parents:
28694
diff
changeset
|
541 /* a number larger than ULONG_MAX even on 64-bit platforms */ |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
542 num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
543 if (num == NULL) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
544 return NULL; |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
545 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
546 value = PyInt_AsUnsignedLongMask(num); |
|
28714
ec2a0f15c14c
Get test_capi & test_getargs2 to pass on alphas
Neal Norwitz <nnorwitz@gmail.com>
parents:
28694
diff
changeset
|
547 if (value != ULONG_MAX) |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
548 return raiseTestError("test_k_code", |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
549 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF"); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
550 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
551 PyTuple_SET_ITEM(tuple, 0, num); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
552 |
|
37555
231e42d0362e
Fix some warnings on HP-UX when using cc/aCC
Neal Norwitz <nnorwitz@gmail.com>
parents:
37117
diff
changeset
|
553 value = 0; |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
554 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
555 return NULL; |
|
28714
ec2a0f15c14c
Get test_capi & test_getargs2 to pass on alphas
Neal Norwitz <nnorwitz@gmail.com>
parents:
28694
diff
changeset
|
556 if (value != ULONG_MAX) |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
557 return raiseTestError("test_k_code", |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
558 "k code returned wrong value for long 0xFFF...FFF"); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
559 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
560 Py_DECREF(num); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
561 num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
562 if (num == NULL) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
563 return NULL; |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
564 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
565 value = PyInt_AsUnsignedLongMask(num); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
566 if (value != (unsigned long)-0x42) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
567 return raiseTestError("test_k_code", |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
568 "PyInt_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF"); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
569 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
570 PyTuple_SET_ITEM(tuple, 0, num); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
571 |
|
37555
231e42d0362e
Fix some warnings on HP-UX when using cc/aCC
Neal Norwitz <nnorwitz@gmail.com>
parents:
37117
diff
changeset
|
572 value = 0; |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
573 if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
574 return NULL; |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
575 if (value != (unsigned long)-0x42) |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
576 return raiseTestError("test_k_code", |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
577 "k code returned wrong value for long -0xFFF..000042"); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
578 |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
579 Py_DECREF(tuple); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
580 Py_INCREF(Py_None); |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
581 return Py_None; |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
582 } |
|
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
583 |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
584 #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
|
585 |
|
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
|
586 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
|
587 |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
588 /* 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
|
589 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
|
590 */ |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
591 static PyObject * |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
592 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
|
593 { |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
594 PyObject *tuple, *obj; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
595 Py_UNICODE *value; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
596 int len; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
597 |
|
49502
e1a88e8b9649
Merged revisions 66891 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48841
diff
changeset
|
598 /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */ |
|
e1a88e8b9649
Merged revisions 66891 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48841
diff
changeset
|
599 /* Just use the macro and check that it compiles */ |
|
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
|
600 x = Py_UNICODE_ISSPACE(25); |
|
49502
e1a88e8b9649
Merged revisions 66891 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48841
diff
changeset
|
601 |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
602 tuple = PyTuple_New(1); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
603 if (tuple == NULL) |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
604 return NULL; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
605 |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
606 obj = PyUnicode_Decode("test", strlen("test"), |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
607 "ascii", NULL); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
608 if (obj == NULL) |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
609 return NULL; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
610 |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
611 PyTuple_SET_ITEM(tuple, 0, obj); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
612 |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
613 value = 0; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
614 if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0) |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
615 return NULL; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
616 if (value != PyUnicode_AS_UNICODE(obj)) |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
617 return raiseTestError("test_u_code", |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
618 "u code returned wrong value for u'test'"); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
619 value = 0; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
620 if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0) |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
621 return NULL; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
622 if (value != PyUnicode_AS_UNICODE(obj) || |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
623 len != PyUnicode_GET_SIZE(obj)) |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
624 return raiseTestError("test_u_code", |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
625 "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
|
626 |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
627 Py_DECREF(tuple); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
628 Py_INCREF(Py_None); |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
629 return Py_None; |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
630 } |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
631 |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
632 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
|
633 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
|
634 { |
|
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
|
635 /* Test that formats can begin with '|'. See issue #4720. */ |
|
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
|
636 PyObject *tuple, *dict = NULL; |
|
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
|
637 static char *kwlist[] = {NULL}; |
|
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
|
638 int result; |
|
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
|
639 tuple = PyTuple_New(0); |
|
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
|
640 if (!tuple) |
|
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
|
641 return NULL; |
|
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
|
642 if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0) |
|
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
|
643 goto done; |
|
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
|
644 dict = PyDict_New(); |
|
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
|
645 if (!dict) |
|
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
|
646 goto done; |
|
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
|
647 result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist); |
|
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
|
648 done: |
|
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
|
649 Py_DECREF(tuple); |
|
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
|
650 Py_XDECREF(dict); |
|
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
|
651 if (result < 0) |
|
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
|
652 return NULL; |
|
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
|
653 else { |
|
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
|
654 Py_RETURN_NONE; |
|
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
|
655 } |
|
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
|
656 } |
|
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
|
657 |
|
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
|
658 static PyObject * |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
659 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
|
660 { |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
661 const char *encoding, *errors = NULL; |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
662 if (!PyArg_ParseTuple(args, "s|s:test_incrementalencoder", |
|
37077
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
663 &encoding, &errors)) |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
664 return NULL; |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
665 return PyCodec_IncrementalEncoder(encoding, errors); |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
666 } |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
667 |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
668 static PyObject * |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
669 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
|
670 { |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
671 const char *encoding, *errors = NULL; |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
672 if (!PyArg_ParseTuple(args, "s|s:test_incrementaldecoder", |
|
37077
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
673 &encoding, &errors)) |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
674 return NULL; |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
675 return PyCodec_IncrementalDecoder(encoding, errors); |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
676 } |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
677 |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
678 #endif |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
679 |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
680 /* 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
|
681 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
|
682 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
|
683 { |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
684 struct triple { |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
685 long input; |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
686 size_t nbits; |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
687 int sign; |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
688 } testcases[] = {{0, 0, 0}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
689 {1L, 1, 1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
690 {-1L, 1, -1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
691 {2L, 2, 1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
692 {-2L, 2, -1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
693 {3L, 2, 1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
694 {-3L, 2, -1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
695 {4L, 3, 1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
696 {-4L, 3, -1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
697 {0x7fffL, 15, 1}, /* one Python long digit */ |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
698 {-0x7fffL, 15, -1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
699 {0xffffL, 16, 1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
700 {-0xffffL, 16, -1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
701 {0xfffffffL, 28, 1}, |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
702 {-0xfffffffL, 28, -1}}; |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
703 int i; |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
704 |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
705 for (i = 0; i < sizeof(testcases) / sizeof(struct triple); ++i) { |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
706 PyObject *plong = PyLong_FromLong(testcases[i].input); |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
707 size_t nbits = _PyLong_NumBits(plong); |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
708 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
|
709 |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
710 Py_DECREF(plong); |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
711 if (nbits != testcases[i].nbits) |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
712 return raiseTestError("test_long_numbits", |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
713 "wrong result for _PyLong_NumBits"); |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
714 if (sign != testcases[i].sign) |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
715 return raiseTestError("test_long_numbits", |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
716 "wrong result for _PyLong_Sign"); |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
717 } |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
718 Py_INCREF(Py_None); |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
719 return Py_None; |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
720 } |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
721 |
|
36989
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
722 /* 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
|
723 |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
724 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
|
725 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
|
726 { |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
727 PyObject *o1 = PyObject_Str(NULL), *o2 = 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
|
728 PyObject *tuple = PyTuple_Pack(2, o1, o2); |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
729 Py_XDECREF(o1); |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
730 Py_XDECREF(o2); |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
731 return tuple; |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
732 } |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
733 |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
734 static PyObject * |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
735 raise_exception(PyObject *self, PyObject *args) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
736 { |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
737 PyObject *exc; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
738 PyObject *exc_args, *v; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
739 int num_args, i; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
740 |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
741 if (!PyArg_ParseTuple(args, "Oi:raise_exception", |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
742 &exc, &num_args)) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
743 return NULL; |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
744 if (!PyExceptionClass_Check(exc)) { |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
745 PyErr_Format(PyExc_TypeError, "an exception class is required"); |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
746 return NULL; |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
747 } |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
748 |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
749 exc_args = PyTuple_New(num_args); |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
750 if (exc_args == NULL) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
751 return NULL; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
752 for (i = 0; i < num_args; ++i) { |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
753 v = PyInt_FromLong(i); |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
754 if (v == NULL) { |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
755 Py_DECREF(exc_args); |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
756 return NULL; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
757 } |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
758 PyTuple_SET_ITEM(exc_args, i, v); |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
759 } |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
760 PyErr_SetObject(exc, exc_args); |
|
30158
4460979deebf
Fix silly leak in test used in test_exceptions.
Michael W. Hudson <mwh@python.net>
parents:
28775
diff
changeset
|
761 Py_DECREF(exc_args); |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
762 return NULL; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
763 } |
|
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
|
764 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
765 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
766 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
767 /* 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
|
768 * `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
|
769 * 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
|
770 * 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
|
771 * 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
|
772 * 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
|
773 */ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
774 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
|
775 |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
776 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
|
777 _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
|
778 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
779 PyObject *rc; |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
780 int success; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
781 PyGILState_STATE s = PyGILState_Ensure(); |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
782 rc = PyObject_CallFunction((PyObject *)callable, ""); |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
783 success = (rc != NULL); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
784 Py_XDECREF(rc); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
785 PyGILState_Release(s); |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
786 return success; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
787 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
788 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
789 /* 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
|
790 * 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
|
791 */ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
792 static void |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
793 _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
|
794 { |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
795 _make_call(callable); |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
796 PyThread_release_lock(thread_done); |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
797 } |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
798 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
799 static PyObject * |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
800 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
|
801 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
802 PyObject *fn; |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
803 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
|
804 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
805 if (!PyArg_ParseTuple(args, "O:test_thread_state", &fn)) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
806 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
|
807 |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
808 if (!PyCallable_Check(fn)) { |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
809 PyErr_Format(PyExc_TypeError, "'%s' object is not callable", |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
810 fn->ob_type->tp_name); |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
811 return NULL; |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
812 } |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
813 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
814 /* Ensure Python is set up for threading */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
815 PyEval_InitThreads(); |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
816 thread_done = PyThread_allocate_lock(); |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
817 if (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
|
818 return PyErr_NoMemory(); |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
819 PyThread_acquire_lock(thread_done, 1); |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
820 |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
821 /* Start a new thread with our callback. */ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
822 PyThread_start_new_thread(_make_call_from_thread, fn); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
823 /* Make the callback with the thread lock held by this thread */ |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
824 success &= _make_call(fn); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
825 /* Do it all again, but this time with the thread-lock released */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
826 Py_BEGIN_ALLOW_THREADS |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
827 success &= _make_call(fn); |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
828 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
829 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
|
830 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
831 /* And once more with and without a thread |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
832 XXX - should use a lock and work out exactly what we are trying |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
833 to test <wink> |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
834 */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
835 Py_BEGIN_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
|
836 PyThread_start_new_thread(_make_call_from_thread, fn); |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
837 success &= _make_call(fn); |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
838 PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
839 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
|
840 |
|
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
|
841 /* Release lock we acquired above. This is required on HP-UX. */ |
|
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
|
842 PyThread_release_lock(thread_done); |
|
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
|
843 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
844 PyThread_free_lock(thread_done); |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
845 if (!success) |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
846 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
|
847 Py_RETURN_NONE; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
848 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
849 #endif |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
850 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
851 /* 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
|
852 static PyObject * |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
853 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
|
854 { |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
855 PyObject *result; |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
856 char *msg; |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
857 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
858 #define CHECK_1_FORMAT(FORMAT, TYPE) \ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
859 result = PyString_FromFormat(FORMAT, (TYPE)1); \ |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
860 if (result == NULL) \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
861 return NULL; \ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
862 if (strcmp(PyString_AsString(result), "1")) { \ |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
863 msg = FORMAT " failed at 1"; \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
864 goto Fail; \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
865 } \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
866 Py_DECREF(result) |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
867 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
868 CHECK_1_FORMAT("%d", int); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
869 CHECK_1_FORMAT("%ld", long); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
870 /* The z width modifier was added in Python 2.5. */ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
871 CHECK_1_FORMAT("%zd", Py_ssize_t); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
872 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
873 /* The u type code was added in Python 2.5. */ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
874 CHECK_1_FORMAT("%u", unsigned int); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
875 CHECK_1_FORMAT("%lu", unsigned long); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
876 CHECK_1_FORMAT("%zu", size_t); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
877 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
878 Py_RETURN_NONE; |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
879 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
880 Fail: |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
881 Py_XDECREF(result); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
882 return raiseTestError("test_string_from_format", msg); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
883 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
884 #undef CHECK_1_FORMAT |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
885 } |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
886 |
|
39371
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
887 /* 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
|
888 static PyObject * |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
889 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
|
890 { |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
891 Py_RETURN_NONE; |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
892 } |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
893 |
|
46589
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
894 /* 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
|
895 static PyObject * |
|
46592
4e47548edd36
Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents:
46589
diff
changeset
|
896 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
|
897 { |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
898 PyObject *file; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
899 PyObject *traceback; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
900 int result; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
901 |
|
46592
4e47548edd36
Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents:
46589
diff
changeset
|
902 if (!PyArg_ParseTuple(args, "OO:traceback_print", |
|
46589
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
903 &traceback, &file)) |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
904 return NULL; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
905 |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
906 result = PyTraceBack_Print(traceback, file); |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
907 if (result < 0) |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
908 return NULL; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
909 Py_RETURN_NONE; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
910 } |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
911 |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
912 static PyMethodDef TestMethods[] = { |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
913 {"raise_exception", raise_exception, METH_VARARGS}, |
|
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
914 {"test_config", (PyCFunction)test_config, METH_NOARGS}, |
|
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
915 {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS}, |
|
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
916 {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, |
|
50370
e782f97116dc
Merged revisions 68051 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50305
diff
changeset
|
917 {"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS}, |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
918 {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
919 {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS}, |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
920 {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS}, |
|
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
|
921 {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS}, |
|
36989
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
922 {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS}, |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
923 {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, |
|
39371
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
924 {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS, |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
925 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
|
926 |
|
39189
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
927 {"getargs_tuple", getargs_tuple, METH_VARARGS}, |
|
45537
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
928 {"getargs_keywords", (PyCFunction)getargs_keywords, |
|
f33f66a2082f
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
Christian Heimes <christian@cheimes.de>
parents:
44864
diff
changeset
|
929 METH_VARARGS|METH_KEYWORDS}, |
|
37674
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
930 {"getargs_b", getargs_b, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
931 {"getargs_B", getargs_B, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
932 {"getargs_H", getargs_H, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
933 {"getargs_I", getargs_I, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
934 {"getargs_k", getargs_k, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
935 {"getargs_i", getargs_i, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
936 {"getargs_l", getargs_l, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
937 {"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
|
938 #ifdef HAVE_LONG_LONG |
|
37674
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
939 {"getargs_L", getargs_L, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
940 {"getargs_K", getargs_K, METH_VARARGS}, |
|
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
941 {"test_longlong_api", test_longlong_api, METH_NOARGS}, |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
942 {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS}, |
|
37077
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
943 {"codec_incrementalencoder", |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
944 (PyCFunction)codec_incrementalencoder, METH_VARARGS}, |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
945 {"codec_incrementaldecoder", |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
946 (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
|
947 #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
|
948 #ifdef Py_USING_UNICODE |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
949 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS}, |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
950 #endif |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
951 #ifdef WITH_THREAD |
|
37674
a4231aa3201a
Add a test for Py_ssize_t. Correct typo in getargs.c.
Georg Brandl <georg@python.org>
parents:
37670
diff
changeset
|
952 {"_test_thread_state", test_thread_state, METH_VARARGS}, |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
953 #endif |
|
46592
4e47548edd36
Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents:
46589
diff
changeset
|
954 {"traceback_print", traceback_print, METH_VARARGS}, |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
955 {NULL, NULL} /* sentinel */ |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
956 }; |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
957 |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
958 #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
|
959 |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
960 typedef struct { |
|
44863
eb4b50f739f6
Patch #1720595: add T_BOOL to the range of structmember types.
Georg Brandl <georg@python.org>
parents:
44350
diff
changeset
|
961 char bool_member; |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
962 char byte_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
963 unsigned char ubyte_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
964 short short_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
965 unsigned short ushort_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
966 int int_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
967 unsigned int uint_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
968 long long_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
969 unsigned long ulong_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
970 float float_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
971 double double_member; |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
972 #ifdef HAVE_LONG_LONG |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
973 PY_LONG_LONG longlong_member; |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
974 unsigned PY_LONG_LONG ulonglong_member; |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
975 #endif |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
976 } all_structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
977 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
978 typedef struct { |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
979 PyObject_HEAD |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
980 all_structmembers structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
981 } test_structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
982 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
983 static struct PyMemberDef test_members[] = { |
|
44863
eb4b50f739f6
Patch #1720595: add T_BOOL to the range of structmember types.
Georg Brandl <georg@python.org>
parents:
44350
diff
changeset
|
984 {"T_BOOL", T_BOOL, offsetof(test_structmembers, structmembers.bool_member), 0, NULL}, |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
985 {"T_BYTE", T_BYTE, offsetof(test_structmembers, structmembers.byte_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
986 {"T_UBYTE", T_UBYTE, offsetof(test_structmembers, structmembers.ubyte_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
987 {"T_SHORT", T_SHORT, offsetof(test_structmembers, structmembers.short_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
988 {"T_USHORT", T_USHORT, offsetof(test_structmembers, structmembers.ushort_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
989 {"T_INT", T_INT, offsetof(test_structmembers, structmembers.int_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
990 {"T_UINT", T_UINT, offsetof(test_structmembers, structmembers.uint_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
991 {"T_LONG", T_LONG, offsetof(test_structmembers, structmembers.long_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
992 {"T_ULONG", T_ULONG, offsetof(test_structmembers, structmembers.ulong_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
993 {"T_FLOAT", T_FLOAT, offsetof(test_structmembers, structmembers.float_member), 0, NULL}, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
994 {"T_DOUBLE", T_DOUBLE, offsetof(test_structmembers, structmembers.double_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
|
995 #ifdef HAVE_LONG_LONG |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
996 {"T_LONGLONG", T_LONGLONG, offsetof(test_structmembers, structmembers.longlong_member), 0, NULL}, |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
997 {"T_ULONGLONG", T_ULONGLONG, offsetof(test_structmembers, structmembers.ulonglong_member), 0, NULL}, |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
998 #endif |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
999 {NULL} |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1000 }; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1001 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1002 |
| 44864 | 1003 static PyObject * |
| 1004 test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | |
| 1005 { | |
| 1006 static char *keywords[] = { | |
| 1007 "T_BOOL", "T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", | |
| 1008 "T_INT", "T_UINT", "T_LONG", "T_ULONG", | |
| 1009 "T_FLOAT", "T_DOUBLE", | |
| 1010 #ifdef HAVE_LONG_LONG | |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1011 "T_LONGLONG", "T_ULONGLONG", |
| 44864 | 1012 #endif |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1013 NULL}; |
| 44864 | 1014 static char *fmt = "|bbBhHiIlkfd" |
| 1015 #ifdef HAVE_LONG_LONG | |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1016 "LK" |
| 44864 | 1017 #endif |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1018 ; |
| 44864 | 1019 test_structmembers *ob; |
| 1020 ob = PyObject_New(test_structmembers, type); | |
| 1021 if (ob == NULL) | |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1022 return NULL; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1023 memset(&ob->structmembers, 0, sizeof(all_structmembers)); |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1024 if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, |
| 44864 | 1025 &ob->structmembers.bool_member, |
| 1026 &ob->structmembers.byte_member, | |
| 1027 &ob->structmembers.ubyte_member, | |
| 1028 &ob->structmembers.short_member, | |
| 1029 &ob->structmembers.ushort_member, | |
| 1030 &ob->structmembers.int_member, | |
| 1031 &ob->structmembers.uint_member, | |
| 1032 &ob->structmembers.long_member, | |
| 1033 &ob->structmembers.ulong_member, | |
| 1034 &ob->structmembers.float_member, | |
| 1035 &ob->structmembers.double_member | |
| 1036 #ifdef HAVE_LONG_LONG | |
| 1037 , &ob->structmembers.longlong_member, | |
| 1038 &ob->structmembers.ulonglong_member | |
| 1039 #endif | |
| 1040 )) { | |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1041 Py_DECREF(ob); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1042 return NULL; |
| 44864 | 1043 } |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1044 return (PyObject *)ob; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1045 } |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1046 |
| 44864 | 1047 static void |
| 1048 test_structmembers_free(PyObject *ob) | |
| 1049 { | |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1050 PyObject_FREE(ob); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1051 } |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1052 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1053 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
|
1054 PyVarObject_HEAD_INIT(NULL, 0) |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1055 "test_structmembersType", |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1056 sizeof(test_structmembers), /* tp_basicsize */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1057 0, /* tp_itemsize */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1058 test_structmembers_free, /* destructor tp_dealloc */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1059 0, /* tp_print */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1060 0, /* tp_getattr */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1061 0, /* tp_setattr */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1062 0, /* tp_compare */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1063 0, /* tp_repr */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1064 0, /* tp_as_number */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1065 0, /* tp_as_sequence */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1066 0, /* tp_as_mapping */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1067 0, /* tp_hash */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1068 0, /* tp_call */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1069 0, /* tp_str */ |
| 44864 | 1070 PyObject_GenericGetAttr, /* tp_getattro */ |
| 1071 PyObject_GenericSetAttr, /* tp_setattro */ | |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1072 0, /* tp_as_buffer */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1073 0, /* tp_flags */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1074 "Type containing all structmember types", |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1075 0, /* traverseproc tp_traverse */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1076 0, /* tp_clear */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1077 0, /* tp_richcompare */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1078 0, /* tp_weaklistoffset */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1079 0, /* tp_iter */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1080 0, /* tp_iternext */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1081 0, /* tp_methods */ |
| 44864 | 1082 test_members, /* tp_members */ |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1083 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1084 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1085 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1086 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1087 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1088 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1089 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1090 0, |
| 44864 | 1091 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
|
1092 }; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1093 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1094 |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
22726
diff
changeset
|
1095 PyMODINIT_FUNC |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1096 init_testcapi(void) |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1097 { |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1098 PyObject *m; |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1099 |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1100 m = Py_InitModule("_testcapi", TestMethods); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
30158
diff
changeset
|
1101 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
30158
diff
changeset
|
1102 return; |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1103 |
|
50395
dcbe99b0ce83
Merged revisions 68097 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
50370
diff
changeset
|
1104 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
|
1105 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
1106 Py_TYPE(&test_structmembersType)=&PyType_Type; |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1107 Py_INCREF(&test_structmembersType); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1108 PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1109 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1110 PyModule_AddObject(m, "CHAR_MAX", PyInt_FromLong(CHAR_MAX)); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1111 PyModule_AddObject(m, "CHAR_MIN", PyInt_FromLong(CHAR_MIN)); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
1112 PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX)); |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1113 PyModule_AddObject(m, "SHRT_MAX", PyInt_FromLong(SHRT_MAX)); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1114 PyModule_AddObject(m, "SHRT_MIN", PyInt_FromLong(SHRT_MIN)); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
1115 PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX)); |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1116 PyModule_AddObject(m, "INT_MAX", PyLong_FromLong(INT_MAX)); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1117 PyModule_AddObject(m, "INT_MIN", PyLong_FromLong(INT_MIN)); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
1118 PyModule_AddObject(m, "UINT_MAX", PyLong_FromUnsignedLong(UINT_MAX)); |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1119 PyModule_AddObject(m, "LONG_MAX", PyInt_FromLong(LONG_MAX)); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1120 PyModule_AddObject(m, "LONG_MIN", PyInt_FromLong(LONG_MIN)); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
1121 PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX)); |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1122 PyModule_AddObject(m, "FLT_MAX", PyFloat_FromDouble(FLT_MAX)); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1123 PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN)); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1124 PyModule_AddObject(m, "DBL_MAX", PyFloat_FromDouble(DBL_MAX)); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1125 PyModule_AddObject(m, "DBL_MIN", PyFloat_FromDouble(DBL_MIN)); |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1126 PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX)); |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1127 PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN)); |
|
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1128 PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX)); |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1129 PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX)); |
|
37670
36bfe46c5c6a
Add PY_SSIZE_T_MIN/MAX to _testcapi.
Georg Brandl <georg@python.org>
parents:
37555
diff
changeset
|
1130 PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN)); |
|
47925
fd054e73e2f2
Added garbage collector overhead and optional default return value to
Robert Schuppenies <okkotonushi@googlemail.com>
parents:
47527
diff
changeset
|
1131 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
|
1132 |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1133 TestError = PyErr_NewException("_testcapi.error", NULL, NULL); |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1134 Py_INCREF(TestError); |
|
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1135 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
|
1136 } |
