[mod_python] mod_python/publisher/solaris truncation problems

Joost Yervante Damad joost.damad at siemens.atea.be
Thu Feb 22 08:09:37 EST 2001


'Rich Salz' wrote about 'Re: [mod_python] mod_python/publisher/solaris truncation problems' - Wed, Feb 21, 2001 at 03:33:57PM CET
> a diff would be more useful. ...

True... but the changes I made are not really meant as a
solution. They merely show how we solved it to have a workable
mod_python. I can get you a diff if you want. (see attachment)
It's not a very usefull diff imho tho :)

-- 
Joost Damad - Siemens IC D NC A - +3214252297
--
Five is a sufficiently close approximation to infinity.
       -- Robert Firth
"One, two, five."
       -- Monty Python and the Holy Grail
-------------- next part --------------
--- mod_python-2.7.2/src/_apachemodule.c	Mon Dec 18 20:50:03 2000
+++ ../delta/changed_src/_apachemodule.c	Wed Feb 21 10:15:03 2001
@@ -48,10 +48,14 @@
  *
  */
 
 #include "mod_python.h"
 
+#ifdef ATEA_DEBUG
+#undef ATEA_DEBUG
+#endif
+ 
 /** 
  ** log_error
  **
  *  A wrpapper to ap_log_error
  * 
@@ -253,11 +257,11 @@
 static PyObject *parse_qsl(PyObject *self, PyObject *args)
 {
 
     PyObject *pairs;
     int i, len;
-    char *qs;
+    char *qs, *cpair;
     int keep_blank_values = 0;
     int strict_parsing = 0; /* XXX not implemented */
 
     if (! PyArg_ParseTuple(args, "s|ii", &qs, &keep_blank_values, 
 			   &strict_parsing)) 
@@ -269,83 +273,131 @@
 	return NULL;
 
     i = 0;
     len = strlen(qs);
 
+	cpair=calloc(1,len);
+	
     while (i < len) {
 
-	PyObject *pair, *key, *val;
-	char *cpair, *ckey, *cval;
+	/*PyObject *pair, *key, *val;*/
+	PyObject *key, *val;
+	/*char *cpair, *ckey, *cval;*/
+	char *ckey, *cval;
 	int plen, j, p, k, v;
 
-	pair = PyString_FromStringAndSize(NULL, len);
+	/* pair = PyString_FromStringAndSize(NULL, len);
 	if (pair == NULL)
-	    return NULL;
+	    return NULL;*/
 
 	/* split by '&' or ';' */
-	cpair = PyString_AS_STRING(pair);
+	/*cpair = PyString_AS_STRING(pair);
+	  cpair=calloc(1,len);*/
+#ifdef ATEA_DEBUG
+	fprintf(stderr, "all pairs: %s\n", cpair);
+#endif
 	j = 0;
 	while ((qs[i] != '&') && (qs[i] != ';') && (i < len)) {
 	    /* replace '+' with ' ' */
 	    cpair[j] = (qs[i] == '+') ? ' ' : qs[i];
 	    i++;
 	    j++;
 	}
 	cpair[j] = '\0';
-	_PyString_Resize(&pair, j);
+	/*_PyString_Resize(&pair, j);*/
 
 	/* split the "abc=def" pair */
-
+#ifdef ATEA_DEBUG
+	fprintf(stderr,"[foo] cpair == %s\n", cpair);
+#endif
 	plen = strlen(cpair);
-	key = PyString_FromStringAndSize(NULL, plen);
-	if (key == NULL) 
-	    return NULL;
-	val = PyString_FromStringAndSize(NULL, plen);
-	if (val == NULL) 
-	    return NULL;
-
-	ckey = PyString_AS_STRING(key);
-	cval = PyString_AS_STRING(val);
+#ifdef ATEA_DEBUG
+	fprintf(stderr,"plen == %d\n", plen);
+#endif
+	/*key = PyString_FromStringAndSize(NULL, plen);
+	  if (key == NULL)
+	      return NULL;
+	  val = PyString_FromStringAndSize(NULL, plen);
+	  if (val == NULL)
+	      return NULL;*/
 
+	/*ckey = PyString_AS_STRING(key);
+	  cval = PyString_AS_STRING(val);*/
+	
+	ckey = calloc(1,plen);
+	cval = calloc(1,plen);
+	/*memset(ckey,0,plen);
+	  memset(cval,0,plen);*/
+#ifdef ATEA_DEBUG
+	fprintf(stderr,"ckey=%s, cval=%s (should be empty)\n", ckey, cval);
+#endif
+	
 	p = 0;
 	k = 0;
 	v = 0;
 	while (p < plen) {
-	    if (cpair[p] != '=') {
-		ckey[k] = cpair[p];
-		k++;
-		p++;
+	    if (cpair[p] != '=')
+		{
+#ifdef ATEA_DEBUG
+			fprintf(stderr,"%d cpair=%s ckey=%s, cval=%s (parsing before '=')\n", p, cpair, ckey, cval);
+#endif
+			ckey[k] = cpair[p];
+			k++;
+			p++;
 	    }
 	    else {
-		p++;      /* skip '=' */
-		while (p < plen) {
-		    cval[v] = cpair[p];
-		    v++;
-		    p++;
-		}
+			p++;      /* skip '=' */
+#ifdef ATEA_DEBUG
+			fprintf(stderr, ">>> entering else branch...\n");
+#endif
+			while (p < plen)
+			{
+#ifdef ATEA_DEBUG
+				fprintf(stderr,"%d cpair=%s ckey=%s, cval=%s (parsing after '=')\n", p, cpair, ckey, cval);
+#endif
+		    	cval[v] = cpair[p];
+		    	v++;
+		    	p++;
+			}
 	    }
 	}
 	ckey[k] = '\0';
 	cval[v] = '\0';
+#ifdef ATEA_DEBUG
+	fprintf(stderr,"ckey=%s, cval=%s\n (final)", ckey, cval);
+#endif
 
 	if (keep_blank_values || (v > 0)) {
 
 	    ap_unescape_url(ckey);
 	    ap_unescape_url(cval);
 
-	    _PyString_Resize(&key, strlen(ckey));
-	    _PyString_Resize(&val, strlen(cval));
+	    /*_PyString_Resize(&key, strlen(ckey));
+	      _PyString_Resize(&val, strlen(cval));*/
 
+		key = PyString_FromStringAndSize(ckey, strlen(ckey));
+		if (key == NULL) {
+		  	free(ckey); free(cval); free(cpair);
+	    	return NULL;
+		}
+		val = PyString_FromStringAndSize(cval, strlen(cval));
+		if (val == NULL) {
+		  	free(ckey); free(cval); free(cpair);
+		    return NULL;
+		}
+		
 	    PyList_Append(pairs, Py_BuildValue("(O,O)", key, val));
 
 	}
-	Py_DECREF(pair);
+	/*Py_DECREF(pair);*/
 	Py_DECREF(key);
 	Py_DECREF(val);
 	i++;
+	free(ckey);
+	free(cval);
     }
-
+	free(cpair);
     return pairs;
 }
 
 
 /* methods of _apache */


More information about the Mod_python mailing list