Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff4949e

Browse files
committed
* Makefile: cosmetics
* socketmodule.c: get rid of makepair(); fix makesocketaddr to fix broken recvfrom() * socketmodule: get rid of getStrarg() * ceval.h: move eval_code() to new file eval.h, so compile.h is no longer needed. * ceval.c: move thread comments to ceval.h; always make save/restore thread functions available (for dynloaded modules) * cdmodule.c, listobject.c: don't include compile.h * flmodule.c: include ceval.h * import.c: include eval.h instead of ceval.h * cgen.py: add forground(); noport(); winopen(""); to initgl(). * bltinmodule.c, socketmodule.c, fileobject.c, posixmodule.c, selectmodule.c: adapt to threads (add BGN/END SAVE macros) * stdwinmodule.c: adapt to threads and use a special stdwin lock. * pythonmain.c: don't include getpythonpath(). * pythonrun.c: use BGN/END SAVE instead of direct calls; also more BGN/END SAVE calls etc. * thread.c: bigger stack size for sun; change exit() to _exit() * threadmodule.c: use BGN/END SAVE macros where possible * timemodule.c: adapt better to threads; use BGN/END SAVE; add longsleep internal function if BSD_TIME; cosmetics
1 parent 25bec8c commit ff4949e

19 files changed

Lines changed: 382 additions & 150 deletions

Include/ceval.h

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2222
2323
******************************************************************/
2424

25-
/* Interface to execute compiled code */
26-
/* This header depends on "compile.h" */
27-
28-
object *eval_code PROTO((codeobject *, object *, object *, object *));
25+
/* Interface to random parts in ceval.c */
2926

3027
object *call_object PROTO((object *, object *));
3128

@@ -34,3 +31,70 @@ object *getlocals PROTO((void));
3431

3532
void printtraceback PROTO((FILE *));
3633
void flushline PROTO((void));
34+
35+
36+
/* Interface for threads.
37+
38+
A module that plans to do a blocking system call (or something else
39+
that lasts a long time and doesn't touch Python data) can allow other
40+
threads to run as follows:
41+
42+
...preparations here...
43+
BGN_SAVE
44+
...blocking system call here...
45+
END_SAVE
46+
...interpretr result here...
47+
48+
The BGN_SAVE/END_SAVE pair expands to a {}-surrounded block.
49+
To leave the block in the middle (e.g., with return), you must insert
50+
a line containing RET_SAVE before the return, e.g.
51+
52+
if (...premature_exit...) {
53+
RET_SAVE
54+
err_errno(IOError);
55+
return NULL;
56+
}
57+
58+
An alternative is:
59+
60+
RET_SAVE
61+
if (...premature_exit...) {
62+
err_errno(IOError);
63+
return NULL;
64+
}
65+
RES_SAVE
66+
67+
For convenience, that the value of 'errno' is restored across
68+
END_SAVE and RET_SAVE.
69+
70+
WARNING: NEVER NEST CALLS TO BGN_SAVE AND END_SAVE!!!
71+
72+
The function init_save_thread() should be called only from
73+
initthread() in "threadmodule.c".
74+
75+
Note that not yet all candidates have been converted to use this
76+
mechanism!
77+
*/
78+
79+
extern void init_save_thread PROTO((void));
80+
extern void *save_thread PROTO((void));
81+
extern void restore_thread PROTO((void *));
82+
83+
#ifdef USE_THREAD
84+
85+
#define BGN_SAVE { \
86+
void *_save; \
87+
_save = save_thread();
88+
#define RET_SAVE restore_thread(_save);
89+
#define RES_SAVE _save = save_thread();
90+
#define END_SAVE restore_thread(_save); \
91+
}
92+
93+
#else /* !USE_THREAD */
94+
95+
#define BGN_SAVE {
96+
#define RET_SAVE
97+
#define RES_SAVE
98+
#define END_SAVE }
99+
100+
#endif /* !USE_THREAD */

Include/eval.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/***********************************************************
2+
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
3+
Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
24+
25+
/* Interface to execute compiled code */
26+
27+
object *eval_code PROTO((codeobject *, object *, object *, object *));

Modules/cdmodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3030
#include "allobjects.h"
3131
#include "import.h"
3232
#include "modsupport.h"
33-
#include "compile.h"
3433
#include "ceval.h"
3534

3635
#define NCALLBACKS 8

Modules/cgen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,8 @@ def mkobject(type, arg):
459459
print 'initgl()'
460460
print '{'
461461
print '\tinitmodule("gl", gl_methods);'
462+
print '\t/* Initialize GL and don\'t go in the background */'
463+
print '\tforeground();'
464+
print '\tnoport();'
465+
print '\twinopen("");'
462466
print '}'

Modules/flmodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3535
#include "import.h"
3636
#include "modsupport.h"
3737
#include "structmember.h"
38-
39-
/* #include "ceval.h" */
40-
extern object *call_object(object *, object *);
38+
#include "ceval.h"
4139

4240
/* Generic Forms Objects */
4341

Modules/posixmodule.c

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
7373

7474
#include "allobjects.h"
7575
#include "modsupport.h"
76+
#include "ceval.h"
7677

7778
extern char *strerror PROTO((int));
7879

@@ -128,9 +129,13 @@ posix_1str(args, func)
128129
int (*func) FPROTO((const char *));
129130
{
130131
char *path1;
132+
int res;
131133
if (!getstrarg(args, &path1))
132134
return NULL;
133-
if ((*func)(path1) < 0)
135+
BGN_SAVE
136+
res = (*func)(path1);
137+
END_SAVE
138+
if (res < 0)
134139
return posix_error();
135140
INCREF(None);
136141
return None;
@@ -142,9 +147,13 @@ posix_2str(args, func)
142147
int (*func) FPROTO((const char *, const char *));
143148
{
144149
char *path1, *path2;
150+
int res;
145151
if (!getstrstrarg(args, &path1, &path2))
146152
return NULL;
147-
if ((*func)(path1, path2) < 0)
153+
BGN_SAVE
154+
res = (*func)(path1, path2);
155+
END_SAVE
156+
if (res < 0)
148157
return posix_error();
149158
INCREF(None);
150159
return None;
@@ -157,9 +166,13 @@ posix_strint(args, func)
157166
{
158167
char *path;
159168
int i;
169+
int res;
160170
if (!getstrintarg(args, &path, &i))
161171
return NULL;
162-
if ((*func)(path, i) < 0)
172+
BGN_SAVE
173+
res = (*func)(path, i);
174+
END_SAVE
175+
if (res < 0)
163176
return posix_error();
164177
INCREF(None);
165178
return None;
@@ -174,9 +187,13 @@ posix_do_stat(self, args, statfunc)
174187
struct stat st;
175188
char *path;
176189
object *v;
190+
int res;
177191
if (!getstrarg(args, &path))
178192
return NULL;
179-
if ((*statfunc)(path, &st) != 0)
193+
BGN_SAVE
194+
res = (*statfunc)(path, &st);
195+
END_SAVE
196+
if (res != 0)
180197
return posix_error();
181198
v = newtupleobject(10);
182199
if (v == NULL)
@@ -227,10 +244,14 @@ posix_getcwd(self, args)
227244
object *args;
228245
{
229246
char buf[1026];
247+
char *res;
230248
extern char *getcwd PROTO((char *, int));
231249
if (!getnoarg(args))
232250
return NULL;
233-
if (getcwd(buf, sizeof buf) == NULL)
251+
BGN_SAVE
252+
res = getcwd(buf, sizeof buf);
253+
END_SAVE
254+
if (res == NULL)
234255
return posix_error();
235256
return newstringobject(buf);
236257
}
@@ -284,10 +305,14 @@ posix_listdir(self, args)
284305
struct direct *ep;
285306
if (!getstrarg(args, &name))
286307
return NULL;
287-
if ((dirp = opendir(name)) == NULL)
308+
BGN_SAVE
309+
if ((dirp = opendir(name)) == NULL) {
310+
RET_SAVE
288311
return posix_error();
312+
}
289313
if ((d = newlistobject(0)) == NULL) {
290314
closedir(dirp);
315+
RET_SAVE
291316
return NULL;
292317
}
293318
while ((ep = readdir(dirp)) != NULL) {
@@ -306,6 +331,7 @@ posix_listdir(self, args)
306331
DECREF(v);
307332
}
308333
closedir(dirp);
334+
END_SAVE
309335
#endif /* !MSDOS */
310336

311337
return d;
@@ -368,11 +394,13 @@ posix_system(self, args)
368394
object *args;
369395
{
370396
char *command;
371-
int sts;
397+
long sts;
372398
if (!getstrarg(args, &command))
373399
return NULL;
400+
BGN_SAVE
374401
sts = system(command);
375-
return newintobject((long)sts);
402+
END_SAVE
403+
return newintobject(sts);
376404
}
377405

378406
#ifndef MSDOS
@@ -411,9 +439,13 @@ posix_uname(self, args)
411439
extern int uname PROTO((struct utsname *));
412440
struct utsname u;
413441
object *v;
442+
int res;
414443
if (!getnoarg(args))
415444
return NULL;
416-
if (uname(&u) < 0)
445+
BGN_SAVE
446+
res = uname(&u);
447+
END_SAVE
448+
if (res < 0)
417449
return posix_error();
418450
v = newtupleobject(5);
419451
if (v == NULL)
@@ -443,6 +475,7 @@ posix_utime(self, args)
443475
object *args;
444476
{
445477
char *path;
478+
int res;
446479

447480
#ifdef UTIME_STRUCT
448481
struct utimbuf buf;
@@ -459,7 +492,10 @@ posix_utime(self, args)
459492

460493
if (!getargs(args, "(s(ll))", &path, &ATIME, &MTIME))
461494
return NULL;
462-
if (utime(path, UTIME_ARG) < 0)
495+
BGN_SAVE
496+
res = utime(path, UTIME_ARG);
497+
END_SAVE
498+
if (res < 0)
463499
return posix_error();
464500
INCREF(None);
465501
return None;
@@ -648,7 +684,9 @@ posix_popen(self, args)
648684
FILE *fp;
649685
if (!getargs(args, "(ss)", &name, &mode))
650686
return NULL;
687+
BGN_SAVE
651688
fp = popen(name, mode);
689+
END_SAVE
652690
if (fp == NULL)
653691
return posix_error();
654692
/* From now on, ignore SIGPIPE and let the error checking
@@ -664,8 +702,11 @@ posix_wait(self, args) /* Also waitpid() */
664702
{
665703
object *v;
666704
int pid, sts;
667-
if (args == NULL)
705+
if (args == NULL) {
706+
BGN_SAVE
668707
pid = wait(&sts);
708+
END_SAVE
709+
}
669710
else {
670711
#ifdef NO_WAITPID
671712
err_setstr(PosixError,
@@ -674,7 +715,9 @@ posix_wait(self, args) /* Also waitpid() */
674715
int options;
675716
if (!getintintarg(args, &pid, &options))
676717
return NULL;
718+
BGN_SAVE
677719
pid = waitpid(pid, &sts, options);
720+
END_SAVE
678721
#endif
679722
}
680723
if (pid == -1)
@@ -719,7 +762,9 @@ posix_readlink(self, args)
719762
int n;
720763
if (!getstrarg(args, &path))
721764
return NULL;
765+
BGN_SAVE
722766
n = readlink(path, buf, (int) sizeof buf);
767+
END_SAVE
723768
if (n < 0)
724769
return posix_error();
725770
return newsizedstringobject(buf, n);

Modules/selectmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2626

2727
#include "allobjects.h"
2828
#include "modsupport.h"
29-
#include "compile.h"
3029
#include "ceval.h"
3130

3231
#include "myselect.h"
@@ -154,7 +153,9 @@ select_select(self, args)
154153
if ( omax > max ) max = omax;
155154
if ( emax > max ) max = emax;
156155

156+
BGN_SAVE
157157
n = select(max, &ifdset, &ofdset, &efdset, tvp);
158+
END_SAVE
158159

159160
if ( n < 0 ) {
160161
err_errno(SelectError);

0 commit comments

Comments
 (0)