aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChloe Kudryavtsev <code@toast.bunkerlabs.net>2023-05-31 19:49:04 +0200
committerChloe Kudryavtsev <code@toast.bunkerlabs.net>2023-05-31 19:49:04 +0200
commit1b8ec244a5b352f087e64e593016d6dc44f66a19 (patch)
tree5159692b5a40b8d673aa144d92414cb360a11245
parentdo not use eggert/tz on MSVC (diff)
fix JANET_REG on windows
the short version appears to be that "ab" "cd" in source to mean "abcd" is a non-standard extension as such, anything that looks like that with a const char[] does not turn out to be true const, and thus can't be used statically this primarily affects MSVC and tcc ... so just make it runtime janet_cfuns_ext only accesses the fields, and therefore all of the data should make it over
-rw-r--r--src/date.h4
-rw-r--r--src/main.c4
-rw-r--r--src/polyfill.h6
-rw-r--r--src/time.c15
-rw-r--r--src/tm.c21
5 files changed, 25 insertions, 25 deletions
diff --git a/src/date.h b/src/date.h
index bda32a0..bd9cf27 100644
--- a/src/date.h
+++ b/src/date.h
@@ -13,7 +13,7 @@
JanetBuffer *strftime_buffer(const char *format, const struct tm *tm, JanetBuffer *buffer);
// time.c
-extern const JanetRegExt jd_time_cfuns[];
+void jd_time_register(JanetTable*, const char*);
time_t *jd_gettime(Janet *argv, int32_t n);
time_t *jd_maketime(void);
JANET_CFUN(jd_gmtime);
@@ -21,7 +21,7 @@ JANET_CFUN(jd_localtime);
JANET_CFUN(jd_time);
// tm.c
-extern const JanetRegExt jd_tm_cfuns[];
+void jd_tm_register(JanetTable*, const char*);
struct tm *jd_gettm(Janet *argv, int32_t n);
struct tm *jd_opttm(Janet *argv, int32_t argc, int32_t n);
struct tm *jd_maketm(void);
diff --git a/src/main.c b/src/main.c
index 3626c24..9d54dc3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,6 @@
#include "date.h"
JANET_MODULE_ENTRY(JanetTable *env) {
- janet_cfuns_ext(env, "date/native", jd_time_cfuns);
- janet_cfuns_ext(env, "date/native", jd_tm_cfuns);
+ jd_time_register(env, "date/native");
+ jd_tm_register(env, "date/native");
}
diff --git a/src/polyfill.h b/src/polyfill.h
index e595ce0..70ea4f5 100644
--- a/src/polyfill.h
+++ b/src/polyfill.h
@@ -21,12 +21,6 @@ const char *janet_optcbytes(const Janet *argv, int32_t argc, int32_t n, const ch
#endif // !defined(JANET_NO_SOURCEMAPS)
#endif // JANET_VERSION_MAJOR < 2 && JANET_VERSION_MINOR < 28
-// JANET_REG is broken on windows, so make it JANET_REG_ (no S no D)
-#ifdef _MSC_VER
-#undef JANET_REG
-#define JANET_REG JANET_REG_
-#endif
-
// timegm
#ifdef _MSC_VER
#define timegm _mkgmtime
diff --git a/src/time.c b/src/time.c
index e43b3cc..a94064d 100644
--- a/src/time.c
+++ b/src/time.c
@@ -82,9 +82,12 @@ JANET_FN(jd_time,
return janet_wrap_abstract(out);
}
-const JanetRegExt jd_time_cfuns[] = {
- JANET_REG("gmtime", jd_gmtime),
- JANET_REG("localtime", jd_localtime),
- JANET_REG("time", jd_time),
- JANET_REG_END
-};
+void jd_time_register(JanetTable *env, const char *regprefix) {
+ const JanetRegExt cfuns[] = {
+ JANET_REG("gmtime", jd_gmtime),
+ JANET_REG("localtime", jd_localtime),
+ JANET_REG("time", jd_time),
+ JANET_REG_END
+ };
+ janet_cfuns_ext(env, regprefix, cfuns);
+}
diff --git a/src/tm.c b/src/tm.c
index 8e99e7f..f263167 100644
--- a/src/tm.c
+++ b/src/tm.c
@@ -340,12 +340,15 @@ JANET_FN(jd_strftime,
return janet_wrap_buffer(strftime_buffer(format, tm, NULL));
}
-const JanetRegExt jd_tm_cfuns[] = {
- JANET_REG("tm", jd_tm),
- JANET_REG("mktime", jd_mktime),
- JANET_REG("mktime!", jd_mktime_inplace),
- JANET_REG("timegm", jd_timegm),
- JANET_REG("timegm!", jd_timegm_inplace),
- JANET_REG("strftime", jd_strftime),
- JANET_REG_END
-};
+void jd_tm_register(JanetTable *env, const char *regprefix) {
+ const JanetRegExt cfuns[] = {
+ JANET_REG("tm", jd_tm),
+ JANET_REG("mktime", jd_mktime),
+ JANET_REG("mktime!", jd_mktime_inplace),
+ JANET_REG("timegm", jd_timegm),
+ JANET_REG("timegm!", jd_timegm_inplace),
+ JANET_REG("strftime", jd_strftime),
+ JANET_REG_END
+ };
+ janet_cfuns_ext(env, regprefix, cfuns);
+}