Mercurial > cpython-lru_cache-weakref
annotate Python/thread_os2.h @ 16862:77a5470299db legacy-trunk
Add warning/error handlin for problematic nested scopes cases as
described in PEP 227.
symtable_check_unoptimized() warns about import * and exec with "in"
when it is used in a function that contains a nested function with
free variables. Warnings are issued unless nested scopes are in
effect, in which case these are SyntaxErrors.
symtable_check_shadow() warns about assignments in a function scope
that shadow free variables defined in a nested scope. This will
always generate a warning -- and will behave differently with nested
scopes than without.
Restore full checking for free vars in children, even when nested
scopes are not enabled. This is needed to support warnings for
shadowing.
Change symtable_warn() to return an int-- the return value of
PyErr_WarnExplicit.
Sundry cleanup: Remove commented out code. Break long lines.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Wed, 28 Feb 2001 22:54:51 +0000 |
| parents | 6f6f965c5e2d |
| children | ebfd87e87884 |
| rev | line source |
|---|---|
| 2649 | 1 /* This code implemented by cvale@netcom.com */ |
| 2 | |
| 3 #define INCL_DOSPROCESS | |
| 4 #define INCL_DOSSEMAPHORES | |
| 5 #include "os2.h" | |
| 6 #include "limits.h" | |
| 7 | |
| 8 #include "process.h" | |
| 9 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
10 long PyThread_get_thread_ident(void); |
| 2649 | 11 |
| 12 | |
| 13 /* | |
| 14 * Initialization of the C package, should not be needed. | |
| 15 */ | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
16 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
17 PyThread__init_thread(void) |
| 2649 | 18 { |
| 19 } | |
| 20 | |
| 21 /* | |
| 22 * Thread support. | |
| 23 */ | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
24 int |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
25 PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 2649 | 26 { |
| 27 int aThread; | |
| 28 int success = 1; | |
| 29 | |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
30 aThread = _beginthread(func,NULL,65536,arg); |
| 2649 | 31 |
| 32 if( aThread == -1 ) { | |
| 33 success = 0; | |
| 34 fprintf(stderr,"aThread failed == %d",aThread); | |
| 35 dprintf(("_beginthread failed. return %ld\n", errno)); | |
| 36 } | |
| 37 | |
| 38 return success; | |
| 39 } | |
| 40 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
41 long |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
42 PyThread_get_thread_ident(void) |
| 2649 | 43 { |
| 44 PPIB pib; | |
| 45 PTIB tib; | |
| 46 | |
| 47 if (!initialized) | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
48 PyThread_init_thread(); |
| 2649 | 49 |
| 50 DosGetInfoBlocks(&tib,&pib); | |
| 51 return tib->tib_ptib2->tib2_ultid; | |
| 52 } | |
| 53 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
54 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
55 do_PyThread_exit_thread(int no_cleanup) |
| 2649 | 56 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
57 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); |
| 2649 | 58 if (!initialized) |
| 59 if (no_cleanup) | |
| 60 _exit(0); | |
| 61 else | |
| 62 exit(0); | |
| 63 _endthread(); | |
| 64 } | |
| 65 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
66 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
67 PyThread_exit_thread(void) |
| 2649 | 68 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
69 do_PyThread_exit_thread(0); |
| 2649 | 70 } |
| 71 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
72 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
73 PyThread__exit_thread(void) |
| 2649 | 74 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
75 do_PyThread_exit_thread(1); |
| 2649 | 76 } |
| 77 | |
| 78 #ifndef NO_EXIT_PROG | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
79 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
80 do_PyThread_exit_prog(int status, int no_cleanup) |
| 2649 | 81 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
82 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 2649 | 83 if (!initialized) |
| 84 if (no_cleanup) | |
| 85 _exit(status); | |
| 86 else | |
| 87 exit(status); | |
| 88 } | |
| 89 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
90 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
91 PyThread_exit_prog(int status) |
| 2649 | 92 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
93 do_PyThread_exit_prog(status, 0); |
| 2649 | 94 } |
| 95 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
96 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
97 PyThread__exit_prog(int status) |
| 2649 | 98 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
99 do_PyThread_exit_prog(status, 1); |
| 2649 | 100 } |
| 101 #endif /* NO_EXIT_PROG */ | |
| 102 | |
| 103 /* | |
| 104 * Lock support. It has too be implemented as semaphores. | |
| 105 * I [Dag] tried to implement it with mutex but I could find a way to | |
| 106 * tell whether a thread already own the lock or not. | |
| 107 */ | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
108 PyThread_type_lock |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
109 PyThread_allocate_lock(void) |
| 2649 | 110 { |
| 111 HMTX aLock; | |
| 112 APIRET rc; | |
| 113 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
114 dprintf(("PyThread_allocate_lock called\n")); |
| 2649 | 115 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
116 PyThread_init_thread(); |
| 2649 | 117 |
| 118 DosCreateMutexSem(NULL, /* Sem name */ | |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13255
diff
changeset
|
119 &aLock, /* the semaphore */ |
| 2649 | 120 0, /* shared ? */ |
| 121 0); /* initial state */ | |
| 122 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
123 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); |
| 2649 | 124 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
125 return (PyThread_type_lock) aLock; |
| 2649 | 126 } |
| 127 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
128 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
129 PyThread_free_lock(PyThread_type_lock aLock) |
| 2649 | 130 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
131 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2649 | 132 |
| 133 DosCloseMutexSem((HMTX)aLock); | |
| 134 } | |
| 135 | |
| 136 /* | |
| 137 * Return 1 on success if the lock was acquired | |
| 138 * | |
| 139 * and 0 if the lock was not acquired. This means a 0 is returned | |
| 140 * if the lock has already been acquired by this thread! | |
| 141 */ | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
142 int |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
143 PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) |
| 2649 | 144 { |
| 145 int success = 1; | |
| 146 ULONG rc, count; | |
| 147 PID pid = 0; | |
| 148 TID tid = 0; | |
| 149 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
150 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(), |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
151 aLock, waitflag)); |
| 2649 | 152 |
| 153 DosQueryMutexSem((HMTX)aLock,&pid,&tid,&count); | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
154 if( tid == PyThread_get_thread_ident() ) { /* if we own this lock */ |
| 2649 | 155 success = 0; |
| 156 } else { | |
| 157 rc = DosRequestMutexSem((HMTX) aLock, | |
| 158 (waitflag == 1 ? SEM_INDEFINITE_WAIT : 0)); | |
| 159 | |
| 160 if( rc != 0) { | |
| 161 success = 0; /* We failed */ | |
| 162 } | |
| 163 } | |
| 164 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
165 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
166 PyThread_get_thread_ident(),aLock, waitflag, success)); |
| 2649 | 167 |
| 168 return success; | |
| 169 } | |
| 170 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
171 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
172 PyThread_release_lock(PyThread_type_lock aLock) |
| 2649 | 173 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
174 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2649 | 175 |
| 176 if ( DosReleaseMutexSem( (HMTX) aLock ) != 0 ) { | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
177 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
178 PyThread_get_thread_ident(), aLock, GetLastError())); |
| 2649 | 179 } |
| 180 } | |
| 181 | |
| 182 /* | |
| 183 * Semaphore support. | |
| 184 */ | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
185 PyThread_type_sema |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
186 PyThread_allocate_sema(int value) |
| 2649 | 187 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
188 return (PyThread_type_sema) 0; |
| 2649 | 189 } |
| 190 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
191 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
192 PyThread_free_sema(PyThread_type_sema aSemaphore) |
| 2649 | 193 { |
| 194 | |
| 195 } | |
| 196 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
197 int |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
198 PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag) |
| 2649 | 199 { |
|
4371
c277ee8c669c
Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents:
2649
diff
changeset
|
200 return -1; |
| 2649 | 201 } |
| 202 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
203 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
204 PyThread_up_sema(PyThread_type_sema aSemaphore) |
| 2649 | 205 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
206 dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore)); |
| 2649 | 207 } |
