You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2014/02/02 23:50:25 UTC

svn commit: r1563742 - in /tcl/rivet/trunk: ChangeLog src/apache-2/TclWebapache.c src/apache-2/mod_rivet.c src/apache-2/mod_rivet.h src/rivetcmds/rivetInspect.c

Author: mxmanghi
Date: Sun Feb  2 22:50:24 2014
New Revision: 1563742

URL: http://svn.apache.org/r1563742
Log:
    * src/apache-2/mod_rivet.[c|h]: further optimizing code avoiding to
    allocate a TclWebRequest structure on every request. This structure
    is allocate when the interpreter is initialized and a pointer
    stored in rivet globals
    * src/rivetcmd/rivetInspect.c: impoved consistence if Tcl objects handling


Modified:
    tcl/rivet/trunk/ChangeLog
    tcl/rivet/trunk/src/apache-2/TclWebapache.c
    tcl/rivet/trunk/src/apache-2/mod_rivet.c
    tcl/rivet/trunk/src/apache-2/mod_rivet.h
    tcl/rivet/trunk/src/rivetcmds/rivetInspect.c

Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1563742&r1=1563741&r2=1563742&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Sun Feb  2 22:50:24 2014
@@ -1,3 +1,10 @@
+2013-02-02 Massimo Manghi <mx...@apache.org>
+    * src/apache-2/mod_rivet.[c|h]: further optimizing code avoiding to
+    allocate a TclWebRequest structure on every request. This structure
+    is allocate when the interpreter is initialized and a pointer
+    stored in rivet globals
+    * src/rivetcmd/rivetInspect.c: impoved consistence if Tcl objects handling
+
 2014-01-30 Massimo Manghi <mx...@apache.org>
     * src/apache-2/mod_rivet.c: this ChangeLog entry is meant to amend the
     2014-01-27 entry that missed to point out as small still important change

Modified: tcl/rivet/trunk/src/apache-2/TclWebapache.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/TclWebapache.c?rev=1563742&r1=1563741&r2=1563742&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/TclWebapache.c (original)
+++ tcl/rivet/trunk/src/apache-2/TclWebapache.c Sun Feb  2 22:50:24 2014
@@ -55,15 +55,19 @@ else if (source == VAR_SRC_POST) { i = r
 int
 TclWeb_InitRequest(TclWebRequest *req, Tcl_Interp *interp, void *arg)
 {
-    request_rec *r;
+    request_rec *r = (request_rec *)arg;
 
-    r = (request_rec *)arg;
     req->interp = interp;
     req->req = r;
     req->apachereq = ApacheRequest_new(r);
     req->headers_printed = 0;
     req->headers_set = 0;
     req->environment_set = 0;
+
+    /* we will test against NULL to check if a charset 
+       was specified in the conf */
+
+    req->charset = NULL;
     return TCL_OK;
 }
 

Modified: tcl/rivet/trunk/src/apache-2/mod_rivet.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/mod_rivet.c?rev=1563742&r1=1563741&r2=1563742&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/apache-2/mod_rivet.c Sun Feb  2 22:50:24 2014
@@ -713,6 +713,7 @@ Rivet_PerInterpInit(server_rec *s, rivet
                                             (Tcl_NamespaceDeleteProc *)NULL);
     globals->page_aborting = 0;
     globals->abort_code = NULL;
+    globals->tclwebreq = (TclWebRequest *)apr_pcalloc(p, sizeof(TclWebRequest));
 
     /* Eval Rivet's init.tcl file to load in the Tcl-level commands. */
 
@@ -1254,11 +1255,6 @@ Rivet_SendContent(request_rec *r)
     interp = rsc->server_interp;
     globals = Tcl_GetAssocData(interp, "rivet", NULL);
     globals->r = r;
-    globals->req = (TclWebRequest *)apr_pcalloc(r->pool, sizeof(TclWebRequest));
-
-/* we will test against NULL to check if a charset was specified in the conf */
-
-    globals->req->charset = NULL;
 
 #ifndef USE_APACHE_RSC
     if (r->per_dir_config != NULL)
@@ -1347,6 +1343,9 @@ Rivet_SendContent(request_rec *r)
     }
 
     /* Apache Request stuff */
+
+    //globals->req = (TclWebRequest *)apr_pcalloc(r->pool, sizeof(TclWebRequest));
+    globals->req = globals->tclwebreq;
     TclWeb_InitRequest(globals->req, interp, r);
     ApacheRequest_set_post_max(globals->req->apachereq, rsc->upload_max);
     ApacheRequest_set_temp_dir(globals->req->apachereq, rsc->upload_dir);
@@ -1391,7 +1390,7 @@ Rivet_SendContent(request_rec *r)
         int content_type_len = strlen(r->content_type);
 
         if (((ctype==RIVET_TEMPLATE) && (content_type_len > strlen(RIVET_TEMPLATE_CTYPE))) || \
-             ((ctype==RIVET_TCLFILE)  && (content_type_len > strlen(RIVET_TCLFILE_CTYPE)))) {
+             ((ctype==RIVET_TCLFILE) && (content_type_len > strlen(RIVET_TCLFILE_CTYPE)))) {
             
             char* charset;
 
@@ -1442,6 +1441,10 @@ sendcleanup:
         globals->abort_code = NULL;
     }
 
+    /* We reset this pointer to signal we have terminated the request processing */
+
+    globals->r = NULL;
+
     Tcl_MutexUnlock(&sendMutex);
     return retval;
 }

Modified: tcl/rivet/trunk/src/apache-2/mod_rivet.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/mod_rivet.h?rev=1563742&r1=1563741&r2=1563742&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/mod_rivet.h (original)
+++ tcl/rivet/trunk/src/apache-2/mod_rivet.h Sun Feb  2 22:50:24 2014
@@ -96,7 +96,7 @@ typedef struct _rivet_server_conf {
     apr_table_t *rivet_server_vars;
     apr_table_t *rivet_dir_vars;
     apr_table_t *rivet_user_vars;
-    char **objCacheList;		    /* Array of cached objects (for priority handling) */
+    char **objCacheList;		        /* Array of cached objects (for priority handling) */
     Tcl_HashTable *objCache;		    /* Objects cache - the key is the script name */
 
     Tcl_Channel *outchannel;		    /* stuff for buffering output */
@@ -105,12 +105,14 @@ typedef struct _rivet_server_conf {
 /* eventually we will transfer 'global' variables in here and 'de-globalize' them */
 
 typedef struct _rivet_interp_globals {
-    request_rec     *r;			    /* request rec */
-    TclWebRequest   *req;	            /* TclWeb API request */
-    Tcl_Namespace   *rivet_ns;              /* Rivet commands namespace */
-    int             page_aborting;	    /* set by abort_page. */
-					    /* to be reset by Rivet_SendContent */
-    Tcl_Obj*        abort_code;
+    request_rec     *r;			        /* request rec              */
+    TclWebRequest   *req;	            /* TclWeb API request       */
+    Tcl_Namespace   *rivet_ns;          /* Rivet commands namespace */
+    int             page_aborting;	    /* set by abort_page.       */
+    Tcl_Obj*        abort_code;			/* To be reset by Rivet_SendContent */
+    TclWebRequest   *tclwebreq;         /* We reset 'req' upon request processing completion
+                                           but we don't want to reallocate this on every req 
+                                           therefore this pointer stores the */
 } rivet_interp_globals;
 
 int Rivet_ParseExecFile(TclWebRequest *req, char *filename, int toplevel);

Modified: tcl/rivet/trunk/src/rivetcmds/rivetInspect.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/rivetcmds/rivetInspect.c?rev=1563742&r1=1563741&r2=1563742&view=diff
==============================================================================
--- tcl/rivet/trunk/src/rivetcmds/rivetInspect.c (original)
+++ tcl/rivet/trunk/src/rivetcmds/rivetInspect.c Sun Feb  2 22:50:24 2014
@@ -39,6 +39,8 @@
 
 #include "mod_rivet.h"
 
+/* These arrays must be kept aligned. confDirectives must be NULL terminated */
+
 static const char* confDirectives[] = 
 { 
                     "ServerInitScript", 
@@ -194,7 +196,7 @@ Rivet_ReadConfParameter ( Tcl_Interp* in
         par_value=Tcl_NewStringObj("<undef>",-1);
     }
 
-    Tcl_IncrRefCount(par_value);
+    //Tcl_IncrRefCount(par_value);
 
     return par_value;
 }
@@ -213,31 +215,24 @@ Rivet_ReadConfParameter ( Tcl_Interp* in
  *
  */
 
-Tcl_Obj* Rivet_ReadConfTable (  Tcl_Interp*           interp,
-                                apr_table_t*          table)
+static Tcl_Obj* 
+Rivet_ReadConfTable (Tcl_Interp*   interp,
+                     apr_table_t*  table)
 {
-    Tcl_Obj*                key;
-    Tcl_Obj*                val;
-    apr_array_header_t      *arr;
-    apr_table_entry_t       *elts;
-    int                     nelts,i;
-    int                     tcl_status = TCL_OK;
-    Tcl_Obj*                keyval_list = Tcl_NewObj();
+    Tcl_Obj*            key;
+    Tcl_Obj*            val;
+    apr_array_header_t *arr;
+    apr_table_entry_t  *elts;
+    int                 nelts,i;
+    int                 tcl_status  = TCL_OK;
+    Tcl_Obj*            keyval_list = Tcl_NewObj();
 
-    Tcl_IncrRefCount(keyval_list);
+    //Tcl_IncrRefCount(keyval_list);
 
     arr   = (apr_array_header_t*) apr_table_elts( table );
     elts  = (apr_table_entry_t *) arr->elts;
     nelts = arr->nelts;
 
-/*
-    if (Tcl_IsShared(keyval_list))
-    {
-        fprintf(stderr,"building duplicate keyval_list\n");
-        keyval_list = Tcl_DuplicateObj(keyval_list);
-    }
- */
-
     for (i = 0; i < nelts; i++)
     {
         key = Tcl_NewStringObj( elts[i].key, -1);
@@ -329,6 +324,8 @@ Tcl_Obj* Rivet_BuildConfDictionary ( Tcl
             Tcl_Obj** objArrayPnt;
             int       objArrayCnt;
             Tcl_Obj*  val;
+            
+            Tcl_IncrRefCount(keyval_list);
 
             key_list[0] = Tcl_NewStringObj(section_names[it],-1);
             Tcl_IncrRefCount(key_list[0]);
@@ -398,6 +395,7 @@ Tcl_Obj* Rivet_CurrentConfDict ( Tcl_Int
         par_value = Rivet_ReadConfParameter(interp,rivet_conf,par_name);
         if (par_value != NULL)
         {
+            Tcl_IncrRefCount(par_value);
             Tcl_DictObjPut(interp,dictObj,par_name,par_value);
             Tcl_DecrRefCount(par_value);
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org