添付ファイルの情報



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

filebregexp_no_exception2.diff
格納ファイル名:attach/4A756E6B2F3333_627265676578705F6E6F5F657863657074696F6E322E64696666
ページ:Junk/33
格納ファイル名:attach/4A756E6B2F3333_627265676578705F6E6F5F657863657074696F6E322E64696666
MD5ハッシュ値:e520a9d8f09ab73cd7229768f85b6b80
サイズ:5.5KB (5631 bytes)
Content-type:application/octet-stream
登録日時:2007/08/09 21:49:38
アクセス数:384
MD5ハッシュ値:e520a9d8f09ab73cd7229768f85b6b80
filebregexp_no_exception2.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
Index: bregexec.cpp
===================================================================
--- bregexec.cpp	(revision 1112)
+++ bregexec.cpp	(working copy)
@@ -77,7 +77,21 @@
 #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>
 
+#if _MSC_VER > 1000
+#define __STR2__(x) #x
+#define __STR1__(x) __STR2__(x)
+#define __LOC__ __FILE__ "("__STR1__(__LINE__)") : warning MESSAGE: "
+#endif
 
 #define KANJI
 
@@ -147,14 +161,21 @@
  */
 
 /*
- - bregexec - match a regexp against a string
+ - bregexec_main - match a regexp against a string
+   renamed from bregexp
+
+	This function catch stack overflow exception
+	and rewind the stack area.
+	because regmatch() use recursive call,
+	stack area can run out.
  */
-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 +187,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 */
@@ -191,7 +207,7 @@
     }
 
 	////////// exception started
-	try {
+	__try {
 
 
 
@@ -591,8 +607,7 @@
 //	    Safefree(startpos);
 	    delete [] startpos;
     }
-	if (savestack)
-		delete [] savestack;
+    //	2007.06.23 savestack is moved to outer scope
     return 1;
 
 phooey:
@@ -600,33 +615,75 @@
 //		Safefree(startpos);
 		delete [] startpos;
 
-	if (savestack)
-		delete [] savestack;
+    //	2007.06.23 savestack is moved to outer scope
 	
 	return 0;
 
 }		// error handler start
-	catch (const char* err){
-		strcpy(msg,err);
-
-		if (savestack)
-			delete [] savestack;
-
+#if _MSC_VER >= 1310
+	__except ( (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW)?
+				EXCEPTION_EXECUTE_HANDLER: EXCEPTION_CONTINUE_SEARCH ){
+		_resetstkoflw();	// recovers from a stack overflow condition
+		strcpy(msg,"stack overflow");
 		return 0;
 	}
-	catch (...){
-		strcpy(msg,"fatal error");
-
-		if (savestack)
-			delete [] savestack;
-
+#else
+#if _MSC_VER > 1000
+#pragma message( __LOC__ "Stack overflow recovery will not work. The _resetstkoflw() function is declared in malloc.h for VC7.1 or lator." )
+#endif
+	__except ( EXCEPTION_CONTINUE_SEARCH ){
+		// We'll never get here.
 		return 0;
 	}
+#endif
 
 
 
 
 }
+
+
+/*
+	bregexec : C++ exception wrapper for bregexec_main
+
+	@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 );
+	}
+	catch (const char* err){
+		strcpy(msg,err);
+		ret = 0;
+	}
+	catch (...){
+		strcpy(msg,"fatal error");
+		ret = 0;
+	}
+
+	// ensure 
+	if (savestack)
+		delete [] savestack;
+	return ret;
+}
+
 ////////////////////////////////XXXXXXXXXXXXX
 /*
  - regmatch - main matching routine
Index: BREGEXP.rc
===================================================================
--- BREGEXP.rc	(revision 1112)
+++ 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 1112)
+++ 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;




    


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