Mercurial > cpython-lru_cache-weakref
annotate Modules/_testcapimodule.c @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | a171048daf76 |
| children | 51028709abc3 |
| 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 |
|
50369
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
176 /* Issue #4701: Check that PyObject_Hash implicitly calls |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
177 * PyType_Ready if it hasn't already been called |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
178 */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
179 static PyTypeObject _HashInheritanceTester_Type = { |
|
50394
9c2ac78666d4
Fixed compile error on windows.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
50369
diff
changeset
|
180 PyObject_HEAD_INIT(NULL) |
|
50369
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
181 0, /* Number of items for varobject */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
182 "hashinheritancetester", /* Name of this type */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
183 sizeof(PyObject), /* Basic object size */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
184 0, /* Item size for varobject */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
185 (destructor)PyObject_Del, /* tp_dealloc */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
186 0, /* tp_print */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
187 0, /* tp_getattr */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
188 0, /* tp_setattr */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
189 0, /* tp_compare */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
190 0, /* tp_repr */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
191 0, /* tp_as_number */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
192 0, /* tp_as_sequence */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
193 0, /* tp_as_mapping */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
194 0, /* tp_hash */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
195 0, /* tp_call */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
196 0, /* tp_str */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
197 PyObject_GenericGetAttr, /* tp_getattro */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
198 0, /* tp_setattro */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
199 0, /* tp_as_buffer */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
200 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
201 0, /* tp_doc */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
202 0, /* tp_traverse */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
203 0, /* tp_clear */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
204 0, /* tp_richcompare */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
205 0, /* tp_weaklistoffset */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
206 0, /* tp_iter */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
207 0, /* tp_iternext */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
208 0, /* tp_methods */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
209 0, /* tp_members */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
210 0, /* tp_getset */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
211 0, /* tp_base */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
212 0, /* tp_dict */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
213 0, /* tp_descr_get */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
214 0, /* tp_descr_set */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
215 0, /* tp_dictoffset */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
216 0, /* tp_init */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
217 0, /* tp_alloc */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
218 PyType_GenericNew, /* tp_new */ |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
219 }; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
220 |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
221 static PyObject* |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
222 test_lazy_hash_inheritance(PyObject* self) |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
223 { |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
224 PyTypeObject *type; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
225 PyObject *obj; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
226 long hash; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
227 |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
228 type = &_HashInheritanceTester_Type; |
|
53810
8f7cf5cb21bb
fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents:
52210
diff
changeset
|
229 |
| 53820 | 230 if (type->tp_dict != NULL) |
| 231 /* The type has already been initialized. This probably means | |
| 232 -R is being used. */ | |
| 233 Py_RETURN_NONE; | |
|
53810
8f7cf5cb21bb
fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents:
52210
diff
changeset
|
234 |
|
8f7cf5cb21bb
fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents:
52210
diff
changeset
|
235 |
|
50369
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
236 obj = PyObject_New(PyObject, type); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
237 if (obj == NULL) { |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
238 PyErr_Clear(); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
239 PyErr_SetString( |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
240 TestError, |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
241 "test_lazy_hash_inheritance: failed to create object"); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
242 return NULL; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
243 } |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
244 |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
245 if (type->tp_dict != NULL) { |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
246 PyErr_SetString( |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
247 TestError, |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
248 "test_lazy_hash_inheritance: type initialised too soon"); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
249 Py_DECREF(obj); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
250 return NULL; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
251 } |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
252 |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
253 hash = PyObject_Hash(obj); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
254 if ((hash == -1) && PyErr_Occurred()) { |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
255 PyErr_Clear(); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
256 PyErr_SetString( |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
257 TestError, |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
258 "test_lazy_hash_inheritance: could not hash object"); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
259 Py_DECREF(obj); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
260 return NULL; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
261 } |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
262 |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
263 if (type->tp_dict == NULL) { |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
264 PyErr_SetString( |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
265 TestError, |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
266 "test_lazy_hash_inheritance: type not initialised by hash()"); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
267 Py_DECREF(obj); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
268 return NULL; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
269 } |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
270 |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
271 if (type->tp_hash != PyType_Type.tp_hash) { |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
272 PyErr_SetString( |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
273 TestError, |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
274 "test_lazy_hash_inheritance: unexpected hash function"); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
275 Py_DECREF(obj); |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
276 return NULL; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
277 } |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
278 |
| 53820 | 279 Py_DECREF(obj); |
|
53810
8f7cf5cb21bb
fix running test_capi with -R ::
Benjamin Peterson <benjamin@python.org>
parents:
52210
diff
changeset
|
280 |
|
50369
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
281 Py_RETURN_NONE; |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
282 } |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
283 |
|
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
284 |
|
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 |
|
50277
10097bd65564
make global static
Benjamin Peterson <benjamin@python.org>
parents:
50276
diff
changeset
|
586 static volatile int x; |
|
50276
8751288ddd96
use a global variable, so the compiler doesn't optimize the assignment out
Benjamin Peterson <benjamin@python.org>
parents:
50264
diff
changeset
|
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 */ |
|
50276
8751288ddd96
use a global variable, so the compiler doesn't optimize the assignment out
Benjamin Peterson <benjamin@python.org>
parents:
50264
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 * |
|
52210
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
633 test_widechar(PyObject *self) |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
634 { |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
635 #if defined(SIZEOF_WCHAR_T) && (SIZEOF_WCHAR_T == 4) |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
636 const wchar_t wtext[2] = {(wchar_t)0x10ABCDu}; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
637 size_t wtextlen = 1; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
638 #else |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
639 const wchar_t wtext[3] = {(wchar_t)0xDBEAu, (wchar_t)0xDFCDu}; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
640 size_t wtextlen = 2; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
641 #endif |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
642 PyObject *wide, *utf8; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
643 |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
644 wide = PyUnicode_FromWideChar(wtext, wtextlen); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
645 if (wide == NULL) |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
646 return NULL; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
647 |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
648 utf8 = PyUnicode_FromString("\xf4\x8a\xaf\x8d"); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
649 if (utf8 == NULL) { |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
650 Py_DECREF(wide); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
651 return NULL; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
652 } |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
653 |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
654 if (PyUnicode_GET_SIZE(wide) != PyUnicode_GET_SIZE(utf8)) { |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
655 Py_DECREF(wide); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
656 Py_DECREF(utf8); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
657 return raiseTestError("test_widechar", |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
658 "wide string and utf8 string have different length"); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
659 } |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
660 if (PyUnicode_Compare(wide, utf8)) { |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
661 Py_DECREF(wide); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
662 Py_DECREF(utf8); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
663 if (PyErr_Occurred()) |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
664 return NULL; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
665 return raiseTestError("test_widechar", |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
666 "wide string and utf8 string are differents"); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
667 } |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
668 |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
669 Py_DECREF(wide); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
670 Py_DECREF(utf8); |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
671 Py_RETURN_NONE; |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
672 } |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
673 |
|
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
674 static PyObject * |
|
50262
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
675 test_empty_argparse(PyObject *self) |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
676 { |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
677 /* Test that formats can begin with '|'. See issue #4720. */ |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
678 PyObject *tuple, *dict = NULL; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
679 static char *kwlist[] = {NULL}; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
680 int result; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
681 tuple = PyTuple_New(0); |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
682 if (!tuple) |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
683 return NULL; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
684 if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0) |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
685 goto done; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
686 dict = PyDict_New(); |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
687 if (!dict) |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
688 goto done; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
689 result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist); |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
690 done: |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
691 Py_DECREF(tuple); |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
692 Py_XDECREF(dict); |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
693 if (result < 0) |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
694 return NULL; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
695 else { |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
696 Py_RETURN_NONE; |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
697 } |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
698 } |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
699 |
|
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
700 static PyObject * |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
701 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
|
702 { |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
703 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
|
704 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
|
705 &encoding, &errors)) |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
706 return NULL; |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
707 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
|
708 } |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
709 |
|
38173
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
710 static PyObject * |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
711 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
|
712 { |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
713 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
|
714 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
|
715 &encoding, &errors)) |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
716 return NULL; |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
717 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
|
718 } |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
719 |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
720 #endif |
|
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
721 |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
722 /* 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
|
723 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
|
724 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
|
725 { |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
726 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
|
727 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
|
728 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
|
729 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
|
730 } 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
|
731 {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
|
732 {-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
|
733 {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
|
734 {-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
|
735 {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
|
736 {-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
|
737 {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
|
738 {-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
|
739 {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
|
740 {-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
|
741 {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
|
742 {-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
|
743 {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
|
744 {-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
|
745 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
|
746 |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
747 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
|
748 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
|
749 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
|
750 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
|
751 |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
752 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
|
753 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
|
754 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
|
755 "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
|
756 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
|
757 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
|
758 "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
|
759 } |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
760 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
|
761 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
|
762 } |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24363
diff
changeset
|
763 |
|
36989
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
764 /* 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
|
765 |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
766 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
|
767 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
|
768 { |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
769 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
|
770 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
|
771 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
|
772 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
|
773 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
|
774 } |
|
aba814aa4c6a
Move test code out of xxmodule and into _testcapimodule.c where it belongs.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36501
diff
changeset
|
775 |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
776 static PyObject * |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
777 raise_exception(PyObject *self, PyObject *args) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
778 { |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
779 PyObject *exc; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
780 PyObject *exc_args, *v; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
781 int num_args, i; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
782 |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
783 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
|
784 &exc, &num_args)) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
785 return NULL; |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
786 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
|
787 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
|
788 return NULL; |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
789 } |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
790 |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
791 exc_args = PyTuple_New(num_args); |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
792 if (exc_args == NULL) |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
793 return NULL; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
794 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
|
795 v = PyInt_FromLong(i); |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
796 if (v == NULL) { |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
797 Py_DECREF(exc_args); |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
798 return NULL; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
799 } |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
800 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
|
801 } |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
802 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
|
803 Py_DECREF(exc_args); |
|
20117
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
804 return NULL; |
|
e026f517f655
Add tests for new PyErr_NormalizeException() behavior
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18835
diff
changeset
|
805 } |
|
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
|
806 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
807 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
808 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
809 /* 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
|
810 * `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
|
811 * 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
|
812 * 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
|
813 * 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
|
814 * 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
|
815 */ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
816 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
|
817 |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
818 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
|
819 _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
|
820 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
821 PyObject *rc; |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
822 int success; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
823 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
|
824 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
|
825 success = (rc != NULL); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
826 Py_XDECREF(rc); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
827 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
|
828 return success; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
829 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
830 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
831 /* 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
|
832 * 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
|
833 */ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
834 static void |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
835 _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
|
836 { |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
837 _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
|
838 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
|
839 } |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
840 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
841 static PyObject * |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
842 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
|
843 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
844 PyObject *fn; |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
845 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
|
846 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
847 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
|
848 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
|
849 |
|
48841
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
850 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
|
851 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
|
852 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
|
853 return NULL; |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
854 } |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
855 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
856 /* 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
|
857 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
|
858 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
|
859 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
|
860 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
|
861 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
|
862 |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
863 /* 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
|
864 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
|
865 /* 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
|
866 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
|
867 /* 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
|
868 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
|
869 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
|
870 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
|
871 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
|
872 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
873 /* 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
|
874 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
|
875 to test <wink> |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
876 */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
877 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
|
878 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
|
879 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
|
880 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
|
881 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
|
882 |
|
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
|
883 /* 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
|
884 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
|
885 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
37077
diff
changeset
|
886 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
|
887 if (!success) |
|
76e71cecc4d3
#3643 add a few more checks to _testcapi to prevent segfaults
Benjamin Peterson <benjamin@python.org>
parents:
47925
diff
changeset
|
888 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
|
889 Py_RETURN_NONE; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
890 } |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
891 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
892 /* test Py_AddPendingCalls using threads */ |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
893 static int _pending_callback(void *arg) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
894 { |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
895 /* we assume the argument is callable object to which we own a reference */ |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
896 PyObject *callable = (PyObject *)arg; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
897 PyObject *r = PyObject_CallObject(callable, NULL); |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
898 Py_DECREF(callable); |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
899 Py_XDECREF(r); |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
900 return r != NULL ? 0 : -1; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
901 } |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
902 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
903 /* The following requests n callbacks to _pending_callback. It can be |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
904 * run from any python thread. |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
905 */ |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
906 PyObject *pending_threadfunc(PyObject *self, PyObject *arg) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
907 { |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
908 PyObject *callable; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
909 int r; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
910 if (PyArg_ParseTuple(arg, "O", &callable) == 0) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
911 return NULL; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
912 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
913 /* create the reference for the callbackwhile we hold the lock */ |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
914 Py_INCREF(callable); |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
915 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
916 Py_BEGIN_ALLOW_THREADS |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
917 r = Py_AddPendingCall(&_pending_callback, callable); |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
918 Py_END_ALLOW_THREADS |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
919 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
920 if (r<0) { |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
921 Py_DECREF(callable); /* unsuccessful add, destroy the extra reference */ |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
922 Py_INCREF(Py_False); |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
923 return Py_False; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
924 } |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
925 Py_INCREF(Py_True); |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
926 return Py_True; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
927 } |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
928 #endif |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
929 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
930 /* 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
|
931 static PyObject * |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
932 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
|
933 { |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
934 PyObject *result; |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
935 char *msg; |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
936 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
937 #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
|
938 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
|
939 if (result == NULL) \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
940 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
|
941 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
|
942 msg = FORMAT " failed at 1"; \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
943 goto Fail; \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
944 } \ |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
945 Py_DECREF(result) |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
946 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
947 CHECK_1_FORMAT("%d", int); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
948 CHECK_1_FORMAT("%ld", long); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
949 /* 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
|
950 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
|
951 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
952 /* 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
|
953 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
|
954 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
|
955 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
|
956 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
957 Py_RETURN_NONE; |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
958 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
959 Fail: |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
960 Py_XDECREF(result); |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
961 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
|
962 |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
963 #undef CHECK_1_FORMAT |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
964 } |
|
380dad395599
Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
Tim Peters <tim.peters@gmail.com>
parents:
37822
diff
changeset
|
965 |
|
39371
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
966 /* 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
|
967 static PyObject * |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
968 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
|
969 { |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
970 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
|
971 } |
|
a9c742d6c888
Change fix for segfaulting property(), add a NEWS entry and a test.
Georg Brandl <georg@python.org>
parents:
39189
diff
changeset
|
972 |
|
46589
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
973 /* 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
|
974 static PyObject * |
|
46592
4e47548edd36
Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents:
46589
diff
changeset
|
975 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
|
976 { |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
977 PyObject *file; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
978 PyObject *traceback; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
979 int result; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
980 |
|
46592
4e47548edd36
Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents:
46589
diff
changeset
|
981 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
|
982 &traceback, &file)) |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
983 return NULL; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
984 |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
985 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
|
986 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
|
987 return NULL; |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
988 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
|
989 } |
|
07a4e1710262
Fix a bug introduced by the warnings rewrite where tracebacks were being
Brett Cannon <bcannon@gmail.com>
parents:
45537
diff
changeset
|
990 |
| 53930 | 991 /* To test that the result of PyCode_NewEmpty has the right members. */ |
| 992 static PyObject * | |
| 993 code_newempty(PyObject *self, PyObject *args) | |
| 994 { | |
| 995 const char *filename; | |
| 996 const char *funcname; | |
| 997 int firstlineno; | |
| 998 | |
| 999 if (!PyArg_ParseTuple(args, "ssi:code_newempty", | |
| 1000 &filename, &funcname, &firstlineno)) | |
| 1001 return NULL; | |
| 1002 | |
| 1003 return (PyObject *)PyCode_NewEmpty(filename, funcname, firstlineno); | |
| 1004 } | |
| 1005 | |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1006 static PyMethodDef TestMethods[] = { |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1007 {"raise_exception", raise_exception, METH_VARARGS}, |
|
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1008 {"test_config", (PyCFunction)test_config, METH_NOARGS}, |
|
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1009 {"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
|
1010 {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, |
|
50369
7aaef4d5f880
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
Nick Coghlan <ncoghlan@gmail.com>
parents:
50277
diff
changeset
|
1011 {"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
|
1012 {"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
|
1013 {"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
|
1014 {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS}, |
|
50262
bd3c5de4cc54
fix #4720: the format to PyArg_ParseTupleAndKeywords can now start with '|'
Benjamin Peterson <benjamin@python.org>
parents:
49502
diff
changeset
|
1015 {"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
|
1016 {"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
|
1017 {"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
|
1018 {"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
|
1019 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
|
1020 |
|
39189
17d5671fffcc
Part of bug #1523610: fix miscalculation of buffer length.
Georg Brandl <georg@python.org>
parents:
38175
diff
changeset
|
1021 {"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
|
1022 {"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
|
1023 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
|
1024 {"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
|
1025 {"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
|
1026 {"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
|
1027 {"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
|
1028 {"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
|
1029 {"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
|
1030 {"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
|
1031 {"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
|
1032 #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
|
1033 {"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
|
1034 {"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
|
1035 {"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
|
1036 {"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
|
1037 {"codec_incrementalencoder", |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
1038 (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
|
1039 {"codec_incrementaldecoder", |
|
38400b662404
Add tests for the C APIs PyCodec_IncrementalEncoder() and
Walter Dörwald <walter@livinglogic.de>
parents:
36989
diff
changeset
|
1040 (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
|
1041 #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
|
1042 #ifdef Py_USING_UNICODE |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1043 {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS}, |
|
52210
c73dd25c01c1
Issue 4474: On platforms with sizeof(wchar_t) == 4 and
Mark Dickinson <dickinsm@gmail.com>
parents:
50675
diff
changeset
|
1044 {"test_widechar", (PyCFunction)test_widechar, METH_NOARGS}, |
|
21667
0d3bb68e3a28
Fixed "u#" parser marker to pass through Unicode objects as-is without
Marc-André Lemburg <mal@egenix.com>
parents:
21073
diff
changeset
|
1045 #endif |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1046 #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
|
1047 {"_test_thread_state", test_thread_state, METH_VARARGS}, |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50396
diff
changeset
|
1048 {"_pending_threadfunc", pending_threadfunc, METH_VARARGS}, |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28652
diff
changeset
|
1049 #endif |
|
46592
4e47548edd36
Rename the test_traceback_print() function to traceback_print() to prevent
Brett Cannon <bcannon@gmail.com>
parents:
46589
diff
changeset
|
1050 {"traceback_print", traceback_print, METH_VARARGS}, |
| 53930 | 1051 {"code_newempty", code_newempty, METH_VARARGS}, |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1052 {NULL, NULL} /* sentinel */ |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1053 }; |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1054 |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
1055 #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
|
1056 |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1057 typedef struct { |
|
44863
eb4b50f739f6
Patch #1720595: add T_BOOL to the range of structmember types.
Georg Brandl <georg@python.org>
parents:
44350
diff
changeset
|
1058 char bool_member; |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1059 char byte_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1060 unsigned char ubyte_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1061 short short_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1062 unsigned short ushort_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1063 int int_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1064 unsigned int uint_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1065 long long_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1066 unsigned long ulong_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1067 float float_member; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1068 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
|
1069 #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
|
1070 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
|
1071 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
|
1072 #endif |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1073 } all_structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1074 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1075 typedef struct { |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1076 PyObject_HEAD |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1077 all_structmembers structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1078 } test_structmembers; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1079 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1080 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
|
1081 {"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
|
1082 {"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
|
1083 {"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
|
1084 {"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
|
1085 {"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
|
1086 {"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
|
1087 {"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
|
1088 {"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
|
1089 {"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
|
1090 {"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
|
1091 {"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
|
1092 #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
|
1093 {"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
|
1094 {"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
|
1095 #endif |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1096 {NULL} |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1097 }; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1098 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1099 |
| 44864 | 1100 static PyObject * |
| 1101 test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | |
| 1102 { | |
| 1103 static char *keywords[] = { | |
| 1104 "T_BOOL", "T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", | |
| 1105 "T_INT", "T_UINT", "T_LONG", "T_ULONG", | |
| 1106 "T_FLOAT", "T_DOUBLE", | |
| 1107 #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
|
1108 "T_LONGLONG", "T_ULONGLONG", |
| 44864 | 1109 #endif |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1110 NULL}; |
| 44864 | 1111 static char *fmt = "|bbBhHiIlkfd" |
| 1112 #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
|
1113 "LK" |
| 44864 | 1114 #endif |
|
42007
e8413971212d
Patch #1733960: Allow T_LONGLONG to accept ints.
Martin v. Löwis <martin@v.loewis.de>
parents:
40226
diff
changeset
|
1115 ; |
| 44864 | 1116 test_structmembers *ob; |
| 1117 ob = PyObject_New(test_structmembers, type); | |
| 1118 if (ob == NULL) | |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1119 return NULL; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1120 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
|
1121 if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, |
| 44864 | 1122 &ob->structmembers.bool_member, |
| 1123 &ob->structmembers.byte_member, | |
| 1124 &ob->structmembers.ubyte_member, | |
| 1125 &ob->structmembers.short_member, | |
| 1126 &ob->structmembers.ushort_member, | |
| 1127 &ob->structmembers.int_member, | |
| 1128 &ob->structmembers.uint_member, | |
| 1129 &ob->structmembers.long_member, | |
| 1130 &ob->structmembers.ulong_member, | |
| 1131 &ob->structmembers.float_member, | |
| 1132 &ob->structmembers.double_member | |
| 1133 #ifdef HAVE_LONG_LONG | |
| 1134 , &ob->structmembers.longlong_member, | |
| 1135 &ob->structmembers.ulonglong_member | |
| 1136 #endif | |
| 1137 )) { | |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1138 Py_DECREF(ob); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1139 return NULL; |
| 44864 | 1140 } |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1141 return (PyObject *)ob; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1142 } |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1143 |
| 44864 | 1144 static void |
| 1145 test_structmembers_free(PyObject *ob) | |
| 1146 { | |
|
40176
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1147 PyObject_FREE(ob); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1148 } |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1149 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1150 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
|
1151 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
|
1152 "test_structmembersType", |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1153 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
|
1154 0, /* tp_itemsize */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1155 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
|
1156 0, /* tp_print */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1157 0, /* tp_getattr */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1158 0, /* tp_setattr */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1159 0, /* tp_compare */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1160 0, /* tp_repr */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1161 0, /* tp_as_number */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1162 0, /* tp_as_sequence */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1163 0, /* tp_as_mapping */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1164 0, /* tp_hash */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1165 0, /* tp_call */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1166 0, /* tp_str */ |
| 44864 | 1167 PyObject_GenericGetAttr, /* tp_getattro */ |
| 1168 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
|
1169 0, /* tp_as_buffer */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1170 0, /* tp_flags */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1171 "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
|
1172 0, /* traverseproc tp_traverse */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1173 0, /* tp_clear */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1174 0, /* tp_richcompare */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1175 0, /* tp_weaklistoffset */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1176 0, /* tp_iter */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1177 0, /* tp_iternext */ |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1178 0, /* tp_methods */ |
| 44864 | 1179 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
|
1180 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1181 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1182 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1183 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1184 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1185 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1186 0, |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1187 0, |
| 44864 | 1188 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
|
1189 }; |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1190 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1191 |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
22726
diff
changeset
|
1192 PyMODINIT_FUNC |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1193 init_testcapi(void) |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1194 { |
|
22726
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1195 PyObject *m; |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1196 |
|
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1197 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
|
1198 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
30158
diff
changeset
|
1199 return; |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1200 |
|
50394
9c2ac78666d4
Fixed compile error on windows.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
50369
diff
changeset
|
1201 Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type; |
|
50396
1c5d942128b6
Just inserted blank line.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
50394
diff
changeset
|
1202 |
|
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
|
1203 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
|
1204 Py_INCREF(&test_structmembersType); |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1205 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
|
1206 |
|
0c1cb92dac97
Patch #1549049: Rewrite type conversion in structmember.
Martin v. Löwis <martin@v.loewis.de>
parents:
39371
diff
changeset
|
1207 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
|
1208 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
|
1209 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
|
1210 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
|
1211 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
|
1212 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
|
1213 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
|
1214 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
|
1215 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
|
1216 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
|
1217 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
|
1218 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
|
1219 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
|
1220 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
|
1221 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
|
1222 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
|
1223 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
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1230 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
|
1231 Py_INCREF(TestError); |
|
c84110f05dc3
Switch to using METH_NOARGS where possible.
Fred Drake <fdrake@acm.org>
parents:
21667
diff
changeset
|
1232 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
|
1233 } |
