tcl-mod_dtcl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject cvs commit: tcl-moddtcl mod_dtcl.c mod_dtcl.h tcl_commands.c
Date Thu, 28 Jun 2001 15:31:50 GMT
davidw      01/06/28 08:31:49

  Modified:    .        mod_dtcl.c mod_dtcl.h tcl_commands.c
  Log:
  More globals removed.  Still runs.
  
  Revision  Changes    Path
  1.35      +49 -48    tcl-moddtcl/mod_dtcl.c
  
  Index: mod_dtcl.c
  ===================================================================
  RCS file: /home/cvs/tcl-moddtcl/mod_dtcl.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- mod_dtcl.c	2001/06/25 23:30:01	1.34
  +++ mod_dtcl.c	2001/06/28 15:31:33	1.35
  @@ -57,7 +57,7 @@
    * originally written at the National Center for Supercomputing Applications,
    * University of Illinois, Urbana-Champaign.  */
   
  -/* $Id: mod_dtcl.c,v 1.34 2001/06/25 23:30:01 davidw Exp $  */
  +/* $Id: mod_dtcl.c,v 1.35 2001/06/28 15:31:33 davidw Exp $  */
   
   /* mod_dtcl.c by David Welton <davidw@apache.org> - originally mod_include.  */
   /* See http://tcl.apache.org/mod_dtcl/credits.ttml for additional credits. */
  @@ -94,19 +94,18 @@
   static Tcl_Obj *namespacePrologue;      /* initial bit of Tcl for namespace creation */
   module MODULE_VAR_EXPORT dtcl_module;
   
  -static char **objCacheList; 		/* Array of cached objects (for priority handling) */
  -static Tcl_HashTable objCache; 		/* Objects cache - the key is the script name */
   
  -int buffer_output = 0;           /* Start with output buffering off */
  +int buffer_output = 0;          /* Start with output buffering off */
   int headers_printed = 0; 	/* has the header been printed yet? */
  -static int headers_set = 0; 	        /* has the header been set yet? */
  -int content_sent = 0;            /* make sure something gets sent */
  +static int headers_set = 0;     /* has the header been set yet? */
  +int content_sent = 0;           /* make sure something gets sent */
   
   //dtcl_interp_globals globals;
   
   #define GETREQINTERP(req) ((dtcl_server_conf *)ap_get_module_config(req->server->module_config,
&dtcl_module))->server_interp
   
   static void tcl_init_stuff(server_rec *s, pool *p);
  +static int get_ttml_file(request_rec *r, dtcl_server_conf *dsc, Tcl_Interp *interp, char
*filename, int toplevel, Tcl_Obj *outbuf);
   static int send_content(request_rec *);
   static int execute_and_check(Tcl_Interp *interp, Tcl_Obj *outbuf, request_rec *r);
   
  @@ -381,7 +380,7 @@
   
   /* Parse and execute a ttml file */
   
  -static int get_ttml_file(request_rec *r, Tcl_Interp *interp, char *filename, int toplevel,
Tcl_Obj *outbuf)
  +static int get_ttml_file(request_rec *r, dtcl_server_conf *dsc, Tcl_Interp *interp, char
*filename, int toplevel, Tcl_Obj *outbuf)
   {
       /* BEGIN PARSER  */
       char inside = 0;	/* are we inside the starting/ending delimiters  */
  @@ -395,9 +394,6 @@
   
       FILE *f = NULL;
   
  -    dtcl_server_conf *conf = NULL;
  -    conf = dtcl_get_conf(r);
  -
       if (!(f = ap_pfopen(r->pool, filename, "r")))
       {
   	ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
  @@ -409,8 +405,8 @@
       if (toplevel)
       {
   	Tcl_SetStringObj(outbuf, "namespace eval request {\n", -1);
  -	if (conf->dtcl_before_script)
  -	    Tcl_AppendObjToObj(outbuf, conf->dtcl_before_script);
  +	if (dsc->dtcl_before_script)
  +	    Tcl_AppendObjToObj(outbuf, dsc->dtcl_before_script);
   	Tcl_AppendToObj(outbuf, "buffer_add \"", -1);
       }
       else
  @@ -525,8 +521,8 @@
   
       if (toplevel)
       {
  -	if (conf->dtcl_after_script)
  -	    Tcl_AppendObjToObj(outbuf, conf->dtcl_after_script);
  +	if (dsc->dtcl_after_script)
  +	    Tcl_AppendObjToObj(outbuf, dsc->dtcl_after_script);
   
   /* 	Tcl_AppendToObj(outbuf, "\n}\nnamespace delete request\n", -1); seems redundant */
   	Tcl_AppendToObj(outbuf, "\n}\n", -1);
  @@ -581,7 +577,7 @@
   
   /* This is a seperate function so that it may be called from 'Parse' */
   
  -int get_parse_exec_file(request_rec *r, int toplevel)
  +int get_parse_exec_file(request_rec *r, dtcl_server_conf *dsc, int toplevel)
   {
       char *hashKey = NULL;
       int isNew = 0;
  @@ -591,16 +587,14 @@
       Tcl_HashEntry *entry = NULL;
       Tcl_Interp *interp = GETREQINTERP(r);
   
  -    dtcl_server_conf *dsc = (dtcl_server_conf *)ap_get_module_config(r->server->module_config,
&dtcl_module);
  -
       /* Look for the script's compiled version. If it's not found,
          create it. */
  -    if (dsc->cache_size)
  +    if (*(dsc->cache_size))
       {
   	hashKey = ap_psprintf(r->pool, "%s%ld%ld%d", r->filename, r->finfo.st_mtime,
r->finfo.st_ctime, toplevel);
  -	entry = Tcl_CreateHashEntry(&objCache, hashKey, &isNew);
  +	entry = Tcl_CreateHashEntry(dsc->objCache, hashKey, &isNew);
       }
  -    if (isNew || !dsc->cache_size)
  +    if (isNew || *(dsc->cache_size) == 0)
       {
   	outbuf = Tcl_NewObj();
   	Tcl_IncrRefCount(outbuf);
  @@ -608,7 +602,7 @@
   	if(!strcmp(r->content_type, "application/x-httpd-tcl"))
   	{
   	    /* It's a TTML file  */
  -	    result = get_ttml_file(r, interp, r->filename, 1, outbuf);
  +	    result = get_ttml_file(r, dsc, interp, r->filename, 1, outbuf);
   	} else {
   	    /* It's a plain Tcl file */
   	    result = get_tcl_file(r, interp, r->filename, &(r->finfo), outbuf);
  @@ -616,20 +610,19 @@
   	if (result != TCL_OK)
   	    return result;
   
  -	if (dsc->cache_size)
  +	if (*(dsc->cache_size))
   	    Tcl_SetHashValue(entry, (ClientData)outbuf);
   
  -	if (dsc->cache_free) {
  -	    /* This MUST be malloc-ed, because it's permanent */
  -	    objCacheList[--(dsc->cache_free) ] = strdup(hashKey);
  -	} else if (dsc->cache_size) { /* if it's zero, we just skip this... */
  +	if (*(dsc->cache_free)) {
  +	    dsc->objCacheList[-- *(dsc->cache_free) ] = strdup(hashKey);
  +	} else if (*(dsc->cache_size)) { /* if it's zero, we just skip this... */
   	    Tcl_HashEntry *delEntry;
  -	    delEntry = Tcl_FindHashEntry(&objCache, objCacheList[dsc->cache_size - 1]);
  +	    delEntry = Tcl_FindHashEntry(dsc->objCache, dsc->objCacheList[*(dsc->cache_size)
- 1]);
   	    Tcl_DecrRefCount((Tcl_Obj *)Tcl_GetHashValue(delEntry));
   	    Tcl_DeleteHashEntry(delEntry);
  -	    free(objCacheList[dsc->cache_size - 1]);
  -	    memmove(objCacheList + 1, objCacheList, sizeof(char *)*(dsc->cache_size -1));
  -	    objCacheList[0] = strdup(hashKey);
  +	    free(dsc->objCacheList[*(dsc->cache_size) - 1]);
  +	    memmove((dsc->objCacheList) + 1, dsc->objCacheList, sizeof(char *) * (*(dsc->cache_size)
-1));
  +	    dsc->objCacheList[0] = strdup(hashKey);
   	}
       } else {
   	outbuf = (Tcl_Obj *)Tcl_GetHashValue(entry);
  @@ -650,7 +643,6 @@
       Tcl_Interp *interp;
   
       dtcl_server_conf *dsc;
  -    ApacheUpload *upload;
   
       dtcl_interp_globals globals;
       globals.r = r;		/* Assign request to global request var */
  @@ -804,7 +796,7 @@
       }
   #endif /* USE_ONLY_UPLOAD_COMMAND == 1 */
   
  -    get_parse_exec_file(r, 1);
  +    get_parse_exec_file(r, dsc, 1);
       /* reset globals  */
       buffer_output = 0;
       headers_printed = 0;
  @@ -840,7 +832,6 @@
       Tcl_Interp *interp;
       dtcl_server_conf *dsc = (dtcl_server_conf *) ap_get_module_config(s->module_config,
&dtcl_module);
       server_rec *sr;
  -
       /* Initialize TCL stuff  */
   
       interp = Tcl_CreateInterp();
  @@ -878,7 +869,7 @@
   
   #if DBG
       ap_log_error(APLOG_MARK, APLOG_ERR, s, "Config string = \"%s\"", Tcl_GetStringFromObj(dsc->dtcl_global_init_script,
NULL));  /* XXX */
  -    ap_log_error(APLOG_MARK, APLOG_ERR, s, "Cache size = \"%d\"", dsc->dtcl_dsc->cache_size);
 /* XXX */
  +    ap_log_error(APLOG_MARK, APLOG_ERR, s, "Cache size = \"%d\"", *(dsc->cache_size));
 /* XXX */
   #endif
   
       if (dsc->dtcl_global_init_script != NULL)
  @@ -892,19 +883,19 @@
       }
   
       /* This is what happens if it is not set by the user */
  -    if(dsc->cache_size < 0)
  +    if(*(dsc->cache_size) < 0)
       {
   	if (ap_max_requests_per_child != 0)
  -	    dsc->cache_size = ap_max_requests_per_child / 2;
  +	    *(dsc->cache_size) = ap_max_requests_per_child / 2;
   	else
  -	    dsc->cache_size = 10; /* Arbitrary number FIXME */
  -	dsc->cache_free = dsc->cache_size;
  -    } else if (dsc->cache_size > 0) {
  -	dsc->cache_free = dsc->cache_size;
  +	    *(dsc->cache_size) = 10; /* Arbitrary number FIXME */
  +	*(dsc->cache_free) = *(dsc->cache_size);
  +    } else if (*(dsc->cache_size) > 0) {
  +	*(dsc->cache_free) = *(dsc->cache_size);
       }
       /* Initializing cache structures */
  -    objCacheList = malloc(dsc->cache_size * sizeof(char *));
  -    Tcl_InitHashTable(&objCache, TCL_STRING_KEYS);
  +    dsc->objCacheList = ap_pcalloc(p, *(dsc->cache_size) * sizeof(char *));
  +    Tcl_InitHashTable(dsc->objCache, TCL_STRING_KEYS);
   
       sr = s;
       while (sr)
  @@ -979,7 +970,7 @@
   {
       server_rec *s = cmd->server;
       dtcl_server_conf *dsc = (dtcl_server_conf *)ap_get_module_config(s->module_config,
&dtcl_module);
  -    dsc->cache_size = strtol(arg, NULL, 10);
  +    *(dsc->cache_size) = strtol(arg, NULL, 10);
       return NULL;
   }
   
  @@ -1025,6 +1016,10 @@
   	newconfig->dtcl_before_script = ddc->dtcl_before_script ? ddc->dtcl_before_script
: dsc->dtcl_before_script;
   	newconfig->dtcl_after_script = ddc->dtcl_after_script ? ddc->dtcl_after_script
: dsc->dtcl_after_script;
   	newconfig->dtcl_error_script = ddc->dtcl_error_script ? ddc->dtcl_error_script
: dsc->dtcl_error_script;
  +	newconfig->cache_size = dsc->cache_size;
  +	newconfig->cache_free = dsc->cache_free;
  +	newconfig->objCacheList = dsc->objCacheList;
  +	newconfig->objCache = dsc->objCache;
   	return newconfig;
       }
       return dsc;
  @@ -1040,11 +1035,17 @@
       dsc->dtcl_before_script = NULL;
       dsc->dtcl_after_script = NULL;
       dsc->dtcl_error_script = NULL;
  -    dsc->cache_size = -1;
  -    dsc->cache_free = 0;
  +    
  +    /* these are pointers so that they can be passed around...  */
  +    dsc->cache_size = ap_pcalloc(p, sizeof(int));
  +    dsc->cache_free = ap_pcalloc(p, sizeof(int));
  +    *(dsc->cache_size) = -1;
  +    *(dsc->cache_free) = 0;
       dsc->upload_max = 0;
  -    dsc->upload_dir = "/tmp";
       dsc->server_name = ap_pstrdup(p, s->server_hostname);
  +    dsc->upload_dir = "/tmp";
  +    dsc->objCacheList = NULL;
  +    dsc->objCache = ap_pcalloc(p, sizeof(Tcl_HashTable));
       return dsc;
   }
   
  @@ -1077,8 +1078,8 @@
   
       dsc->dtcl_error_script = overrides->dtcl_error_script ? overrides->dtcl_error_script
: base->dtcl_error_script;
   
  -    dsc->cache_size = overrides->cache_size ? overrides->cache_size : base->cache_size;
  -    dsc->cache_free = overrides->cache_free ? overrides->cache_free : base->cache_free;
  +/*     dsc->cache_size = overrides->cache_size ? overrides->cache_size : base->cache_size;
  +    dsc->cache_free = overrides->cache_free ? overrides->cache_free : base->cache_free;
 */
       dsc->upload_max = overrides->upload_max ? overrides->upload_max : base->upload_max;
       dsc->upload_files_to_var = overrides->upload_files_to_var ? overrides->upload_files_to_var
: base->upload_files_to_var;
       dsc->server_name = overrides->server_name ? overrides->server_name : base->server_name;
  
  
  
  1.8       +7 -4      tcl-moddtcl/mod_dtcl.h
  
  Index: mod_dtcl.h
  ===================================================================
  RCS file: /home/cvs/tcl-moddtcl/mod_dtcl.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- mod_dtcl.h	2001/06/25 23:30:02	1.7
  +++ mod_dtcl.h	2001/06/28 15:31:36	1.8
  @@ -61,19 +61,22 @@
       Tcl_Obj *dtcl_before_script;        /* script run before each page */
       Tcl_Obj *dtcl_after_script;         /*            after            */
       Tcl_Obj *dtcl_error_script;         /*            for errors */
  -    int cache_size;
  -    int cache_free;
  +    int *cache_size;
  +    int *cache_free;
       int upload_max;
       int upload_files_to_var;
       char *server_name;
       char *upload_dir;
  +
  +    char **objCacheList;    /* Array of cached objects (for priority handling) */
  +    Tcl_HashTable *objCache; /* Objects cache - the key is the script name */
   } dtcl_server_conf;
   
   /* eventually we will transfer 'global' variables in here and
      'de-globalize' them */
   
   typedef struct {
  -    request_rec *r;		/* request rec */
  +    request_rec *r;         /* request rec */
       ApacheRequest *req;     /* libapreq request  */
   } dtcl_interp_globals;
   
  @@ -83,7 +86,7 @@
   } obuff;
   
   int memwrite(obuff *, char *, int);
  -int get_parse_exec_file(request_rec *r,  int toplevel);
  +int get_parse_exec_file(request_rec *r, dtcl_server_conf *dsc, int toplevel);
   int set_header_type(request_rec *, char *);
   int print_headers(request_rec *);
   int print_error(request_rec *, int, char *);
  
  
  
  1.12      +3 -2      tcl-moddtcl/tcl_commands.c
  
  Index: tcl_commands.c
  ===================================================================
  RCS file: /home/cvs/tcl-moddtcl/tcl_commands.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- tcl_commands.c	2001/06/25 23:30:03	1.11
  +++ tcl_commands.c	2001/06/28 15:31:37	1.12
  @@ -36,6 +36,7 @@
       struct stat finfo;
   
       dtcl_interp_globals *globals = Tcl_GetAssocData(interp, "dtcl", NULL);
  +    dtcl_server_conf *dsc = dtcl_get_conf(globals->r);
   
       if (objc != 2)
       {
  @@ -55,7 +56,7 @@
   	Tcl_AddErrorInfo(interp, Tcl_PosixError(interp));
   	return TCL_ERROR;
       }
  -    if (get_parse_exec_file(globals->r, 0) == OK)
  +    if (get_parse_exec_file(globals->r, dsc, 0) == OK)
   	return TCL_OK;
       else
   	return TCL_ERROR;
  @@ -824,7 +825,7 @@
   		       "<tr><td><font color=\"#ffffff\">Free cache size: %d</font><br></td></tr>\n"
   		       "<tr><td><font color=\"#ffffff\">PID: %d</font><br></td></tr>\n"
   		       "</table>\n"
  -		       "</td></tr></table>\n", dsc->cache_free, getpid());
  +		       "</td></tr></table>\n", *(dsc->cache_free), getpid());
   /*     print_headers(globals->r);
       flush_output_buffer(globals->r);  */
       memwrite(&obuffer, tble, strlen(tble));
  
  
  

Mime
View raw message