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:
parent
2a4bcc262f
commit
532dac1b95
@ -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
|
* specify from where we connect, and in general don't care about a
|
||||||
* port */
|
* port */
|
||||||
int32_t current_offset = 3;
|
int32_t current_offset = 3;
|
||||||
if (janet_keyeq(argv[current_offset], "stream") ||
|
if (janet_checktype(argv[3], JANET_KEYWORD)) {
|
||||||
janet_keyeq(argv[current_offset], "datagram")) {
|
|
||||||
current_offset = 4;
|
current_offset = 4;
|
||||||
}
|
}
|
||||||
host = (char *)janet_getcstring(argv, current_offset);
|
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;
|
ai = NULL;
|
||||||
if (argc >= 3 && is_unix == 0) {
|
if (argc >= 3 && is_unix == 0) {
|
||||||
if (argc == 4 ||
|
if (argc == 4 || !janet_checktype(argv[3], JANET_KEYWORD)) {
|
||||||
(!janet_keyeq(argv[3], "stream") &&
|
|
||||||
!janet_keyeq(argv[3], "datagram"))) {
|
|
||||||
ai = janet_get_addrinfo(argv, 0, socktype, 0, &is_unix, 1);
|
ai = janet_get_addrinfo(argv, 0, socktype, 0, &is_unix, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user