@@ -611,6 +611,16 @@ PyObject *query_pattern_assertions(Query *self, PyObject *args) {
611
611
return item ;
612
612
}
613
613
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
+
614
624
PyObject * query_set_match_limit (Query * self , PyObject * args ) {
615
625
uint32_t match_limit ;
616
626
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)) {
730
740
return PyLong_FromSize_t (ts_query_capture_count (self -> query ));
731
741
}
732
742
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
+
733
747
PyObject * query_get_match_limit (Query * self , void * Py_UNUSED (payload )) {
734
748
return PyLong_FromSize_t (ts_query_cursor_match_limit (self -> cursor ));
735
749
}
@@ -738,6 +752,9 @@ PyObject *query_get_did_exceed_match_limit(Query *self, void *Py_UNUSED(payload)
738
752
return PyLong_FromSize_t (ts_query_cursor_did_exceed_match_limit (self -> cursor ));
739
753
}
740
754
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." );
741
758
PyDoc_STRVAR (query_set_match_limit_doc , "set_match_limit(self, match_limit)\n--\n\n"
742
759
"Set the maximum number of in-progress matches." DOC_RAISES
743
760
"ValueError\n\n If set to ``0``." );
@@ -798,6 +815,12 @@ PyDoc_STRVAR(query_is_pattern_guaranteed_at_step_doc,
798
815
"Check if a pattern is guaranteed to match once a given byte offset is reached." );
799
816
800
817
static 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
+ },
801
824
{
802
825
.ml_name = "set_match_limit" ,
803
826
.ml_meth = (PyCFunction )query_set_match_limit ,
@@ -902,13 +925,18 @@ static PyGetSetDef query_accessors[] = {
902
925
PyDoc_STR ("The number of patterns in the query." ), NULL },
903
926
{"capture_count" , (getter )query_get_capture_count , NULL ,
904
927
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 },
905
932
{"match_limit" , (getter )query_get_match_limit , NULL ,
906
933
PyDoc_STR ("The maximum number of in-progress matches." ), NULL },
907
934
{"did_exceed_match_limit" , (getter )query_get_did_exceed_match_limit , NULL ,
908
935
PyDoc_STR ("Check if the query exceeded its maximum number of "
909
936
"in-progress matches during its last execution." ),
910
937
NULL },
911
- {NULL }};
938
+ {NULL },
939
+ };
912
940
913
941
static PyType_Slot query_type_slots [] = {
914
942
{Py_tp_doc , PyDoc_STR ("A set of patterns that match nodes in a syntax tree." DOC_RAISES
0 commit comments