-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalize loader searching algorithm #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,8 +69,8 @@ evmc_create_fn evmc_load(const char* filename, enum evmc_loader_error_code* erro | |
// Create name buffer with the prefix. | ||
const char prefix[] = "evmc_create_"; | ||
const size_t prefix_length = strlen(prefix); | ||
char name[sizeof(prefix) + PATH_MAX_LENGTH]; | ||
strcpy_s(name, sizeof(name), prefix); | ||
char prefixed_name[sizeof(prefix) + PATH_MAX_LENGTH]; | ||
strcpy_s(prefixed_name, sizeof(prefixed_name), prefix); | ||
|
||
// Find filename in the path. | ||
const char* sep_pos = strrchr(filename, '/'); | ||
|
@@ -87,30 +87,28 @@ evmc_create_fn evmc_load(const char* filename, enum evmc_loader_error_code* erro | |
if (strncmp(name_pos, lib_prefix, lib_prefix_length) == 0) | ||
name_pos += lib_prefix_length; | ||
|
||
strcpy_s(name + prefix_length, PATH_MAX_LENGTH, name_pos); | ||
char* base_name = prefixed_name + prefix_length; | ||
strcpy_s(base_name, PATH_MAX_LENGTH, name_pos); | ||
|
||
// Trim the file extension. | ||
char* ext_pos = strrchr(name, '.'); | ||
char* ext_pos = strrchr(prefixed_name, '.'); | ||
if (ext_pos) | ||
*ext_pos = 0; | ||
|
||
// Replace all "-" with "_". | ||
char* dash_pos = name; | ||
char* dash_pos = base_name; | ||
while ((dash_pos = strchr(dash_pos, '-')) != NULL) | ||
*dash_pos++ = '_'; | ||
|
||
// Search for the "full name" based function name. | ||
create_fn = DLL_GET_CREATE_FN(handle, name); | ||
if (!create_fn) | ||
// Search for the built function name. | ||
while ((create_fn = DLL_GET_CREATE_FN(handle, prefixed_name)) == NULL) | ||
{ | ||
// Try the "short name" based function name. | ||
const char* short_name_pos = strrchr(name, '_'); | ||
if (short_name_pos) | ||
{ | ||
short_name_pos += 1; | ||
memmove(name + prefix_length, short_name_pos, strlen(short_name_pos) + 1); | ||
create_fn = DLL_GET_CREATE_FN(handle, name); | ||
} | ||
// Shorten the base name by skipping the `word_` segment. | ||
const char* shorter_name_pos = strchr(base_name, '_'); | ||
if (!shorter_name_pos) | ||
break; | ||
|
||
memmove(base_name, shorter_name_pos + 1, strlen(shorter_name_pos) + 1); | ||
} | ||
|
||
if (!create_fn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Practically this part wouldn't be needed if in the above loop on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. I will check it out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it will get messy. I would need to add another loop terminating condition (like strlen == 0) and we don't want to check for "evmc_create_" but "evmc_create". Also, the naming convention will change soon and we might want to try "evmc_create" first. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what exactly is the logic here? It removes the prefixes?
example
offexample_interpreter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But also
a_b_c_d
->b_c_d
->c_d
->d
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasoning for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
evmc-example-vm
:) I want it to come up with function nameevmc_create_example_vm()
while previously it tried onlyevmc_create_evmc_example_vm()
andevmc_create_vm()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that may not be the most sound reasoning :)
Why not just name the file
example-vm
(and the creator appropriately) and be done with it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 3 reasons:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't notice the old code was doing the very same weird logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was, but not fully. It was skipping all leading words except the last one.