File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -491,6 +491,25 @@ func (re *Regexp) Study(flags int) error {
491
491
return nil
492
492
}
493
493
494
+ // SetJITStackSize used for change JIT stack size.
495
+ // The arguments are a starting size for the stack, and a maximum size to which it is
496
+ // allowed to grow. See also pcre_assign_jit_stack
497
+ func (re * Regexp ) SetJITStackSize (startSize int , maxSize int ) error {
498
+ if len (re .extra ) == 0 {
499
+ return errors .New ("can't set JIT stack size: have no extra data" )
500
+ }
501
+
502
+ stack := C .pcre_jit_stack_alloc (C .int (startSize ), C .int (maxSize ))
503
+ if stack == nil {
504
+ return errors .New ("can't allocate JIT stack" )
505
+ }
506
+ extra := (* C .pcre_extra )(unsafe .Pointer (& re .extra [0 ]))
507
+ C .pcre_assign_jit_stack (extra , nil , unsafe .Pointer (stack ))
508
+ // We should later release stack by pcre_jit_stack_free, but do not it yet
509
+
510
+ return nil
511
+ }
512
+
494
513
// Matcher objects provide a place for storing match results.
495
514
// They can be created by the NewMatcher and NewMatcherString functions,
496
515
// or they can be initialized with Reset or ResetString.
Original file line number Diff line number Diff line change @@ -224,6 +224,19 @@ func BenchmarkExecWithoutStudy(b *testing.B) {
224
224
}
225
225
}
226
226
227
+ func TestJITStackSize (t * testing.T ) {
228
+ re := MustCompileJIT (`aaa|bb|cc` , 0 , STUDY_JIT_COMPILE )
229
+ err := re .SetJITStackSize (64 * 1024 , 1024 * 1024 )
230
+ if err != nil {
231
+ t .Errorf ("Error call of SetJITStackSize: %s" , err )
232
+ }
233
+
234
+ m := re .NewMatcherString (`bb` , 0 )
235
+ if ! m .Matches {
236
+ t .Error ("The match should be matched" )
237
+ }
238
+ }
239
+
227
240
func TestPartial (t * testing.T ) {
228
241
re := MustCompile (`^abc` , 0 )
229
242
You can’t perform that action at this time.
0 commit comments