@@ -611,6 +611,16 @@ PyObject *query_pattern_assertions(Query *self, PyObject *args) {
611611 return item ;
612612}
613613
614+ PyObject * query_set_timeout_micros (Query * self , PyObject * args ) {
615+ uint32_t timeout_micros ;
616+ if (!PyArg_ParseTuple (args , "I:set_timeout_micros" , & timeout_micros )) {
617+ return NULL ;
618+ }
619+ ts_query_cursor_set_timeout_micros (self -> cursor , timeout_micros );
620+ Py_INCREF (self );
621+ return (PyObject * )self ;
622+ }
623+
614624PyObject * query_set_match_limit (Query * self , PyObject * args ) {
615625 uint32_t match_limit ;
616626 if (!PyArg_ParseTuple (args , "I:set_match_limit" , & match_limit )) {
@@ -730,6 +740,10 @@ PyObject *query_get_capture_count(Query *self, void *Py_UNUSED(payload)) {
730740 return PyLong_FromSize_t (ts_query_capture_count (self -> query ));
731741}
732742
743+ PyObject * query_get_timeout_micros (Query * self , void * Py_UNUSED (payload )) {
744+ return PyLong_FromSize_t (ts_query_cursor_timeout_micros (self -> cursor ));
745+ }
746+
733747PyObject * query_get_match_limit (Query * self , void * Py_UNUSED (payload )) {
734748 return PyLong_FromSize_t (ts_query_cursor_match_limit (self -> cursor ));
735749}
@@ -738,6 +752,9 @@ PyObject *query_get_did_exceed_match_limit(Query *self, void *Py_UNUSED(payload)
738752 return PyLong_FromSize_t (ts_query_cursor_did_exceed_match_limit (self -> cursor ));
739753}
740754
755+ PyDoc_STRVAR (query_set_timeout_micros_doc , "set_timeout_micros(self, timeout_micros)\n--\n\n"
756+ "Set the maximum duration in microseconds that query "
757+ "execution should be allowed to take before halting." );
741758PyDoc_STRVAR (query_set_match_limit_doc , "set_match_limit(self, match_limit)\n--\n\n"
742759 "Set the maximum number of in-progress matches." DOC_RAISES
743760 "ValueError\n\n If set to ``0``." );
@@ -798,6 +815,12 @@ PyDoc_STRVAR(query_is_pattern_guaranteed_at_step_doc,
798815 "Check if a pattern is guaranteed to match once a given byte offset is reached." );
799816
800817static PyMethodDef query_methods [] = {
818+ {
819+ .ml_name = "set_timeout_micros" ,
820+ .ml_meth = (PyCFunction )query_set_timeout_micros ,
821+ .ml_flags = METH_VARARGS ,
822+ .ml_doc = query_set_timeout_micros_doc ,
823+ },
801824 {
802825 .ml_name = "set_match_limit" ,
803826 .ml_meth = (PyCFunction )query_set_match_limit ,
@@ -902,13 +925,18 @@ static PyGetSetDef query_accessors[] = {
902925 PyDoc_STR ("The number of patterns in the query." ), NULL },
903926 {"capture_count" , (getter )query_get_capture_count , NULL ,
904927 PyDoc_STR ("The number of captures in the query." ), NULL },
928+ {"timeout_micros" , (getter )query_get_timeout_micros , NULL ,
929+ PyDoc_STR ("The maximum duration in microseconds that query "
930+ "execution should be allowed to take before halting." ),
931+ NULL },
905932 {"match_limit" , (getter )query_get_match_limit , NULL ,
906933 PyDoc_STR ("The maximum number of in-progress matches." ), NULL },
907934 {"did_exceed_match_limit" , (getter )query_get_did_exceed_match_limit , NULL ,
908935 PyDoc_STR ("Check if the query exceeded its maximum number of "
909936 "in-progress matches during its last execution." ),
910937 NULL },
911- {NULL }};
938+ {NULL },
939+ };
912940
913941static PyType_Slot query_type_slots [] = {
914942 {Py_tp_doc , PyDoc_STR ("A set of patterns that match nodes in a syntax tree." DOC_RAISES
0 commit comments