Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
58132c67
Commit
58132c67
authored
Dec 17, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AMK's latest; plus three null bytes that I added for purify
parent
e4eb2231
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
157 additions
and
167 deletions
+157
-167
Modules/pcre-int.h
Modules/pcre-int.h
+3
-4
Modules/pcre.h
Modules/pcre.h
+4
-4
Modules/pcremodule.c
Modules/pcremodule.c
+29
-13
Modules/pypcre.c
Modules/pypcre.c
+121
-146
No files found.
Modules/pcre-int
ernal
.h
→
Modules/pcre-int.h
View file @
58132c67
...
...
@@ -3,7 +3,7 @@
*************************************************/
#define PCRE_VERSION "1.0
1 19-Nov
-1997"
#define PCRE_VERSION "1.0
2 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_EO
L
must correspond in order to the list of escapes immediately above. */
OP_EO
D
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 */
...
...
Modules/pcre.h
View file @
58132c67
...
...
@@ -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
,
c
onst
c
har
**
,
int
*
,
PyObject
*
);
#else
extern
pcre
*
pcre_compile
(
const
char
*
,
int
,
char
**
,
int
*
);
extern
pcre
*
pcre_compile
(
const
char
*
,
int
,
c
onst
c
har
**
,
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
,
c
onst
c
har
**
);
extern
c
onst
c
har
*
pcre_version
(
void
);
#endif
/* End of pcre.h */
Modules/pcremodule.c
View file @
58132c67
/***********************************************************
Copyright 199
1-1995
by Stichting Mathematisch Centrum, Amsterdam,
Copyright 199
7
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-int
ernal
.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
;
c
onst
c
har
*
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 trigge
re
d an exception of some sort */
Py_DECREF
(
results
);
Py_DECREF
(
value
);
return
NULL
;
...
...
Modules/pypcre.c
View file @
58132c67
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment