@@ -526,21 +526,58 @@ sre_search(SRE_STATE* state, SRE_CODE* pattern)
526526 return sre_ucs4_search (state , pattern );
527527}
528528
529- static PyObject *
530- pattern_match (PatternObject * self , PyObject * args , PyObject * kw )
529+ /*[clinic]
530+ module _sre
531+ class _sre.SRE_Pattern
532+
533+ _sre.SRE_Pattern.match as pattern_match
534+
535+ self: self(type="PatternObject *")
536+ pattern: object
537+ pos: Py_ssize_t = 0
538+ endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
539+
540+ Matches zero or more characters at the beginning of the string.
541+ [clinic]*/
542+
543+ PyDoc_STRVAR (pattern_match__doc__ ,
544+ "match(pattern, pos=0, endpos=sys.maxsize)\n"
545+ "Matches zero or more characters at the beginning of the string." );
546+
547+ #define PATTERN_MATCH_METHODDEF \
548+ {"match", (PyCFunction)pattern_match, METH_VARARGS|METH_KEYWORDS, pattern_match__doc__},
549+
550+ static PyObject *
551+ pattern_match_impl (PatternObject * self , PyObject * pattern , Py_ssize_t pos , Py_ssize_t endpos );
552+
553+ static PyObject *
554+ pattern_match (PyObject * self , PyObject * args , PyObject * kwargs )
555+ {
556+ PyObject * return_value = NULL ;
557+ static char * _keywords [] = {"pattern" , "pos" , "endpos" , NULL };
558+ PyObject * pattern ;
559+ Py_ssize_t pos = 0 ;
560+ Py_ssize_t endpos = PY_SSIZE_T_MAX ;
561+
562+ if (!PyArg_ParseTupleAndKeywords (args , kwargs ,
563+ "O|nn:match" , _keywords ,
564+ & pattern , & pos , & endpos ))
565+ goto exit ;
566+ return_value = pattern_match_impl ((PatternObject * )self , pattern , pos , endpos );
567+
568+ exit :
569+ return return_value ;
570+ }
571+
572+ static PyObject *
573+ pattern_match_impl (PatternObject * self , PyObject * pattern , Py_ssize_t pos , Py_ssize_t endpos )
574+ /*[clinic checksum: 63e59c5f3019efe6c1f3acdec42b2d3595e14a09]*/
531575{
532576 SRE_STATE state ;
533577 Py_ssize_t status ;
578+ PyObject * string ;
534579
535- PyObject * string ;
536- Py_ssize_t start = 0 ;
537- Py_ssize_t end = PY_SSIZE_T_MAX ;
538- static char * kwlist [] = { "pattern" , "pos" , "endpos" , NULL };
539- if (!PyArg_ParseTupleAndKeywords (args , kw , "O|nn:match" , kwlist ,
540- & string , & start , & end ))
541- return NULL ;
542-
543- string = state_init (& state , self , string , start , end );
580+ string = state_init (& state , (PatternObject * )self , pattern , pos , endpos );
544581 if (!string )
545582 return NULL ;
546583
@@ -556,7 +593,7 @@ pattern_match(PatternObject* self, PyObject* args, PyObject* kw)
556593
557594 state_fini (& state );
558595
559- return pattern_new_match (self , & state , status );
596+ return ( PyObject * ) pattern_new_match (self , & state , status );
560597}
561598
562599static PyObject *
@@ -1254,10 +1291,6 @@ pattern_repr(PatternObject *obj)
12541291 return result ;
12551292}
12561293
1257- PyDoc_STRVAR (pattern_match_doc ,
1258- "match(string[, pos[, endpos]]) -> match object or None.\n\
1259- Matches zero or more characters at the beginning of the string" );
1260-
12611294PyDoc_STRVAR (pattern_fullmatch_doc ,
12621295"fullmatch(string[, pos[, endpos]]) -> match object or None.\n\
12631296 Matches against all of the string" );
@@ -1295,8 +1328,7 @@ PyDoc_STRVAR(pattern_subn_doc,
12951328PyDoc_STRVAR (pattern_doc , "Compiled regular expression objects" );
12961329
12971330static PyMethodDef pattern_methods [] = {
1298- {"match" , (PyCFunction ) pattern_match , METH_VARARGS |METH_KEYWORDS ,
1299- pattern_match_doc },
1331+ PATTERN_MATCH_METHODDEF
13001332 {"fullmatch" , (PyCFunction ) pattern_fullmatch , METH_VARARGS |METH_KEYWORDS ,
13011333 pattern_fullmatch_doc },
13021334 {"search" , (PyCFunction ) pattern_search , METH_VARARGS |METH_KEYWORDS ,
0 commit comments