1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-18 06:34:48 +00:00

Check type instead of value

Primarily because trying to check the value results in a panic when the
value is not the type of value requested from the API. Also probably
cheaper and the previous idea of just getting the value then comparing
was pretty stupid (needed a string comparison... and was going to do
pointer comparison).
This commit is contained in:
llmII 2021-09-06 09:45:58 -05:00
parent 2a4bcc262f
commit 532dac1b95
No known key found for this signature in database
GPG Key ID: E3AD2E259F58A9A0

View File

@ -302,8 +302,7 @@ static struct addrinfo *janet_get_addrinfo(Janet *argv, int32_t offset, int sock
* specify from where we connect, and in general don't care about a
* port */
int32_t current_offset = 3;
if (janet_keyeq(argv[current_offset], "stream") ||
janet_keyeq(argv[current_offset], "datagram")) {
if (janet_checktype(argv[3], JANET_KEYWORD)) {
current_offset = 4;
}
host = (char *)janet_getcstring(argv, current_offset);
@ -419,12 +418,9 @@ JANET_CORE_FN(cfun_net_connect,
}
}
/* TODO: check if need bind and bind! */
ai = NULL;
if (argc >= 3 && is_unix == 0) {
if (argc == 4 ||
(!janet_keyeq(argv[3], "stream") &&
!janet_keyeq(argv[3], "datagram"))) {
if (argc == 4 || !janet_checktype(argv[3], JANET_KEYWORD)) {
ai = janet_get_addrinfo(argv, 0, socktype, 0, &is_unix, 1);
}
}