添付ファイルの情報



[添付ファイル一覧] [全ページの添付ファイル一覧]

filebregexp_no_exception.diff
格納ファイル名:attach/4A756E6B2F3333_627265676578705F6E6F5F657863657074696F6E2E64696666
ページ:Junk/33
格納ファイル名:attach/4A756E6B2F3333_627265676578705F6E6F5F657863657074696F6E2E64696666
MD5ハッシュ値:b513507cf0f84dc3ef3bdf3f228601fd
サイズ:5.8KB (5924 bytes)
Content-type:application/octet-stream
登録日時:2007/06/23 02:11:27
アクセス数:213
MD5ハッシュ値:b513507cf0f84dc3ef3bdf3f228601fd
filebregexp_no_exception.diff
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Index: bregexec.cpp
===================================================================
--- bregexec.cpp	(revision 1102)
+++ bregexec.cpp	(working copy)
@@ -77,8 +77,16 @@
 #include <string.h>
 #include <ctype.h>
 
+//	From Here 
+/*
+	2007.06.23 genta : SEH support
+	These inclusion must be before "sv.h" because
+	"sv.h" include definition of BOOL that conflicts
+	typdef in "windows.h"
+*/	
+#include <windows.h>
+#include <malloc.h>
 
-
 #define KANJI
 
 
@@ -87,7 +95,6 @@
 
 
 
-
 #include "global.h"
 //#include "handy.h"  in perl.h
 #include "sv.h"
@@ -104,6 +111,8 @@
 static int regrepeat(char *p, int max,GLOBAL*);
 
 
+//	2007.06.23 genta : SEH support
+DWORD SEHFilter(DWORD code, LPEXCEPTION_POINTERS pInfo);
 
 
 
@@ -147,14 +156,16 @@
  */
 
 /*
- - bregexec - match a regexp against a string
+ - bregexec_main - match a regexp against a string
+   renamed from bregexp
  */
-BOOL bregexec(register regexp *prog,char *stringarg,
+static BOOL bregexec_main(register regexp *prog,char *stringarg,
 register char *strend,	/* pointer to null at end of string */
 char *strbeg,	/* real beginning of string */
 int minend,		/* end of match must be at least minend after stringarg */
 int safebase,	/* no need to remember string in subbase */
-char *msg)		/* fatal error message */
+char *msg,      /* fatal error message */
+GLOBAL *globalp)/* global workarea */
 {
     register char *s;
     register int i;
@@ -166,13 +177,8 @@
 
 	if (startpos == strend)	// length 0  bye bye
 		return 0;
+	//	initialization of global has been moved.
 
-
-	GLOBAL global;
-	GLOBAL *globalp;
-	globalp = &global;
-	memset((void*)globalp,0,sizeof(GLOBAL));
-
 	multiline = prog->pmflags & PMf_MULTILINE;
 	kanji_mode_flag = prog->pmflags & PMf_KANJI;	// using KANJI_MODE macro
     int minlen = 0;		/* must match at least this many chars */
@@ -591,8 +597,7 @@
 //	    Safefree(startpos);
 	    delete [] startpos;
     }
-	if (savestack)
-		delete [] savestack;
+    //	2007.06.23 savestack is moved to outer scope
     return 1;
 
 phooey:
@@ -600,8 +605,7 @@
 //		Safefree(startpos);
 		delete [] startpos;
 
-	if (savestack)
-		delete [] savestack;
+    //	2007.06.23 savestack is moved to outer scope
 	
 	return 0;
 
@@ -609,16 +613,14 @@
 	catch (const char* err){
 		strcpy(msg,err);
 
-		if (savestack)
-			delete [] savestack;
+	    //	2007.06.23 savestack is moved to outer scope
 
 		return 0;
 	}
 	catch (...){
 		strcpy(msg,"fatal error");
 
-		if (savestack)
-			delete [] savestack;
+	    //	2007.06.23 savestack is moved to outer scope
 
 		return 0;
 	}
@@ -627,6 +629,52 @@
 
 
 }
+
+
+/*
+	bregexec : SEH wrapper for bregexec_main
+	because regmatch() use recursive call,
+	stack area can run out.
+
+	This function catch stack overflow exception
+	and rewind the stack area.
+
+	@author genta
+	@date 2007.06.23 created
+ */
+BOOL bregexec(register regexp *prog,char *stringarg,
+register char *strend,	/* pointer to null at end of string */
+char *strbeg,	/* real beginning of string */
+int minend,		/* end of match must be at least minend after stringarg */
+int safebase,	/* no need to remember string in subbase */
+char *msg)		/* fatal error message */
+{
+	BOOL ret;
+	GLOBAL global_body;
+	memset((void*)&global_body,0,sizeof(global_body));
+
+	GLOBAL *globalp = &global_body;
+
+	__try {
+		/* memory management is moved from bregexec_main()
+		   to ensure memory release even in case of stack overflow
+		*/
+		ret = bregexec_main( prog, stringarg, strend, strbeg,
+			minend, safebase, msg, &global_body );
+	}
+	__except (SEHFilter(GetExceptionCode(), GetExceptionInformation()) ){
+
+		_resetstkoflw();
+		strcpy(msg,"stack overflow");
+		ret = 0;
+	}
+
+	// ensure 
+	if (savestack)
+		delete [] savestack;
+	return ret;
+}
+
 ////////////////////////////////XXXXXXXXXXXXX
 /*
  - regmatch - main matching routine
@@ -1383,3 +1431,24 @@
 	}
 	savestack = (union any*)buf;
 }
+
+/*!
+	@brief Windows exception handling filter
+
+*/
+DWORD SEHFilter(DWORD code, LPEXCEPTION_POINTERS pInfo)
+{
+#if 0
+	if( EXCEPTION_NONCONTINUABLE == pInfo->ExceptionRecord->ExceptionFlags ){
+		OutputDebugString( "NOT CONTINUABLE\n" );
+	}
+	else {
+		OutputDebugString( "CONTINUABLE\n" );
+	}
+#endif
+	if( EXCEPTION_STACK_OVERFLOW == code ){
+//		OutputDebugString( "Stack Overflow !!! Exception handled\n" );
+		return EXCEPTION_EXECUTE_HANDLER;
+	}
+	return EXCEPTION_CONTINUE_SEARCH;
+}
Index: BREGEXP.rc
===================================================================
--- BREGEXP.rc	(revision 1102)
+++ BREGEXP.rc	(working copy)
@@ -7,7 +7,8 @@
 //
 // Generated from the TEXTINCLUDE 2 resource.
 //
-#include "afxres.h"
+//#include "afxres.h"
+#include "windows.h"
 
 /////////////////////////////////////////////////////////////////////////////
 #undef APSTUDIO_READONLY_SYMBOLS
@@ -28,7 +29,7 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 2,0,4,291
+ FILEVERSION 2,0,4,292
  PRODUCTVERSION 2,0,4,29
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
@@ -47,7 +48,7 @@
             VALUE "Comments", "Regular Expression Engine for SAKURA\0"
             VALUE "CompanyName", "Tatsuo Baba\0"
             VALUE "FileDescription", "BREGEXP\0"
-            VALUE "FileVersion", "2, 0, 4, 291\0"
+            VALUE "FileVersion", "2, 0, 4, 292\0"
             VALUE "InternalName", "BREGEXP\0"
             VALUE "LegalCopyright", "Copyright (C) 1999-2000 Tatsuo Baba\0"
             VALUE "LegalTrademarks", "\0"
Index: main.cpp
===================================================================
--- main.cpp	(revision 1102)
+++ main.cpp	(working copy)
@@ -28,7 +28,7 @@
 {
 	//	2003.11.01 Karoto : Change version info
 	//	2006.07.14 genta : Change version info
-	static char version[] = "Bregexp.dll V1.02 for SAKURA "
+	static char version[] = "Bregexp.dll No stack overflow "
 __DATE__;
 
 	return version;
@@ -385,3 +385,4 @@
     delete [] r->endp;
     delete [] r;
 }
+




    


    ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS