Skip to content

Commit fd03158

Browse files
committed
[Dependency Scanning] Remove the C string getter in favour of client-side string construction
(Using string length provided by the type)
1 parent 39483f0 commit fd03158

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ SWIFTSCAN_BEGIN_DECLS
3636
/**
3737
* A character string used to pass around dependency scan result metadata.
3838
* Lifetime of the string is strictly tied to the object whose field it
39-
* represents. When the owning object is released, string memory is freed. Use
40-
* \c swiftscan_get_C_string() to retrieve the string data.
39+
* represents. When the owning object is released, string memory is freed.
4140
*/
4241
typedef struct {
4342
const void *data;
@@ -95,12 +94,6 @@ typedef struct {
9594
/// scan (command line arguments, working directory, etc.)
9695
typedef struct swiftscan_scan_invocation_s *swiftscan_scan_invocation_t;
9796

98-
//=== String Functions ----------------------------------------------------===//
99-
100-
/// Retrieve the character data associated with the given string.
101-
SWIFTSCAN_PUBLIC const char *
102-
swiftscan_get_C_string(swiftscan_string_ref_t string);
103-
10497
//=== Dependency Result Functions -----------------------------------------===//
10598

10699
SWIFTSCAN_PUBLIC swiftscan_string_ref_t

tools/libSwiftScan/libSwiftScan.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ using namespace swift::dependencies;
2222

2323
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DependencyScanningTool, swiftscan_scanner_t);
2424

25-
//=== String Functions ----------------------------------------------------===//
26-
27-
const char *swiftscan_get_C_string(swiftscan_string_ref_t string) {
28-
return static_cast<const char *>(string.data);
29-
}
30-
3125
//=== Private Cleanup Functions -------------------------------------------===//
3226

3327
/// Free the given string.
@@ -124,7 +118,7 @@ swiftscan_dependency_graph_create(swiftscan_scanner_t scanner,
124118
int argc = invocation->argv->count;
125119
std::vector<const char *> Compilation;
126120
for (int i = 0; i < argc; ++i)
127-
Compilation.push_back(swiftscan_get_C_string(invocation->argv->strings[i]));
121+
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
128122

129123
// Execute the scan and bridge the result
130124
auto ScanResult = ScanningTool->getDependencies(Compilation, {});
@@ -142,13 +136,13 @@ swiftscan_batch_scan_result_create(swiftscan_scanner_t scanner,
142136
int argc = invocation->argv->count;
143137
std::vector<const char *> Compilation;
144138
for (int i = 0; i < argc; ++i)
145-
Compilation.push_back(swiftscan_get_C_string(invocation->argv->strings[i]));
139+
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
146140

147141
std::vector<BatchScanInput> BatchInput;
148142
for (size_t i = 0; i < batch_input->count; ++i) {
149143
swiftscan_batch_scan_entry_s *Entry = batch_input->modules[i];
150-
BatchInput.push_back({swiftscan_get_C_string(Entry->module_name),
151-
swiftscan_get_C_string(Entry->arguments),
144+
BatchInput.push_back({get_C_string(Entry->module_name),
145+
get_C_string(Entry->arguments),
152146
/*outputPath*/ "", Entry->is_swift});
153147
}
154148

@@ -176,7 +170,7 @@ swiftscan_import_set_create(swiftscan_scanner_t scanner,
176170
int argc = invocation->argv->count;
177171
std::vector<const char *> Compilation;
178172
for (int i = 0; i < argc; ++i)
179-
Compilation.push_back(swiftscan_get_C_string(invocation->argv->strings[i]));
173+
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
180174

181175
// Execute the scan and bridge the result
182176
auto PreScanResult = ScanningTool->getImports(Compilation);

tools/libSwiftScan/libSwiftScan.exports

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,3 @@ swiftscan_dependency_graph_dispose
5151
swiftscan_batch_scan_result_dispose
5252
swiftscan_import_set_dispose
5353
swiftscan_scanner_dispose
54-
swiftscan_get_C_string

0 commit comments

Comments
 (0)