mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
* 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:
parent
25bec8c8dc
commit
ff4949eeee
19 changed files with 382 additions and 150 deletions
|
|
@ -22,10 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
/* Interface to execute compiled code */
|
/* Interface to random parts in ceval.c */
|
||||||
/* This header depends on "compile.h" */
|
|
||||||
|
|
||||||
object *eval_code PROTO((codeobject *, object *, object *, object *));
|
|
||||||
|
|
||||||
object *call_object PROTO((object *, object *));
|
object *call_object PROTO((object *, object *));
|
||||||
|
|
||||||
|
|
@ -34,3 +31,70 @@ object *getlocals PROTO((void));
|
||||||
|
|
||||||
void printtraceback PROTO((FILE *));
|
void printtraceback PROTO((FILE *));
|
||||||
void flushline PROTO((void));
|
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
Include/eval.h
Normal file
27
Include/eval.h
Normal file
|
|
@ -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 *));
|
||||||
|
|
@ -30,7 +30,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "import.h"
|
#include "import.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
#include "compile.h"
|
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
|
|
||||||
#define NCALLBACKS 8
|
#define NCALLBACKS 8
|
||||||
|
|
|
||||||
|
|
@ -459,4 +459,8 @@ print
|
||||||
print 'initgl()'
|
print 'initgl()'
|
||||||
print '{'
|
print '{'
|
||||||
print '\tinitmodule("gl", gl_methods);'
|
print '\tinitmodule("gl", gl_methods);'
|
||||||
|
print '\t/* Initialize GL and don\'t go in the background */'
|
||||||
|
print '\tforeground();'
|
||||||
|
print '\tnoport();'
|
||||||
|
print '\twinopen("");'
|
||||||
print '}'
|
print '}'
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "import.h"
|
#include "import.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
#include "structmember.h"
|
#include "structmember.h"
|
||||||
|
#include "ceval.h"
|
||||||
/* #include "ceval.h" */
|
|
||||||
extern object *call_object(object *, object *);
|
|
||||||
|
|
||||||
/* Generic Forms Objects */
|
/* Generic Forms Objects */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
#include "ceval.h"
|
||||||
|
|
||||||
extern char *strerror PROTO((int));
|
extern char *strerror PROTO((int));
|
||||||
|
|
||||||
|
|
@ -128,9 +129,13 @@ posix_1str(args, func)
|
||||||
int (*func) FPROTO((const char *));
|
int (*func) FPROTO((const char *));
|
||||||
{
|
{
|
||||||
char *path1;
|
char *path1;
|
||||||
|
int res;
|
||||||
if (!getstrarg(args, &path1))
|
if (!getstrarg(args, &path1))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((*func)(path1) < 0)
|
BGN_SAVE
|
||||||
|
res = (*func)(path1);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -142,9 +147,13 @@ posix_2str(args, func)
|
||||||
int (*func) FPROTO((const char *, const char *));
|
int (*func) FPROTO((const char *, const char *));
|
||||||
{
|
{
|
||||||
char *path1, *path2;
|
char *path1, *path2;
|
||||||
|
int res;
|
||||||
if (!getstrstrarg(args, &path1, &path2))
|
if (!getstrstrarg(args, &path1, &path2))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((*func)(path1, path2) < 0)
|
BGN_SAVE
|
||||||
|
res = (*func)(path1, path2);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -157,9 +166,13 @@ posix_strint(args, func)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
int i;
|
int i;
|
||||||
|
int res;
|
||||||
if (!getstrintarg(args, &path, &i))
|
if (!getstrintarg(args, &path, &i))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((*func)(path, i) < 0)
|
BGN_SAVE
|
||||||
|
res = (*func)(path, i);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -174,9 +187,13 @@ posix_do_stat(self, args, statfunc)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *path;
|
char *path;
|
||||||
object *v;
|
object *v;
|
||||||
|
int res;
|
||||||
if (!getstrarg(args, &path))
|
if (!getstrarg(args, &path))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((*statfunc)(path, &st) != 0)
|
BGN_SAVE
|
||||||
|
res = (*statfunc)(path, &st);
|
||||||
|
END_SAVE
|
||||||
|
if (res != 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
v = newtupleobject(10);
|
v = newtupleobject(10);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
|
|
@ -227,10 +244,14 @@ posix_getcwd(self, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
char buf[1026];
|
char buf[1026];
|
||||||
|
char *res;
|
||||||
extern char *getcwd PROTO((char *, int));
|
extern char *getcwd PROTO((char *, int));
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (getcwd(buf, sizeof buf) == NULL)
|
BGN_SAVE
|
||||||
|
res = getcwd(buf, sizeof buf);
|
||||||
|
END_SAVE
|
||||||
|
if (res == NULL)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
return newstringobject(buf);
|
return newstringobject(buf);
|
||||||
}
|
}
|
||||||
|
|
@ -284,10 +305,14 @@ posix_listdir(self, args)
|
||||||
struct direct *ep;
|
struct direct *ep;
|
||||||
if (!getstrarg(args, &name))
|
if (!getstrarg(args, &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((dirp = opendir(name)) == NULL)
|
BGN_SAVE
|
||||||
|
if ((dirp = opendir(name)) == NULL) {
|
||||||
|
RET_SAVE
|
||||||
return posix_error();
|
return posix_error();
|
||||||
|
}
|
||||||
if ((d = newlistobject(0)) == NULL) {
|
if ((d = newlistobject(0)) == NULL) {
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
RET_SAVE
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
while ((ep = readdir(dirp)) != NULL) {
|
while ((ep = readdir(dirp)) != NULL) {
|
||||||
|
|
@ -306,6 +331,7 @@ posix_listdir(self, args)
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
END_SAVE
|
||||||
#endif /* !MSDOS */
|
#endif /* !MSDOS */
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
|
@ -368,11 +394,13 @@ posix_system(self, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
char *command;
|
char *command;
|
||||||
int sts;
|
long sts;
|
||||||
if (!getstrarg(args, &command))
|
if (!getstrarg(args, &command))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
sts = system(command);
|
sts = system(command);
|
||||||
return newintobject((long)sts);
|
END_SAVE
|
||||||
|
return newintobject(sts);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MSDOS
|
#ifndef MSDOS
|
||||||
|
|
@ -411,9 +439,13 @@ posix_uname(self, args)
|
||||||
extern int uname PROTO((struct utsname *));
|
extern int uname PROTO((struct utsname *));
|
||||||
struct utsname u;
|
struct utsname u;
|
||||||
object *v;
|
object *v;
|
||||||
|
int res;
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (uname(&u) < 0)
|
BGN_SAVE
|
||||||
|
res = uname(&u);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
v = newtupleobject(5);
|
v = newtupleobject(5);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
|
|
@ -443,6 +475,7 @@ posix_utime(self, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
|
int res;
|
||||||
|
|
||||||
#ifdef UTIME_STRUCT
|
#ifdef UTIME_STRUCT
|
||||||
struct utimbuf buf;
|
struct utimbuf buf;
|
||||||
|
|
@ -459,7 +492,10 @@ posix_utime(self, args)
|
||||||
|
|
||||||
if (!getargs(args, "(s(ll))", &path, &ATIME, &MTIME))
|
if (!getargs(args, "(s(ll))", &path, &ATIME, &MTIME))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (utime(path, UTIME_ARG) < 0)
|
BGN_SAVE
|
||||||
|
res = utime(path, UTIME_ARG);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -648,7 +684,9 @@ posix_popen(self, args)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
if (!getargs(args, "(ss)", &name, &mode))
|
if (!getargs(args, "(ss)", &name, &mode))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
fp = popen(name, mode);
|
fp = popen(name, mode);
|
||||||
|
END_SAVE
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
/* From now on, ignore SIGPIPE and let the error checking
|
/* From now on, ignore SIGPIPE and let the error checking
|
||||||
|
|
@ -664,8 +702,11 @@ posix_wait(self, args) /* Also waitpid() */
|
||||||
{
|
{
|
||||||
object *v;
|
object *v;
|
||||||
int pid, sts;
|
int pid, sts;
|
||||||
if (args == NULL)
|
if (args == NULL) {
|
||||||
|
BGN_SAVE
|
||||||
pid = wait(&sts);
|
pid = wait(&sts);
|
||||||
|
END_SAVE
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef NO_WAITPID
|
#ifdef NO_WAITPID
|
||||||
err_setstr(PosixError,
|
err_setstr(PosixError,
|
||||||
|
|
@ -674,7 +715,9 @@ posix_wait(self, args) /* Also waitpid() */
|
||||||
int options;
|
int options;
|
||||||
if (!getintintarg(args, &pid, &options))
|
if (!getintintarg(args, &pid, &options))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
pid = waitpid(pid, &sts, options);
|
pid = waitpid(pid, &sts, options);
|
||||||
|
END_SAVE
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
|
|
@ -719,7 +762,9 @@ posix_readlink(self, args)
|
||||||
int n;
|
int n;
|
||||||
if (!getstrarg(args, &path))
|
if (!getstrarg(args, &path))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
n = readlink(path, buf, (int) sizeof buf);
|
n = readlink(path, buf, (int) sizeof buf);
|
||||||
|
END_SAVE
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
return newsizedstringobject(buf, n);
|
return newsizedstringobject(buf, n);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
#include "compile.h"
|
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
|
|
||||||
#include "myselect.h"
|
#include "myselect.h"
|
||||||
|
|
@ -154,7 +153,9 @@ select_select(self, args)
|
||||||
if ( omax > max ) max = omax;
|
if ( omax > max ) max = omax;
|
||||||
if ( emax > max ) max = emax;
|
if ( emax > max ) max = emax;
|
||||||
|
|
||||||
|
BGN_SAVE
|
||||||
n = select(max, &ifdset, &ofdset, &efdset, tvp);
|
n = select(max, &ifdset, &ofdset, &efdset, tvp);
|
||||||
|
END_SAVE
|
||||||
|
|
||||||
if ( n < 0 ) {
|
if ( n < 0 ) {
|
||||||
err_errno(SelectError);
|
err_errno(SelectError);
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* Socket module */
|
/* Socket module */
|
||||||
|
|
||||||
/* XXX Ought to fix getStr*arg calls to use getargs(args, "s#", ...) */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This module provides an interface to Berkeley socket IPC.
|
This module provides an interface to Berkeley socket IPC.
|
||||||
|
|
||||||
|
|
@ -72,6 +70,7 @@ Socket methods:
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
#include "ceval.h"
|
||||||
|
|
||||||
#include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
|
#include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
|
||||||
|
|
||||||
|
|
@ -171,7 +170,9 @@ setipaddr(name, addr_ret)
|
||||||
((long) d3 << 8) | ((long) d4 << 0));
|
((long) d3 << 8) | ((long) d4 << 0));
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
BGN_SAVE
|
||||||
hp = gethostbyname(name);
|
hp = gethostbyname(name);
|
||||||
|
END_SAVE
|
||||||
if (hp == NULL) {
|
if (hp == NULL) {
|
||||||
err_setstr(SocketError, "host not found");
|
err_setstr(SocketError, "host not found");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -256,16 +257,16 @@ getsockaddrarg(s, args, addr_ret, len_ret)
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
{
|
{
|
||||||
static struct sockaddr_un addr;
|
static struct sockaddr_un addr;
|
||||||
object *path;
|
char *path;
|
||||||
int len;
|
int len;
|
||||||
if (!getStrarg(args, &path))
|
if (!getargs(args, "s#", &path, &len))
|
||||||
return 0;
|
return 0;
|
||||||
if ((len = getstringsize(path)) > sizeof addr.sun_path) {
|
if (len > sizeof addr.sun_path) {
|
||||||
err_setstr(SocketError, "AF_UNIX path too long");
|
err_setstr(SocketError, "AF_UNIX path too long");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
memcpy(addr.sun_path, getstringvalue(path), len);
|
memcpy(addr.sun_path, path, len);
|
||||||
*addr_ret = (struct sockaddr *) &addr;
|
*addr_ret = (struct sockaddr *) &addr;
|
||||||
*len_ret = len + sizeof addr.sun_family;
|
*len_ret = len + sizeof addr.sun_family;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -274,11 +275,11 @@ getsockaddrarg(s, args, addr_ret, len_ret)
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
{
|
{
|
||||||
static struct sockaddr_in addr;
|
static struct sockaddr_in addr;
|
||||||
object *host;
|
char *host;
|
||||||
int port;
|
int port;
|
||||||
if (!getStrintarg(args, &host, &port))
|
if (!getargs(args, "(si)", &host, &port))
|
||||||
return 0;
|
return 0;
|
||||||
if (setipaddr(getstringvalue(host), &addr) < 0)
|
if (setipaddr(host, &addr) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
|
|
@ -344,7 +345,9 @@ sock_accept(s, args)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!getsockaddrlen(s, &addrlen))
|
if (!getsockaddrlen(s, &addrlen))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
|
newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
|
||||||
|
END_SAVE
|
||||||
if (newfd < 0)
|
if (newfd < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
/* Create the new object with unspecified family,
|
/* Create the new object with unspecified family,
|
||||||
|
|
@ -370,7 +373,7 @@ sock_allowbroadcast(s, args)
|
||||||
{
|
{
|
||||||
int flag;
|
int flag;
|
||||||
int res;
|
int res;
|
||||||
if (!getintarg(args, &flag))
|
if (!getargs(args, "i", &flag))
|
||||||
return NULL;
|
return NULL;
|
||||||
res = setsockopt(s->sock_fd, SOL_SOCKET, SO_BROADCAST,
|
res = setsockopt(s->sock_fd, SOL_SOCKET, SO_BROADCAST,
|
||||||
&flag, sizeof flag);
|
&flag, sizeof flag);
|
||||||
|
|
@ -461,9 +464,13 @@ sock_bind(s, args)
|
||||||
{
|
{
|
||||||
struct sockaddr *addr;
|
struct sockaddr *addr;
|
||||||
int addrlen;
|
int addrlen;
|
||||||
|
int res;
|
||||||
if (!getsockaddrarg(s, args, &addr, &addrlen))
|
if (!getsockaddrarg(s, args, &addr, &addrlen))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (bind(s->sock_fd, addr, addrlen) < 0)
|
BGN_SAVE
|
||||||
|
res = bind(s->sock_fd, addr, addrlen);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -481,7 +488,9 @@ sock_close(s, args)
|
||||||
{
|
{
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
(void) close(s->sock_fd);
|
(void) close(s->sock_fd);
|
||||||
|
END_SAVE
|
||||||
s->sock_fd = -1;
|
s->sock_fd = -1;
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -497,9 +506,13 @@ sock_connect(s, args)
|
||||||
{
|
{
|
||||||
struct sockaddr *addr;
|
struct sockaddr *addr;
|
||||||
int addrlen;
|
int addrlen;
|
||||||
|
int res;
|
||||||
if (!getsockaddrarg(s, args, &addr, &addrlen))
|
if (!getsockaddrarg(s, args, &addr, &addrlen))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (connect(s->sock_fd, addr, addrlen) < 0)
|
BGN_SAVE
|
||||||
|
res = connect(s->sock_fd, addr, addrlen);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -527,9 +540,13 @@ sock_listen(s, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
int backlog;
|
int backlog;
|
||||||
|
int res;
|
||||||
if (!getintarg(args, &backlog))
|
if (!getintarg(args, &backlog))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (listen(s->sock_fd, backlog) < 0)
|
BGN_SAVE
|
||||||
|
res = listen(s->sock_fd, backlog);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -549,15 +566,15 @@ sock_makefile(s, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
extern int fclose PROTO((FILE *));
|
extern int fclose PROTO((FILE *));
|
||||||
object *mode;
|
char *mode;
|
||||||
int fd;
|
int fd;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
if (!getStrarg(args, &mode))
|
if (!getargs(args, "s", &mode))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((fd = dup(s->sock_fd)) < 0 ||
|
if ((fd = dup(s->sock_fd)) < 0 ||
|
||||||
(fp = fdopen(fd, getstringvalue(mode))) == NULL)
|
(fp = fdopen(fd, mode)) == NULL)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
return newopenfileobject(fp, "<socket>", getstringvalue(mode), fclose);
|
return newopenfileobject(fp, "<socket>", mode, fclose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -579,7 +596,9 @@ sock_recv(s, args)
|
||||||
buf = newsizedstringobject((char *) 0, len);
|
buf = newsizedstringobject((char *) 0, len);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
n = recv(s->sock_fd, getstringvalue(buf), len, flags);
|
n = recv(s->sock_fd, getstringvalue(buf), len, flags);
|
||||||
|
END_SAVE
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
if (resizestring(&buf, n) < 0)
|
if (resizestring(&buf, n) < 0)
|
||||||
|
|
@ -600,10 +619,13 @@ sock_recvfrom(s, args)
|
||||||
int addrlen, len, n;
|
int addrlen, len, n;
|
||||||
if (!getintarg(args, &len))
|
if (!getintarg(args, &len))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (!getsockaddrlen(s, &addrlen))
|
||||||
|
return NULL;
|
||||||
buf = newsizedstringobject((char *) 0, len);
|
buf = newsizedstringobject((char *) 0, len);
|
||||||
addrlen = sizeof addrbuf;
|
BGN_SAVE
|
||||||
n = recvfrom(s->sock_fd, getstringvalue(buf), len, 0,
|
n = recvfrom(s->sock_fd, getstringvalue(buf), len, 0,
|
||||||
addrbuf, &addrlen);
|
addrbuf, &addrlen);
|
||||||
|
END_SAVE
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
if (resizestring(&buf, n) < 0)
|
if (resizestring(&buf, n) < 0)
|
||||||
|
|
@ -620,16 +642,17 @@ sock_send(s, args)
|
||||||
sockobject *s;
|
sockobject *s;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
object *buf;
|
char *buf;
|
||||||
int len, n, flags;
|
int len, n, flags;
|
||||||
if (!getStrintarg(args, &buf, &flags)) {
|
if (!getargs(args, "(s#i)", &buf, &len, &flags)) {
|
||||||
err_clear();
|
err_clear();
|
||||||
if (!getStrarg(args, &buf))
|
if (!getargs(args, "s#", &buf, &len))
|
||||||
return NULL;
|
return NULL;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
}
|
}
|
||||||
len = getstringsize(buf);
|
BGN_SAVE
|
||||||
n = send(s->sock_fd, getstringvalue(buf), len, flags);
|
n = send(s->sock_fd, buf, len, flags);
|
||||||
|
END_SAVE
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
|
|
@ -644,19 +667,20 @@ sock_sendto(s, args)
|
||||||
sockobject *s;
|
sockobject *s;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
object *buf;
|
object *addro;
|
||||||
|
char *buf;
|
||||||
struct sockaddr *addr;
|
struct sockaddr *addr;
|
||||||
int addrlen, len, n;
|
int addrlen, len, n;
|
||||||
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
|
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
|
||||||
err_badarg();
|
err_badarg();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!getStrarg(gettupleitem(args, 0), &buf) ||
|
if (!getargs(args, "(s#O)", &buf, &len, &addro) ||
|
||||||
!getsockaddrarg(s, gettupleitem(args, 1), &addr, &addrlen))
|
!getsockaddrarg(s, addro, &addr, &addrlen))
|
||||||
return NULL;
|
return NULL;
|
||||||
len = getstringsize(buf);
|
BGN_SAVE
|
||||||
n = sendto(s->sock_fd, getstringvalue(buf), len, 0,
|
n = sendto(s->sock_fd, buf, len, 0, addr, addrlen);
|
||||||
addr, addrlen);
|
END_SAVE
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
|
|
@ -672,9 +696,13 @@ sock_shutdown(s, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
int how;
|
int how;
|
||||||
|
int res;
|
||||||
if (!getintarg(args, &how))
|
if (!getintarg(args, &how))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (shutdown(s->sock_fd, how) < 0)
|
BGN_SAVE
|
||||||
|
res = shutdown(s->sock_fd, how);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -758,13 +786,19 @@ socket_gethostname(self, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
int res;
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (gethostname(buf, (int) sizeof buf - 1) < 0)
|
BGN_SAVE
|
||||||
|
res = gethostname(buf, (int) sizeof buf - 1);
|
||||||
|
END_SAVE
|
||||||
|
if (res < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
buf[sizeof buf - 1] = '\0';
|
buf[sizeof buf - 1] = '\0';
|
||||||
return newstringobject(buf);
|
return newstringobject(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Python interface to gethostbyname(name). */
|
/* Python interface to gethostbyname(name). */
|
||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
|
|
@ -775,9 +809,9 @@ socket_gethostbyname(self, args)
|
||||||
{
|
{
|
||||||
object *name;
|
object *name;
|
||||||
struct sockaddr_in addrbuf;
|
struct sockaddr_in addrbuf;
|
||||||
if (!getStrarg(args, &name))
|
if (!getargs(args, "s", &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (setipaddr(getstringvalue(name), &addrbuf) < 0)
|
if (setipaddr(name, &addrbuf) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
return makeipaddr(&addrbuf);
|
return makeipaddr(&addrbuf);
|
||||||
}
|
}
|
||||||
|
|
@ -793,11 +827,13 @@ socket_getservbyname(self, args)
|
||||||
object *self;
|
object *self;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
object *name, *proto;
|
char *name, *proto;
|
||||||
struct servent *sp;
|
struct servent *sp;
|
||||||
if (!getStrStrarg(args, &name, &proto))
|
if (!getargs(args, "(ss)", &name, &proto))
|
||||||
return NULL;
|
return NULL;
|
||||||
sp = getservbyname(getstringvalue(name), getstringvalue(proto));
|
BGN_SAVE
|
||||||
|
sp = getservbyname(name, proto);
|
||||||
|
END_SAVE
|
||||||
if (sp == NULL) {
|
if (sp == NULL) {
|
||||||
err_setstr(SocketError, "service/proto not found");
|
err_setstr(SocketError, "service/proto not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -827,7 +863,9 @@ socket_socket(self, args)
|
||||||
return NULL;
|
return NULL;
|
||||||
proto = 0;
|
proto = 0;
|
||||||
}
|
}
|
||||||
|
BGN_SAVE
|
||||||
fd = socket(family, type, proto);
|
fd = socket(family, type, proto);
|
||||||
|
END_SAVE
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
s = newsockobject(fd, family, type, proto);
|
s = newsockobject(fd, family, type, proto);
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,29 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
|
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
#include "ceval.h"
|
||||||
|
|
||||||
#include "stdwin.h"
|
#include "stdwin.h"
|
||||||
|
|
||||||
|
#ifdef USE_THREAD
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
static type_lock StdwinLock; /* Lock held when interpreter not locked */
|
||||||
|
|
||||||
|
#define BGN_STDWIN BGN_SAVE acquire_lock(StdwinLock, 1);
|
||||||
|
#define RET_STDWIN release_lock(StdwinLock); RET_SAVE
|
||||||
|
#define END_STDWIN release_lock(StdwinLock); END_SAVE
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define BGN_STDWIN BGN_SAVE
|
||||||
|
#define RET_STDWIN RET_SAVE
|
||||||
|
#define END_STDWIN END_SAVE
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static object *StdwinError; /* Exception stdwin.error */
|
static object *StdwinError; /* Exception stdwin.error */
|
||||||
|
|
||||||
/* Window and menu object types declared here because of forward references */
|
/* Window and menu object types declared here because of forward references */
|
||||||
|
|
@ -1727,14 +1745,17 @@ stdwin_get_poll_event(poll, args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
again:
|
again:
|
||||||
|
BGN_STDWIN
|
||||||
if (poll) {
|
if (poll) {
|
||||||
if (!wpollevent(&e)) {
|
if (!wpollevent(&e)) {
|
||||||
|
RET_STDWIN
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wgetevent(&e);
|
wgetevent(&e);
|
||||||
|
END_STDWIN
|
||||||
if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
|
if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
|
||||||
/* Turn keyboard interrupts into exceptions */
|
/* Turn keyboard interrupts into exceptions */
|
||||||
err_set(KeyboardInterrupt);
|
err_set(KeyboardInterrupt);
|
||||||
|
|
@ -1919,7 +1940,9 @@ stdwin_askfile(self, args)
|
||||||
return NULL;
|
return NULL;
|
||||||
strncpy(buf, dflt, sizeof buf);
|
strncpy(buf, dflt, sizeof buf);
|
||||||
buf[sizeof buf - 1] = '\0';
|
buf[sizeof buf - 1] = '\0';
|
||||||
|
BGN_STDWIN
|
||||||
ret = waskfile(prompt, buf, sizeof buf, new);
|
ret = waskfile(prompt, buf, sizeof buf, new);
|
||||||
|
END_STDWIN
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
err_set(KeyboardInterrupt);
|
err_set(KeyboardInterrupt);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1936,7 +1959,9 @@ stdwin_askync(self, args)
|
||||||
int new, ret;
|
int new, ret;
|
||||||
if (!getstrintarg(args, &prompt, &new))
|
if (!getstrintarg(args, &prompt, &new))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_STDWIN
|
||||||
ret = waskync(prompt, new);
|
ret = waskync(prompt, new);
|
||||||
|
END_STDWIN
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
err_set(KeyboardInterrupt);
|
err_set(KeyboardInterrupt);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1956,7 +1981,9 @@ stdwin_askstr(self, args)
|
||||||
return NULL;
|
return NULL;
|
||||||
strncpy(buf, dflt, sizeof buf);
|
strncpy(buf, dflt, sizeof buf);
|
||||||
buf[sizeof buf - 1] = '\0';
|
buf[sizeof buf - 1] = '\0';
|
||||||
|
BGN_STDWIN
|
||||||
ret = waskstr(prompt, buf, sizeof buf);
|
ret = waskstr(prompt, buf, sizeof buf);
|
||||||
|
END_STDWIN
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
err_set(KeyboardInterrupt);
|
err_set(KeyboardInterrupt);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1972,7 +1999,9 @@ stdwin_message(self, args)
|
||||||
char *msg;
|
char *msg;
|
||||||
if (!getstrarg(args, &msg))
|
if (!getstrarg(args, &msg))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_STDWIN
|
||||||
wmessage(msg);
|
wmessage(msg);
|
||||||
|
END_STDWIN
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
@ -2185,4 +2214,9 @@ initstdwin()
|
||||||
StdwinError = newstringobject("stdwin.error");
|
StdwinError = newstringobject("stdwin.error");
|
||||||
if (StdwinError == NULL || dictinsert(d, "error", StdwinError) != 0)
|
if (StdwinError == NULL || dictinsert(d, "error", StdwinError) != 0)
|
||||||
fatal("can't define stdwin.error");
|
fatal("can't define stdwin.error");
|
||||||
|
#ifdef USE_THREAD
|
||||||
|
StdwinLock = allocate_lock();
|
||||||
|
if (StdwinLock == NULL)
|
||||||
|
fatal("can't allocate stdwin lock");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
#include "compile.h"
|
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
|
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
extern void init_save_thread PROTO((void));
|
|
||||||
extern void* save_thread PROTO((void));
|
|
||||||
extern void restore_thread PROTO((void *));
|
|
||||||
|
|
||||||
object *ThreadError;
|
object *ThreadError;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,7 +78,6 @@ lock_acquire_lock(self, args)
|
||||||
lockobject *self;
|
lockobject *self;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
void *save;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (args != NULL) {
|
if (args != NULL) {
|
||||||
|
|
@ -93,11 +87,9 @@ lock_acquire_lock(self, args)
|
||||||
else
|
else
|
||||||
i = 1;
|
i = 1;
|
||||||
|
|
||||||
save = save_thread();
|
BGN_SAVE
|
||||||
|
|
||||||
i = acquire_lock(self->lock_lock, i);
|
i = acquire_lock(self->lock_lock, i);
|
||||||
|
END_SAVE
|
||||||
restore_thread(save);
|
|
||||||
|
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
|
|
@ -193,8 +185,6 @@ t_bootstrap(args_raw)
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
fprintf(stderr, "Unhandled exception in thread:\n");
|
fprintf(stderr, "Unhandled exception in thread:\n");
|
||||||
print_error(); /* From pythonmain.c */
|
print_error(); /* From pythonmain.c */
|
||||||
fprintf(stderr, "Exiting the entire program\n");
|
|
||||||
goaway(1);
|
|
||||||
}
|
}
|
||||||
(void) save_thread();
|
(void) save_thread();
|
||||||
exit_thread();
|
exit_thread();
|
||||||
|
|
@ -251,7 +241,7 @@ thread_allocate_lock(self, args)
|
||||||
{
|
{
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
return newlockobject();
|
return (object *) newlockobject();
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist thread_methods[] = {
|
static struct methodlist thread_methods[] = {
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* Time module */
|
/* Time module */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
|
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
#include "ceval.h"
|
||||||
|
|
||||||
#include "sigtype.h"
|
#include "sigtype.h"
|
||||||
|
|
||||||
|
|
@ -104,14 +104,13 @@ time_sleep(self, args)
|
||||||
object *self;
|
object *self;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
void *save, *save_thread(), restore_thread();
|
long secs;
|
||||||
int secs;
|
|
||||||
SIGTYPE (*sigsave)() = 0; /* Initialized to shut lint up */
|
SIGTYPE (*sigsave)() = 0; /* Initialized to shut lint up */
|
||||||
if (!getintarg(args, &secs))
|
if (!getargs(args, "l", &secs))
|
||||||
return NULL;
|
return NULL;
|
||||||
save = save_thread();
|
BGN_SAVE
|
||||||
if (setjmp(sleep_intr)) {
|
if (setjmp(sleep_intr)) {
|
||||||
restore_thread(save);
|
RET_SAVE
|
||||||
signal(SIGINT, sigsave);
|
signal(SIGINT, sigsave);
|
||||||
err_set(KeyboardInterrupt);
|
err_set(KeyboardInterrupt);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -119,8 +118,12 @@ time_sleep(self, args)
|
||||||
sigsave = signal(SIGINT, SIG_IGN);
|
sigsave = signal(SIGINT, SIG_IGN);
|
||||||
if (sigsave != (SIGTYPE (*)()) SIG_IGN)
|
if (sigsave != (SIGTYPE (*)()) SIG_IGN)
|
||||||
signal(SIGINT, sleep_catcher);
|
signal(SIGINT, sleep_catcher);
|
||||||
sleep(secs);
|
#ifdef BSD_TIME
|
||||||
restore_thread(save);
|
longsleep(secs);
|
||||||
|
#else
|
||||||
|
sleep((int)secs);
|
||||||
|
#endif
|
||||||
|
END_SAVE
|
||||||
signal(SIGINT, sigsave);
|
signal(SIGINT, sigsave);
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -151,14 +154,13 @@ time_millisleep(self, args)
|
||||||
object *self;
|
object *self;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
void *save, *save_thread(), restore_thread();
|
|
||||||
long msecs;
|
long msecs;
|
||||||
SIGTYPE (*sigsave)();
|
SIGTYPE (*sigsave)();
|
||||||
if (!getlongarg(args, &msecs))
|
if (!getlongarg(args, &msecs))
|
||||||
return NULL;
|
return NULL;
|
||||||
save = save_thread();
|
BGN_SAVE
|
||||||
if (setjmp(sleep_intr)) {
|
if (setjmp(sleep_intr)) {
|
||||||
restore_thread(save);
|
RET_SAVE
|
||||||
signal(SIGINT, sigsave);
|
signal(SIGINT, sigsave);
|
||||||
err_set(KeyboardInterrupt);
|
err_set(KeyboardInterrupt);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -167,7 +169,7 @@ time_millisleep(self, args)
|
||||||
if (sigsave != (SIGTYPE (*)()) SIG_IGN)
|
if (sigsave != (SIGTYPE (*)()) SIG_IGN)
|
||||||
signal(SIGINT, sleep_catcher);
|
signal(SIGINT, sleep_catcher);
|
||||||
millisleep(msecs);
|
millisleep(msecs);
|
||||||
restore_thread(save);
|
END_SAVE
|
||||||
signal(SIGINT, sigsave);
|
signal(SIGINT, sigsave);
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -249,12 +251,12 @@ inittime()
|
||||||
#define MacTicks (* (long *)0x16A)
|
#define MacTicks (* (long *)0x16A)
|
||||||
|
|
||||||
#ifdef THINK_C_3_0
|
#ifdef THINK_C_3_0
|
||||||
sleep(msecs)
|
sleep(secs)
|
||||||
int msecs;
|
int secs;
|
||||||
{
|
{
|
||||||
register long deadline;
|
register long deadline;
|
||||||
|
|
||||||
deadline = MacTicks + msecs * 60;
|
deadline = MacTicks + mecs * 60;
|
||||||
while (MacTicks < deadline) {
|
while (MacTicks < deadline) {
|
||||||
if (intrcheck())
|
if (intrcheck())
|
||||||
sleep_catcher(SIGINT);
|
sleep_catcher(SIGINT);
|
||||||
|
|
@ -295,7 +297,6 @@ millitimer()
|
||||||
if (gettimeofday(&t, &tz) != 0)
|
if (gettimeofday(&t, &tz) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
return t.tv_sec*1000 + t.tv_usec/1000;
|
return t.tv_sec*1000 + t.tv_usec/1000;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
millisleep(msecs)
|
millisleep(msecs)
|
||||||
|
|
@ -307,6 +308,15 @@ millisleep(msecs)
|
||||||
(void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
|
(void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
longsleep(secs)
|
||||||
|
long secs;
|
||||||
|
{
|
||||||
|
struct timeval t;
|
||||||
|
t.tv_sec = secs;
|
||||||
|
t.tv_usec = 0;
|
||||||
|
(void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* BSD_TIME */
|
#endif /* BSD_TIME */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
#include "ceval.h"
|
||||||
|
|
||||||
#define BUF(v) GETSTRINGVALUE((stringobject *)v)
|
#define BUF(v) GETSTRINGVALUE((stringobject *)v)
|
||||||
|
|
||||||
|
|
@ -93,7 +94,11 @@ newfileobject(name, mode)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
f->f_fp = fopen(name, mode);
|
{
|
||||||
|
BGN_SAVE
|
||||||
|
f->f_fp = fopen(name, mode);
|
||||||
|
END_SAVE
|
||||||
|
}
|
||||||
if (f->f_fp == NULL) {
|
if (f->f_fp == NULL) {
|
||||||
err_errno(IOError);
|
err_errno(IOError);
|
||||||
DECREF(f);
|
DECREF(f);
|
||||||
|
|
@ -115,8 +120,11 @@ static void
|
||||||
file_dealloc(f)
|
file_dealloc(f)
|
||||||
fileobject *f;
|
fileobject *f;
|
||||||
{
|
{
|
||||||
if (f->f_fp != NULL && f->f_close != NULL)
|
if (f->f_fp != NULL && f->f_close != NULL) {
|
||||||
|
BGN_SAVE
|
||||||
(*f->f_close)(f->f_fp);
|
(*f->f_close)(f->f_fp);
|
||||||
|
END_SAVE
|
||||||
|
}
|
||||||
if (f->f_name != NULL)
|
if (f->f_name != NULL)
|
||||||
DECREF(f->f_name);
|
DECREF(f->f_name);
|
||||||
if (f->f_mode != NULL)
|
if (f->f_mode != NULL)
|
||||||
|
|
@ -162,10 +170,13 @@ file_close(f, args)
|
||||||
int sts = 0;
|
int sts = 0;
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
errno = 0;
|
|
||||||
if (f->f_fp != NULL) {
|
if (f->f_fp != NULL) {
|
||||||
if (f->f_close != NULL)
|
if (f->f_close != NULL) {
|
||||||
|
BGN_SAVE
|
||||||
|
errno = 0;
|
||||||
sts = (*f->f_close)(f->f_fp);
|
sts = (*f->f_close)(f->f_fp);
|
||||||
|
END_SAVE
|
||||||
|
}
|
||||||
f->f_fp = NULL;
|
f->f_fp = NULL;
|
||||||
}
|
}
|
||||||
if (sts == EOF)
|
if (sts == EOF)
|
||||||
|
|
@ -183,6 +194,7 @@ file_seek(f, args)
|
||||||
{
|
{
|
||||||
long offset;
|
long offset;
|
||||||
int whence;
|
int whence;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (f->f_fp == NULL)
|
if (f->f_fp == NULL)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
|
|
@ -192,8 +204,11 @@ file_seek(f, args)
|
||||||
if (!getargs(args, "(li)", &offset, &whence))
|
if (!getargs(args, "(li)", &offset, &whence))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
BGN_SAVE
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (fseek(f->f_fp, offset, whence) != 0) {
|
ret = fseek(f->f_fp, offset, whence);
|
||||||
|
END_SAVE
|
||||||
|
if (ret != 0) {
|
||||||
err_errno(IOError);
|
err_errno(IOError);
|
||||||
clearerr(f->f_fp);
|
clearerr(f->f_fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -212,8 +227,10 @@ file_tell(f, args)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
errno = 0;
|
errno = 0;
|
||||||
offset = ftell(f->f_fp);
|
offset = ftell(f->f_fp);
|
||||||
|
END_SAVE
|
||||||
if (offset == -1L) {
|
if (offset == -1L) {
|
||||||
err_errno(IOError);
|
err_errno(IOError);
|
||||||
clearerr(f->f_fp);
|
clearerr(f->f_fp);
|
||||||
|
|
@ -239,12 +256,17 @@ file_flush(f, args)
|
||||||
fileobject *f;
|
fileobject *f;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
|
int res;
|
||||||
|
|
||||||
if (f->f_fp == NULL)
|
if (f->f_fp == NULL)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
BGN_SAVE
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (fflush(f->f_fp) != 0) {
|
res = fflush(f->f_fp);
|
||||||
|
END_SAVE
|
||||||
|
if (res != 0) {
|
||||||
err_errno(IOError);
|
err_errno(IOError);
|
||||||
clearerr(f->f_fp);
|
clearerr(f->f_fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -258,11 +280,15 @@ file_isatty(f, args)
|
||||||
fileobject *f;
|
fileobject *f;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
|
long res;
|
||||||
if (f->f_fp == NULL)
|
if (f->f_fp == NULL)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
return newintobject((long)isatty((int)fileno(f->f_fp)));
|
BGN_SAVE
|
||||||
|
res = isatty((int)fileno(f->f_fp));
|
||||||
|
END_SAVE
|
||||||
|
return newintobject(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
|
|
@ -290,6 +316,7 @@ file_read(f, args)
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
n1 = 0;
|
n1 = 0;
|
||||||
|
BGN_SAVE
|
||||||
for (;;) {
|
for (;;) {
|
||||||
n3 = fread(BUF(v)+n1, 1, n2-n1, f->f_fp);
|
n3 = fread(BUF(v)+n1, 1, n2-n1, f->f_fp);
|
||||||
/* XXX Error check? */
|
/* XXX Error check? */
|
||||||
|
|
@ -300,10 +327,13 @@ file_read(f, args)
|
||||||
break;
|
break;
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
n2 = n1 + BUFSIZ;
|
n2 = n1 + BUFSIZ;
|
||||||
|
RET_SAVE
|
||||||
if (resizestring(&v, n2) < 0)
|
if (resizestring(&v, n2) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
RES_SAVE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
END_SAVE
|
||||||
if (n1 != n2)
|
if (n1 != n2)
|
||||||
resizestring(&v, n1);
|
resizestring(&v, n1);
|
||||||
return v;
|
return v;
|
||||||
|
|
@ -321,7 +351,6 @@ getline(f, n)
|
||||||
fileobject *f;
|
fileobject *f;
|
||||||
int n;
|
int n;
|
||||||
{
|
{
|
||||||
void *save, *save_thread(), restore_thread();
|
|
||||||
register FILE *fp;
|
register FILE *fp;
|
||||||
register int c;
|
register int c;
|
||||||
register char *buf, *end;
|
register char *buf, *end;
|
||||||
|
|
@ -336,18 +365,18 @@ getline(f, n)
|
||||||
buf = BUF(v);
|
buf = BUF(v);
|
||||||
end = buf + n2;
|
end = buf + n2;
|
||||||
|
|
||||||
save = save_thread();
|
BGN_SAVE
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((c = getc(fp)) == EOF) {
|
if ((c = getc(fp)) == EOF) {
|
||||||
clearerr(fp);
|
clearerr(fp);
|
||||||
if (intrcheck()) {
|
if (intrcheck()) {
|
||||||
restore_thread(save);
|
RET_SAVE
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
err_set(KeyboardInterrupt);
|
err_set(KeyboardInterrupt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (n < 0 && buf == BUF(v)) {
|
if (n < 0 && buf == BUF(v)) {
|
||||||
restore_thread(save);
|
RET_SAVE
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
err_setstr(EOFError,
|
err_setstr(EOFError,
|
||||||
"EOF when reading a line");
|
"EOF when reading a line");
|
||||||
|
|
@ -365,15 +394,15 @@ getline(f, n)
|
||||||
break;
|
break;
|
||||||
n1 = n2;
|
n1 = n2;
|
||||||
n2 += 1000;
|
n2 += 1000;
|
||||||
restore_thread(save);
|
RET_SAVE
|
||||||
if (resizestring(&v, n2) < 0)
|
if (resizestring(&v, n2) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
save = save_thread();
|
RES_SAVE
|
||||||
buf = BUF(v) + n1;
|
buf = BUF(v) + n1;
|
||||||
end = BUF(v) + n2;
|
end = BUF(v) + n2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
restore_thread(save);
|
END_SAVE
|
||||||
|
|
||||||
n1 = buf - BUF(v);
|
n1 = buf - BUF(v);
|
||||||
if (n1 != n2)
|
if (n1 != n2)
|
||||||
|
|
@ -464,8 +493,10 @@ file_write(f, args)
|
||||||
if (!getargs(args, "s#", &s, &n))
|
if (!getargs(args, "s#", &s, &n))
|
||||||
return NULL;
|
return NULL;
|
||||||
f->f_softspace = 0;
|
f->f_softspace = 0;
|
||||||
|
BGN_SAVE
|
||||||
errno = 0;
|
errno = 0;
|
||||||
n2 = fwrite(s, 1, n, f->f_fp);
|
n2 = fwrite(s, 1, n, f->f_fp);
|
||||||
|
END_SAVE
|
||||||
if (n2 != n) {
|
if (n2 != n) {
|
||||||
err_errno(IOError);
|
err_errno(IOError);
|
||||||
clearerr(f->f_fp);
|
clearerr(f->f_fp);
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
#include "compile.h" /* Needed by ceval.h */
|
#include "ceval.h"
|
||||||
#include "ceval.h" /* For call_object() */
|
|
||||||
|
|
||||||
object *
|
object *
|
||||||
newlistobject(size)
|
newlistobject(size)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "bltinmodule.h"
|
#include "bltinmodule.h"
|
||||||
#include "import.h"
|
#include "import.h"
|
||||||
#include "pythonrun.h"
|
#include "pythonrun.h"
|
||||||
#include "compile.h" /* For ceval.h */
|
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
|
||||||
|
|
@ -218,13 +217,17 @@ builtin_execfile(self, v)
|
||||||
"execfile arguments must be filename[,dict[,dict]]");
|
"execfile arguments must be filename[,dict[,dict]]");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
BGN_SAVE
|
||||||
fp = fopen(getstringvalue(str), "r");
|
fp = fopen(getstringvalue(str), "r");
|
||||||
|
END_SAVE
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
err_setstr(IOError, "execfile cannot open the file argument");
|
err_setstr(IOError, "execfile cannot open the file argument");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
w = run_file(fp, getstringvalue(str), file_input, globals, locals);
|
w = run_file(fp, getstringvalue(str), file_input, globals, locals);
|
||||||
|
BGN_SAVE
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
END_SAVE
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,9 +327,11 @@ builtin_input(self, v)
|
||||||
}
|
}
|
||||||
m = add_module("__main__");
|
m = add_module("__main__");
|
||||||
d = getmoduledict(m);
|
d = getmoduledict(m);
|
||||||
|
BGN_SAVE
|
||||||
while ((c = getc(in)) != EOF && (c == ' ' || c == '\t'))
|
while ((c = getc(in)) != EOF && (c == ' ' || c == '\t'))
|
||||||
;
|
;
|
||||||
ungetc(c, in);
|
ungetc(c, in);
|
||||||
|
END_SAVE
|
||||||
return run_file(in, "<stdin>", expr_input, d, d);
|
return run_file(in, "<stdin>", expr_input, d, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "sysmodule.h"
|
#include "sysmodule.h"
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "frameobject.h"
|
#include "frameobject.h"
|
||||||
|
#include "eval.h"
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
#include "opcode.h"
|
#include "opcode.h"
|
||||||
#include "bltinmodule.h"
|
#include "bltinmodule.h"
|
||||||
|
|
@ -83,48 +84,28 @@ static object *build_class PROTO((object *, object *));
|
||||||
|
|
||||||
static frameobject *current_frame;
|
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
|
#ifdef USE_THREAD
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
static type_lock interpreter_lock;
|
static type_lock interpreter_lock;
|
||||||
|
|
||||||
void
|
void
|
||||||
init_save_thread()
|
init_save_thread()
|
||||||
{
|
{
|
||||||
#ifdef USE_THREAD
|
|
||||||
if (interpreter_lock)
|
if (interpreter_lock)
|
||||||
fatal("2nd call to init_save_thread");
|
fatal("2nd call to init_save_thread");
|
||||||
interpreter_lock = allocate_lock();
|
interpreter_lock = allocate_lock();
|
||||||
acquire_lock(interpreter_lock, 1);
|
acquire_lock(interpreter_lock, 1);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#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 *
|
void *
|
||||||
save_thread()
|
save_thread()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "pythonrun.h"
|
#include "pythonrun.h"
|
||||||
#include "marshal.h"
|
#include "marshal.h"
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "ceval.h"
|
#include "eval.h"
|
||||||
#include "osdefs.h"
|
#include "osdefs.h"
|
||||||
|
|
||||||
extern int verbose; /* Defined in pythonmain.c */
|
extern int verbose; /* Defined in pythonmain.c */
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
|
|
||||||
extern char *getpythonpath();
|
|
||||||
|
|
||||||
extern int debugging; /* Needed by parser.c */
|
extern int debugging; /* Needed by parser.c */
|
||||||
extern int verbose; /* Needed by import.c */
|
extern int verbose; /* Needed by import.c */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "errcode.h"
|
#include "errcode.h"
|
||||||
#include "sysmodule.h"
|
#include "sysmodule.h"
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
|
#include "eval.h"
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
#include "pythonrun.h"
|
#include "pythonrun.h"
|
||||||
#include "import.h"
|
#include "import.h"
|
||||||
|
|
||||||
#ifdef USE_THREAD
|
|
||||||
extern void *save_thread();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern char *getpythonpath();
|
extern char *getpythonpath();
|
||||||
|
|
||||||
extern grammar gram; /* From graminit.c */
|
extern grammar gram; /* From graminit.c */
|
||||||
|
|
@ -127,7 +124,6 @@ run_tty_1(fp, filename)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *filename;
|
char *filename;
|
||||||
{
|
{
|
||||||
void *save, *save_thread(), restore_thread();
|
|
||||||
object *m, *d, *v, *w;
|
object *m, *d, *v, *w;
|
||||||
node *n;
|
node *n;
|
||||||
char *ps1, *ps2;
|
char *ps1, *ps2;
|
||||||
|
|
@ -150,9 +146,9 @@ run_tty_1(fp, filename)
|
||||||
w = NULL;
|
w = NULL;
|
||||||
ps2 = "";
|
ps2 = "";
|
||||||
}
|
}
|
||||||
save = save_thread();
|
BGN_SAVE
|
||||||
err = parsefile(fp, filename, &gram, single_input, ps1, ps2, &n);
|
err = parsefile(fp, filename, &gram, single_input, ps1, ps2, &n);
|
||||||
restore_thread(save);
|
END_SAVE
|
||||||
XDECREF(v);
|
XDECREF(v);
|
||||||
XDECREF(w);
|
XDECREF(w);
|
||||||
if (err == E_EOF)
|
if (err == E_EOF)
|
||||||
|
|
@ -330,8 +326,12 @@ parse_file(fp, filename, start, n_ret)
|
||||||
int start;
|
int start;
|
||||||
node **n_ret;
|
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);
|
(char *)0, (char *)0, n_ret);
|
||||||
|
END_SAVE
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Simplified interface to parsestring */
|
/* Simplified interface to parsestring */
|
||||||
|
|
@ -367,6 +367,18 @@ goaway(sts)
|
||||||
{
|
{
|
||||||
flushline();
|
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()
|
/* XXX Call doneimport() before donecalls(), since donecalls()
|
||||||
calls wdone(), and doneimport() may close windows */
|
calls wdone(), and doneimport() may close windows */
|
||||||
doneimport();
|
doneimport();
|
||||||
|
|
@ -384,12 +396,8 @@ goaway(sts)
|
||||||
}
|
}
|
||||||
#endif /* TRACE_REFS */
|
#endif /* TRACE_REFS */
|
||||||
|
|
||||||
#ifdef USE_THREAD
|
|
||||||
(void) save_thread();
|
|
||||||
exit_prog(sts);
|
|
||||||
#else
|
|
||||||
exit(sts);
|
exit(sts);
|
||||||
#endif
|
#endif /* USE_THREAD */
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ static int exiting;
|
||||||
#include <lwp/lwp.h>
|
#include <lwp/lwp.h>
|
||||||
#include <lwp/stackdep.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 */
|
#define NSTACKS 2 /* # stacks to be put in cache initialy */
|
||||||
|
|
||||||
struct lock {
|
struct lock {
|
||||||
|
|
@ -90,7 +90,7 @@ void exit_thread _P0()
|
||||||
exit(0);
|
exit(0);
|
||||||
#ifdef __sgi
|
#ifdef __sgi
|
||||||
exiting = 1;
|
exiting = 1;
|
||||||
exit(0);
|
_exit(0);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SOLARIS
|
#ifdef SOLARIS
|
||||||
thread_exit();
|
thread_exit();
|
||||||
|
|
@ -113,7 +113,7 @@ static void exit_sig _P0()
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("exiting in exit_sig\n");
|
printf("exiting in exit_sig\n");
|
||||||
#endif
|
#endif
|
||||||
exit(exit_status);
|
_exit(exit_status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -255,7 +255,7 @@ void exit_prog _P1(status, int status)
|
||||||
exiting = 1;
|
exiting = 1;
|
||||||
do_exit = 1;
|
do_exit = 1;
|
||||||
exit_status = status;
|
exit_status = status;
|
||||||
exit(status);
|
_exit(status);
|
||||||
#endif
|
#endif
|
||||||
#ifdef sun
|
#ifdef sun
|
||||||
pod_exit(status);
|
pod_exit(status);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue