Skip to content

Commit bd074b7

Browse files
authored
Merge pull request #13 from danipen/sync-create-regex
Sync create oniguruma regex
2 parents 5784411 + 17d9a8a commit bd074b7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,7 @@ onigwrap/src/libonigwrap.so
377377
.idea/.idea.TextMateSharp.dir/.idea/encodings.xml
378378
.idea/.idea.TextMateSharp.dir/.idea/indexLayout.xml
379379
.idea/.idea.TextMateSharp.dir/.idea/vcs.xml
380+
onigwrap/src/onigwrap.lib
381+
onigwrap/src/onigwrap.exp
382+
onigwrap/src/onigwrap.dll
383+
onigwrap/src/onig_s.lib

src/TextMateSharp/Internal/Oniguruma/ORegex.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace TextMateSharp.Internal.Oniguruma
66
{
77
public class ORegex : IDisposable
88
{
9+
private static object _createRegexSync = new object();
10+
911
private IntPtr _regex;
1012
private IntPtr _region;
1113
private bool _disposed = false;
@@ -28,13 +30,16 @@ public unsafe ORegex(string pattern, bool ignoreCase = true, bool multiline = fa
2830
pattern = UnicodeCharEscape.AddBracesToUnicodePatterns(pattern);
2931
pattern = UnicodeCharEscape.ConstraintUnicodePatternLenght(pattern);
3032

31-
fixed (char* patternPtr = pattern)
33+
lock (_createRegexSync)
3234
{
33-
_regex = OnigInterop.onigwrap_create(
34-
patternPtr,
35-
Encoding.Unicode.GetByteCount(patternPtr, pattern.Length),
36-
ignoreCaseArg,
37-
multilineArg);
35+
fixed (char* patternPtr = pattern)
36+
{
37+
_regex = OnigInterop.onigwrap_create(
38+
patternPtr,
39+
Encoding.Unicode.GetByteCount(patternPtr, pattern.Length),
40+
ignoreCaseArg,
41+
multilineArg);
42+
}
3843
}
3944

4045
if (!Valid)

0 commit comments

Comments
 (0)