@@ -811,32 +811,6 @@ _sre_SRE_Pattern_prefixmatch_impl(PatternObject *self, PyTypeObject *cls,
811811 return match ;
812812}
813813
814- /*[clinic input]
815- _sre.SRE_Pattern.match
816-
817- cls: defining_class
818- /
819- string: object
820- pos: Py_ssize_t = 0
821- endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
822-
823- Matches zero or more characters at the beginning of the string.
824-
825- This is the legacy method name. Modern Python also provides it under the name
826- 'prefixmatch' to allow code to be explicitly clear about the intended behavior.
827-
828- [clinic start generated code]*/
829-
830- static PyObject *
831- _sre_SRE_Pattern_match_impl (PatternObject * self , PyTypeObject * cls ,
832- PyObject * string , Py_ssize_t pos ,
833- Py_ssize_t endpos )
834- /*[clinic end generated code: output=ec6208ea58a0cca0 input=7541a63c722fcfdf]*/
835- {
836- /* TODO - https://github.com/python/cpython/issues/86519 - If we ever
837- * want a PendingDeprecationWarning here, wait until year >=2030. */
838- return _sre_SRE_Pattern_prefixmatch_impl (self , cls , string , pos , endpos );
839- }
840814
841815/*[clinic input]
842816_sre.SRE_Pattern.fullmatch
@@ -2929,23 +2903,6 @@ _sre_SRE_Scanner_prefixmatch_impl(ScannerObject *self, PyTypeObject *cls)
29292903 return match ;
29302904}
29312905
2932- /*[clinic input]
2933- _sre.SRE_Scanner.match
2934-
2935- cls: defining_class
2936- /
2937-
2938- [clinic start generated code]*/
2939-
2940- static PyObject *
2941- _sre_SRE_Scanner_match_impl (ScannerObject * self , PyTypeObject * cls )
2942- /*[clinic end generated code: output=6e22c149dc0f0325 input=b5146e1f30278cb7]*/
2943- {
2944- /* TODO(https://bugs.python.org/issue42353): Plan if we EVER want to
2945- * issue a PendingDeprecationWarning here. */
2946- return _sre_SRE_Scanner_prefixmatch_impl (self , cls );
2947- }
2948-
29492906
29502907/*[clinic input]
29512908_sre.SRE_Scanner.search
@@ -3206,7 +3163,7 @@ pattern_richcompare(PyObject *lefto, PyObject *righto, int op)
32063163
32073164static PyMethodDef pattern_methods [] = {
32083165 _SRE_SRE_PATTERN_PREFIXMATCH_METHODDEF
3209- _SRE_SRE_PATTERN_MATCH_METHODDEF
3166+ { "match" , NULL }, /* filled in by sre_exec() */
32103167 _SRE_SRE_PATTERN_FULLMATCH_METHODDEF
32113168 _SRE_SRE_PATTERN_SEARCH_METHODDEF
32123169 _SRE_SRE_PATTERN_SUB_METHODDEF
@@ -3334,7 +3291,7 @@ static PyType_Spec match_spec = {
33343291
33353292static PyMethodDef scanner_methods [] = {
33363293 _SRE_SRE_SCANNER_PREFIXMATCH_METHODDEF
3337- _SRE_SRE_SCANNER_MATCH_METHODDEF
3294+ { "match" , NULL }, /* filled in by sre_exec() */
33383295 _SRE_SRE_SCANNER_SEARCH_METHODDEF
33393296 {NULL, NULL}
33403297};
@@ -3438,11 +3395,40 @@ do { \
34383395 } \
34393396} while (0)
34403397
3398+
3399+ static void
3400+ copy_prefixmatch_method_def_to_match (PyMethodDef * method_defs )
3401+ {
3402+ /* We could implement logic to scan the null filled sentry
3403+ * terminated list for the two method names. But we're a
3404+ * bunch of static structs. We just guarantee their position
3405+ * and flag deviation from this via debug build assertions.
3406+ */
3407+ assert (method_defs );
3408+ PyMethodDef * prefixmatch_md = & method_defs [0 ];
3409+ assert (prefixmatch_md -> ml_name != NULL );
3410+ assert (strcmp (prefixmatch_md -> ml_name , "prefixmatch" ) == 0 );
3411+
3412+ PyMethodDef * match_md = & method_defs [1 ];
3413+ assert (match_md -> ml_name != NULL );
3414+ assert (strcmp (match_md -> ml_name , "match" ) == 0 );
3415+ /* If the public stable C API struct ever changed (!) and
3416+ * somehow wound up with unexpected layout and alignment
3417+ * constraints, fix the memcpy below. */
3418+ assert (offsetof(PyMethodDef , ml_meth ) == sizeof (PyMethodDef .ml_name ));
3419+ memcpy (& match_md -> ml_meth , & prefixmatch_md -> ml_meth ,
3420+ sizeof (PyMethodDef ) - offsetof(PyMethodDef , ml_meth ));
3421+ }
3422+
3423+
34413424static int
34423425sre_exec (PyObject * m )
34433426{
34443427 _sremodulestate * state ;
34453428
3429+ copy_prefixmatch_method_def_to_match (pattern_methods );
3430+ copy_prefixmatch_method_def_to_match (scanner_methods );
3431+
34463432 /* Create heap types */
34473433 state = get_sre_module_state (m );
34483434 CREATE_TYPE (m , state -> Pattern_Type , & pattern_spec );
0 commit comments