Commit 65b7ef2
authored
Use the Toolhelp32 API to enumerate loaded Win32 modules. (#892)
This PR replaces our call to `EnumProcessModules()` with one to
`CreateToolhelp32Snapshot(TH32CS_SNAPMODULE)`. Three reasons:
1. `EnumProcessModules()` requires us to specify a large, fixed-size
buffer to contain all the `HMODULE` handles;
2. `EnumProcessModules()` does not own any references to the handles it
returns, meaning that a module can be unloaded while we are iterating
over them (while `CreateToolhelp32Snapshot()` temporarily bumps the
refcounts of the handles it produces); and
3. `CreateToolhelp32Snapshot()` lets us produce a lazy sequence of
`HMODULE` values rather than an array, letting us write somewhat
Swiftier code that uses it.
The overhead of using `CreateToolhelp32Snapshot()` was negligible (below
the noise level when measuring).
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.1 parent 4ca12ee commit 65b7ef2
File tree
2 files changed
+56
-19
lines changed- Sources/Testing/Support
- Additions
2 files changed
+56
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 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 | + | |
53 | 105 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
92 | 77 | | |
93 | 78 | | |
94 | 79 | | |
| |||
0 commit comments