if (ch < 256 && (set[ch >> 4] & (1 << (ch & 15))))
return ok;
set += 16;
- }
+ }
else {
/* <CHARSET> <bitmap> (32 bits per code word) */
if (ch < 256 && (set[ch >> 5] & (1 << (ch & 31))))
else
block = -1;
set += 64;
- if (block >=0 &&
+ if (block >=0 &&
(set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31))))
return ok;
set += count*8;
while (ptr < end && (SRE_CODE) *ptr != chr)
ptr++;
break;
-
+
case SRE_OP_NOT_LITERAL_IGNORE:
/* repeated non-literal */
chr = pattern[1];
* - Recursive SRE_MATCH() returned false, and will continue the
* outside 'for' loop: must be protected when breaking, since the next
* OP could potentially depend on lastmark;
- *
+ *
* - Recursive SRE_MATCH() returned false, and will be called again
* inside a local for/while loop: must be protected between each
* loop iteration, since the recursive SRE_MATCH() could do anything,
/* state->lastmark is the highest valid index in the
state->mark array. If it is increased by more than 1,
the intervening marks must be set to NULL to signal
- that these marks have not been encountered. */
+ that these marks have not been encountered. */
int j = state->lastmark + 1;
while (j < i)
state->mark[j++] = NULL;
RETURN_ON_ERROR(ret);
RETURN_SUCCESS;
}
-
+
LASTMARK_RESTORE();
-
+
ctx->ptr--;
ctx->count--;
}
RETURN_ON_ERROR(ret);
DATA_LOOKUP_AT(SRE_MATCH_CONTEXT, ctx, ctx_pos);
if (ret < (int) ctx->pattern[1])
- /* didn't match minimum number of times */
+ /* didn't match minimum number of times */
RETURN_FAILURE;
/* advance past minimum matches of repeat */
ctx->count = ret;
}
break;
}
-
}
ptr++;
}
return status;
}
-
+
LOCAL(int)
SRE_LITERAL_TEMPLATE(SRE_CHAR* ptr, int len)
{
for (i = 0; i < n; i++) {
PyObject *o = PyList_GET_ITEM(code, i);
- if (PyInt_Check(o))
- self->code[i] = (SRE_CODE) PyInt_AsLong(o);
- else
- self->code[i] = (SRE_CODE) PyLong_AsUnsignedLong(o);
+ unsigned long value = PyInt_Check(o) ? (unsigned long)PyInt_AsLong(o)
+ : PyLong_AsUnsignedLong(o);
+ self->code[i] = (SRE_CODE) value;
+ if ((unsigned long) self->code[i] != value) {
+ PyErr_SetString(PyExc_OverflowError,
+ "regular expression code size limit exceeded");
+ break;
+ }
}
if (PyErr_Occurred()) {
/* given a python object, return a data pointer, a length (in
characters), and a character size. return NULL if the object
is not a string (or not compatible) */
-
+
PyBufferProcs *buffer;
int size, bytes, charsize;
void* ptr;
while (state.start <= state.end) {
PyObject* item;
-
+
state_reset(&state);
state.ptr = state.start;
pattern_error(status);
goto error;
}
-
+
/* don't bother to build a match object */
switch (self->groups) {
case 0:
Py_DECREF(list);
state_fini(&state);
return NULL;
-
+
}
#if PY_VERSION_HEX >= 0x02020000
pattern_error(status);
goto error;
}
-
+
if (state.start == state.ptr) {
if (last == state.end)
break;
Py_DECREF(list);
state_fini(&state);
return NULL;
-
+
}
static PyObject*
pattern_error(status);
goto error;
}
-
+
b = STATE_OFFSET(&state, state.start);
e = STATE_OFFSET(&state, state.ptr);
if (status < 0)
goto error;
}
-
+
i = e;
n = n + 1;
state_fini(&state);
Py_DECREF(filter);
return NULL;
-
+
}
static PyObject*
if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
return NULL;
-
+
copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize);
if (!copy)
return NULL;
{
#ifdef USE_BUILTIN_COPY
PatternObject* copy;
-
+
PyObject* memo;
if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
return NULL;
PyDoc_STRVAR(pattern_sub_doc,
"sub(repl, string[, count = 0]) --> newstring\n\
Return the string obtained by replacing the leftmost non-overlapping\n\
- occurrences of pattern in string by the replacement repl.");
+ occurrences of pattern in string by the replacement repl.");
PyDoc_STRVAR(pattern_subn_doc,
"subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\
Return the tuple (new_string, number_of_subs_made) found by replacing\n\
the leftmost non-overlapping occurrences of pattern with the\n\
- replacement repl.");
+ replacement repl.");
PyDoc_STRVAR(pattern_doc, "Compiled regular expression objects");
static PyMethodDef pattern_methods[] = {
- {"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS,
+ {"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS,
pattern_match_doc},
- {"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS,
+ {"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS,
pattern_search_doc},
{"sub", (PyCFunction) pattern_sub, METH_VARARGS|METH_KEYWORDS,
pattern_sub_doc},
{"subn", (PyCFunction) pattern_subn, METH_VARARGS|METH_KEYWORDS,
pattern_subn_doc},
- {"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS,
+ {"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS,
pattern_split_doc},
- {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
+ {"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
pattern_findall_doc},
#if PY_VERSION_HEX >= 0x02020000
{"finditer", (PyCFunction) pattern_finditer, METH_VARARGS,
{NULL, NULL}
};
-static PyObject*
+static PyObject*
pattern_getattr(PatternObject* self, char* name)
{
PyObject* res;
#ifdef USE_BUILTIN_COPY
MatchObject* copy;
int slots, offset;
-
+
if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
return NULL;
{
#ifdef USE_BUILTIN_COPY
MatchObject* copy;
-
+
PyObject* memo;
if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
return NULL;
{NULL, NULL}
};
-static PyObject*
+static PyObject*
match_getattr(MatchObject* self, char* name)
{
PyObject* res;
{NULL, NULL}
};
-static PyObject*
+static PyObject*
scanner_getattr(ScannerObject* self, char* name)
{
PyObject* res;
{NULL, NULL}
};
-#if PY_VERSION_HEX < 0x02030000
+#if PY_VERSION_HEX < 0x02030000
DL_EXPORT(void) init_sre(void)
#else
PyMODINIT_FUNC init_sre(void)