Mercurial > cpython-lru_cache-weakref
annotate Modules/threadmodule.c @ 45222:cdd2ea080e23 2.5
Backport LaTex version of r60651:
Fix documentation for Calendar.iterweekdays(): firstweekday is a property.
Fixes second part of #2018.
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Thu, 07 Feb 2008 19:55:47 +0000 |
| parents | a1863833c4e6 |
| children | e8bee3097d44 6620a510e9a9 |
| rev | line source |
|---|---|
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Thread module */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 /* Interface to Sjoerd's portable C thread library */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
| 4751 | 5 #include "Python.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
7 #ifndef WITH_THREAD |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
8 #error "Error! The rest of Python is not compiled with thread support." |
|
25127
5165a0ee84c6
--with(out)-thread is deprecated according to configure --help
Neal Norwitz <nnorwitz@gmail.com>
parents:
24471
diff
changeset
|
9 #error "Rerun configure, adding a --with-threads option." |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
10 #error "Then run `make clean' followed by `make'." |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
11 #endif |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
12 |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
13 #include "pythread.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
| 4751 | 15 static PyObject *ThreadError; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 /* Lock objects */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 typedef struct { |
| 4751 | 21 PyObject_HEAD |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
22 PyThread_type_lock lock_lock; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 } lockobject; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 static void |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
26 lock_dealloc(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 { |
| 40230 | 28 assert(self->lock_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 /* Unlock the lock so it's safe to free it */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
30 PyThread_acquire_lock(self->lock_lock, 0); |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
31 PyThread_release_lock(self->lock_lock); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
33 PyThread_free_lock(self->lock_lock); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
34 PyObject_Del(self); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
| 4751 | 37 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
38 lock_PyThread_acquire_lock(lockobject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 { |
| 22709 | 40 int i = 1; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 |
| 22709 | 42 if (!PyArg_ParseTuple(args, "|i:acquire", &i)) |
| 43 return NULL; | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 |
| 4751 | 45 Py_BEGIN_ALLOW_THREADS |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
46 i = PyThread_acquire_lock(self->lock_lock, i); |
| 4751 | 47 Py_END_ALLOW_THREADS |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
34998
25a0e1faa8a5
Delete some vestigial code; execution will never reach the 'if' statement if args is NULL
Andrew M. Kuchling <amk@amk.ca>
parents:
34619
diff
changeset
|
49 return PyBool_FromLong((long)i); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
52 PyDoc_STRVAR(acquire_doc, |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
53 "acquire([wait]) -> None or bool\n\ |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
54 (acquire_lock() is an obsolete synonym)\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
55 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
56 Lock the lock. Without argument, this blocks if the lock is already\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
57 locked (even by the same thread), waiting for another thread to release\n\ |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
58 the lock, and return None once the lock is acquired.\n\ |
|
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
59 With an argument, this will only block if the argument is true,\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
60 and the return value reflects whether the lock is acquired.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
61 The blocking operation is not interruptible."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
62 |
| 4751 | 63 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
64 lock_PyThread_release_lock(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 /* Sanity check: the lock must be locked */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
67 if (PyThread_acquire_lock(self->lock_lock, 0)) { |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
68 PyThread_release_lock(self->lock_lock); |
| 4751 | 69 PyErr_SetString(ThreadError, "release unlocked lock"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 return NULL; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
73 PyThread_release_lock(self->lock_lock); |
| 4751 | 74 Py_INCREF(Py_None); |
| 75 return Py_None; | |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
78 PyDoc_STRVAR(release_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
79 "release()\n\ |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
80 (release_lock() is an obsolete synonym)\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
81 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
82 Release the lock, allowing another thread that is blocked waiting for\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
83 the lock to acquire the lock. The lock must be in the locked state,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
84 but it needn't be locked by the same thread that unlocks it."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
85 |
| 4751 | 86 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
87 lock_locked_lock(lockobject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
89 if (PyThread_acquire_lock(self->lock_lock, 0)) { |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
90 PyThread_release_lock(self->lock_lock); |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
91 return PyBool_FromLong(0L); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 } |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
93 return PyBool_FromLong(1L); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
96 PyDoc_STRVAR(locked_doc, |
|
22865
7014921820a5
Lock methods acquire() and locked() now return bools.
Guido van Rossum <guido@python.org>
parents:
22709
diff
changeset
|
97 "locked() -> bool\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
98 (locked_lock() is an obsolete synonym)\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
99 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
100 Return whether the lock is in the locked state."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
101 |
| 4751 | 102 static PyMethodDef lock_methods[] = { |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
103 {"acquire_lock", (PyCFunction)lock_PyThread_acquire_lock, |
| 22709 | 104 METH_VARARGS, acquire_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
105 {"acquire", (PyCFunction)lock_PyThread_acquire_lock, |
| 22709 | 106 METH_VARARGS, acquire_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
107 {"release_lock", (PyCFunction)lock_PyThread_release_lock, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
108 METH_NOARGS, release_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
109 {"release", (PyCFunction)lock_PyThread_release_lock, |
|
22562
303b6ad13a32
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22561
diff
changeset
|
110 METH_NOARGS, release_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
111 {"locked_lock", (PyCFunction)lock_locked_lock, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
112 METH_NOARGS, locked_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
113 {"locked", (PyCFunction)lock_locked_lock, |
|
22562
303b6ad13a32
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22561
diff
changeset
|
114 METH_NOARGS, locked_doc}, |
|
36737
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36324
diff
changeset
|
115 {"__enter__", (PyCFunction)lock_PyThread_acquire_lock, |
|
fa92fe15251a
Updates to the with-statement:
Guido van Rossum <guido@python.org>
parents:
36324
diff
changeset
|
116 METH_VARARGS, acquire_doc}, |
|
36926
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
117 {"__exit__", (PyCFunction)lock_PyThread_release_lock, |
|
fc10ff322df1
Um, I thought I'd already checked this in.
Guido van Rossum <guido@python.org>
parents:
36895
diff
changeset
|
118 METH_VARARGS, release_doc}, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
119 {NULL, NULL} /* sentinel */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 |
| 4751 | 122 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
123 lock_getattr(lockobject *self, char *name) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 { |
| 4751 | 125 return Py_FindMethod(lock_methods, (PyObject *)self, name); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
| 4751 | 128 static PyTypeObject Locktype = { |
| 129 PyObject_HEAD_INIT(&PyType_Type) | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
130 0, /*ob_size*/ |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
20468
diff
changeset
|
131 "thread.lock", /*tp_name*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
132 sizeof(lockobject), /*tp_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
133 0, /*tp_itemsize*/ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 /* methods */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
135 (destructor)lock_dealloc, /*tp_dealloc*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
136 0, /*tp_print*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
137 (getattrfunc)lock_getattr, /*tp_getattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
138 0, /*tp_setattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
139 0, /*tp_compare*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
140 0, /*tp_repr*/ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
143 static lockobject * |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
144 newlockobject(void) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
145 { |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
146 lockobject *self; |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
147 self = PyObject_New(lockobject, &Locktype); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
148 if (self == NULL) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
149 return NULL; |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
150 self->lock_lock = PyThread_allocate_lock(); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
151 if (self->lock_lock == NULL) { |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
152 PyObject_Del(self); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
153 self = NULL; |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
154 PyErr_SetString(ThreadError, "can't allocate lock"); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
155 } |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
156 return self; |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
157 } |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
158 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
159 /* Thread-local objects */ |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
160 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
161 #include "structmember.h" |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
162 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
163 typedef struct { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
164 PyObject_HEAD |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
165 PyObject *key; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
166 PyObject *args; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
167 PyObject *kw; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
168 PyObject *dict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
169 } localobject; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
170 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
171 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
172 local_new(PyTypeObject *type, PyObject *args, PyObject *kw) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
173 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
174 localobject *self; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
175 PyObject *tdict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
176 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
177 if (type->tp_init == PyBaseObject_Type.tp_init |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
178 && ((args && PyObject_IsTrue(args)) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
179 || (kw && PyObject_IsTrue(kw)))) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
180 PyErr_SetString(PyExc_TypeError, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
181 "Initialization arguments are not supported"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
182 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
183 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
184 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
185 self = (localobject *)type->tp_alloc(type, 0); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
186 if (self == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
187 return NULL; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
188 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
189 Py_XINCREF(args); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
190 self->args = args; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
191 Py_XINCREF(kw); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
192 self->kw = kw; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
193 self->dict = NULL; /* making sure */ |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
194 self->key = PyString_FromFormat("thread.local.%p", self); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
195 if (self->key == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
196 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
197 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
198 self->dict = PyDict_New(); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
199 if (self->dict == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
200 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
201 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
202 tdict = PyThreadState_GetDict(); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
203 if (tdict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
204 PyErr_SetString(PyExc_SystemError, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
205 "Couldn't get thread-state dictionary"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
206 goto err; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
207 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
208 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
209 if (PyDict_SetItem(tdict, self->key, self->dict) < 0) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
210 goto err; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
211 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
212 return (PyObject *)self; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
213 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
214 err: |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
215 Py_DECREF(self); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
216 return NULL; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
217 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
218 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
219 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
220 local_traverse(localobject *self, visitproc visit, void *arg) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
221 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
222 Py_VISIT(self->args); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
223 Py_VISIT(self->kw); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
224 Py_VISIT(self->dict); |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
225 return 0; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
226 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
227 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
228 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
229 local_clear(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
230 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
231 Py_CLEAR(self->key); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
232 Py_CLEAR(self->args); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
233 Py_CLEAR(self->kw); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
234 Py_CLEAR(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
235 return 0; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
236 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
237 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
238 static void |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
239 local_dealloc(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
240 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
241 PyThreadState *tstate; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
242 if (self->key |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
243 && (tstate = PyThreadState_Get()) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
244 && tstate->interp) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
245 for(tstate = PyInterpreterState_ThreadHead(tstate->interp); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
246 tstate; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
247 tstate = PyThreadState_Next(tstate)) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
248 if (tstate->dict && |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
249 PyDict_GetItem(tstate->dict, self->key)) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
250 PyDict_DelItem(tstate->dict, self->key); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
251 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
252 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
253 local_clear(self); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
254 self->ob_type->tp_free((PyObject*)self); |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
255 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
256 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
257 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
258 _ldict(localobject *self) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
259 { |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
260 PyObject *tdict, *ldict; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
261 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
262 tdict = PyThreadState_GetDict(); |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
263 if (tdict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
264 PyErr_SetString(PyExc_SystemError, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
265 "Couldn't get thread-state dictionary"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
266 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
267 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
268 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
269 ldict = PyDict_GetItem(tdict, self->key); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
270 if (ldict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
271 ldict = PyDict_New(); /* we own ldict */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
272 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
273 if (ldict == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
274 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
275 else { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
276 int i = PyDict_SetItem(tdict, self->key, ldict); |
| 36895 | 277 Py_DECREF(ldict); /* now ldict is borrowed */ |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
278 if (i < 0) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
279 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
280 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
281 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
282 Py_CLEAR(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
283 Py_INCREF(ldict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
284 self->dict = ldict; /* still borrowed */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
285 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
286 if (self->ob_type->tp_init != PyBaseObject_Type.tp_init && |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
287 self->ob_type->tp_init((PyObject*)self, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
288 self->args, self->kw) < 0) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
289 /* we need to get rid of ldict from thread so |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
290 we create a new one the next time we do an attr |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
291 acces */ |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
292 PyDict_DelItem(tdict, self->key); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
293 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
294 } |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
295 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
296 } |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
297 else if (self->dict != ldict) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
298 Py_CLEAR(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
299 Py_INCREF(ldict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
300 self->dict = ldict; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
301 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
302 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
303 return ldict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
304 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
305 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
306 static int |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
307 local_setattro(localobject *self, PyObject *name, PyObject *v) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
308 { |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
309 PyObject *ldict; |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
310 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
311 ldict = _ldict(self); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
312 if (ldict == NULL) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
313 return -1; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
314 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
315 return PyObject_GenericSetAttr((PyObject *)self, name, v); |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
316 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
317 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
318 static PyObject * |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
319 local_getdict(localobject *self, void *closure) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
320 { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
321 if (self->dict == NULL) { |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
322 PyErr_SetString(PyExc_AttributeError, "__dict__"); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
323 return NULL; |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
324 } |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
325 |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
326 Py_INCREF(self->dict); |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
327 return self->dict; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
328 } |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
329 |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
330 static PyGetSetDef local_getset[] = { |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
331 {"__dict__", (getter)local_getdict, (setter)NULL, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
332 "Local-data dictionary", NULL}, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
333 {NULL} /* Sentinel */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
334 }; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
335 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
336 static PyObject *local_getattro(localobject *, PyObject *); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
337 |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
338 static PyTypeObject localtype = { |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
339 PyObject_HEAD_INIT(NULL) |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
340 /* ob_size */ 0, |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
341 /* tp_name */ "thread._local", |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
342 /* tp_basicsize */ sizeof(localobject), |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
343 /* tp_itemsize */ 0, |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
344 /* tp_dealloc */ (destructor)local_dealloc, |
|
37305
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
345 /* tp_print */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
346 /* tp_getattr */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
347 /* tp_setattr */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
348 /* tp_compare */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
349 /* tp_repr */ 0, |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
350 /* tp_as_number */ 0, |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
351 /* tp_as_sequence */ 0, |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
352 /* tp_as_mapping */ 0, |
|
37305
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
353 /* tp_hash */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
354 /* tp_call */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
355 /* tp_str */ 0, |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
356 /* tp_getattro */ (getattrofunc)local_getattro, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
357 /* tp_setattro */ (setattrofunc)local_setattro, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
358 /* tp_as_buffer */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
359 /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
360 /* tp_doc */ "Thread-local data", |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
361 /* tp_traverse */ (traverseproc)local_traverse, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
362 /* tp_clear */ (inquiry)local_clear, |
|
37305
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
363 /* tp_richcompare */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
364 /* tp_weaklistoffset */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
365 /* tp_iter */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
366 /* tp_iternext */ 0, |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
367 /* tp_methods */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
368 /* tp_members */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
369 /* tp_getset */ local_getset, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
370 /* tp_base */ 0, |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
371 /* tp_dict */ 0, /* internal use */ |
|
37305
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
372 /* tp_descr_get */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
373 /* tp_descr_set */ 0, |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
374 /* tp_dictoffset */ offsetof(localobject, dict), |
|
37305
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
375 /* tp_init */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
376 /* tp_alloc */ 0, |
|
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
377 /* tp_new */ local_new, |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
378 /* tp_free */ 0, /* Low-level free-mem routine */ |
|
37305
5e1b6f553763
Remove unnecessary casts from type object initializers.
Georg Brandl <georg@python.org>
parents:
36926
diff
changeset
|
379 /* tp_is_gc */ 0, /* For PyObject_IS_GC */ |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
380 }; |
|
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
381 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
382 static PyObject * |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
383 local_getattro(localobject *self, PyObject *name) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
384 { |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
385 PyObject *ldict, *value; |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
386 |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
387 ldict = _ldict(self); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
388 if (ldict == NULL) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
389 return NULL; |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
390 |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
391 if (self->ob_type != &localtype) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
392 /* use generic lookup for subtypes */ |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
393 return PyObject_GenericGetAttr((PyObject *)self, name); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
394 |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
395 /* Optimization: just look in dict ourselves */ |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
396 value = PyDict_GetItem(ldict, name); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
397 if (value == NULL) |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
398 /* Fall back on generic to get __class__ and __dict__ */ |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
399 return PyObject_GenericGetAttr((PyObject *)self, name); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
400 |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
401 Py_INCREF(value); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
402 return value; |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
403 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 /* Module functions */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
407 struct bootstate { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
408 PyInterpreterState *interp; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
409 PyObject *func; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
410 PyObject *args; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
411 PyObject *keyw; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
412 }; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
414 static void |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
415 t_bootstrap(void *boot_raw) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
416 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
417 struct bootstate *boot = (struct bootstate *) boot_raw; |
| 35117 | 418 PyThreadState *tstate; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
419 PyObject *res; |
|
961
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
420 |
| 35117 | 421 tstate = PyThreadState_New(boot->interp); |
| 422 | |
| 423 PyEval_AcquireThread(tstate); | |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
424 res = PyEval_CallObjectWithKeywords( |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
425 boot->func, boot->args, boot->keyw); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 if (res == NULL) { |
|
8433
7cdff8aa8318
t_bootstrap(): Use PyErr_ExceptionMatches(...) instead of PyErr_Occurred(...).
Fred Drake <fdrake@acm.org>
parents:
7211
diff
changeset
|
427 if (PyErr_ExceptionMatches(PyExc_SystemExit)) |
| 4751 | 428 PyErr_Clear(); |
|
2568
2c61786327cf
implement exit_thread through SystemExit exception
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
429 else { |
|
28889
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
430 PyObject *file; |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
431 PySys_WriteStderr( |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
432 "Unhandled exception in thread started by "); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
433 file = PySys_GetObject("stderr"); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
434 if (file) |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
435 PyFile_WriteObject(boot->func, file, 0); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
436 else |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
437 PyObject_Print(boot->func, stderr, 0); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
438 PySys_WriteStderr("\n"); |
|
7211
c764217ae6eb
Don't store the exception info from an unhandled exception in a thread
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
439 PyErr_PrintEx(0); |
|
2568
2c61786327cf
implement exit_thread through SystemExit exception
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
440 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 } |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
442 else |
| 4751 | 443 Py_DECREF(res); |
|
28889
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
444 Py_DECREF(boot->func); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
445 Py_DECREF(boot->args); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
446 Py_XDECREF(boot->keyw); |
|
96b6cc5d408b
When an unhandled exception happens, report the repr() of the function
Guido van Rossum <guido@python.org>
parents:
25127
diff
changeset
|
447 PyMem_DEL(boot_raw); |
| 35117 | 448 PyThreadState_Clear(tstate); |
| 449 PyThreadState_DeleteCurrent(); | |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8567
diff
changeset
|
450 PyThread_exit_thread(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 |
| 4751 | 453 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
454 thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 { |
|
14363
5da406ebef55
The second argument to start_new_thread() is not a tuple, as pointed
Guido van Rossum <guido@python.org>
parents:
13820
diff
changeset
|
456 PyObject *func, *args, *keyw = NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
457 struct bootstate *boot; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
458 long ident; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38084
diff
changeset
|
460 if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38084
diff
changeset
|
461 &func, &args, &keyw)) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 return NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
463 if (!PyCallable_Check(func)) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
464 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
465 "first arg must be callable"); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
466 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
467 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
468 if (!PyTuple_Check(args)) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
469 PyErr_SetString(PyExc_TypeError, |
|
14363
5da406ebef55
The second argument to start_new_thread() is not a tuple, as pointed
Guido van Rossum <guido@python.org>
parents:
13820
diff
changeset
|
470 "2nd arg must be a tuple"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 return NULL; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 } |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
473 if (keyw != NULL && !PyDict_Check(keyw)) { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
474 PyErr_SetString(PyExc_TypeError, |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
475 "optional 3rd arg must be a dictionary"); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
476 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
477 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
478 boot = PyMem_NEW(struct bootstate, 1); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
479 if (boot == NULL) |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
480 return PyErr_NoMemory(); |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
29498
diff
changeset
|
481 boot->interp = PyThreadState_GET()->interp; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
482 boot->func = func; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
483 boot->args = args; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
484 boot->keyw = keyw; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
485 Py_INCREF(func); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
486 Py_INCREF(args); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
487 Py_XINCREF(keyw); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
488 PyEval_InitThreads(); /* Start the interpreter's thread-awareness */ |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
489 ident = PyThread_start_new_thread(t_bootstrap, (void*) boot); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
490 if (ident == -1) { |
|
34619
0dd146fed9dd
The error message "can't start new thread" should not end in a
Guido van Rossum <guido@python.org>
parents:
33254
diff
changeset
|
491 PyErr_SetString(ThreadError, "can't start new thread"); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
492 Py_DECREF(func); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
493 Py_DECREF(args); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
494 Py_XDECREF(keyw); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
495 PyMem_DEL(boot); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
496 return NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
4944
diff
changeset
|
497 } |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
498 return PyInt_FromLong(ident); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
501 PyDoc_STRVAR(start_new_doc, |
| 20266 | 502 "start_new_thread(function, args[, kwargs])\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
503 (start_new() is an obsolete synonym)\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
504 \n\ |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
505 Start a new thread and return its identifier. The thread will call the\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
506 function with positional arguments from the tuple args and keyword arguments\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
507 taken from the optional dictionary kwargs. The thread exits when the\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
508 function returns; the return value is ignored. The thread will also exit\n\ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20266
diff
changeset
|
509 when the function raises an unhandled exception; a stack trace will be\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
510 printed unless the exception is SystemExit.\n"); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
511 |
| 4751 | 512 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
513 thread_PyThread_exit_thread(PyObject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
514 { |
| 4751 | 515 PyErr_SetNone(PyExc_SystemExit); |
|
2568
2c61786327cf
implement exit_thread through SystemExit exception
Guido van Rossum <guido@python.org>
parents:
2123
diff
changeset
|
516 return NULL; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
518 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
519 PyDoc_STRVAR(exit_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
520 "exit()\n\ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
521 (PyThread_exit_thread() is an obsolete synonym)\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
522 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
523 This is synonymous to ``raise SystemExit''. It will cause the current\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
524 thread to exit silently unless the exception is caught."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
525 |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
526 static PyObject * |
| 29498 | 527 thread_PyThread_interrupt_main(PyObject * self) |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
528 { |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
529 PyErr_SetInterrupt(); |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
530 Py_INCREF(Py_None); |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
531 return Py_None; |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
532 } |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
533 |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
534 PyDoc_STRVAR(interrupt_doc, |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
535 "interrupt_main()\n\ |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
536 \n\ |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
537 Raise a KeyboardInterrupt in the main thread.\n\ |
| 29498 | 538 A subthread can use this function to interrupt the main thread." |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
539 ); |
|
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
540 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
541 #ifndef NO_EXIT_PROG |
| 4751 | 542 static PyObject * |
|
13497
95454b73ea91
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
543 thread_PyThread_exit_prog(PyObject *self, PyObject *args) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
544 { |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 int sts; |
| 22709 | 546 if (!PyArg_ParseTuple(args, "i:exit_prog", &sts)) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
547 return NULL; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
548 Py_Exit(sts); /* Calls PyThread_exit_prog(sts) or _PyThread_exit_prog(sts) */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
549 for (;;) { } /* Should not be reached */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
550 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
551 #endif |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
552 |
|
37616
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
553 static lockobject *newlockobject(void); |
|
1e9d7e66c1bc
remove forward declarations, move constructor functions. makes code C++ safe.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37305
diff
changeset
|
554 |
| 4751 | 555 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
556 thread_PyThread_allocate_lock(PyObject *self) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
557 { |
| 4751 | 558 return (PyObject *) newlockobject(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
559 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
560 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
561 PyDoc_STRVAR(allocate_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
562 "allocate_lock() -> lock object\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
563 (allocate() is an obsolete synonym)\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
564 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
565 Create a new lock object. See LockType.__doc__ for information about locks."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
566 |
| 4751 | 567 static PyObject * |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
568 thread_get_ident(PyObject *self) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
569 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
570 long ident; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
571 ident = PyThread_get_thread_ident(); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
572 if (ident == -1) { |
| 4751 | 573 PyErr_SetString(ThreadError, "no current thread ident"); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
574 return NULL; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
575 } |
| 4751 | 576 return PyInt_FromLong(ident); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
577 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
578 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
579 PyDoc_STRVAR(get_ident_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
580 "get_ident() -> integer\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
581 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
582 Return a non-zero integer that uniquely identifies the current thread\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
583 amongst other threads that exist simultaneously.\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
584 This may be used to identify per-thread resources.\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
585 Even though on some platforms threads identities may appear to be\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
586 allocated consecutive numbers starting at 1, this behavior should not\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
587 be relied upon, and the number should be seen purely as a magic cookie.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
588 A thread's identity may be reused for another thread after it exits."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
589 |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
590 static PyObject * |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
591 thread_stack_size(PyObject *self, PyObject *args) |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
592 { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
593 size_t old_size; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
594 Py_ssize_t new_size = 0; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
595 int rc; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
596 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
597 if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size)) |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
598 return NULL; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
599 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
600 if (new_size < 0) { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
601 PyErr_SetString(PyExc_ValueError, |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
602 "size must be 0 or a positive value"); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
603 return NULL; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
604 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
605 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
606 old_size = PyThread_get_stacksize(); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
607 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
608 rc = PyThread_set_stacksize((size_t) new_size); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
609 if (rc == -1) { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
610 PyErr_Format(PyExc_ValueError, |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
611 "size not valid: %zd bytes", |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
612 new_size); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
613 return NULL; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
614 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
615 if (rc == -2) { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
616 PyErr_SetString(ThreadError, |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
617 "setting stack size not supported"); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
618 return NULL; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
619 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
620 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
621 return PyInt_FromSsize_t((Py_ssize_t) old_size); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
622 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
623 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
624 PyDoc_STRVAR(stack_size_doc, |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
625 "stack_size([size]) -> size\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
626 \n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
627 Return the thread stack size used when creating new threads. The\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
628 optional size argument specifies the stack size (in bytes) to be used\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
629 for subsequently created threads, and must be 0 (use platform or\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
630 configured default) or a positive integer value of at least 32,768 (32k).\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
631 If changing the thread stack size is unsupported, a ThreadError\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
632 exception is raised. If the specified size is invalid, a ValueError\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
633 exception is raised, and the stack size is unmodified. 32k bytes\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
634 currently the minimum supported stack size value to guarantee\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
635 sufficient stack space for the interpreter itself.\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
636 \n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
637 Note that some platforms may have particular restrictions on values for\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
638 the stack size, such as requiring a minimum stack size larger than 32kB or\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
639 requiring allocation in multiples of the system memory page size\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
640 - platform documentation should be referred to for more information\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
641 (4kB pages are common; using multiples of 4096 for the stack size is\n\ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
642 the suggested approach in the absence of more specific information)."); |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
643 |
| 4751 | 644 static PyMethodDef thread_methods[] = { |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
645 {"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
646 METH_VARARGS, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
647 start_new_doc}, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
648 {"start_new", (PyCFunction)thread_PyThread_start_new_thread, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
649 METH_VARARGS, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
650 start_new_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
651 {"allocate_lock", (PyCFunction)thread_PyThread_allocate_lock, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
652 METH_NOARGS, allocate_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
653 {"allocate", (PyCFunction)thread_PyThread_allocate_lock, |
|
22584
bcd1fdf13acf
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22562
diff
changeset
|
654 METH_NOARGS, allocate_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
655 {"exit_thread", (PyCFunction)thread_PyThread_exit_thread, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
656 METH_NOARGS, exit_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
657 {"exit", (PyCFunction)thread_PyThread_exit_thread, |
|
22584
bcd1fdf13acf
Missed change METH_OLDARGS to METH_NOARGS for two aliased functions
Neal Norwitz <nnorwitz@gmail.com>
parents:
22562
diff
changeset
|
658 METH_NOARGS, exit_doc}, |
| 29498 | 659 {"interrupt_main", (PyCFunction)thread_PyThread_interrupt_main, |
|
29444
8d160095eb66
Add interrupt_main() to thread module.
Kurt B. Kaiser <kbk@shore.net>
parents:
28889
diff
changeset
|
660 METH_NOARGS, interrupt_doc}, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
661 {"get_ident", (PyCFunction)thread_get_ident, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
21313
diff
changeset
|
662 METH_NOARGS, get_ident_doc}, |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
663 {"stack_size", (PyCFunction)thread_stack_size, |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
664 METH_VARARGS, |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38592
diff
changeset
|
665 stack_size_doc}, |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
666 #ifndef NO_EXIT_PROG |
| 22709 | 667 {"exit_prog", (PyCFunction)thread_PyThread_exit_prog, |
| 668 METH_VARARGS}, | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
669 #endif |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
670 {NULL, NULL} /* sentinel */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
671 }; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
672 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
673 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
674 /* Initialization function */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
675 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
676 PyDoc_STRVAR(thread_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
677 "This module provides primitive operations to write multi-threaded programs.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
678 The 'threading' module provides a more convenient interface."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
679 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
680 PyDoc_STRVAR(lock_doc, |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
681 "A lock object is a synchronization primitive. To create a lock,\n\ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
682 call the PyThread_allocate_lock() function. Methods are:\n\ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
683 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
684 acquire() -- lock the lock, possibly blocking until it can be obtained\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
685 release() -- unlock of the lock\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
686 locked() -- test whether the lock is currently locked\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
687 \n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
688 A lock is not owned by the thread that locked it; another thread may\n\ |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
689 unlock it. A thread attempting to lock a lock that it has already locked\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22865
diff
changeset
|
690 will block until another thread unlocks it. Deadlocks may ensue."); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
691 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
692 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13497
diff
changeset
|
693 initthread(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 { |
| 4751 | 695 PyObject *m, *d; |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
696 |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
697 /* Initialize types: */ |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
698 if (PyType_Ready(&localtype) < 0) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
699 return; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
700 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
701 /* Create the module and add the functions */ |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
702 m = Py_InitModule3("thread", thread_methods, thread_doc); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35117
diff
changeset
|
703 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35117
diff
changeset
|
704 return; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 /* Add a symbolic constant */ |
| 4751 | 707 d = PyModule_GetDict(m); |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5927
diff
changeset
|
708 ThreadError = PyErr_NewException("thread.error", NULL, NULL); |
| 4751 | 709 PyDict_SetItemString(d, "error", ThreadError); |
|
8562
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
710 Locktype.tp_doc = lock_doc; |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
711 Py_INCREF(&Locktype); |
|
ff9adb57b8b5
Added doc strings. Also export LockType from the modoule, and give it
Guido van Rossum <guido@python.org>
parents:
8433
diff
changeset
|
712 PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
713 |
| 35085 | 714 Py_INCREF(&localtype); |
|
35086
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
715 if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0) |
|
c6b7fadf0ada
Consistently use hard tabs for indentation.
Michael W. Hudson <mwh@python.net>
parents:
35085
diff
changeset
|
716 return; |
|
32673
97768d87394a
Implemented thread-local data as proposed on python-dev:
Jim Fulton <jim@zope.com>
parents:
31797
diff
changeset
|
717 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
718 /* Initialize the C thread library */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
719 PyThread_init_thread(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 } |
