Skip to content

Commit

Permalink
* Makefile: cosmetics
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gvanrossum committed Aug 5, 1992
1 parent 25bec8c commit ff4949e
Show file tree
Hide file tree
Showing 19 changed files with 382 additions and 150 deletions.
72 changes: 68 additions & 4 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/

/* Interface to execute compiled code */
/* This header depends on "compile.h" */

object *eval_code PROTO((codeobject *, object *, object *, object *));
/* Interface to random parts in ceval.c */

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

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

void printtraceback PROTO((FILE *));
void flushline PROTO((void));


/* Interface for threads.
A module that plans to do a blocking system call (or something else
that lasts a long time and doesn't touch Python data) can allow other
threads to run as follows:
...preparations here...
BGN_SAVE
...blocking system call here...
END_SAVE
...interpretr result here...
The BGN_SAVE/END_SAVE pair expands to a {}-surrounded block.
To leave the block in the middle (e.g., with return), you must insert
a line containing RET_SAVE before the return, e.g.
if (...premature_exit...) {
RET_SAVE
err_errno(IOError);
return NULL;
}
An alternative is:
RET_SAVE
if (...premature_exit...) {
err_errno(IOError);
return NULL;
}
RES_SAVE
For convenience, that the value of 'errno' is restored across
END_SAVE and RET_SAVE.
WARNING: NEVER NEST CALLS TO BGN_SAVE AND END_SAVE!!!
The function init_save_thread() should be called only from
initthread() in "threadmodule.c".
Note that not yet all candidates have been converted to use this
mechanism!
*/

extern void init_save_thread PROTO((void));
extern void *save_thread PROTO((void));
extern void restore_thread PROTO((void *));

#ifdef USE_THREAD

#define BGN_SAVE { \
void *_save; \
_save = save_thread();
#define RET_SAVE restore_thread(_save);
#define RES_SAVE _save = save_thread();
#define END_SAVE restore_thread(_save); \
}

#else /* !USE_THREAD */

#define BGN_SAVE {
#define RET_SAVE
#define RES_SAVE
#define END_SAVE }

#endif /* !USE_THREAD */
27 changes: 27 additions & 0 deletions Include/eval.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/***********************************************************
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/

/* Interface to execute compiled code */

object *eval_code PROTO((codeobject *, object *, object *, object *));
1 change: 0 additions & 1 deletion Modules/cdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h"
#include "import.h"
#include "modsupport.h"
#include "compile.h"
#include "ceval.h"

#define NCALLBACKS 8
Expand Down
4 changes: 4 additions & 0 deletions Modules/cgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,8 @@ def mkobject(type, arg):
print 'initgl()'
print '{'
print '\tinitmodule("gl", gl_methods);'
print '\t/* Initialize GL and don\'t go in the background */'
print '\tforeground();'
print '\tnoport();'
print '\twinopen("");'
print '}'
4 changes: 1 addition & 3 deletions Modules/flmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "import.h"
#include "modsupport.h"
#include "structmember.h"

/* #include "ceval.h" */
extern object *call_object(object *, object *);
#include "ceval.h"

/* Generic Forms Objects */

Expand Down
67 changes: 56 additions & 11 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#include "allobjects.h"
#include "modsupport.h"
#include "ceval.h"

extern char *strerror PROTO((int));

Expand Down Expand Up @@ -128,9 +129,13 @@ posix_1str(args, func)
int (*func) FPROTO((const char *));
{
char *path1;
int res;
if (!getstrarg(args, &path1))
return NULL;
if ((*func)(path1) < 0)
BGN_SAVE
res = (*func)(path1);
END_SAVE
if (res < 0)
return posix_error();
INCREF(None);
return None;
Expand All @@ -142,9 +147,13 @@ posix_2str(args, func)
int (*func) FPROTO((const char *, const char *));
{
char *path1, *path2;
int res;
if (!getstrstrarg(args, &path1, &path2))
return NULL;
if ((*func)(path1, path2) < 0)
BGN_SAVE
res = (*func)(path1, path2);
END_SAVE
if (res < 0)
return posix_error();
INCREF(None);
return None;
Expand All @@ -157,9 +166,13 @@ posix_strint(args, func)
{
char *path;
int i;
int res;
if (!getstrintarg(args, &path, &i))
return NULL;
if ((*func)(path, i) < 0)
BGN_SAVE
res = (*func)(path, i);
END_SAVE
if (res < 0)
return posix_error();
INCREF(None);
return None;
Expand All @@ -174,9 +187,13 @@ posix_do_stat(self, args, statfunc)
struct stat st;
char *path;
object *v;
int res;
if (!getstrarg(args, &path))
return NULL;
if ((*statfunc)(path, &st) != 0)
BGN_SAVE
res = (*statfunc)(path, &st);
END_SAVE
if (res != 0)
return posix_error();
v = newtupleobject(10);
if (v == NULL)
Expand Down Expand Up @@ -227,10 +244,14 @@ posix_getcwd(self, args)
object *args;
{
char buf[1026];
char *res;
extern char *getcwd PROTO((char *, int));
if (!getnoarg(args))
return NULL;
if (getcwd(buf, sizeof buf) == NULL)
BGN_SAVE
res = getcwd(buf, sizeof buf);
END_SAVE
if (res == NULL)
return posix_error();
return newstringobject(buf);
}
Expand Down Expand Up @@ -284,10 +305,14 @@ posix_listdir(self, args)
struct direct *ep;
if (!getstrarg(args, &name))
return NULL;
if ((dirp = opendir(name)) == NULL)
BGN_SAVE
if ((dirp = opendir(name)) == NULL) {
RET_SAVE
return posix_error();
}
if ((d = newlistobject(0)) == NULL) {
closedir(dirp);
RET_SAVE
return NULL;
}
while ((ep = readdir(dirp)) != NULL) {
Expand All @@ -306,6 +331,7 @@ posix_listdir(self, args)
DECREF(v);
}
closedir(dirp);
END_SAVE
#endif /* !MSDOS */

return d;
Expand Down Expand Up @@ -368,11 +394,13 @@ posix_system(self, args)
object *args;
{
char *command;
int sts;
long sts;
if (!getstrarg(args, &command))
return NULL;
BGN_SAVE
sts = system(command);
return newintobject((long)sts);
END_SAVE
return newintobject(sts);
}

#ifndef MSDOS
Expand Down Expand Up @@ -411,9 +439,13 @@ posix_uname(self, args)
extern int uname PROTO((struct utsname *));
struct utsname u;
object *v;
int res;
if (!getnoarg(args))
return NULL;
if (uname(&u) < 0)
BGN_SAVE
res = uname(&u);
END_SAVE
if (res < 0)
return posix_error();
v = newtupleobject(5);
if (v == NULL)
Expand Down Expand Up @@ -443,6 +475,7 @@ posix_utime(self, args)
object *args;
{
char *path;
int res;

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

if (!getargs(args, "(s(ll))", &path, &ATIME, &MTIME))
return NULL;
if (utime(path, UTIME_ARG) < 0)
BGN_SAVE
res = utime(path, UTIME_ARG);
END_SAVE
if (res < 0)
return posix_error();
INCREF(None);
return None;
Expand Down Expand Up @@ -648,7 +684,9 @@ posix_popen(self, args)
FILE *fp;
if (!getargs(args, "(ss)", &name, &mode))
return NULL;
BGN_SAVE
fp = popen(name, mode);
END_SAVE
if (fp == NULL)
return posix_error();
/* From now on, ignore SIGPIPE and let the error checking
Expand All @@ -664,8 +702,11 @@ posix_wait(self, args) /* Also waitpid() */
{
object *v;
int pid, sts;
if (args == NULL)
if (args == NULL) {
BGN_SAVE
pid = wait(&sts);
END_SAVE
}
else {
#ifdef NO_WAITPID
err_setstr(PosixError,
Expand All @@ -674,7 +715,9 @@ posix_wait(self, args) /* Also waitpid() */
int options;
if (!getintintarg(args, &pid, &options))
return NULL;
BGN_SAVE
pid = waitpid(pid, &sts, options);
END_SAVE
#endif
}
if (pid == -1)
Expand Down Expand Up @@ -719,7 +762,9 @@ posix_readlink(self, args)
int n;
if (!getstrarg(args, &path))
return NULL;
BGN_SAVE
n = readlink(path, buf, (int) sizeof buf);
END_SAVE
if (n < 0)
return posix_error();
return newsizedstringobject(buf, n);
Expand Down
3 changes: 2 additions & 1 deletion Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#include "allobjects.h"
#include "modsupport.h"
#include "compile.h"
#include "ceval.h"

#include "myselect.h"
Expand Down Expand Up @@ -154,7 +153,9 @@ select_select(self, args)
if ( omax > max ) max = omax;
if ( emax > max ) max = emax;

BGN_SAVE
n = select(max, &ifdset, &ofdset, &efdset, tvp);
END_SAVE

if ( n < 0 ) {
err_errno(SelectError);
Expand Down
Loading

0 comments on commit ff4949e

Please sign in to comment.