* 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
This commit is contained in:
Guido van Rossum 1992-08-05 19:58:53 +00:00
parent 25bec8c8dc
commit ff4949eeee
19 changed files with 382 additions and 150 deletions

View file

@ -33,7 +33,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "bltinmodule.h"
#include "import.h"
#include "pythonrun.h"
#include "compile.h" /* For ceval.h */
#include "ceval.h"
#include "modsupport.h"
@ -218,13 +217,17 @@ builtin_execfile(self, v)
"execfile arguments must be filename[,dict[,dict]]");
return NULL;
}
BGN_SAVE
fp = fopen(getstringvalue(str), "r");
END_SAVE
if (fp == NULL) {
err_setstr(IOError, "execfile cannot open the file argument");
return NULL;
}
w = run_file(fp, getstringvalue(str), file_input, globals, locals);
BGN_SAVE
fclose(fp);
END_SAVE
return w;
}
@ -324,9 +327,11 @@ builtin_input(self, v)
}
m = add_module("__main__");
d = getmoduledict(m);
BGN_SAVE
while ((c = getc(in)) != EOF && (c == ' ' || c == '\t'))
;
ungetc(c, in);
END_SAVE
return run_file(in, "<stdin>", expr_input, d, d);
}

View file

@ -30,6 +30,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "sysmodule.h"
#include "compile.h"
#include "frameobject.h"
#include "eval.h"
#include "ceval.h"
#include "opcode.h"
#include "bltinmodule.h"
@ -83,48 +84,28 @@ static object *build_class PROTO((object *, object *));
static frameobject *current_frame;
/* 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:
void *x;
...preparations here...
x = save_thread();
...blocking system call here...
restore_thread(x);
...interpretr result here...
For convenience, that the value of 'errno' is restored across the
the call to restore_thread().
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!
*/
#ifdef USE_THREAD
#include <errno.h>
#include "thread.h"
static type_lock interpreter_lock;
void
init_save_thread()
{
#ifdef USE_THREAD
if (interpreter_lock)
fatal("2nd call to init_save_thread");
interpreter_lock = allocate_lock();
acquire_lock(interpreter_lock, 1);
#endif
}
#endif
/* Functions save_thread and restore_thread are always defined so
dynamically loaded modules needn't be compiled separately for use
with and without threads: */
void *
save_thread()
{

View file

@ -35,7 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "pythonrun.h"
#include "marshal.h"
#include "compile.h"
#include "ceval.h"
#include "eval.h"
#include "osdefs.h"
extern int verbose; /* Defined in pythonmain.c */

View file

@ -26,8 +26,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h"
extern char *getpythonpath();
extern int debugging; /* Needed by parser.c */
extern int verbose; /* Needed by import.c */

View file

@ -33,14 +33,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "errcode.h"
#include "sysmodule.h"
#include "compile.h"
#include "eval.h"
#include "ceval.h"
#include "pythonrun.h"
#include "import.h"
#ifdef USE_THREAD
extern void *save_thread();
#endif
extern char *getpythonpath();
extern grammar gram; /* From graminit.c */
@ -127,7 +124,6 @@ run_tty_1(fp, filename)
FILE *fp;
char *filename;
{
void *save, *save_thread(), restore_thread();
object *m, *d, *v, *w;
node *n;
char *ps1, *ps2;
@ -150,9 +146,9 @@ run_tty_1(fp, filename)
w = NULL;
ps2 = "";
}
save = save_thread();
BGN_SAVE
err = parsefile(fp, filename, &gram, single_input, ps1, ps2, &n);
restore_thread(save);
END_SAVE
XDECREF(v);
XDECREF(w);
if (err == E_EOF)
@ -330,8 +326,12 @@ parse_file(fp, filename, start, n_ret)
int start;
node **n_ret;
{
return parsefile(fp, filename, &gram, start,
int ret;
BGN_SAVE
ret = parsefile(fp, filename, &gram, start,
(char *)0, (char *)0, n_ret);
END_SAVE
return ret;
}
/* Simplified interface to parsestring */
@ -366,6 +366,18 @@ goaway(sts)
int sts;
{
flushline();
#ifdef USE_THREAD
/* Other threads may still be active, so skip most of the
cleanup actions usually done (these are mostly for
debugging anyway). */
(void *) save_thread();
donecalls();
exit_prog(sts);
#else /* USE_THREAD */
/* XXX Call doneimport() before donecalls(), since donecalls()
calls wdone(), and doneimport() may close windows */
@ -384,12 +396,8 @@ goaway(sts)
}
#endif /* TRACE_REFS */
#ifdef USE_THREAD
(void) save_thread();
exit_prog(sts);
#else
exit(sts);
#endif
#endif /* USE_THREAD */
/*NOTREACHED*/
}

View file

@ -17,7 +17,7 @@ static int exiting;
#include <lwp/lwp.h>
#include <lwp/stackdep.h>
#define STACKSIZE 1000 /* stacksize for a thread */
#define STACKSIZE 16000 /* stacksize for a thread */
#define NSTACKS 2 /* # stacks to be put in cache initialy */
struct lock {
@ -90,7 +90,7 @@ void exit_thread _P0()
exit(0);
#ifdef __sgi
exiting = 1;
exit(0);
_exit(0);
#endif
#ifdef SOLARIS
thread_exit();
@ -113,7 +113,7 @@ static void exit_sig _P0()
#ifdef DEBUG
printf("exiting in exit_sig\n");
#endif
exit(exit_status);
_exit(exit_status);
}
}
#endif
@ -255,7 +255,7 @@ void exit_prog _P1(status, int status)
exiting = 1;
do_exit = 1;
exit_status = status;
exit(status);
_exit(status);
#endif
#ifdef sun
pod_exit(status);