Update of /cvsroot/monetdb/MonetDB5/src/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv7207/src/mal

Modified Files:
        mal.mx mal_authorize.mx mal_client.mx mal_debugger.mx 
        mal_factory.mx mal_import.mx mal_interpreter.mx 
        mal_readline.mx mal_scenario.mx mal_session.mx 
Log Message:
Introduced Client (+thread) reuse
(and removed many unused fields of the client struct)


Index: mal_factory.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_factory.mx,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- mal_factory.mx      1 Jun 2007 06:48:28 -0000       1.69
+++ mal_factory.mx      6 Nov 2007 23:20:53 -0000       1.70
@@ -435,7 +435,7 @@
                if( isConstant(mb,i) > 0 ){
                        lhs = &stk->stk[i];
                        rhs = &getConstant(mb,i);
-                       VALcopy2(lhs,rhs);
+                       VALcopy(lhs,rhs);
                } else {
                        lhs = &stk->stk[i];
                        lhs->vtype = getVarGDKType(mb,i);

Index: mal_import.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_import.mx,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- mal_import.mx       29 Oct 2007 20:09:55 -0000      1.71
+++ mal_import.mx       6 Nov 2007 23:20:54 -0000       1.72
@@ -239,7 +239,7 @@
        } else {
                c->fdin = bstream_create(fd, 128 * BLOCK);
                MSinitClientPrg(c,"user","main");       /* re-initialize 
context */
-               msg= runScenario(c);
+               msg = runScenario(c);
        }
 
        @:restoreClient()@

Index: mal_scenario.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_scenario.mx,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- mal_scenario.mx     6 Sep 2007 11:08:50 -0000       1.113
+++ mal_scenario.mx     6 Nov 2007 23:20:55 -0000       1.114
@@ -154,7 +154,6 @@
 
 mal_export str setScenario(Client c, str nme);
 mal_export str runScenario(Client c);
-mal_export str runScenarioBody(Client c);
 mal_export str fillScenario(Client c, Scenario scen);
 mal_export void clrScenario(Client c);
 mal_export str getScenarioLanguage(Client c);
@@ -419,9 +418,6 @@
        c->state[MAL_SCENARIO_ENGINE] = 0;
        c->state[MAL_SCENARIO_INITCLIENT] = 0;
        c->state[MAL_SCENARIO_EXITCLIENT] = 0;
-       if (scen->initClientCmd)
-               return((*scen->initClientCmd) (c));
-
        return(MAL_SUCCEED);
 }
 
@@ -576,7 +572,7 @@
 Access control enforcement. Except for the server owner
 running a scenario should be explicitly permitted.
 @c
-str
+static str
 runScenarioBody(Client c)
 {
        str msg= MAL_SUCCEED;
@@ -585,6 +581,8 @@
        struct tms t0,t1;
 #endif
 
+       if (c->phase[MAL_SCENARIO_INITCLIENT])
+               (*c->phase[MAL_SCENARIO_INITCLIENT]) (c);
        while (c->mode > FINISHING) {
                msg = MAL_SUCCEED;
                @:runPhase(MAL_SCENARIO_READER)@
@@ -597,8 +595,8 @@
                @:runPhase(MAL_SCENARIO_OPTIMIZE)@
                @:runPhase(MAL_SCENARIO_SCHEDULER)@
                @:runPhase(MAL_SCENARIO_ENGINE)@
-               start= GDKusec()-start;
                c->actions++;
+               start = GDKusec()-start;
                c->totaltime += start;
 #ifdef HAVE_TIMES
                times(&t1);
@@ -608,45 +606,21 @@
                c->workload.tms_cstime += t1.tms_cstime-t0.tms_cstime;
 #endif
        }
+       if (c->phase[MAL_SCENARIO_EXITCLIENT])
+               (*c->phase[MAL_SCENARIO_EXITCLIENT]) (c);
        return msg;
 }
 str
 runScenario(Client c)
 {
-       int cnt = 0;
        str msg = MAL_SUCCEED;
-       Client c1;
-
-       if( c== 0 || c->phase[MAL_SCENARIO_READER] == 0) return msg;
 
-       msg= runScenarioBody(c);
-       if( msg != MAL_SUCCEED && 
-               strcmp(msg,"MALException:client.quit:Server stopped."))
+       if (c == 0 || c->phase[MAL_SCENARIO_READER] == 0) 
+               return msg;
+       msg = runScenarioBody(c);
+       if (msg != MAL_SUCCEED && 
+           strcmp(msg,"MALException:client.quit:Server stopped."))
                stream_printf(c->fdout,"!%s\n",msg);
-#ifdef MAL_SCENARIO_DEBUG
-       printf("About to terminate scenario %s\n", c->scenario);
-#endif
[EMAIL PROTECTED]
-Check if we are closing the last client, because then we also
-have to call the scenario exit.
[EMAIL PROTECTED]
-       if( c->scenario)
-               for (c1 = mal_clients; c1 < mal_clients + MAL_MAXCLIENTS; c1++)
-                       if (c1->scenario && strcmp(c->scenario, c1->scenario) 
== 0)
-                               cnt++;
-
-       if (c->phase[MAL_SCENARIO_EXITCLIENT]) {
-#ifdef MAL_SCENARIO_DEBUG
-               printf("Calling client exit function \n");
-#endif
-               (*c->phase[MAL_SCENARIO_EXITCLIENT]) (c);
-       }
-#ifdef MAL_SCENARIO_DEBUG
-               printf("scenario client cnt %d\n",cnt);
-#endif
-       if (cnt == 1) {
-               exitScenario(c);
-       }
        return msg;
 }
 

Index: mal.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal.mx,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- mal.mx      20 Jul 2007 13:21:47 -0000      1.133
+++ mal.mx      6 Nov 2007 23:20:52 -0000       1.134
@@ -362,19 +362,23 @@
 memory leakage problems later on.
 @c
 void mal_exit(void){
-       int reruns=0, t = 0;
-       int freeclient=0, finishing=0, claimed=0, awaiting=0;
+       int t = 0;
        str err;
-       Client cntxt = mal_clients;
 
 @-
 Before continuing we should make sure that all clients
 (except the console) have left the scene.
 @c
+       MCexitPending();
        if( MCgetClient() != mal_clients){
                stream_printf(mal_clients->fdout,"#MALexit: non-admin 
attempt\n");
                return;
        }
+#if 0
+       int reruns=0;
+       int freeclient=0, finishing=0, claimed=0, awaiting=0;
+       Client cntxt = mal_clients;
+
        do{
                freeclient=0; finishing=0; claimed=0; awaiting=0;
                for(cntxt= mal_clients+1;  cntxt<mal_clients+MAL_MAXCLIENTS; 
cntxt++){
@@ -390,10 +394,11 @@
                if(reruns) 
                        stream_printf(mal_clients->fdout,"#MALexit: clients 
still active\n");
        } while (++reruns<3 && finishing+claimed+awaiting );
-       if( reruns== 3)
+       if( reruns == 3)
                stream_printf(mal_clients->fdout,"#MALexit: server forced exit"
                        " %d finishing %d claimed %d waiting\n", 
                                finishing,claimed,awaiting);
+#endif
 @c
 #if 0
        /* skip this to solve random crashes, needs work */
@@ -402,8 +407,6 @@
        unloadLibraries(); 
 
        finishNamespace();
-       if( cntxt->cwd)
-               GDKfree(cntxt->cwd);
        if( cntxt->prompt)
                GDKfree(cntxt->prompt);
        if( cntxt->errbuf)

Index: mal_session.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_session.mx,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- mal_session.mx      29 Oct 2007 20:09:55 -0000      1.145
+++ mal_session.mx      6 Nov 2007 23:20:55 -0000       1.146
@@ -41,7 +41,6 @@
 
 mal_export str MALreader(Client c);
 mal_export str MALexitClient(Client c);
-mal_export str MALexitSession(Client c);
 mal_export str MALparser(Client c);
 mal_export str MALengine(Client c);
 mal_export void MSresetInstructions(MalBlkPtr mb, int start);
@@ -53,10 +52,10 @@
 @c
 #include "mal_config.h"
 #include "mal_session.h"
-#include "mal_instruction.h"   /* for pushEndInstruction() */
-#include "mal_interpreter.h"   /* for showErrors(), runMAL(), 
garbageElement(), garbageCollector() */
-#include "mal_linker.h"                /* for initLibraries() */
-#include "mal_parser.h"                /* for parseMAL() */
+#include "mal_instruction.h" /* for pushEndInstruction() */
+#include "mal_interpreter.h" /* for showErrors(), runMAL(), garbageElement() */
+#include "mal_linker.h"             /* for initLibraries() */
+#include "mal_parser.h"             /* for parseMAL() */
 #include "mal_namespace.h"
 #include "mal_readline.h"
 #include "mal_authorize.h"
@@ -153,12 +152,7 @@
 @+ Client authorization
 The default method to interact with the database server is to
 connect using a port number. The first line received should contain
-authorization information, such as user name and a possible session key.
-
-No encryption scheme is performed yet.
-
-An example initialization string would be "guest:23" which indicates access
-of the client named 'guest' to a session previously started under identity 23.
+authorization information, such as user name.
 
 @{
 The scheduleClient receives a challenge response consisting of
@@ -169,7 +163,6 @@
 {
        char *user = command, *algo = NULL, *passwd = NULL, *lang = NULL;
        char *database = NULL, *s;
-       int key = 0;
        Client c;
        MT_Id p;
 
@@ -322,6 +315,13 @@
                        SABAOTHfreeStatus(&stats);
                }
 
+               /* find and reactivate client */
+               c = MCfindClient(uid, lang, fin, fout); 
+               if (c != NULL) {
+                       GDKfree(command);
+                       return;
+               }
+
                c = MCinitClient(uid, fin, fout);
                if (c == NULL) {
                        stream_printf(fout, "!Out of client slots\n");
@@ -329,9 +329,9 @@
                        GDKfree(command);
                        return;
                }
+               /* move this back !! */
                c->nspace = newModule(NULL, putName("user", 4));
                c->nspace->outer = mal_clients[0].nspace->outer;
-               c->sessionkey = key;
 
                if (!lang) {
                        if ((s = defaultScenario(c))) {
@@ -466,13 +466,18 @@
        if (msg) {
                showException(MAL, "serveClient", "could not initialize default 
scenario");
                c->mode = FINISHING + 1;
-       } else
+       } else {
                do {
-                       runScenario(c);
-                       if (c->mode == FINISHING)
+                       do {
+                               runScenario(c);
+                               if (c->mode == FINISHING)
+                                       break;
+                               resetScenario(c);
+                       } while (c->scenario);
+                       if (!MCwait(c))
                                break;
-                       resetScenario(c);
-               } while (c->scenario);
+               } while(c->scenario && c->mode != FINISHING);
+       }
 @-
 At this stage we should clean out the MAL block
 @c
@@ -481,7 +486,6 @@
 
        if (c->mode > FINISHING) {
                if (isAdministrator(c)) {
-                       /* old OIDflushdelta =0; */
                        if (c->scenario) {
                                exitScenario(c);
                        }
@@ -512,12 +516,6 @@
        MSresetVariables(c->curprg->def, 0, oldstate.vtop);
 @c
 str
-MALexitSession(Client c)
-{
-       (void) c;
-       return 0;
-}
-str
 MALexitClient(Client c)
 {
        if (c->glb) {
@@ -533,14 +531,13 @@
 {
        int r= 1;
 
-       if( c == mal_clients){
+       if (c == mal_clients){
                r= readConsole(c);
                if (r <0 && c->fdin->eof == 0 )
                        r= MCreadClient(c);
                if( r > 0)
                        return MAL_SUCCEED;
-       } else
-       if (MCreadClient(c) > 0)
+       } else if (MCreadClient(c) > 0)
                return MAL_SUCCEED;
        c->mode = FINISHING;
        if (c->fdin)

Index: mal_client.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_client.mx,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -d -r1.161 -r1.162
--- mal_client.mx       5 Nov 2007 19:27:44 -0000       1.161
+++ mal_client.mx       6 Nov 2007 23:20:52 -0000       1.162
@@ -118,8 +118,6 @@
 typedef struct CLIENT {
        int idx;        /* entry in mal_clients */
        oid user;       /* user id in the auth administration */
-       int sessionkey; /* NOTUSED ANYMORE */
-       int permission; /* access mode */
 @-
 The actions for a client is separated into several stages: parsing,
 strategic optimization, tactial optimization, and execution. 
@@ -131,7 +129,6 @@
 @h
        str     scenario;  /* scenario management references */
        str     oldscenario;
-       str     srcFile;        /* NULL for stdin, or file name */
        void    *state[7], *oldstate[7];
        MALfcn  phase[7], oldphase[7];
        sht             stage;          /* keep track of the phase being ran */
@@ -161,31 +158,15 @@
 @h
        time_t      login;  
        time_t      lastcmd;    /* set when input is received */
-       time_t      delay;              /* not yet used */
+       time_t      delay;      /* not yet used */
 @-
 Communication channels for the interconnect are stored here.
 It is perfectly legal to have a client without input stream.
 It will simple terminate after consuming the input buffer.
 @h
+       str       srcFile;  /* NULL for stdin, or file name */
        bstream  *fdin;
-       bstream  *console;      /* always available for reading */
-       int      yycur;         /* the scanners current position */
-       ClientInput *bak;   /* used for recursive script and string execution */
-       stream   *fdout;    /* streams from and to user. */
-
-       str output;     /* output buffer */
-       str prompt;         /* acknowledge prompt */
-       int promptlength;
[EMAIL PROTECTED]
-In interactive mode, reading one line at a time, we should be
-aware of parsing compound structures, such as functions and
-barrier blocks. The level of nesting is maintained in blkmode,
-which is reset to zero upon encountering an end instruction,
-or the closing bracket has been detected. Once the complete
-structure has been parsed the program can be checked and executed.
-Nesting is indicated using a '+' before the prompt.
[EMAIL PROTECTED]
-       int blkmode;        /* control block parsing */
+       int       yycur;    /* the scanners current position */
 @-
 Keeping track of instructions executed is a valueable tool for
 script processing and debugging. 
@@ -198,6 +179,21 @@
 type information
 @h
        bitset  listing;        
+       str prompt;         /* acknowledge prompt */
+       int promptlength;
+       ClientInput *bak;   /* used for recursive script and string execution */
+
+       stream   *fdout;    /* streams from and to user. */
[EMAIL PROTECTED]
+In interactive mode, reading one line at a time, we should be
+aware of parsing compound structures, such as functions and
+barrier blocks. The level of nesting is maintained in blkmode,
+which is reset to zero upon encountering an end instruction,
+or the closing bracket has been detected. Once the complete
+structure has been parsed the program can be checked and executed.
+Nesting is indicated using a '+' before the prompt.
[EMAIL PROTECTED]
+       int blkmode;        /* control block parsing */
 @-
 The MAL debugger uses the client record to keep track of
 any pervasive debugger command. For detailed information
@@ -205,18 +201,17 @@
 @{
 @h
        bitset debug;
-       void  *mdb;        /* context upon suspend */
-       void  *notused;
-       str  history;                   /* where to keep console history */
-       short mode;           /* FREECLIENT..BLOCKED */
-       str cwd;            /* working directory of client */
+       void  *mdb;            /* context upon suspend */
+       str    history;        /* where to keep console history */
+       short  mode;           /* FREECLIENT..BLOCKED */
 @-
 Client records are organized into a two-level dependency
 tree, where children may be created to deal with parallel processing
 activities. Each client runs in its own process thread. Its identity
 is retained here for access by others (=father).
 @h
-       Thread      mythread;
+       MT_Sema         s;          /* sema to (de)activate thread */ 
+       Thread          mythread;
        size_t          mypid;
        str             errbuf;     /* location of GDK exceptions */
        struct CLIENT   *father;    
@@ -237,8 +232,8 @@
 a request has been received and we have to wait for
 the next one. 
 @h
-       int                     actions;
-       lng                     totaltime;      /* sum of elapsed processing 
times */
+       int             actions;
+       lng             totaltime;      /* sum of elapsed processing times */
 #ifdef HAVE_TIMES
        struct tms      workload;
 #endif
@@ -246,21 +241,24 @@
 
 mal_export ClientRec mal_clients[MAL_MAXCLIENTS+1];
 
-mal_export Client   MCgetClient   (void);
-mal_export Client   MCinitClient(oid user, bstream *fin, stream *fout);
-mal_export void     MCinitClientThread(Client c);
-mal_export void     MCcloseClient    (Client c);
-mal_export Client   MCforkClient     (Client c);
-mal_export int     MCcountClients(void);
-mal_export int      MCreadClient  (Client c);
-mal_export str     MCsuspendClient(int id, int timeout);
-mal_export str     MCawakeClient(int id);
-mal_export void     MCcleanupClients(void);
-mal_export void     MCtraceAllClients(int flag);
-mal_export void     MCtraceClient(oid which, int flag);
+mal_export Client  MCgetClient   (void);
+mal_export Client  MCfindClient(oid user, str scen, bstream *fin, stream 
*fout);
+mal_export Client  MCinitClient(oid user, bstream *fin, stream *fout);
+mal_export void    MCinitClientThread(Client c);
+mal_export void    MCcloseClient    (Client c);
+mal_export Client  MCforkClient     (Client c);
+mal_export int    MCcountClients(void);
+mal_export int     MCreadClient  (Client c);
+mal_export str    MCsuspendClient(int id, int timeout);
+mal_export str    MCawakeClient(int id);
+mal_export int     MCwait(Client c);
+mal_export void    MCcleanupClients(void);
+mal_export void    MCexitPending(void);
+mal_export void    MCtraceAllClients(int flag);
+mal_export void    MCtraceClient(oid which, int flag);
 
-mal_export void     MCpushClientInput(Client c, bstream *new_input, int 
listing, char *prompt);
-mal_export void     MCpopClientInput(Client c);
+mal_export void    MCpushClientInput(Client c, bstream *new_input, int 
listing, char *prompt);
+mal_export void    MCpopClientInput(Client c);
 
 #endif /* _MAL_CLIENT_H_ */
 @-
@@ -305,15 +303,6 @@
 
 ClientRec   mal_clients[MAL_MAXCLIENTS+1];
 
-void THRsuspend(Thread h){
-       (void) h;
-       /* printf("suspend Thread %d %d\n", h->tid, (int) h->pid);*/
-}
-void THRawake(Thread h){
-       (void) h;
-       /* printf("awake Thread %d %d\n", h->tid, (int) h->pid);*/
-}
-
 void MCpushClientInput(Client c, bstream *new_input, int listing, char *prompt)
 {
        ClientInput *x = (ClientInput*)GDKmalloc(sizeof(ClientInput));
@@ -402,8 +391,94 @@
        return NULL;
 }
 
-Client MCinitClient(oid user, bstream *fin, stream *fout) {
-       Client c;
+Client MCfindClient(oid user, str scen, bstream *fin, stream *fout) 
+{
+       Client c = NULL;
+       Scenario s = findScenario(scen);
+
+       if (!s) 
+               return NULL;
+
+       mal_set_lock(mal_contextLock, "newClient");
+       if (mal_clients[CONSOLE].user &&
+           mal_clients[CONSOLE].mode == FINISHING) {
+               showException(MAL,"newClient", "system shutdown in progress");
+               mal_unset_lock(mal_contextLock, "newClient");
+               return NULL;
+       }
+       for (c = mal_clients; c < mal_clients+MAL_MAXCLIENTS; c++) {
+               if (c->mode == AWAITING && c->scenario == s->name) {
+                       c->mode = CLAIMED;
+                       break;
+               }
+       }
+       mal_unset_lock(mal_contextLock, "newClient");
+
+       if (c == mal_clients+MAL_MAXCLIENTS) 
+               return NULL;
+#ifdef MAL_CLIENT_DEBUG
+       printf("Client found %d\n", (int)(c-mal_clients));
+#endif
+       if (c) {
+               /* TODO reset client */
+               c->user = user; 
+               c->fdin = fin ? fin : bstream_create(GDKin,0);
+               c->yycur = 0;
+               c->bak = NULL;
+
+               c->listing = 0;
+               c->fdout = fout ? fout : GDKstdout;
+               c->mdb = 0;
+
+               /* (re)activate thread */
+               MT_up_sema(c->s, "MCfindClient");
+               return c;
+       }
+       return NULL;
+}
+
+static void
+MCexitClient(Client c)
+{
+       if (c->father == NULL) { /* normal client */
+               if( c->fdout && c->fdout != GDKstdout){
+                       MPresetProfiler(c->fdout);
+                       (void) stream_close(c->fdout);
+                       (void) stream_destroy(c->fdout);
+               }
+               assert(c->bak==NULL);
+               if(c->fdin){
+                       /* missing protection against closing stdin stream */
+                       (void) stream_close(c->fdin->s);
+                       (void) stream_destroy(c->fdin->s);
+                       (void) bstream_destroy(c->fdin);
+               }
+               c->fdout = NULL;
+               c->fdin= NULL;
+       } 
+}
+
+int
+MCwait(Client c) 
+{
+       if (c != mal_clients && c->mode == FINISHING) {
+               mal_set_lock(mal_contextLock, "wait");
+               c->mode = AWAITING;
+               /* close streams */
+               MCexitClient(c);
+               /* wait for work */
+               mal_unset_lock(mal_contextLock, "wait");
+               MT_down_sema(c->s, "MSserveClient");
+               c->mythread->data[1] = c->fdin;
+               c->mythread->data[0] = c->fdout;
+               return (c->mode == CLAIMED);
+       }
+       return 1;
+}
+
+Client MCinitClient(oid user, bstream *fin, stream *fout) 
+{
+       Client c = NULL; 
        str prompt;
 
        if ((c = MCnewClient()) == NULL)
@@ -413,35 +488,22 @@
        c->scenario = NULL;
        c->oldscenario = NULL;
        c->srcFile = NULL;
-       c->sessionkey = 0;
        c->blkmode = 0;
 
        c->fdin = fin ? fin : bstream_create(GDKin,0);
-       c->console = c->fdin;
        c->yycur = 0;
        c->bak = NULL;
 
        c->listing = 0;
        c->fdout = fout ? fout : GDKstdout;
        c->mdb = 0;
-       c->notused = 0;
        c->history = 0;
[EMAIL PROTECTED]
-The output buffer is currently not used. Beware to garbage
-collect the buffer when in use.
[EMAIL PROTECTED]
-       c->output = 0;
-/*
-       if(c->nspace==0)
-               c->nspace = newModule(NULL, putName("guest",5));
-*/
        c->curprg = c->backup = 0;
        c->glb = 0;
 
        c->father = NULL;
        c->login = c->lastcmd= time(0);
        c->delay= TIMEOUT;
-       c->mode = AWAITING;
        c->stage = 0;
        c->itrace = 0;
        c->debugOptimizer = c->debugScheduler= 0;
@@ -450,15 +512,16 @@
        c->vmfoot = 0;
        c->errbuf = 0;
 
-       c->cwd= GDKstrdup(monet_cwd);
        prompt = !fin? GDKgetenv("monet_prompt"): PROMPT1;
        c->prompt= GDKstrdup(prompt);
        c->promptlength= strlen(prompt);
 
        c->actions =0;
        c->totaltime= 0;
+       MT_init_sema(c->s, 0, "MCinitClient");
        return c;
 }
+
 @-
 The administrator should be initialized to enable
 interpretation of the command line arguments, before
@@ -468,11 +531,7 @@
 {
        Thread t;
        char cname[11 + 1];
-/*     still unsafe, race conditions, garbage left over??
-       if( c->mythread){
-               t= c->mythread;
-       } else
-*/
+
        snprintf(cname, 11, SZFMT, (size_t)(c->user));
        cname[11] = '\0';
        c->mypid = MT_getpid();
@@ -555,24 +614,7 @@
        Thread t= c->mythread;
        c->mode = FINISHING;
 
-       /* epilogue actions have been done already */
-       if (c->father == NULL) { /* normal client */
-               if( c->fdout && c->fdout != GDKstdout){
-                       MPresetProfiler(c->fdout);
-                       (void) stream_close(c->fdout);
-                       (void) stream_destroy(c->fdout);
-               }
-               assert(c->bak==NULL);
-               if(c->fdin){
-                       /* missing protection against closing stdin stream */
-                       (void) stream_close(c->fdin->s);
-                       (void) stream_destroy(c->fdin->s);
-                       (void) bstream_destroy(c->fdin);
-               }
-               c->fdout = NULL;
-               c->fdin= NULL;
-       } 
-       /* forked client also */
+       MCexitClient(c);
 
        /* scope list and curprg can not be removed, 
           because the client may reside in a
@@ -586,10 +628,10 @@
                c->nspace=0;
        }
           */
-       /* re-use output buffer */
        c->scenario = NULL;
-       if(c->prompt) GDKfree(c->prompt); c->prompt = NULL;
-       if(c->cwd) GDKfree(c->cwd); c->cwd = NULL;
+       if(c->prompt) 
+               GDKfree(c->prompt); 
+       c->prompt = NULL;
        c->promptlength=-1;
        if(c->errbuf){
                GDKsetbuf(0);
@@ -607,7 +649,6 @@
        c->mode = FREECLIENT;
        if (t) 
                THRdel(t);      /* you may perform suicide */
-       /* THRsuspend(c->mythread); still unsafe */
 }
 
 @-
@@ -646,29 +687,31 @@
        Client c;
        for(c = mal_clients; c < mal_clients+MAL_MAXCLIENTS; c++) {
                /* if( c->nspace){ freeModuleList(c->nspace); c->nspace=0;}*/
-               if( c->cwd){ 
-                       GDKfree(c->cwd); 
-                       c->cwd = NULL;
-               }
-               if( c->prompt){ 
+               if( c->prompt) { 
                        GDKfree(c->prompt); 
                        c->prompt = NULL;
                }
                c->user = oid_nil;
                assert(c->bak==NULL);
-               if( c->fdin){
-                       (void) stream_close(c->fdin->s);
-                       (void) stream_destroy(c->fdin->s); 
-                       (void) bstream_destroy(c->fdin);
-                       c->fdin= NULL;
-               }
-               if( c->fdout && c->fdout != GDKstdout){
-                       MPresetProfiler(c->fdout);
-                       (void) stream_destroy(c->fdout); 
-                       c->fdout= NULL;
+               MCexitClient(c);
+       }
+}
+void 
+MCexitPending()
+{
+       Client c;
+
+       mal_set_lock(mal_contextLock, "MCexitPending");
+       for (c = mal_clients+1; c < mal_clients+MAL_MAXCLIENTS; c++) {
+               if (c->mode == AWAITING) {
+                       c->mode = FINISHING;
+                       /* (re)activate thread */
+                       MT_up_sema(c->s, "MCfindClient");
                }
        }
+       mal_unset_lock(mal_contextLock, "MCexitPending");
 }
+
 str
 MCsuspendClient(int id, int timeout){
        if( id<0 || id>MAL_MAXCLIENTS)

Index: mal_authorize.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_authorize.mx,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- mal_authorize.mx    29 Oct 2007 20:09:54 -0000      1.53
+++ mal_authorize.mx    6 Nov 2007 23:20:52 -0000       1.54
@@ -47,7 +47,7 @@
 mal_export str AUTHremoveScenario(str *username, str *scenario);
 mal_export str AUTHresolveUser(str *ret, oid *uid);
 mal_export str AUTHgetUsername(str *ret);
-mal_export str AUTHgetUsers(bat *ret, bat *scenarios);
+mal_export str AUTHgetUsers(BAT **ret, bat *scenarios);
 
 mal_export str AUTHrequireAdmin(void);
 mal_export str AUTHrequirteAdminOrUser(str *username);
@@ -777,7 +777,7 @@
  * scenarios.
  */
 str
-AUTHgetUsers(bat *ret, bat *scenarios) {
+AUTHgetUsers(BAT **ret, bat *scenarios) {
        BAT *b, *r;
        str tmp;
 
@@ -822,10 +822,8 @@
                BBPunfix(*scenarios);
        } else {
                r = BATcopy(user, user->htype, user->ttype, FALSE);
-               BBPunfix(*scenarios);
        }
-
-       *ret = BBPcacheid(r);
+       *ret = r;
        return(NULL);
 }
 

Index: mal_debugger.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_debugger.mx,v
retrieving revision 1.210
retrieving revision 1.211
diff -u -d -r1.210 -r1.211
--- mal_debugger.mx     4 Oct 2007 10:37:06 -0000       1.210
+++ mal_debugger.mx     6 Nov 2007 23:20:53 -0000       1.211
@@ -869,7 +869,7 @@
                                break;
                        if(cntxt->mode == FINISHING)
                                break;
-               } else {
+               } else if (cntxt == mal_clients) {
                        /* switch to mdb streams */
                        r= readConsole(cntxt);
                        if( r <= 0)
@@ -1194,8 +1194,8 @@
                                if( *b == 0){
                                        strcat(fname,name+1);
                                } else
-                               if( cntxt->cwd && *b !='/'){
-                                       strcpy(fname,cntxt->cwd);
+                               if( monet_cwd && *b !='/'){
+                                       strcpy(fname,monet_cwd);
                                        strcat(fname,name);
                                } else 
                                        strcat(fname,name+1);

Index: mal_interpreter.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_interpreter.mx,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -d -r1.202 -r1.203
--- mal_interpreter.mx  4 Oct 2007 13:04:44 -0000       1.202
+++ mal_interpreter.mx  6 Nov 2007 23:20:54 -0000       1.203
@@ -61,7 +61,6 @@
 mal_export ptr getArgValue(MalStkPtr stk, InstrPtr pci, int k);
 mal_export ptr getArgReference(MalStkPtr stk, InstrPtr pci, int k);
 
-#define VALcopy2(lhs,rhs) if( (rhs)->vtype < TYPE_str) *lhs = *rhs; else 
VALcopy(lhs,rhs);
 #endif /*  _MAL_INTERPRET_H*/
 @c
 #include "mal_config.h"
@@ -201,7 +200,7 @@
        if( isConstant(mb,i) > 0 ){
                lhs = &stk->stk[i];
                rhs = &getConstant(mb,i);
-               VALcopy2(lhs,rhs);
+               VALcopy(lhs,rhs);
        } else {
                lhs = &stk->stk[i];
                lhs->vtype = getVarGDKType(mb,i);
@@ -296,7 +295,7 @@
                        if( k== pp->argc-1) k--; 
 
                        rhs = &env->stk[pci->argv[i]];
-                       VALcopy2(lhs,rhs);
+                       VALcopy(lhs,rhs);
                        if( lhs->vtype == TYPE_bat)
                                BBPincref(lhs->val.br.id, TRUE);
                }
@@ -398,7 +397,7 @@
                assert(stk);
                for(i=pci->retc; i<pci->argc; i++){
                        lhs= &stk->stk[pci->argv[i]];
-                       VALcopy2(lhs, argv[i]);
+                       VALcopy(lhs, argv[i]);
                        if( lhs->vtype == TYPE_bat)
                                BBPincref(lhs->val.br.id,TRUE);
                }
@@ -900,7 +899,7 @@
                                for(i=0;i < pci->retc; i++){
                                        rhs = &stk->stk[pp->argv[i]];
                                        lhs = &env->stk[pci->argv[i]];
-                                       VALcopy2(lhs,rhs);
+                                       VALcopy(lhs,rhs);
                                        if( lhs->vtype == TYPE_bat )
                                                BBPincref(lhs->val.br.id, 
TRUE); 
                                }
@@ -937,7 +936,7 @@
        for(k=0, i=pci->retc; k<pci->retc && i<pci->argc; i++,k++){
                lhs = &stk->stk[pci->argv[k]];
                rhs = &stk->stk[pci->argv[i]];
-               VALcopy2(lhs,rhs);
+               VALcopy(lhs,rhs);
                if( lhs->vtype == TYPE_bat)
                        BBPincref(lhs->val.br.id, TRUE);
        }
@@ -1022,16 +1021,12 @@
                        /* update the bigfoot information */
                        updateBigFoot(cntxt, bid, TRUE);
                        /* BAT *b;*/
-                       if( backup[i] ){
-                               if( backup[i]== bid){
-                                       /* target and source are identical, 
which means its
-                                          logical reference count is one too 
high . */
-                                       BBPreleaselref(backup[i]);
-                               } else { 
+                       if (backup[i]){
+                               if (backup[i] != bid) {
                                        /* possible garbage collect the 
variable */
                                        updateBigFoot(cntxt, backup[i], FALSE);
-                                       BBPdecref(backup[i],TRUE);
                                }
+                               BBPdecref(backup[i], TRUE);
                                backup[i]=0;
                                sbackup[i]=0;
                        } 

Index: mal_readline.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_readline.mx,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- mal_readline.mx     15 Sep 2007 08:11:34 -0000      1.55
+++ mal_readline.mx     6 Nov 2007 23:20:55 -0000       1.56
@@ -474,17 +474,16 @@
        return line;
 }
 int 
-readConsole(Client cntxt){
+readConsole(Client cntxt)
+{
        /* execute from stdin */
        struct stat statb;
        char *buf;
 
-       if( cntxt->promptlength == 0)
+       assert(cntxt == mal_clients);
+       if (cntxt->promptlength == 0 || 
+          !(fstat(fileno(stdin), &statb) == 0 && S_ISCHR(statb.st_mode))  )
                return -1;
-       if( cntxt->fdin->s == cntxt->console->s){
-               if ( !(fstat(fileno(stdin), &statb) == 0 && 
S_ISCHR(statb.st_mode))  )
-                       return -1;
-       }
 
        /* read lines and move string to client buffer. */
 #ifdef HAVE_LIBREADLINE


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to