static PyObject*pattern_new_match(_sremodulestate *, PatternObject*, SRE_STATE*, Py_ssize_t);
static PyObject *pattern_scanner(_sremodulestate *, PatternObject *, PyObject *, Py_ssize_t, Py_ssize_t);
+#define _PatternObject_CAST(op) ((PatternObject *)(op))
+#define _MatchObject_CAST(op) ((MatchObject *)(op))
+#define _TemplateObject_CAST(op) ((TemplateObject *)(op))
+#define _ScannerObject_CAST(op) ((ScannerObject *)(op))
+
/*[clinic input]
module _sre
class _sre.SRE_Pattern "PatternObject *" "get_sre_module_state_by_class(tp)->Pattern_Type"
}
static int
-pattern_traverse(PatternObject *self, visitproc visit, void *arg)
+pattern_traverse(PyObject *op, visitproc visit, void *arg)
{
+ PatternObject *self = _PatternObject_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->groupindex);
Py_VISIT(self->indexgroup);
}
static int
-pattern_clear(PatternObject *self)
+pattern_clear(PyObject *op)
{
+ PatternObject *self = _PatternObject_CAST(op);
Py_CLEAR(self->groupindex);
Py_CLEAR(self->indexgroup);
Py_CLEAR(self->pattern);
}
static void
-pattern_dealloc(PatternObject* self)
+pattern_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
-
PyObject_GC_UnTrack(self);
- if (self->weakreflist != NULL) {
- PyObject_ClearWeakRefs((PyObject *) self);
+ PatternObject *obj = _PatternObject_CAST(self);
+ if (obj->weakreflist != NULL) {
+ PyObject_ClearWeakRefs(self);
}
(void)pattern_clear(self);
tp->tp_free(self);
#endif /* Py_DEBUG */
static PyObject *
-pattern_repr(PatternObject *obj)
+pattern_repr(PyObject *self)
{
static const struct {
const char *name;
{"re.DEBUG", SRE_FLAG_DEBUG},
{"re.ASCII", SRE_FLAG_ASCII},
};
+
+ PatternObject *obj = _PatternObject_CAST(self);
PyObject *result = NULL;
PyObject *flag_items;
size_t i;
/* PatternObject's 'groupindex' method. */
static PyObject *
-pattern_groupindex(PatternObject *self, void *Py_UNUSED(ignored))
+pattern_groupindex(PyObject *op, void *Py_UNUSED(ignored))
{
+ PatternObject *self = _PatternObject_CAST(op);
if (self->groupindex == NULL)
return PyDict_New();
return PyDictProxy_New(self->groupindex);
/* match methods */
static int
-match_traverse(MatchObject *self, visitproc visit, void *arg)
+match_traverse(PyObject *op, visitproc visit, void *arg)
{
+ MatchObject *self = _MatchObject_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->string);
Py_VISIT(self->regs);
}
static int
-match_clear(MatchObject *self)
+match_clear(PyObject *op)
{
+ MatchObject *self = _MatchObject_CAST(op);
Py_CLEAR(self->string);
Py_CLEAR(self->regs);
Py_CLEAR(self->pattern);
}
static void
-match_dealloc(MatchObject* self)
+match_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
-
PyObject_GC_UnTrack(self);
(void)match_clear(self);
tp->tp_free(self);
}
static PyObject*
-match_group(MatchObject* self, PyObject* args)
+match_group(PyObject *op, PyObject* args)
{
+ MatchObject *self = _MatchObject_CAST(op);
PyObject* result;
Py_ssize_t i, size;
}
static PyObject*
-match_getitem(MatchObject* self, PyObject* name)
+match_getitem(PyObject *op, PyObject* name)
{
+ MatchObject *self = _MatchObject_CAST(op);
return match_getslice(self, name, Py_None);
}
For 0 returns the entire match.");
static PyObject *
-match_lastindex_get(MatchObject *self, void *Py_UNUSED(ignored))
+match_lastindex_get(PyObject *op, void *Py_UNUSED(ignored))
{
+ MatchObject *self = _MatchObject_CAST(op);
if (self->lastindex >= 0)
return PyLong_FromSsize_t(self->lastindex);
Py_RETURN_NONE;
}
static PyObject *
-match_lastgroup_get(MatchObject *self, void *Py_UNUSED(ignored))
+match_lastgroup_get(PyObject *op, void *Py_UNUSED(ignored))
{
+ MatchObject *self = _MatchObject_CAST(op);
if (self->pattern->indexgroup &&
self->lastindex >= 0 &&
self->lastindex < PyTuple_GET_SIZE(self->pattern->indexgroup))
}
static PyObject *
-match_regs_get(MatchObject *self, void *Py_UNUSED(ignored))
+match_regs_get(PyObject *op, void *Py_UNUSED(ignored))
{
+ MatchObject *self = _MatchObject_CAST(op);
if (self->regs) {
return Py_NewRef(self->regs);
} else
/* scanner methods (experimental) */
static int
-scanner_traverse(ScannerObject *self, visitproc visit, void *arg)
+scanner_traverse(PyObject *op, visitproc visit, void *arg)
{
+ ScannerObject *self = _ScannerObject_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->pattern);
return 0;
}
static int
-scanner_clear(ScannerObject *self)
+scanner_clear(PyObject *op)
{
+ ScannerObject *self = _ScannerObject_CAST(op);
Py_CLEAR(self->pattern);
return 0;
}
static void
-scanner_dealloc(ScannerObject* self)
+scanner_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
-
PyObject_GC_UnTrack(self);
- state_fini(&self->state);
+ ScannerObject *scanner = _ScannerObject_CAST(self);
+ state_fini(&scanner->state);
(void)scanner_clear(self);
tp->tp_free(self);
Py_DECREF(tp);
/* template methods */
static int
-template_traverse(TemplateObject *self, visitproc visit, void *arg)
+template_traverse(PyObject *op, visitproc visit, void *arg)
{
+ TemplateObject *self = _TemplateObject_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->literal);
for (Py_ssize_t i = 0, n = Py_SIZE(self); i < n; i++) {
}
static int
-template_clear(TemplateObject *self)
+template_clear(PyObject *op)
{
+ TemplateObject *self = _TemplateObject_CAST(op);
Py_CLEAR(self->literal);
for (Py_ssize_t i = 0, n = Py_SIZE(self); i < n; i++) {
Py_CLEAR(self->items[i].literal);
}
static void
-template_dealloc(TemplateObject *self)
+template_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
-
PyObject_GC_UnTrack(self);
(void)template_clear(self);
tp->tp_free(self);
static Py_hash_t
-pattern_hash(PatternObject *self)
+pattern_hash(PyObject *op)
{
+ PatternObject *self = _PatternObject_CAST(op);
+
Py_hash_t hash, hash2;
hash = PyObject_Hash(self->pattern);
};
static PyGetSetDef pattern_getset[] = {
- {"groupindex", (getter)pattern_groupindex, (setter)NULL,
+ {"groupindex", pattern_groupindex, NULL,
"A dictionary mapping group names to group numbers."},
{NULL} /* Sentinel */
};
};
static PyType_Slot pattern_slots[] = {
- {Py_tp_dealloc, (destructor)pattern_dealloc},
- {Py_tp_repr, (reprfunc)pattern_repr},
- {Py_tp_hash, (hashfunc)pattern_hash},
+ {Py_tp_dealloc, pattern_dealloc},
+ {Py_tp_repr, pattern_repr},
+ {Py_tp_hash, pattern_hash},
{Py_tp_doc, (void *)pattern_doc},
{Py_tp_richcompare, pattern_richcompare},
{Py_tp_methods, pattern_methods},
};
static PyMethodDef match_methods[] = {
- {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc},
+ {"group", match_group, METH_VARARGS, match_group_doc},
_SRE_SRE_MATCH_START_METHODDEF
_SRE_SRE_MATCH_END_METHODDEF
_SRE_SRE_MATCH_SPAN_METHODDEF
};
static PyGetSetDef match_getset[] = {
- {"lastindex", (getter)match_lastindex_get, (setter)NULL,
+ {"lastindex", match_lastindex_get, NULL,
"The integer index of the last matched capturing group."},
- {"lastgroup", (getter)match_lastgroup_get, (setter)NULL,
+ {"lastgroup", match_lastgroup_get, NULL,
"The name of the last matched capturing group."},
- {"regs", (getter)match_regs_get, (setter)NULL},
+ {"regs", match_regs_get, NULL, NULL},
{NULL}
};