mirror of
https://github.com/janet-lang/janet
synced 2024-11-13 04:09:54 +00:00
refactor(c-api): Make JanetRange use size_t
as well
This commit is contained in:
parent
8d3574066b
commit
a3e5afd610
@ -348,36 +348,36 @@ ssize_t janet_getssize(const Janet *argv, int32_t n) {
|
||||
return janet_unwrap_ssize(x);
|
||||
}
|
||||
|
||||
int32_t janet_gethalfrange(const Janet *argv, int32_t n, int32_t length, const char *which) {
|
||||
int32_t raw = janet_getinteger(argv, n);
|
||||
int32_t not_raw = raw;
|
||||
size_t janet_gethalfrange(const Janet *argv, int32_t n, size_t length, const char *which) {
|
||||
ssize_t raw = janet_getssize(argv, n);
|
||||
ssize_t not_raw = raw;
|
||||
if (not_raw < 0) not_raw += length + 1;
|
||||
if (not_raw < 0 || not_raw > length)
|
||||
janet_panicf("%s index %d out of range [%d,%d]", which, (int64_t) raw, -(int64_t)length - 1, (int64_t) length);
|
||||
return not_raw;
|
||||
if (not_raw < 0 || (size_t) not_raw > length)
|
||||
janet_panicf("%s index %d out of range [%o,%o]", which, (int64_t) raw, -(uint64_t)length - 1, (uint64_t) length);
|
||||
return (size_t) not_raw;
|
||||
}
|
||||
|
||||
int32_t janet_getstartrange(const Janet *argv, int32_t argc, int32_t n, int32_t length) {
|
||||
size_t janet_getstartrange(const Janet *argv, int32_t argc, int32_t n, size_t length) {
|
||||
if (n >= argc || janet_checktype(argv[n], JANET_NIL)) {
|
||||
return 0;
|
||||
}
|
||||
return janet_gethalfrange(argv, n, length, "start");
|
||||
}
|
||||
|
||||
int32_t janet_getendrange(const Janet *argv, int32_t argc, int32_t n, int32_t length) {
|
||||
size_t janet_getendrange(const Janet *argv, int32_t argc, int32_t n, size_t length) {
|
||||
if (n >= argc || janet_checktype(argv[n], JANET_NIL)) {
|
||||
return length;
|
||||
}
|
||||
return janet_gethalfrange(argv, n, length, "end");
|
||||
}
|
||||
|
||||
int32_t janet_getargindex(const Janet *argv, int32_t n, int32_t length, const char *which) {
|
||||
int32_t raw = janet_getinteger(argv, n);
|
||||
int32_t not_raw = raw;
|
||||
size_t janet_getargindex(const Janet *argv, int32_t n, size_t length, const char *which) {
|
||||
ssize_t raw = janet_getssize(argv, n);
|
||||
ssize_t not_raw = raw;
|
||||
if (not_raw < 0) not_raw += length;
|
||||
if (not_raw < 0 || not_raw > length)
|
||||
janet_panicf("%s index %d out of range [%d,%d)", which, (int64_t)raw, -(int64_t)length, (int64_t)length);
|
||||
return not_raw;
|
||||
if (not_raw < 0 || (size_t) not_raw > length)
|
||||
janet_panicf("%s index %d out of range [%o,%o)", which, (int64_t)raw, -(uint64_t)length, (uint64_t)length);
|
||||
return (size_t) not_raw;
|
||||
}
|
||||
|
||||
JanetView janet_getindexed(const Janet *argv, int32_t n) {
|
||||
@ -422,7 +422,7 @@ void *janet_getabstract(const Janet *argv, int32_t n, const JanetAbstractType *a
|
||||
JanetRange janet_getslice(int32_t argc, const Janet *argv) {
|
||||
janet_arity(argc, 1, 3);
|
||||
JanetRange range;
|
||||
int32_t length = janet_length(argv[0]);
|
||||
size_t length = janet_length(argv[0]);
|
||||
range.start = janet_getstartrange(argv, argc, 1, length);
|
||||
range.end = janet_getendrange(argv, argc, 2, length);
|
||||
if (range.end < range.start)
|
||||
|
@ -1237,8 +1237,8 @@ struct JanetDictView {
|
||||
};
|
||||
|
||||
struct JanetRange {
|
||||
int32_t start;
|
||||
int32_t end;
|
||||
size_t start;
|
||||
size_t end;
|
||||
};
|
||||
|
||||
struct JanetRNG {
|
||||
@ -2043,10 +2043,10 @@ JANET_API JanetByteView janet_getbytes(const Janet *argv, int32_t n);
|
||||
JANET_API JanetDictView janet_getdictionary(const Janet *argv, int32_t n);
|
||||
JANET_API void *janet_getabstract(const Janet *argv, int32_t n, const JanetAbstractType *at);
|
||||
JANET_API JanetRange janet_getslice(int32_t argc, const Janet *argv);
|
||||
JANET_API int32_t janet_gethalfrange(const Janet *argv, int32_t n, int32_t length, const char *which);
|
||||
JANET_API int32_t janet_getstartrange(const Janet *argv, int32_t argc, int32_t n, int32_t length);
|
||||
JANET_API int32_t janet_getendrange(const Janet *argv, int32_t argc, int32_t n, int32_t length);
|
||||
JANET_API int32_t janet_getargindex(const Janet *argv, int32_t n, int32_t length, const char *which);
|
||||
JANET_API size_t janet_gethalfrange(const Janet *argv, int32_t n, size_t length, const char *which);
|
||||
JANET_API size_t janet_getstartrange(const Janet *argv, int32_t argc, int32_t n, size_t length);
|
||||
JANET_API size_t janet_getendrange(const Janet *argv, int32_t argc, int32_t n, size_t length);
|
||||
JANET_API size_t janet_getargindex(const Janet *argv, int32_t n, size_t length, const char *which);
|
||||
JANET_API uint64_t janet_getflags(const Janet *argv, int32_t n, const char *flags);
|
||||
|
||||
/* Optionals */
|
||||
|
Loading…
Reference in New Issue
Block a user