Skip to content

Commit e9a1fac

Browse files
committed
Merge 9.0 - Add testhandlecount command.
2 parents f881b91 + 9952492 commit e9a1fac

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

generic/tclTest.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ static Tcl_ObjCmdProc TestInterpResolverCmd;
334334
static Tcl_ObjCmdProc TestcpuidCmd;
335335
#endif
336336
static Tcl_ObjCmdProc TestApplyLambdaCmd;
337+
#ifdef _WIN32
338+
static Tcl_ObjCmdProc TestHandleCountCmd;
339+
#endif
337340

338341
static const Tcl_Filesystem testReportingFilesystem = {
339342
"reporting",
@@ -725,6 +728,10 @@ Tcltest_Init(
725728
NULL, NULL);
726729
Tcl_CreateObjCommand(interp, "testlutil", TestLutilCmd,
727730
NULL, NULL);
731+
#if defined(_WIN32)
732+
Tcl_CreateObjCommand(interp, "testhandlecount", TestHandleCountCmd,
733+
NULL, NULL);
734+
#endif
728735

729736
if (TclObjTest_Init(interp) != TCL_OK) {
730737
return TCL_ERROR;
@@ -8824,6 +8831,46 @@ TestLutilCmd(
88248831
return ret;
88258832
}
88268833

8834+
#ifdef _WIN32
8835+
/*
8836+
*----------------------------------------------------------------------
8837+
*
8838+
* TestHandleCountCmd --
8839+
*
8840+
* This procedure implements the "testhandlecount" command. It returns
8841+
* the number of open handles in the process.
8842+
*
8843+
* Results:
8844+
* A standard Tcl result.
8845+
*
8846+
* Side effects:
8847+
* None.
8848+
*
8849+
*----------------------------------------------------------------------
8850+
*/
8851+
8852+
static int
8853+
TestHandleCountCmd(
8854+
TCL_UNUSED(void *),
8855+
Tcl_Interp *interp, /* Current interpreter. */
8856+
int objc, /* Number of arguments. */
8857+
Tcl_Obj *const objv[]) /* Arguments. */
8858+
{
8859+
DWORD count;
8860+
if (objc != 1) {
8861+
Tcl_WrongNumArgs(interp, 1, objv, "");
8862+
return TCL_ERROR;
8863+
}
8864+
if (GetProcessHandleCount(GetCurrentProcess(), &count)) {
8865+
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(count));
8866+
return TCL_OK;
8867+
}
8868+
Tcl_SetObjResult(interp, Tcl_NewStringObj(
8869+
"GetProcessHandleCount failed", -1));
8870+
return TCL_ERROR;
8871+
}
8872+
#endif /* _WIN32 */
8873+
88278874
/*
88288875
* Local Variables:
88298876
* mode: c

0 commit comments

Comments
 (0)