[Dependency Scanning] Remove the C string getter in favour of client-side string construction

(Using string length provided by the type)
This commit is contained in:
Artem Chikin
2020-12-17 10:39:03 -08:00
parent 39483f0a91
commit fd031589a0
3 changed files with 6 additions and 20 deletions

View File

@@ -36,8 +36,7 @@ SWIFTSCAN_BEGIN_DECLS
/**
* A character string used to pass around dependency scan result metadata.
* Lifetime of the string is strictly tied to the object whose field it
* represents. When the owning object is released, string memory is freed. Use
* \c swiftscan_get_C_string() to retrieve the string data.
* represents. When the owning object is released, string memory is freed.
*/
typedef struct {
const void *data;
@@ -95,12 +94,6 @@ typedef struct {
/// scan (command line arguments, working directory, etc.)
typedef struct swiftscan_scan_invocation_s *swiftscan_scan_invocation_t;
//=== String Functions ----------------------------------------------------===//
/// Retrieve the character data associated with the given string.
SWIFTSCAN_PUBLIC const char *
swiftscan_get_C_string(swiftscan_string_ref_t string);
//=== Dependency Result Functions -----------------------------------------===//
SWIFTSCAN_PUBLIC swiftscan_string_ref_t

View File

@@ -22,12 +22,6 @@ using namespace swift::dependencies;
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DependencyScanningTool, swiftscan_scanner_t);
//=== String Functions ----------------------------------------------------===//
const char *swiftscan_get_C_string(swiftscan_string_ref_t string) {
return static_cast<const char *>(string.data);
}
//=== Private Cleanup Functions -------------------------------------------===//
/// Free the given string.
@@ -124,7 +118,7 @@ swiftscan_dependency_graph_create(swiftscan_scanner_t scanner,
int argc = invocation->argv->count;
std::vector<const char *> Compilation;
for (int i = 0; i < argc; ++i)
Compilation.push_back(swiftscan_get_C_string(invocation->argv->strings[i]));
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
// Execute the scan and bridge the result
auto ScanResult = ScanningTool->getDependencies(Compilation, {});
@@ -142,13 +136,13 @@ swiftscan_batch_scan_result_create(swiftscan_scanner_t scanner,
int argc = invocation->argv->count;
std::vector<const char *> Compilation;
for (int i = 0; i < argc; ++i)
Compilation.push_back(swiftscan_get_C_string(invocation->argv->strings[i]));
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
std::vector<BatchScanInput> BatchInput;
for (size_t i = 0; i < batch_input->count; ++i) {
swiftscan_batch_scan_entry_s *Entry = batch_input->modules[i];
BatchInput.push_back({swiftscan_get_C_string(Entry->module_name),
swiftscan_get_C_string(Entry->arguments),
BatchInput.push_back({get_C_string(Entry->module_name),
get_C_string(Entry->arguments),
/*outputPath*/ "", Entry->is_swift});
}
@@ -176,7 +170,7 @@ swiftscan_import_set_create(swiftscan_scanner_t scanner,
int argc = invocation->argv->count;
std::vector<const char *> Compilation;
for (int i = 0; i < argc; ++i)
Compilation.push_back(swiftscan_get_C_string(invocation->argv->strings[i]));
Compilation.push_back(get_C_string(invocation->argv->strings[i]));
// Execute the scan and bridge the result
auto PreScanResult = ScanningTool->getImports(Compilation);

View File

@@ -51,4 +51,3 @@ swiftscan_dependency_graph_dispose
swiftscan_batch_scan_result_dispose
swiftscan_import_set_dispose
swiftscan_scanner_dispose
swiftscan_get_C_string