| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#define USE_COMPAT_CONST |
| 15 |
#include "tclWinInt.h" |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
int TclplatformtestInit _ANSI_ARGS_((Tcl_Interp *interp)); |
| 21 |
static int TesteventloopCmd _ANSI_ARGS_((ClientData dummy, |
| 22 |
Tcl_Interp *interp, int argc, char **argv)); |
| 23 |
static int TestvolumetypeCmd _ANSI_ARGS_((ClientData dummy, |
| 24 |
Tcl_Interp *interp, int objc, |
| 25 |
Tcl_Obj *CONST objv[])); |
| 26 |
static int TestwinclockCmd _ANSI_ARGS_(( ClientData dummy, |
| 27 |
Tcl_Interp* interp, |
| 28 |
int objc, |
| 29 |
Tcl_Obj *CONST objv[] )); |
| 30 |
static int TestwinsleepCmd _ANSI_ARGS_(( ClientData dummy, |
| 31 |
Tcl_Interp* interp, |
| 32 |
int objc, |
| 33 |
Tcl_Obj *CONST objv[] )); |
| 34 |
static Tcl_ObjCmdProc TestExceptionCmd; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
int |
| 55 |
TclplatformtestInit(interp) |
| 56 |
Tcl_Interp *interp; |
| 57 |
{ |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
Tcl_CreateCommand(interp, "testeventloop", TesteventloopCmd, |
| 63 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 64 |
Tcl_CreateObjCommand(interp, "testvolumetype", TestvolumetypeCmd, |
| 65 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 66 |
Tcl_CreateObjCommand(interp, "testwinclock", TestwinclockCmd, |
| 67 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 68 |
Tcl_CreateObjCommand( interp, |
| 69 |
"testwinsleep", |
| 70 |
TestwinsleepCmd, |
| 71 |
(ClientData) 0, |
| 72 |
(Tcl_CmdDeleteProc *) NULL ); |
| 73 |
Tcl_CreateObjCommand(interp, "testexcept", TestExceptionCmd, NULL, NULL); |
| 74 |
return TCL_OK; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
static int |
| 96 |
TesteventloopCmd(clientData, interp, argc, argv) |
| 97 |
ClientData clientData; |
| 98 |
Tcl_Interp *interp; |
| 99 |
int argc; |
| 100 |
char **argv; |
| 101 |
{ |
| 102 |
static int *framePtr = NULL; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
if (argc < 2) { |
| 107 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], |
| 108 |
" option ... \"", (char *) NULL); |
| 109 |
return TCL_ERROR; |
| 110 |
} |
| 111 |
if (strcmp(argv[1], "done") == 0) { |
| 112 |
*framePtr = 1; |
| 113 |
} else if (strcmp(argv[1], "wait") == 0) { |
| 114 |
int *oldFramePtr; |
| 115 |
int done; |
| 116 |
MSG msg; |
| 117 |
int oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
oldFramePtr = framePtr; |
| 124 |
framePtr = &done; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
done = 0; |
| 132 |
while (!done) { |
| 133 |
if (!GetMessage(&msg, NULL, 0, 0)) { |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
PostQuitMessage(msg.wParam); |
| 140 |
break; |
| 141 |
} |
| 142 |
TranslateMessage(&msg); |
| 143 |
DispatchMessage(&msg); |
| 144 |
} |
| 145 |
(void) Tcl_SetServiceMode(oldMode); |
| 146 |
framePtr = oldFramePtr; |
| 147 |
} else { |
| 148 |
Tcl_AppendResult(interp, "bad option \"", argv[1], |
| 149 |
"\": must be done or wait", (char *) NULL); |
| 150 |
return TCL_ERROR; |
| 151 |
} |
| 152 |
return TCL_OK; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
static int |
| 173 |
TestvolumetypeCmd(clientData, interp, objc, objv) |
| 174 |
ClientData clientData; |
| 175 |
Tcl_Interp *interp; |
| 176 |
int objc; |
| 177 |
Tcl_Obj *CONST objv[]; |
| 178 |
{ |
| 179 |
#define VOL_BUF_SIZE 32 |
| 180 |
int found; |
| 181 |
char volType[VOL_BUF_SIZE]; |
| 182 |
char *path; |
| 183 |
|
| 184 |
if (objc > 2) { |
| 185 |
Tcl_WrongNumArgs(interp, 1, objv, "?name?"); |
| 186 |
return TCL_ERROR; |
| 187 |
} |
| 188 |
if (objc == 2) { |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
path = Tcl_GetString(objv[1]); |
| 194 |
} else { |
| 195 |
path = NULL; |
| 196 |
} |
| 197 |
found = GetVolumeInformationA(path, NULL, 0, NULL, NULL, |
| 198 |
NULL, volType, VOL_BUF_SIZE); |
| 199 |
|
| 200 |
if (found == 0) { |
| 201 |
Tcl_AppendResult(interp, "could not get volume type for \"", |
| 202 |
(path?path:""), "\"", (char *) NULL); |
| 203 |
TclWinConvertError(GetLastError()); |
| 204 |
return TCL_ERROR; |
| 205 |
} |
| 206 |
Tcl_SetResult(interp, volType, TCL_VOLATILE); |
| 207 |
return TCL_OK; |
| 208 |
#undef VOL_BUF_SIZE |
| 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 |
static int |
| 238 |
TestwinclockCmd( ClientData dummy, |
| 239 |
|
| 240 |
Tcl_Interp* interp, |
| 241 |
|
| 242 |
int objc, |
| 243 |
|
| 244 |
Tcl_Obj *CONST objv[] ) |
| 245 |
|
| 246 |
{ |
| 247 |
CONST static FILETIME posixEpoch = { 0xD53E8000, 0x019DB1DE }; |
| 248 |
|
| 249 |
|
| 250 |
Tcl_Time tclTime; |
| 251 |
FILETIME sysTime; |
| 252 |
Tcl_Obj* result; |
| 253 |
LARGE_INTEGER t1, t2; |
| 254 |
LARGE_INTEGER p1, p2; |
| 255 |
|
| 256 |
if ( objc != 1 ) { |
| 257 |
Tcl_WrongNumArgs( interp, 1, objv, "" ); |
| 258 |
return TCL_ERROR; |
| 259 |
} |
| 260 |
|
| 261 |
QueryPerformanceCounter( &p1 ); |
| 262 |
|
| 263 |
Tcl_GetTime( &tclTime ); |
| 264 |
GetSystemTimeAsFileTime( &sysTime ); |
| 265 |
t1.LowPart = posixEpoch.dwLowDateTime; |
| 266 |
t1.HighPart = posixEpoch.dwHighDateTime; |
| 267 |
t2.LowPart = sysTime.dwLowDateTime; |
| 268 |
t2.HighPart = sysTime.dwHighDateTime; |
| 269 |
t2.QuadPart -= t1.QuadPart; |
| 270 |
|
| 271 |
QueryPerformanceCounter( &p2 ); |
| 272 |
|
| 273 |
result = Tcl_NewObj(); |
| 274 |
Tcl_ListObjAppendElement |
| 275 |
( interp, result, Tcl_NewIntObj( (int) (t2.QuadPart / 10000000 ) ) ); |
| 276 |
Tcl_ListObjAppendElement |
| 277 |
( interp, result, |
| 278 |
Tcl_NewIntObj( (int) ( (t2.QuadPart / 10 ) % 1000000 ) ) ); |
| 279 |
Tcl_ListObjAppendElement( interp, result, Tcl_NewIntObj( tclTime.sec ) ); |
| 280 |
Tcl_ListObjAppendElement( interp, result, Tcl_NewIntObj( tclTime.usec ) ); |
| 281 |
|
| 282 |
Tcl_ListObjAppendElement( interp, result, Tcl_NewWideIntObj( p1.QuadPart ) ); |
| 283 |
Tcl_ListObjAppendElement( interp, result, Tcl_NewWideIntObj( p2.QuadPart ) ); |
| 284 |
|
| 285 |
Tcl_SetObjResult( interp, result ); |
| 286 |
|
| 287 |
return TCL_OK; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
static int |
| 314 |
TestwinsleepCmd( ClientData clientData, |
| 315 |
|
| 316 |
Tcl_Interp* interp, |
| 317 |
|
| 318 |
int objc, |
| 319 |
|
| 320 |
Tcl_Obj * CONST * objv ) |
| 321 |
|
| 322 |
{ |
| 323 |
int ms; |
| 324 |
if ( objc != 2 ) { |
| 325 |
Tcl_WrongNumArgs( interp, 1, objv, "ms" ); |
| 326 |
return TCL_ERROR; |
| 327 |
} |
| 328 |
if ( Tcl_GetIntFromObj( interp, objv[1], &ms ) != TCL_OK ) { |
| 329 |
return TCL_ERROR; |
| 330 |
} |
| 331 |
Sleep( (DWORD) ms ); |
| 332 |
return TCL_OK; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
static int |
| 359 |
TestExceptionCmd( |
| 360 |
ClientData dummy, |
| 361 |
Tcl_Interp* interp, |
| 362 |
int objc, |
| 363 |
Tcl_Obj *CONST objv[]) |
| 364 |
{ |
| 365 |
static char *cmds[] = { |
| 366 |
"access_violation", |
| 367 |
"datatype_misalignment", |
| 368 |
"array_bounds", |
| 369 |
"float_denormal", |
| 370 |
"float_divbyzero", |
| 371 |
"float_inexact", |
| 372 |
"float_invalidop", |
| 373 |
"float_overflow", |
| 374 |
"float_stack", |
| 375 |
"float_underflow", |
| 376 |
"int_divbyzero", |
| 377 |
"int_overflow", |
| 378 |
"private_instruction", |
| 379 |
"inpageerror", |
| 380 |
"illegal_instruction", |
| 381 |
"noncontinue", |
| 382 |
"stack_overflow", |
| 383 |
"invalid_disp", |
| 384 |
"guard_page", |
| 385 |
"invalid_handle", |
| 386 |
"ctrl+c", |
| 387 |
NULL |
| 388 |
}; |
| 389 |
static DWORD exceptions[] = { |
| 390 |
EXCEPTION_ACCESS_VIOLATION, |
| 391 |
EXCEPTION_DATATYPE_MISALIGNMENT, |
| 392 |
EXCEPTION_ARRAY_BOUNDS_EXCEEDED, |
| 393 |
EXCEPTION_FLT_DENORMAL_OPERAND, |
| 394 |
EXCEPTION_FLT_DIVIDE_BY_ZERO, |
| 395 |
EXCEPTION_FLT_INEXACT_RESULT, |
| 396 |
EXCEPTION_FLT_INVALID_OPERATION, |
| 397 |
EXCEPTION_FLT_OVERFLOW, |
| 398 |
EXCEPTION_FLT_STACK_CHECK, |
| 399 |
EXCEPTION_FLT_UNDERFLOW, |
| 400 |
EXCEPTION_INT_DIVIDE_BY_ZERO, |
| 401 |
EXCEPTION_INT_OVERFLOW, |
| 402 |
EXCEPTION_PRIV_INSTRUCTION, |
| 403 |
EXCEPTION_IN_PAGE_ERROR, |
| 404 |
EXCEPTION_ILLEGAL_INSTRUCTION, |
| 405 |
EXCEPTION_NONCONTINUABLE_EXCEPTION, |
| 406 |
EXCEPTION_STACK_OVERFLOW, |
| 407 |
EXCEPTION_INVALID_DISPOSITION, |
| 408 |
EXCEPTION_GUARD_PAGE, |
| 409 |
EXCEPTION_INVALID_HANDLE, |
| 410 |
CONTROL_C_EXIT |
| 411 |
}; |
| 412 |
int cmd; |
| 413 |
|
| 414 |
if ( objc != 2 ) { |
| 415 |
Tcl_WrongNumArgs(interp, 0, objv, "<type-of-exception>"); |
| 416 |
return TCL_ERROR; |
| 417 |
} |
| 418 |
if (Tcl_GetIndexFromObj(interp, objv[1], cmds, "command", 0, |
| 419 |
&cmd) != TCL_OK) { |
| 420 |
return TCL_ERROR; |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
RaiseException(exceptions[cmd], EXCEPTION_NONCONTINUABLE, 0, NULL); |
| 438 |
|
| 439 |
|
| 440 |
return TCL_OK; |
| 441 |
} |