mirror of
https://github.com/janet-lang/janet
synced 2025-01-10 07:30:26 +00:00
Merge branch 'master' into compile-opt
This commit is contained in:
commit
bed80bf1d3
@ -19,3 +19,8 @@ tasks:
|
|||||||
ninja
|
ninja
|
||||||
ninja test
|
ninja test
|
||||||
sudo ninja install
|
sudo ninja install
|
||||||
|
- meson_min: |
|
||||||
|
cd janet
|
||||||
|
meson setup build_meson_min --buildtype=release -Dsingle_threaded=true -Dnanbox=false -Ddynamic_modules=false -Ddocstrings=false -Dnet=false -Dsourcemaps=false -Dpeg=false -Dassembler=false -Dint_types=false -Dreduced_os=true -Dffi=false
|
||||||
|
cd build_meson_min
|
||||||
|
ninja
|
||||||
|
38
.github/workflows/test.yml
vendored
38
.github/workflows/test.yml
vendored
@ -39,27 +39,57 @@ jobs:
|
|||||||
shell: cmd
|
shell: cmd
|
||||||
run: build_win test
|
run: build_win test
|
||||||
|
|
||||||
|
test-windows-min:
|
||||||
|
name: Build and test on Windows Minimal build
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ windows-2019 ]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout the repository
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Setup MSVC
|
||||||
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- name: Install Python Dependencies
|
||||||
|
run: pip install meson ninja
|
||||||
|
- name: Build
|
||||||
|
shell: cmd
|
||||||
|
run: |
|
||||||
|
meson setup build_meson_min --buildtype=release -Dsingle_threaded=true -Dnanbox=false -Ddynamic_modules=false -Ddocstrings=false -Dnet=false -Dsourcemaps=false -Dpeg=false -Dassembler=false -Dint_types=false -Dreduced_os=true -Dffi=false
|
||||||
|
cd build_meson_min
|
||||||
|
ninja
|
||||||
|
|
||||||
test-mingw:
|
test-mingw:
|
||||||
name: Build on Windows with Mingw (no test yet)
|
name: Build on Windows with Mingw
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: msys2 {0}
|
shell: msys2 {0}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
msystem: [ UCRT64, CLANG64 ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Setup Mingw
|
- name: Setup Mingw
|
||||||
uses: msys2/setup-msys2@v2
|
uses: msys2/setup-msys2@v2
|
||||||
with:
|
with:
|
||||||
msystem: UCRT64
|
msystem: ${{ matrix.msystem }}
|
||||||
update: true
|
update: true
|
||||||
install: >-
|
install: >-
|
||||||
base-devel
|
base-devel
|
||||||
git
|
git
|
||||||
gcc
|
gcc
|
||||||
- name: Build the project
|
- name: Build
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: make -j4 CC=gcc JANET_NO_AMALG=1
|
run: make -j4 CC=gcc
|
||||||
|
- name: Test
|
||||||
|
shell: cmd
|
||||||
|
run: make -j4 CC=gcc test
|
||||||
|
|
||||||
test-mingw-linux:
|
test-mingw-linux:
|
||||||
name: Build and test with Mingw on Linux + Wine
|
name: Build and test with Mingw on Linux + Wine
|
||||||
|
1
examples/sample-bad-bundle/badmod.janet
Normal file
1
examples/sample-bad-bundle/badmod.janet
Normal file
@ -0,0 +1 @@
|
|||||||
|
(def abc 123)
|
7
examples/sample-bad-bundle/bundle.janet
Normal file
7
examples/sample-bad-bundle/bundle.janet
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
(defn install
|
||||||
|
[manifest &]
|
||||||
|
(bundle/add-file manifest "badmod.janet"))
|
||||||
|
|
||||||
|
(defn check
|
||||||
|
[&]
|
||||||
|
(error "Check failed!"))
|
@ -4305,10 +4305,10 @@
|
|||||||
(do-hook module bundle-name :clean man))
|
(do-hook module bundle-name :clean man))
|
||||||
(do-hook module bundle-name :build man)
|
(do-hook module bundle-name :build man)
|
||||||
(do-hook module bundle-name :install man)
|
(do-hook module bundle-name :install man)
|
||||||
(when check
|
|
||||||
(do-hook module bundle-name :check man))
|
|
||||||
(if (empty? (get man :files)) (print "no files installed, is this a valid bundle?"))
|
(if (empty? (get man :files)) (print "no files installed, is this a valid bundle?"))
|
||||||
(sync-manifest man))
|
(sync-manifest man)
|
||||||
|
(when check
|
||||||
|
(do-hook module bundle-name :check man)))
|
||||||
(print "installed " bundle-name)
|
(print "installed " bundle-name)
|
||||||
bundle-name)
|
bundle-name)
|
||||||
|
|
||||||
@ -4677,7 +4677,8 @@
|
|||||||
(setdyn *lint-error* error-level)
|
(setdyn *lint-error* error-level)
|
||||||
(setdyn *lint-warn* error-level)
|
(setdyn *lint-warn* error-level)
|
||||||
(when-let [profile.janet (dyn *profilepath*)]
|
(when-let [profile.janet (dyn *profilepath*)]
|
||||||
(dofile profile.janet :exit true :env env))
|
(dofile profile.janet :exit true :env env)
|
||||||
|
(put env *current-file* nil))
|
||||||
(repl getchunk nil env)))))
|
(repl getchunk nil env)))))
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -31,11 +31,13 @@
|
|||||||
#ifndef JANET_SINGLE_THREADED
|
#ifndef JANET_SINGLE_THREADED
|
||||||
#ifndef JANET_WINDOWS
|
#ifndef JANET_WINDOWS
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#else
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef JANET_USE_STDATOMIC
|
#ifdef JANET_USE_STDATOMIC
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
/* We don't need stdatomic on most compilers since we use compiler builtins for atomic operations.
|
/* We don't need stdatomic on most compilers since we use compiler builtins for atomic operations.
|
||||||
@ -546,8 +548,8 @@ void *janet_optabstract(const Janet *argv, int32_t argc, int32_t n, const JanetA
|
|||||||
/* Atomic refcounts */
|
/* Atomic refcounts */
|
||||||
|
|
||||||
JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x) {
|
JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x) {
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef _MSC_VER
|
||||||
return InterlockedIncrement(x);
|
return _InterlockedIncrement(x);
|
||||||
#elif defined(JANET_USE_STDATOMIC)
|
#elif defined(JANET_USE_STDATOMIC)
|
||||||
return atomic_fetch_add_explicit(x, 1, memory_order_relaxed) + 1;
|
return atomic_fetch_add_explicit(x, 1, memory_order_relaxed) + 1;
|
||||||
#else
|
#else
|
||||||
@ -556,8 +558,8 @@ JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
|
JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef _MSC_VER
|
||||||
return InterlockedDecrement(x);
|
return _InterlockedDecrement(x);
|
||||||
#elif defined(JANET_USE_STDATOMIC)
|
#elif defined(JANET_USE_STDATOMIC)
|
||||||
return atomic_fetch_add_explicit(x, -1, memory_order_acq_rel) - 1;
|
return atomic_fetch_add_explicit(x, -1, memory_order_acq_rel) - 1;
|
||||||
#else
|
#else
|
||||||
@ -566,8 +568,8 @@ JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x) {
|
JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x) {
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef _MSC_VER
|
||||||
return InterlockedOr(x, 0);
|
return _InterlockedOr(x, 0);
|
||||||
#elif defined(JANET_USE_STDATOMIC)
|
#elif defined(JANET_USE_STDATOMIC)
|
||||||
return atomic_load_explicit(x, memory_order_acquire);
|
return atomic_load_explicit(x, memory_order_acquire);
|
||||||
#else
|
#else
|
||||||
|
@ -47,7 +47,7 @@ typedef struct {
|
|||||||
#ifndef JANET_WINDOWS
|
#ifndef JANET_WINDOWS
|
||||||
JanetStream *stream;
|
JanetStream *stream;
|
||||||
#endif
|
#endif
|
||||||
JanetTable* watch_descriptors;
|
JanetTable *watch_descriptors;
|
||||||
JanetChannel *channel;
|
JanetChannel *channel;
|
||||||
uint32_t default_flags;
|
uint32_t default_flags;
|
||||||
int is_watching;
|
int is_watching;
|
||||||
@ -85,9 +85,9 @@ static uint32_t decode_watch_flags(const Janet *options, int32_t n) {
|
|||||||
}
|
}
|
||||||
JanetKeyword keyw = janet_unwrap_keyword(options[i]);
|
JanetKeyword keyw = janet_unwrap_keyword(options[i]);
|
||||||
const JanetWatchFlagName *result = janet_strbinsearch(watcher_flags_linux,
|
const JanetWatchFlagName *result = janet_strbinsearch(watcher_flags_linux,
|
||||||
sizeof(watcher_flags_linux) / sizeof(JanetWatchFlagName),
|
sizeof(watcher_flags_linux) / sizeof(JanetWatchFlagName),
|
||||||
sizeof(JanetWatchFlagName),
|
sizeof(JanetWatchFlagName),
|
||||||
keyw);
|
keyw);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
janet_panicf("unknown inotify flag %v", options[i]);
|
janet_panicf("unknown inotify flag %v", options[i]);
|
||||||
}
|
}
|
||||||
@ -154,99 +154,97 @@ static void watcher_callback_read(JanetFiber *fiber, JanetAsyncEvent event) {
|
|||||||
janet_schedule(fiber, janet_wrap_nil());
|
janet_schedule(fiber, janet_wrap_nil());
|
||||||
janet_async_end(fiber);
|
janet_async_end(fiber);
|
||||||
break;
|
break;
|
||||||
case JANET_ASYNC_EVENT_ERR:
|
case JANET_ASYNC_EVENT_ERR: {
|
||||||
{
|
janet_schedule(fiber, janet_wrap_nil());
|
||||||
janet_schedule(fiber, janet_wrap_nil());
|
janet_async_end(fiber);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
read_more:
|
||||||
|
case JANET_ASYNC_EVENT_HUP:
|
||||||
|
case JANET_ASYNC_EVENT_INIT:
|
||||||
|
case JANET_ASYNC_EVENT_READ: {
|
||||||
|
Janet name = janet_wrap_nil();
|
||||||
|
|
||||||
|
/* Assumption - read will never return partial events *
|
||||||
|
* From documentation:
|
||||||
|
*
|
||||||
|
* The behavior when the buffer given to read(2) is too small to
|
||||||
|
* return information about the next event depends on the kernel
|
||||||
|
* version: before Linux 2.6.21, read(2) returns 0; since Linux
|
||||||
|
* 2.6.21, read(2) fails with the error EINVAL. Specifying a buffer
|
||||||
|
* of size
|
||||||
|
*
|
||||||
|
* sizeof(struct inotify_event) + NAME_MAX + 1
|
||||||
|
*
|
||||||
|
* will be sufficient to read at least one event. */
|
||||||
|
ssize_t nread;
|
||||||
|
do {
|
||||||
|
nread = read(stream->handle, buf, sizeof(buf));
|
||||||
|
} while (nread == -1 && errno == EINTR);
|
||||||
|
|
||||||
|
/* Check for errors - special case errors that can just be waited on to fix */
|
||||||
|
if (nread == -1) {
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
janet_cancel(fiber, janet_ev_lasterr());
|
||||||
|
fiber->ev_state = NULL;
|
||||||
janet_async_end(fiber);
|
janet_async_end(fiber);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
read_more:
|
if (nread < (ssize_t) sizeof(struct inotify_event)) break;
|
||||||
case JANET_ASYNC_EVENT_HUP:
|
|
||||||
case JANET_ASYNC_EVENT_INIT:
|
|
||||||
case JANET_ASYNC_EVENT_READ:
|
|
||||||
{
|
|
||||||
Janet name = janet_wrap_nil();
|
|
||||||
|
|
||||||
/* Assumption - read will never return partial events *
|
/* Iterate through all events read from the buffer */
|
||||||
* From documentation:
|
char *cursor = buf;
|
||||||
*
|
while (cursor < buf + nread) {
|
||||||
* The behavior when the buffer given to read(2) is too small to
|
struct inotify_event inevent;
|
||||||
* return information about the next event depends on the kernel
|
memcpy(&inevent, cursor, sizeof(inevent));
|
||||||
* version: before Linux 2.6.21, read(2) returns 0; since Linux
|
cursor += sizeof(inevent);
|
||||||
* 2.6.21, read(2) fails with the error EINVAL. Specifying a buffer
|
/* Read path of inevent */
|
||||||
* of size
|
if (inevent.len) {
|
||||||
*
|
name = janet_cstringv(cursor);
|
||||||
* sizeof(struct inotify_event) + NAME_MAX + 1
|
cursor += inevent.len;
|
||||||
*
|
|
||||||
* will be sufficient to read at least one event. */
|
|
||||||
ssize_t nread;
|
|
||||||
do {
|
|
||||||
nread = read(stream->handle, buf, sizeof(buf));
|
|
||||||
} while (nread == -1 && errno == EINTR);
|
|
||||||
|
|
||||||
/* Check for errors - special case errors that can just be waited on to fix */
|
|
||||||
if (nread == -1) {
|
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
janet_cancel(fiber, janet_ev_lasterr());
|
|
||||||
fiber->ev_state = NULL;
|
|
||||||
janet_async_end(fiber);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (nread < (ssize_t) sizeof(struct inotify_event)) break;
|
|
||||||
|
|
||||||
/* Iterate through all events read from the buffer */
|
/* Got an event */
|
||||||
char *cursor = buf;
|
Janet path = janet_table_get(watcher->watch_descriptors, janet_wrap_integer(inevent.wd));
|
||||||
while (cursor < buf + nread) {
|
JanetKV *event = janet_struct_begin(6);
|
||||||
struct inotify_event inevent;
|
janet_struct_put(event, janet_ckeywordv("wd"), janet_wrap_integer(inevent.wd));
|
||||||
memcpy(&inevent, cursor, sizeof(inevent));
|
janet_struct_put(event, janet_ckeywordv("wd-path"), path);
|
||||||
cursor += sizeof(inevent);
|
if (janet_checktype(name, JANET_NIL)) {
|
||||||
/* Read path of inevent */
|
/* We were watching a file directly, so path is the full path. Split into dirname / basename */
|
||||||
if (inevent.len) {
|
JanetString spath = janet_unwrap_string(path);
|
||||||
name = janet_cstringv(cursor);
|
const uint8_t *cursor = spath + janet_string_length(spath);
|
||||||
cursor += inevent.len;
|
const uint8_t *cursor_end = cursor;
|
||||||
|
while (cursor > spath && cursor[0] != '/') {
|
||||||
|
cursor--;
|
||||||
}
|
}
|
||||||
|
if (cursor == spath) {
|
||||||
/* Got an event */
|
|
||||||
Janet path = janet_table_get(watcher->watch_descriptors, janet_wrap_integer(inevent.wd));
|
|
||||||
JanetKV *event = janet_struct_begin(6);
|
|
||||||
janet_struct_put(event, janet_ckeywordv("wd"), janet_wrap_integer(inevent.wd));
|
|
||||||
janet_struct_put(event, janet_ckeywordv("wd-path"), path);
|
|
||||||
if (janet_checktype(name, JANET_NIL)) {
|
|
||||||
/* We were watching a file directly, so path is the full path. Split into dirname / basename */
|
|
||||||
JanetString spath = janet_unwrap_string(path);
|
|
||||||
const uint8_t *cursor = spath + janet_string_length(spath);
|
|
||||||
const uint8_t *cursor_end = cursor;
|
|
||||||
while (cursor > spath && cursor[0] != '/') {
|
|
||||||
cursor--;
|
|
||||||
}
|
|
||||||
if (cursor == spath) {
|
|
||||||
janet_struct_put(event, janet_ckeywordv("dir-name"), path);
|
|
||||||
janet_struct_put(event, janet_ckeywordv("file-name"), name);
|
|
||||||
} else {
|
|
||||||
janet_struct_put(event, janet_ckeywordv("dir-name"), janet_wrap_string(janet_string(spath, (cursor - spath))));
|
|
||||||
janet_struct_put(event, janet_ckeywordv("file-name"), janet_wrap_string(janet_string(cursor + 1, (cursor_end - cursor - 1))));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
janet_struct_put(event, janet_ckeywordv("dir-name"), path);
|
janet_struct_put(event, janet_ckeywordv("dir-name"), path);
|
||||||
janet_struct_put(event, janet_ckeywordv("file-name"), name);
|
janet_struct_put(event, janet_ckeywordv("file-name"), name);
|
||||||
|
} else {
|
||||||
|
janet_struct_put(event, janet_ckeywordv("dir-name"), janet_wrap_string(janet_string(spath, (cursor - spath))));
|
||||||
|
janet_struct_put(event, janet_ckeywordv("file-name"), janet_wrap_string(janet_string(cursor + 1, (cursor_end - cursor - 1))));
|
||||||
}
|
}
|
||||||
janet_struct_put(event, janet_ckeywordv("cookie"), janet_wrap_integer(inevent.cookie));
|
} else {
|
||||||
Janet etype = janet_ckeywordv("type");
|
janet_struct_put(event, janet_ckeywordv("dir-name"), path);
|
||||||
const JanetWatchFlagName *wfn_end = watcher_flags_linux + sizeof(watcher_flags_linux) / sizeof(watcher_flags_linux[0]);
|
janet_struct_put(event, janet_ckeywordv("file-name"), name);
|
||||||
for (const JanetWatchFlagName *wfn = watcher_flags_linux; wfn < wfn_end; wfn++) {
|
|
||||||
if ((inevent.mask & wfn->flag) == wfn->flag) janet_struct_put(event, etype, janet_ckeywordv(wfn->name));
|
|
||||||
}
|
|
||||||
Janet eventv = janet_wrap_struct(janet_struct_end(event));
|
|
||||||
|
|
||||||
janet_channel_give(watcher->channel, eventv);
|
|
||||||
}
|
}
|
||||||
|
janet_struct_put(event, janet_ckeywordv("cookie"), janet_wrap_integer(inevent.cookie));
|
||||||
|
Janet etype = janet_ckeywordv("type");
|
||||||
|
const JanetWatchFlagName *wfn_end = watcher_flags_linux + sizeof(watcher_flags_linux) / sizeof(watcher_flags_linux[0]);
|
||||||
|
for (const JanetWatchFlagName *wfn = watcher_flags_linux; wfn < wfn_end; wfn++) {
|
||||||
|
if ((inevent.mask & wfn->flag) == wfn->flag) janet_struct_put(event, etype, janet_ckeywordv(wfn->name));
|
||||||
|
}
|
||||||
|
Janet eventv = janet_wrap_struct(janet_struct_end(event));
|
||||||
|
|
||||||
/* Read some more if possible */
|
janet_channel_give(watcher->channel, eventv);
|
||||||
goto read_more;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
/* Read some more if possible */
|
||||||
|
goto read_more;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +271,8 @@ static void janet_watcher_unlisten(JanetWatcher *watcher) {
|
|||||||
#define WATCHFLAG_RECURSIVE 0x100000u
|
#define WATCHFLAG_RECURSIVE 0x100000u
|
||||||
|
|
||||||
static const JanetWatchFlagName watcher_flags_windows[] = {
|
static const JanetWatchFlagName watcher_flags_windows[] = {
|
||||||
{"all",
|
{
|
||||||
|
"all",
|
||||||
FILE_NOTIFY_CHANGE_ATTRIBUTES |
|
FILE_NOTIFY_CHANGE_ATTRIBUTES |
|
||||||
FILE_NOTIFY_CHANGE_CREATION |
|
FILE_NOTIFY_CHANGE_CREATION |
|
||||||
FILE_NOTIFY_CHANGE_DIR_NAME |
|
FILE_NOTIFY_CHANGE_DIR_NAME |
|
||||||
@ -282,7 +281,8 @@ static const JanetWatchFlagName watcher_flags_windows[] = {
|
|||||||
FILE_NOTIFY_CHANGE_LAST_WRITE |
|
FILE_NOTIFY_CHANGE_LAST_WRITE |
|
||||||
FILE_NOTIFY_CHANGE_SECURITY |
|
FILE_NOTIFY_CHANGE_SECURITY |
|
||||||
FILE_NOTIFY_CHANGE_SIZE |
|
FILE_NOTIFY_CHANGE_SIZE |
|
||||||
WATCHFLAG_RECURSIVE},
|
WATCHFLAG_RECURSIVE
|
||||||
|
},
|
||||||
{"attributes", FILE_NOTIFY_CHANGE_ATTRIBUTES},
|
{"attributes", FILE_NOTIFY_CHANGE_ATTRIBUTES},
|
||||||
{"creation", FILE_NOTIFY_CHANGE_CREATION},
|
{"creation", FILE_NOTIFY_CHANGE_CREATION},
|
||||||
{"dir-name", FILE_NOTIFY_CHANGE_DIR_NAME},
|
{"dir-name", FILE_NOTIFY_CHANGE_DIR_NAME},
|
||||||
@ -302,9 +302,9 @@ static uint32_t decode_watch_flags(const Janet *options, int32_t n) {
|
|||||||
}
|
}
|
||||||
JanetKeyword keyw = janet_unwrap_keyword(options[i]);
|
JanetKeyword keyw = janet_unwrap_keyword(options[i]);
|
||||||
const JanetWatchFlagName *result = janet_strbinsearch(watcher_flags_windows,
|
const JanetWatchFlagName *result = janet_strbinsearch(watcher_flags_windows,
|
||||||
sizeof(watcher_flags_windows) / sizeof(JanetWatchFlagName),
|
sizeof(watcher_flags_windows) / sizeof(JanetWatchFlagName),
|
||||||
sizeof(JanetWatchFlagName),
|
sizeof(JanetWatchFlagName),
|
||||||
keyw);
|
keyw);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
janet_panicf("unknown windows filewatch flag %v", options[i]);
|
janet_panicf("unknown windows filewatch flag %v", options[i]);
|
||||||
}
|
}
|
||||||
@ -339,19 +339,19 @@ typedef struct {
|
|||||||
|
|
||||||
static void read_dir_changes(OverlappedWatch *ow) {
|
static void read_dir_changes(OverlappedWatch *ow) {
|
||||||
BOOL result = ReadDirectoryChangesW(ow->stream->handle,
|
BOOL result = ReadDirectoryChangesW(ow->stream->handle,
|
||||||
(NotifyChange *) ow->buf,
|
(NotifyChange *) ow->buf,
|
||||||
FILE_INFO_PADDING,
|
FILE_INFO_PADDING,
|
||||||
(ow->flags & WATCHFLAG_RECURSIVE) ? TRUE : FALSE,
|
(ow->flags & WATCHFLAG_RECURSIVE) ? TRUE : FALSE,
|
||||||
ow->flags & ~WATCHFLAG_RECURSIVE,
|
ow->flags & ~WATCHFLAG_RECURSIVE,
|
||||||
NULL,
|
NULL,
|
||||||
(OVERLAPPED *) ow,
|
(OVERLAPPED *) ow,
|
||||||
NULL);
|
NULL);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
janet_panicv(janet_ev_lasterr());
|
janet_panicv(janet_ev_lasterr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* watcher_actions_windows[] = {
|
static const char *watcher_actions_windows[] = {
|
||||||
"unknown",
|
"unknown",
|
||||||
"added",
|
"added",
|
||||||
"removed",
|
"removed",
|
||||||
@ -382,48 +382,47 @@ static void watcher_callback_read(JanetFiber *fiber, JanetAsyncEvent event) {
|
|||||||
case JANET_ASYNC_EVENT_FAILED:
|
case JANET_ASYNC_EVENT_FAILED:
|
||||||
janet_stream_close(ow->stream);
|
janet_stream_close(ow->stream);
|
||||||
break;
|
break;
|
||||||
case JANET_ASYNC_EVENT_COMPLETE:
|
case JANET_ASYNC_EVENT_COMPLETE: {
|
||||||
{
|
if (!watcher->is_watching) {
|
||||||
if (!watcher->is_watching) {
|
janet_stream_close(ow->stream);
|
||||||
janet_stream_close(ow->stream);
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
NotifyChange *fni = (NotifyChange *) ow->buf;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
/* Got an event */
|
|
||||||
|
|
||||||
/* Extract name */
|
|
||||||
Janet filename;
|
|
||||||
if (fni->FileNameLength) {
|
|
||||||
int32_t nbytes = (int32_t) WideCharToMultiByte(CP_UTF8, 0, fni->FileName, fni->FileNameLength / sizeof(wchar_t), NULL, 0, NULL, NULL);
|
|
||||||
janet_assert(nbytes, "bad utf8 path");
|
|
||||||
uint8_t *into = janet_string_begin(nbytes);
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, fni->FileName, fni->FileNameLength / sizeof(wchar_t), (char *) into, nbytes, NULL, NULL);
|
|
||||||
filename = janet_wrap_string(janet_string_end(into));
|
|
||||||
} else {
|
|
||||||
filename = janet_cstringv("");
|
|
||||||
}
|
|
||||||
|
|
||||||
JanetKV *event = janet_struct_begin(3);
|
|
||||||
janet_struct_put(event, janet_ckeywordv("type"), janet_ckeywordv(watcher_actions_windows[fni->Action]));
|
|
||||||
janet_struct_put(event, janet_ckeywordv("file-name"), filename);
|
|
||||||
janet_struct_put(event, janet_ckeywordv("dir-name"), janet_wrap_string(ow->dir_path));
|
|
||||||
Janet eventv = janet_wrap_struct(janet_struct_end(event));
|
|
||||||
|
|
||||||
janet_channel_give(watcher->channel, eventv);
|
|
||||||
|
|
||||||
/* Next event */
|
|
||||||
if (!fni->NextEntryOffset) break;
|
|
||||||
fni = (NotifyChange *) ((char *)fni + fni->NextEntryOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make another call to read directory changes */
|
|
||||||
read_dir_changes(ow);
|
|
||||||
janet_async_in_flight(fiber);
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
NotifyChange *fni = (NotifyChange *) ow->buf;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
/* Got an event */
|
||||||
|
|
||||||
|
/* Extract name */
|
||||||
|
Janet filename;
|
||||||
|
if (fni->FileNameLength) {
|
||||||
|
int32_t nbytes = (int32_t) WideCharToMultiByte(CP_UTF8, 0, fni->FileName, fni->FileNameLength / sizeof(wchar_t), NULL, 0, NULL, NULL);
|
||||||
|
janet_assert(nbytes, "bad utf8 path");
|
||||||
|
uint8_t *into = janet_string_begin(nbytes);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, fni->FileName, fni->FileNameLength / sizeof(wchar_t), (char *) into, nbytes, NULL, NULL);
|
||||||
|
filename = janet_wrap_string(janet_string_end(into));
|
||||||
|
} else {
|
||||||
|
filename = janet_cstringv("");
|
||||||
|
}
|
||||||
|
|
||||||
|
JanetKV *event = janet_struct_begin(3);
|
||||||
|
janet_struct_put(event, janet_ckeywordv("type"), janet_ckeywordv(watcher_actions_windows[fni->Action]));
|
||||||
|
janet_struct_put(event, janet_ckeywordv("file-name"), filename);
|
||||||
|
janet_struct_put(event, janet_ckeywordv("dir-name"), janet_wrap_string(ow->dir_path));
|
||||||
|
Janet eventv = janet_wrap_struct(janet_struct_end(event));
|
||||||
|
|
||||||
|
janet_channel_give(watcher->channel, eventv);
|
||||||
|
|
||||||
|
/* Next event */
|
||||||
|
if (!fni->NextEntryOffset) break;
|
||||||
|
fni = (NotifyChange *)((char *)fni + fni->NextEntryOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make another call to read directory changes */
|
||||||
|
read_dir_changes(ow);
|
||||||
|
janet_async_in_flight(fiber);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,12 +438,12 @@ static void start_listening_ow(OverlappedWatch *ow) {
|
|||||||
|
|
||||||
static void janet_watcher_add(JanetWatcher *watcher, const char *path, uint32_t flags) {
|
static void janet_watcher_add(JanetWatcher *watcher, const char *path, uint32_t flags) {
|
||||||
HANDLE handle = CreateFileA(path,
|
HANDLE handle = CreateFileA(path,
|
||||||
FILE_LIST_DIRECTORY | GENERIC_READ,
|
FILE_LIST_DIRECTORY | GENERIC_READ,
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||||
NULL,
|
NULL,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_FLAG_OVERLAPPED | FILE_FLAG_BACKUP_SEMANTICS,
|
FILE_FLAG_OVERLAPPED | FILE_FLAG_BACKUP_SEMANTICS,
|
||||||
NULL);
|
NULL);
|
||||||
if (handle == INVALID_HANDLE_VALUE) {
|
if (handle == INVALID_HANDLE_VALUE) {
|
||||||
janet_panicv(janet_ev_lasterr());
|
janet_panicv(janet_ev_lasterr());
|
||||||
}
|
}
|
||||||
@ -574,20 +573,20 @@ static const JanetAbstractType janet_filewatch_at = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
JANET_CORE_FN(cfun_filewatch_make,
|
JANET_CORE_FN(cfun_filewatch_make,
|
||||||
"(filewatch/new channel &opt default-flags)",
|
"(filewatch/new channel &opt default-flags)",
|
||||||
"Create a new filewatcher that will give events to a channel channel. See `filewatch/add` for available flags.\n\n"
|
"Create a new filewatcher that will give events to a channel channel. See `filewatch/add` for available flags.\n\n"
|
||||||
"When an event is triggered by the filewatcher, a struct containing information will be given to channel as with `ev/give`. "
|
"When an event is triggered by the filewatcher, a struct containing information will be given to channel as with `ev/give`. "
|
||||||
"The contents of the channel depend on the OS, but will contain some common keys:\n\n"
|
"The contents of the channel depend on the OS, but will contain some common keys:\n\n"
|
||||||
"* `:type` -- the type of the event that was raised.\n\n"
|
"* `:type` -- the type of the event that was raised.\n\n"
|
||||||
"* `:file-name` -- the base file name of the file that triggered the event.\n\n"
|
"* `:file-name` -- the base file name of the file that triggered the event.\n\n"
|
||||||
"* `:dir-name` -- the directory name of the file that triggered the event.\n\n"
|
"* `:dir-name` -- the directory name of the file that triggered the event.\n\n"
|
||||||
"Events also will contain keys specific to the host OS.\n\n"
|
"Events also will contain keys specific to the host OS.\n\n"
|
||||||
"Windows has no extra properties on events.\n\n"
|
"Windows has no extra properties on events.\n\n"
|
||||||
"Linux has the following extra properties on events:\n\n"
|
"Linux has the following extra properties on events:\n\n"
|
||||||
"* `:wd` -- the integer key returned by `filewatch/add` for the path that triggered this.\n\n"
|
"* `:wd` -- the integer key returned by `filewatch/add` for the path that triggered this.\n\n"
|
||||||
"* `:wd-path` -- the string path for watched directory of file. For files, will be the same as `:file-name`, and for directories, will be the same as `:dir-name`.\n\n"
|
"* `:wd-path` -- the string path for watched directory of file. For files, will be the same as `:file-name`, and for directories, will be the same as `:dir-name`.\n\n"
|
||||||
"* `:cookie` -- a randomized integer used to associate related events, such as :moved-from and :moved-to events.\n\n"
|
"* `:cookie` -- a randomized integer used to associate related events, such as :moved-from and :moved-to events.\n\n"
|
||||||
"") {
|
"") {
|
||||||
janet_sandbox_assert(JANET_SANDBOX_FS_READ);
|
janet_sandbox_assert(JANET_SANDBOX_FS_READ);
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetChannel *channel = janet_getchannel(argv, 0);
|
JanetChannel *channel = janet_getchannel(argv, 0);
|
||||||
@ -598,44 +597,44 @@ JANET_CORE_FN(cfun_filewatch_make,
|
|||||||
}
|
}
|
||||||
|
|
||||||
JANET_CORE_FN(cfun_filewatch_add,
|
JANET_CORE_FN(cfun_filewatch_add,
|
||||||
"(filewatch/add watcher path &opt flags)",
|
"(filewatch/add watcher path &opt flags)",
|
||||||
"Add a path to the watcher. Available flags depend on the current OS, and are as follows:\n\n"
|
"Add a path to the watcher. Available flags depend on the current OS, and are as follows:\n\n"
|
||||||
"Windows/MINGW (flags correspond to FILE_NOTIFY_CHANGE_* flags in win32 documentation):\n\n"
|
"Windows/MINGW (flags correspond to FILE_NOTIFY_CHANGE_* flags in win32 documentation):\n\n"
|
||||||
"* `:all` - trigger an event for all of the below triggers.\n\n"
|
"* `:all` - trigger an event for all of the below triggers.\n\n"
|
||||||
"* `:attributes` - FILE_NOTIFY_CHANGE_ATTRIBUTES\n\n"
|
"* `:attributes` - FILE_NOTIFY_CHANGE_ATTRIBUTES\n\n"
|
||||||
"* `:creation` - FILE_NOTIFY_CHANGE_CREATION\n\n"
|
"* `:creation` - FILE_NOTIFY_CHANGE_CREATION\n\n"
|
||||||
"* `:dir-name` - FILE_NOTIFY_CHANGE_DIR_NAME\n\n"
|
"* `:dir-name` - FILE_NOTIFY_CHANGE_DIR_NAME\n\n"
|
||||||
"* `:last-access` - FILE_NOTIFY_CHANGE_LAST_ACCESS\n\n"
|
"* `:last-access` - FILE_NOTIFY_CHANGE_LAST_ACCESS\n\n"
|
||||||
"* `:last-write` - FILE_NOTIFY_CHANGE_LAST_WRITE\n\n"
|
"* `:last-write` - FILE_NOTIFY_CHANGE_LAST_WRITE\n\n"
|
||||||
"* `:security` - FILE_NOTIFY_CHANGE_SECURITY\n\n"
|
"* `:security` - FILE_NOTIFY_CHANGE_SECURITY\n\n"
|
||||||
"* `:size` - FILE_NOTIFY_CHANGE_SIZE\n\n"
|
"* `:size` - FILE_NOTIFY_CHANGE_SIZE\n\n"
|
||||||
"* `:recursive` - watch subdirectories recursively\n\n"
|
"* `:recursive` - watch subdirectories recursively\n\n"
|
||||||
"Linux (flags correspond to IN_* flags from <sys/inotify.h>):\n\n"
|
"Linux (flags correspond to IN_* flags from <sys/inotify.h>):\n\n"
|
||||||
"* `:access` - IN_ACCESS\n\n"
|
"* `:access` - IN_ACCESS\n\n"
|
||||||
"* `:all` - IN_ALL_EVENTS\n\n"
|
"* `:all` - IN_ALL_EVENTS\n\n"
|
||||||
"* `:attrib` - IN_ATTRIB\n\n"
|
"* `:attrib` - IN_ATTRIB\n\n"
|
||||||
"* `:close-nowrite` - IN_CLOSE_NOWRITE\n\n"
|
"* `:close-nowrite` - IN_CLOSE_NOWRITE\n\n"
|
||||||
"* `:close-write` - IN_CLOSE_WRITE\n\n"
|
"* `:close-write` - IN_CLOSE_WRITE\n\n"
|
||||||
"* `:create` - IN_CREATE\n\n"
|
"* `:create` - IN_CREATE\n\n"
|
||||||
"* `:delete` - IN_DELETE\n\n"
|
"* `:delete` - IN_DELETE\n\n"
|
||||||
"* `:delete-self` - IN_DELETE_SELF\n\n"
|
"* `:delete-self` - IN_DELETE_SELF\n\n"
|
||||||
"* `:ignored` - IN_IGNORED\n\n"
|
"* `:ignored` - IN_IGNORED\n\n"
|
||||||
"* `:modify` - IN_MODIFY\n\n"
|
"* `:modify` - IN_MODIFY\n\n"
|
||||||
"* `:move-self` - IN_MOVE_SELF\n\n"
|
"* `:move-self` - IN_MOVE_SELF\n\n"
|
||||||
"* `:moved-from` - IN_MOVED_FROM\n\n"
|
"* `:moved-from` - IN_MOVED_FROM\n\n"
|
||||||
"* `:moved-to` - IN_MOVED_TO\n\n"
|
"* `:moved-to` - IN_MOVED_TO\n\n"
|
||||||
"* `:open` - IN_OPEN\n\n"
|
"* `:open` - IN_OPEN\n\n"
|
||||||
"* `:q-overflow` - IN_Q_OVERFLOW\n\n"
|
"* `:q-overflow` - IN_Q_OVERFLOW\n\n"
|
||||||
"* `:unmount` - IN_UNMOUNT\n\n\n"
|
"* `:unmount` - IN_UNMOUNT\n\n\n"
|
||||||
"On Windows, events will have the following possible types:\n\n"
|
"On Windows, events will have the following possible types:\n\n"
|
||||||
"* `:unknown`\n\n"
|
"* `:unknown`\n\n"
|
||||||
"* `:added`\n\n"
|
"* `:added`\n\n"
|
||||||
"* `:removed`\n\n"
|
"* `:removed`\n\n"
|
||||||
"* `:modified`\n\n"
|
"* `:modified`\n\n"
|
||||||
"* `:renamed-old`\n\n"
|
"* `:renamed-old`\n\n"
|
||||||
"* `:renamed-new`\n\n"
|
"* `:renamed-new`\n\n"
|
||||||
"On Linux, events will a `:type` corresponding to the possible flags, excluding `:all`.\n"
|
"On Linux, events will a `:type` corresponding to the possible flags, excluding `:all`.\n"
|
||||||
"") {
|
"") {
|
||||||
janet_arity(argc, 2, -1);
|
janet_arity(argc, 2, -1);
|
||||||
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
||||||
const char *path = janet_getcstring(argv, 1);
|
const char *path = janet_getcstring(argv, 1);
|
||||||
@ -645,8 +644,8 @@ JANET_CORE_FN(cfun_filewatch_add,
|
|||||||
}
|
}
|
||||||
|
|
||||||
JANET_CORE_FN(cfun_filewatch_remove,
|
JANET_CORE_FN(cfun_filewatch_remove,
|
||||||
"(filewatch/remove watcher path)",
|
"(filewatch/remove watcher path)",
|
||||||
"Remove a path from the watcher.") {
|
"Remove a path from the watcher.") {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
||||||
const char *path = janet_getcstring(argv, 1);
|
const char *path = janet_getcstring(argv, 1);
|
||||||
@ -655,8 +654,8 @@ JANET_CORE_FN(cfun_filewatch_remove,
|
|||||||
}
|
}
|
||||||
|
|
||||||
JANET_CORE_FN(cfun_filewatch_listen,
|
JANET_CORE_FN(cfun_filewatch_listen,
|
||||||
"(filewatch/listen watcher)",
|
"(filewatch/listen watcher)",
|
||||||
"Listen for changes in the watcher.") {
|
"Listen for changes in the watcher.") {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
||||||
janet_watcher_listen(watcher);
|
janet_watcher_listen(watcher);
|
||||||
@ -664,8 +663,8 @@ JANET_CORE_FN(cfun_filewatch_listen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
JANET_CORE_FN(cfun_filewatch_unlisten,
|
JANET_CORE_FN(cfun_filewatch_unlisten,
|
||||||
"(filewatch/unlisten watcher)",
|
"(filewatch/unlisten watcher)",
|
||||||
"Stop listening for changes on a given watcher.") {
|
"Stop listening for changes on a given watcher.") {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
JanetWatcher *watcher = janet_getabstract(argv, 0, &janet_filewatch_at);
|
||||||
janet_watcher_unlisten(watcher);
|
janet_watcher_unlisten(watcher);
|
||||||
|
@ -27,9 +27,10 @@
|
|||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef JANET_REDUCED_OS
|
#ifndef JANET_REDUCED_OS
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -251,7 +252,7 @@ JANET_CORE_FN(os_exit,
|
|||||||
}
|
}
|
||||||
janet_deinit();
|
janet_deinit();
|
||||||
if (argc >= 2 && janet_truthy(argv[1])) {
|
if (argc >= 2 && janet_truthy(argv[1])) {
|
||||||
_exit(status);
|
_Exit(status);
|
||||||
} else {
|
} else {
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,11 @@
|
|||||||
(assert (= 0 (length (bundle/list))) "bundles are listed correctly 7")
|
(assert (= 0 (length (bundle/list))) "bundles are listed correctly 7")
|
||||||
(assert (= 0 (length (bundle/topolist))) "bundles are listed correctly 8")
|
(assert (= 0 (length (bundle/topolist))) "bundles are listed correctly 8")
|
||||||
|
|
||||||
|
# Try installing a bundle that fails check
|
||||||
|
(assert-error "bad test" (bundle/install "./examples/sample-bad-bundle" :check true))
|
||||||
|
(assert (= 0 (length (bundle/list))) "check failure 0")
|
||||||
|
(assert (= 0 (length (bundle/topolist))) "check failure 1")
|
||||||
|
|
||||||
(rmrf syspath)
|
(rmrf syspath)
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user