Skip to content

Commit 06dc666

Browse files
committed
Reflection: Small cleanups for swift-reflection-test
1 parent 0dffbcb commit 06dc666

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ static void errorAndExit(const char *message) {
5555
abort();
5656
}
5757

58-
swift_reflection_section_t
58+
static swift_reflection_section_t
5959
makeLocalSection(void *Buffer, RemoteSection Section,
6060
RemoteReflectionInfo Info) {
61+
if (Section.Size == 0) {
62+
swift_reflection_section_t LS = {NULL, NULL};
63+
return LS;
64+
}
65+
6166
uintptr_t Base
6267
= (uintptr_t)Buffer + Section.StartAddress - Info.StartAddress;
6368
swift_reflection_section_t LS = {
@@ -67,6 +72,7 @@ makeLocalSection(void *Buffer, RemoteSection Section,
6772
return LS;
6873
}
6974

75+
static
7076
uintptr_t getStartAddress(const RemoteSection Sections[], size_t Count) {
7177
uintptr_t Start = 0;
7278
for (size_t i = 0; i < Count; ++i) {
@@ -80,6 +86,7 @@ uintptr_t getStartAddress(const RemoteSection Sections[], size_t Count) {
8086
return Start;
8187
}
8288

89+
static
8390
uintptr_t getEndAddress(const RemoteSection Sections[], size_t Count) {
8491
uintptr_t End = 0;
8592
for (size_t i = 0; i < Count; ++i) {
@@ -89,6 +96,7 @@ uintptr_t getEndAddress(const RemoteSection Sections[], size_t Count) {
8996
return End;
9097
}
9198

99+
static
92100
RemoteReflectionInfo makeRemoteReflectionInfo(RemoteSection fieldmd,
93101
RemoteSection assocty,
94102
RemoteSection builtin,
@@ -118,41 +126,40 @@ RemoteReflectionInfo makeRemoteReflectionInfo(RemoteSection fieldmd,
118126
return Info;
119127
}
120128

121-
swift_reflection_section_t
122-
makeSwiftReflectionSection(uintptr_t Base, size_t Size) {
123-
swift_reflection_section_t section;
124-
section.Begin = (void*)Base;
125-
section.End = (void*)(Base + Size);
126-
return section;
127-
}
128-
129129
static const size_t ReadEnd = 0;
130130
static const size_t WriteEnd = 1;
131131

132+
static
132133
int PipeMemoryReader_getParentReadFD(const PipeMemoryReader *Reader) {
133134
return Reader->from_child[ReadEnd];
134135
}
135136

137+
static
136138
int PipeMemoryReader_getChildWriteFD(const PipeMemoryReader *Reader) {
137139
return Reader->from_child[WriteEnd];
138140
}
139141

142+
static
140143
int PipeMemoryReader_getParentWriteFD(const PipeMemoryReader *Reader) {
141144
return Reader->to_child[WriteEnd];
142145
}
143146

147+
static
144148
int PipeMemoryReader_getChildReadFD(const PipeMemoryReader *Reader) {
145149
return Reader->to_child[ReadEnd];
146150
}
147151

152+
static
148153
uint8_t PipeMemoryReader_getPointerSize(void *Context) {
149154
return sizeof(uintptr_t);
150155
}
151156

157+
static
152158
uint8_t PipeMemoryReader_getSizeSize(void *Context) {
153159
return sizeof(size_t);
154160
}
155161

162+
static
156163
void PipeMemoryReader_collectBytesFromPipe(const PipeMemoryReader *Reader,
157164
void *Dest, size_t Size) {
158165
int ReadFD = PipeMemoryReader_getParentReadFD(Reader);
@@ -167,6 +174,7 @@ void PipeMemoryReader_collectBytesFromPipe(const PipeMemoryReader *Reader,
167174
}
168175
}
169176

177+
static
170178
int PipeMemoryReader_readBytes(void *Context,
171179
addr_t Address, void *Dest, uint64_t Size) {
172180
const PipeMemoryReader *Reader = (const PipeMemoryReader *)Context;
@@ -180,6 +188,7 @@ int PipeMemoryReader_readBytes(void *Context,
180188
return 1;
181189
}
182190

191+
static
183192
addr_t PipeMemoryReader_getSymbolAddress(void *Context, const char *SymbolName,
184193
uint64_t Length) {
185194
const PipeMemoryReader *Reader = (const PipeMemoryReader *)Context;
@@ -193,7 +202,7 @@ addr_t PipeMemoryReader_getSymbolAddress(void *Context, const char *SymbolName,
193202
return (uintptr_t)Address;
194203
}
195204

196-
InstanceKind
205+
static InstanceKind
197206
PipeMemoryReader_receiveInstanceKind(const PipeMemoryReader *Reader) {
198207
int WriteFD = PipeMemoryReader_getParentWriteFD(Reader);
199208
write(WriteFD, REQUEST_INSTANCE_KIND, 2);
@@ -202,7 +211,7 @@ PipeMemoryReader_receiveInstanceKind(const PipeMemoryReader *Reader) {
202211
return KindValue;
203212
}
204213

205-
uintptr_t
214+
static uintptr_t
206215
PipeMemoryReader_receiveInstanceAddress(const PipeMemoryReader *Reader) {
207216
int WriteFD = PipeMemoryReader_getParentWriteFD(Reader);
208217
write(WriteFD, REQUEST_INSTANCE_ADDRESS, 2);
@@ -212,20 +221,13 @@ PipeMemoryReader_receiveInstanceAddress(const PipeMemoryReader *Reader) {
212221
return InstanceAddress;
213222
}
214223

224+
static
215225
void PipeMemoryReader_sendDoneMessage(const PipeMemoryReader *Reader) {
216226
int WriteFD = PipeMemoryReader_getParentWriteFD(Reader);
217227
write(WriteFD, REQUEST_DONE, 2);
218228
}
219229

220-
uint8_t PipeMemoryReader_receivePointerSize(const PipeMemoryReader *Reader) {
221-
int WriteFD = PipeMemoryReader_getParentWriteFD(Reader);
222-
write(WriteFD, REQUEST_POINTER_SIZE, 2);
223-
uint8_t PointerSize = 0;
224-
PipeMemoryReader_collectBytesFromPipe(Reader, (uint8_t*)&PointerSize,
225-
sizeof(PointerSize));
226-
return PointerSize;
227-
}
228-
230+
static
229231
PipeMemoryReader createPipeMemoryReader() {
230232
PipeMemoryReader Reader;
231233
if (pipe(Reader.to_child))
@@ -235,6 +237,7 @@ PipeMemoryReader createPipeMemoryReader() {
235237
return Reader;
236238
}
237239

240+
static
238241
RemoteSection makeRemoteSection(const PipeMemoryReader *Reader) {
239242
uintptr_t Start;
240243
size_t Size;
@@ -246,7 +249,7 @@ RemoteSection makeRemoteSection(const PipeMemoryReader *Reader) {
246249
return RS;
247250
}
248251

249-
void
252+
static void
250253
PipeMemoryReader_receiveReflectionInfo(SwiftReflectionContextRef RC,
251254
const PipeMemoryReader *Reader) {
252255
int WriteFD = PipeMemoryReader_getParentWriteFD(Reader);
@@ -433,6 +436,7 @@ int doDumpHeapInstance(const char *BinaryFilename) {
433436
return EXIT_SUCCESS;
434437
break;
435438
case None:
439+
swift_reflection_destroyReflectionContext(RC);
436440
printf("Done.\n");
437441
return EXIT_SUCCESS;
438442
}

0 commit comments

Comments
 (0)