Commits

Anonymous committed bde5aaf

Checking in AMK's latest installement.
(Two small changes to shup up gcc added.)

  • Participants
  • Parent commits 93c015e
  • Branches legacy-trunk

Comments (0)

Files changed (2)

Modules/pcremodule.c

 	  {
 	    PyMem_DEL(rv);
 	    if (!PyErr_Occurred())
-	      PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, erroroffset));
+	      {
+		PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, erroroffset));
+	      }
 	    return NULL;
 	  }
 	rv->regex_extra=pcre_study(rv->regex, 0, &error);
 }
 
 static PyObject *
-PyPcre_expand_escape(self, args)
-	PyObject *self;
-	PyObject *args;
+PyPcre_expand_escape(pattern, pattern_len, indexptr, typeptr)
+     unsigned char *pattern;
+     int pattern_len, *indexptr, *typeptr;
 {
-  unsigned char c, *pattern;
-  int index, pattern_len;
-  const int context=REPLACEMENT;
-
-  if (!PyArg_ParseTuple(args, "s#i", &pattern, &pattern_len, &index)) 
-    return NULL;
+  unsigned char c;
+  int index = *indexptr;
+  
   if (pattern_len<=index)
     {
       PyErr_SetString(ErrorObject, "escape ends too soon");
       return NULL;
     }
   c=pattern[index]; index++;
+  *typeptr=CHAR;
+
   switch (c)
     {
     case('t'):
-      return Py_BuildValue("ici", CHAR, (char)9, index);
+      *indexptr=index;
+      return Py_BuildValue("c", (char)9);
       break;
     case('n'):
-      return Py_BuildValue("ici", CHAR, (char)10, index);
+      *indexptr = index;
+      return Py_BuildValue("c", (char)10);
       break;
     case('v'):
-      return Py_BuildValue("ici", CHAR, (char)11, index);
+      *indexptr = index;
+      return Py_BuildValue("c", (char)11);
       break;
     case('r'):
-      return Py_BuildValue("ici", CHAR, (char)13, index);
+      *indexptr = index;
+      return Py_BuildValue("c", (char)13);
       break;
     case('f'):
-      return Py_BuildValue("ici", CHAR, (char)12, index);
+      *indexptr = index;
+      return Py_BuildValue("c", (char)12);
       break;
     case('a'):
-      return Py_BuildValue("ici", CHAR, (char)7, index);
+      *indexptr = index;
+      return Py_BuildValue("c", (char)7);
       break;
+    case('b'):
+      *indexptr=index;
+      return Py_BuildValue("c", (char)8);
+      break;
+
     case('x'):
       {
 	int end, length;
 	unsigned char *string;
-	PyObject *v, *result;
+	PyObject *v;
 
 	end=index; 
 	while (end<pattern_len && 
 	free(string);
 	/* The evaluation raised an exception */
 	if (v==NULL) return NULL;
-	result=Py_BuildValue("iOi", CHAR, v, end);
-	Py_DECREF(v);
-	return result;
+	*indexptr = end;
+	return v;
       }
       break;
 
-    case('b'):
-      if (context!=NORMAL)
-	return Py_BuildValue("ici", CHAR, (char)8, index);
-      else 
-	{
-	  unsigned char empty_string[1];
-	  empty_string[0]='\0';
-	  return Py_BuildValue("isi", WORD_BOUNDARY, empty_string, index);
-	}
-      break;
-    case('B'):
-      if (context!=NORMAL)
-	return Py_BuildValue("ici", CHAR, 'B', index);
-      else 
-	{
-	  unsigned char empty_string[1];
-	  empty_string[0]='\0';
-	  return Py_BuildValue("isi", NOT_WORD_BOUNDARY, empty_string, index);
-	}
-      break;
-    case('A'):
-      if (context!=NORMAL)
-	return Py_BuildValue("ici", CHAR, 'A', index);
-      else 
-	{
-	  unsigned char empty_string[1];
-	  empty_string[0]='\0';
-	  return Py_BuildValue("isi", BEGINNING_OF_BUFFER, empty_string, index);
-	}
-      break;
-    case('Z'):
-      if (context!=NORMAL)
-	return Py_BuildValue("ici", CHAR, 'Z', index);
-      else 
-	{
-	  unsigned char empty_string[1];
-	  empty_string[0]='\0';
-	  return Py_BuildValue("isi", END_OF_BUFFER, empty_string, index);
-	}
-      break;
     case('E'):    case('G'):    case('L'):    case('Q'):
     case('U'):    case('l'):    case('u'):
       {
 	return NULL;
       }
 
-    case ('w'):
-      return Py_BuildValue("ici", CHAR, 'w', index);
-      break;
-    case ('W'):
-      return Py_BuildValue("ici", CHAR, 'W', index);
-      break;
-    case ('s'):
-	return Py_BuildValue("ici", CHAR, 's', index);
-      break;
-    case ('S'):
-	return Py_BuildValue("ici", CHAR, 'S', index);
-      break;
-
-    case ('d'):
-	return Py_BuildValue("ici", CHAR, 'd', index);
-      break;
-    case ('D'):
-	return Py_BuildValue("ici", CHAR, 'D', index);
-      break;
-
     case('g'):
       {
 	int end, valid, i;
 	    return NULL;
 	  }
 	    
-	return Py_BuildValue("is#i", MEMORY_REFERENCE, 
-			             pattern+index, end-index, 
-			             end+1);
+	*typeptr = MEMORY_REFERENCE;
+	*indexptr = end+1;
+	return Py_BuildValue("s#", pattern+index, end-index);
       }
     break;
 
 	    PyErr_SetString(ErrorObject, "octal value out of range");
 	    return NULL;
 	  }
-	return Py_BuildValue("ici", CHAR, (unsigned char)octval, i);
+	*indexptr = i;
+	return Py_BuildValue("c", (unsigned char)octval);
       }
       break;
     case('1'):    case('2'):    case('3'):    case('4'):
 		    PyErr_SetString(ErrorObject, "octal value out of range");
 		    return NULL;
 		  }
-		return Py_BuildValue("ici", CHAR, (unsigned char)value, index+3);
+		*indexptr = index+3;
+		return Py_BuildValue("c", (unsigned char)value);
 	      }
 	    else
 	      {
 		/* 2-digit form, so it's a memory reference */
-		if (context==CHARCLASS)
-		  {
-		    PyErr_SetString(ErrorObject, "cannot reference a register "
-				    "from inside a character class");
-		    return NULL;
-		  }
 		value= 10*(pattern[index  ]-'0') +
 		          (pattern[index+1]-'0');
 		if (value<1 || EXTRACT_MAX<=value)
 		    PyErr_SetString(ErrorObject, "memory reference out of range");
 		    return NULL;
 		  }
-		return Py_BuildValue("iii", MEMORY_REFERENCE, 
-				     value, index+2);
+		*typeptr = MEMORY_REFERENCE;
+		*indexptr = index+2;
+		return Py_BuildValue("i", value);
 	      }
 	  }
 	else 
 	  {
 	    /* Single-digit form, like \2, so it's a memory reference */
-	    if (context==CHARCLASS)
-	      {
-		PyErr_SetString(ErrorObject, "cannot reference a register "
-				"from inside a character class");
-		return NULL;
-	      }
-	    return Py_BuildValue("iii", MEMORY_REFERENCE, 
-				 pattern[index]-'0', index+1);
+	    *typeptr = MEMORY_REFERENCE;
+	    *indexptr = index+1;
+	    return Py_BuildValue("i", pattern[index]-'0');
 	  }
       }
       break;
 
     default:
-	return Py_BuildValue("ici", CHAR, c, index);
+	*indexptr = index;
+	return Py_BuildValue("c", c);
 	break;
     }
 }
     {
       if (repl[i]=='\\')
 	{
-	  PyObject *args, *t, *value;
+	  PyObject *value;
 	  int escape_type;
 
 	  if (start!=i)
 	      total_len += i-start;
 	    }
 	  i++;
-	  args=Py_BuildValue("Oi", repl_obj, i);
-	  t=PyPcre_expand_escape(NULL, args);
-	  Py_DECREF(args);
-	  if (t==NULL)
+	  value=PyPcre_expand_escape(repl, size, &i, &escape_type);
+	  if (value==NULL)
 	    {
 	      /* PyPcre_expand_escape triggered an exception of some sort,
 		 so just return */
 	      Py_DECREF(results);
 	      return NULL;
 	    }
-	  value=PyTuple_GetItem(t, 1);
-	  escape_type=PyInt_AsLong(PyTuple_GetItem(t, 0));
 	  switch (escape_type)
 	    {
 	    case (CHAR):
 		    PyErr_SetString(ErrorObject, 
 				    message);
 		    Py_DECREF(result);
-		    Py_DECREF(t);
 		    Py_DECREF(results);
 		    return NULL;
 		  }
 	      }
 	      break;
 	    default:
-	      Py_DECREF(t);
 	      Py_DECREF(results);
 	      PyErr_SetString(ErrorObject, 
 			      "bad escape in replacement");
 	      return NULL;
 	    }
-	  i=start=PyInt_AsLong(PyTuple_GetItem(t, 2));
+	  start=i;
 	  i--; /* Decrement now, because the 'for' loop will increment it */
-	  Py_DECREF(t);
 	}
     } /* endif repl[i]!='\\' */
 
 initpcre()
 {
 	PyObject *m, *d;
-	int a;
 
 	/* Create the module and add the functions */
 	m = Py_InitModule("pcre", pcre_methods);
   for(; (*ptr != 0) && (*ptr != finalchar) && 
 	(pcre_ctypes[*ptr] & ctype_word); ptr++)
     {
+      /* Empty loop body */
     }
   if (*ptr==finalchar)
     return ptr-start;
 
   case 'x':
     {
-      int end, length;
+      int length;
       char *string;
-      PyObject *v, *result;
+      PyObject *result;
       
       i=1;
       while (ptr[i]!=0 && 
       string[length+4]='\0';
       memcpy(string+2, ptr, length+1);
       ptr += length;
-      v=PyRun_String((char *)string, Py_eval_input, 
-		     PyEval_GetGlobals(), PyEval_GetLocals());
+      result=PyRun_String((char *)string, Py_eval_input, 
+			  PyEval_GetGlobals(), PyEval_GetLocals());
       free(string);
       /* The evaluation raised an exception */
-      if (v==NULL) 
+      if (result==NULL) 
 	{
 	  *errorptr="exception occurred during evaluation of \\x";
 	  break;
 	}
-      if (PyString_Size(v)!=1)
+      if (PyString_Size(result)!=1)
 	{
-	  Py_DECREF(v);
+	  Py_DECREF(result);
 	  *errorptr="\\x string is not one byte in length";
 	  break;
 	}
-      c=*(unsigned char *)PyString_AsString(v);
-      Py_DECREF(v);
+      c=*(unsigned char *)PyString_AsString(result);
+      Py_DECREF(result);
       break;
     }
   break;
 		goto FAILED;
 	      }
 	      string = PyString_FromStringAndSize(ptr, idlen);
-	      if (string==NULL)
-		{
+	      if (string==NULL)	{
 		  Py_XDECREF(string);
 		  *errorptr = "exception raised";
 		  goto FAILED;
 		}
 	      intobj = PyDict_GetItem(dictionary, string);
 	      if (intobj==NULL) {
+		Py_DECREF(string);
 		*errorptr = "?P= group identifier isn't defined";
 		goto FAILED;
 	      }
 
 	      refnum = PyInt_AsLong(intobj);
-	       Py_DECREF(string); Py_DECREF(intobj);
+	      Py_DECREF(string); Py_DECREF(intobj);
 	      *code++ = OP_REF;
 	      *code++ = refnum;
 	      /* The continue will cause the top-level for() loop to
 if (md->r1)         free(md->r1); 
 if (md->r2)         free(md->r2); 
 if (md->eptr)       free(md->eptr); 
-if (md->ecode)      free(md->ecode); 
+if (md->ecode)      free(md->ecode);
+return 0;
 }
 
 static int grow_stack(match_data *md)
   int min, max, ctype;
   register int i;
   register int c;
-  BOOL minimize;
+  BOOL minimize = 0;
 
   /* Opening bracket. Check the alternative branches in turn, failing if none
   match. We have to set the start offset if required and there is space
   if ((int)*ecode >= OP_BRA)
     {
     int number = (*ecode - OP_BRA) << 1;
-    int save_offset1, save_offset2;
+    int save_offset1 = 0, save_offset2 = 0;
 
     #ifdef DEBUG
     printf("start bracket %d\n", number/2);
  if (md->point > save_stack_position)
  {
    /* If there are still points remaining on the stack, pop the next one off */
-   int start, end, off_num;
+   int off_num;
 
    md->point--; 
    offset_top = md->offset_top[md->point];