Kaydet (Commit) 58132c67 authored tarafından Guido van Rossum's avatar Guido van Rossum

AMK's latest; plus three null bytes that I added for purify

üst e4eb2231
......@@ -3,7 +3,7 @@
*************************************************/
#define PCRE_VERSION "1.01 19-Nov-1997"
#define PCRE_VERSION "1.02 12-Dec-1997"
/* This is a library of functions to support regular expressions whose syntax
......@@ -114,7 +114,7 @@ enum { ESC_A = 1, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, ESC_w,
/* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
OP_EOL must correspond in order to the list of escapes immediately above. */
OP_EOD must correspond in order to the list of escapes immediately above. */
enum {
OP_END, /* End of pattern */
......@@ -131,8 +131,7 @@ enum {
OP_NOT_WORDCHAR, /* \W */
OP_WORDCHAR, /* \w */
OP_CUT, /* The analogue of Prolog's "cut" operation (extension) */
OP_EOD, /* End of data: or \Z. This must always be the last
of the backslashed meta values. */
OP_EOD, /* End of data: \Z. */
OP_NOT_WORD_BOUNDARY_L, /* localized \B */
OP_WORD_BOUNDARY_L, /* localized \b */
......
......@@ -55,14 +55,14 @@ extern void (*pcre_free)(void *);
/* Functions */
#ifdef FOR_PYTHON
extern pcre *pcre_compile(const char *, int, char **, int *, PyObject *);
extern pcre *pcre_compile(const char *, int, const char **, int *, PyObject *);
#else
extern pcre *pcre_compile(const char *, int, char **, int *);
extern pcre *pcre_compile(const char *, int, const char **, int *);
#endif
extern int pcre_exec(const pcre *, const pcre_extra *, const char *,
int, int, int *, int);
extern int pcre_info(const pcre *, int *, int *);
extern pcre_extra *pcre_study(const pcre *, int, char **);
extern char *pcre_version(void);
extern pcre_extra *pcre_study(const pcre *, int, const char **);
extern const char *pcre_version(void);
#endif /* End of pcre.h */
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
Copyright 1997 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
......@@ -33,6 +33,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include "Python.h"
#include <assert.h>
#ifndef Py_eval_input
/* For Python 1.4, graminit.h has to be explicitly included */
#include "graminit.h"
......@@ -44,7 +45,7 @@ PERFORMANCE OF THIS SOFTWARE.
#endif
#include "pcre.h"
#include "pcre-internal.h"
#include "pcre-int.h"
static PyObject *ErrorObject;
......@@ -127,7 +128,9 @@ PyPcre_exec(self, args)
if (count==PCRE_ERROR_NOMATCH) {Py_INCREF(Py_None); return Py_None;}
if (count<0)
{
PyErr_SetObject(ErrorObject, Py_BuildValue("si", "Regex error", count));
PyObject *errval = Py_BuildValue("si", "Regex execution error", count);
PyErr_SetObject(ErrorObject, errval);
Py_XDECREF(errval);
return NULL;
}
......@@ -191,7 +194,7 @@ PyPcre_compile(self, args)
PcreObject *rv;
PyObject *dictionary;
char *pattern, *newpattern;
char *error;
const char *error;
int num_zeros, i, j;
int patternlen, options, erroroffset;
......@@ -203,12 +206,13 @@ PyPcre_compile(self, args)
return NULL;
/* PCRE doesn't like having null bytes in its pattern, so we have to replace
any zeros in the string with the characters '\0'. */
num_zeros=1;
any zeros in the string with the characters '\000'. This increases the size
of the string by 3*num_zeros, plus 1 byte for the terminating \0. */
num_zeros=1; /* Start at 1; this will give 3 extra bytes of leeway */
for(i=0; i<patternlen; i++) {
if (pattern[i]==0) num_zeros++;
}
newpattern=malloc(patternlen+num_zeros);
newpattern=malloc(patternlen + num_zeros*3 + 4);
if (newpattern==NULL) {
PyErr_SetString(PyExc_MemoryError, "can't allocate memory for new pattern");
return NULL;
......@@ -217,10 +221,16 @@ PyPcre_compile(self, args)
{
if (pattern[i]!=0) newpattern[j]=pattern[i];
else {
newpattern[j++]='\\';
newpattern[j] ='0';
newpattern[j++] ='\\';
newpattern[j++] = '0';
newpattern[j++] = '0';
newpattern[j ] = '0';
}
}
/* Keep purify happy; for pcre, one null byte is enough! */
newpattern[j++]='\0';
newpattern[j++]='\0';
newpattern[j++]='\0';
newpattern[j]='\0';
rv->regex = pcre_compile((char*)newpattern, options,
......@@ -231,21 +241,27 @@ PyPcre_compile(self, args)
PyMem_DEL(rv);
if (!PyErr_Occurred())
{
PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, erroroffset));
PyObject *errval = Py_BuildValue("si", error, erroroffset);
PyErr_SetObject(ErrorObject, errval);
Py_XDECREF(errval);
}
return NULL;
}
rv->regex_extra=pcre_study(rv->regex, 0, &error);
if (rv->regex_extra==NULL && error!=NULL)
{
PyObject *errval = Py_BuildValue("si", error, 0);
PyMem_DEL(rv);
PyErr_SetObject(ErrorObject, Py_BuildValue("si", error, 0));
PyErr_SetObject(ErrorObject, errval);
Py_XDECREF(errval);
return NULL;
}
rv->num_groups = pcre_info(rv->regex, NULL, NULL);
if (rv->num_groups<0)
{
PyErr_SetObject(ErrorObject, Py_BuildValue("si", "Regex error", rv->num_groups));
PyObject *errval = Py_BuildValue("si", error, rv->num_groups);
PyErr_SetObject(ErrorObject, errval);
Py_XDECREF(errval);
PyMem_DEL(rv);
return NULL;
}
......@@ -526,7 +542,7 @@ PyPcre_expand(self, args)
Py_DECREF(r); Py_DECREF(tuple);
if (result==NULL)
{
/* The group() method trigged an exception of some sort */
/* The group() method triggered an exception of some sort */
Py_DECREF(results);
Py_DECREF(value);
return NULL;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment