1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

Allow getting typed arrays from byte sequences.

Fix native importing for .so files in current directory.
This commit is contained in:
Calvin Rose 2020-07-24 07:01:34 -05:00
parent 8f82d19fd1
commit 43438d3824
5 changed files with 51 additions and 19 deletions

View File

@ -1,6 +1,11 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## ??? - Unreleased
- Fix jpm and git with multiple git installs on Windows
- Fix importing a .so file in the current directory
- Allow passing byte sequence types directly to typed-array constructors.
## 1.11.0 - 2020-07-18 ## 1.11.0 - 2020-07-18
- Add `forever` macro. - Add `forever` macro.
- Add `any?` predicate to core. - Add `any?` predicate to core.

View File

@ -20,7 +20,7 @@
project('janet', 'c', project('janet', 'c',
default_options : ['c_std=c99', 'b_lundef=false', 'default_library=both'], default_options : ['c_std=c99', 'b_lundef=false', 'default_library=both'],
version : '1.11.0') version : '1.11.1')
# Global settings # Global settings
janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet') janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet')

View File

@ -28,9 +28,9 @@
#define JANET_VERSION_MAJOR 1 #define JANET_VERSION_MAJOR 1
#define JANET_VERSION_MINOR 11 #define JANET_VERSION_MINOR 11
#define JANET_VERSION_PATCH 0 #define JANET_VERSION_PATCH 1
#define JANET_VERSION_EXTRA "" #define JANET_VERSION_EXTRA "-dev"
#define JANET_VERSION "1.11.0" #define JANET_VERSION "1.11.1-dev"
/* #define JANET_BUILD "local" */ /* #define JANET_BUILD "local" */

View File

@ -63,10 +63,29 @@ typedef void *Clib;
#define error_clib() dlerror() #define error_clib() dlerror()
#endif #endif
static char *get_processed_name(const char *name) {
if (name[0] == '.') return (char *) name;
const char *c;
for (c = name; *c; c++) {
if (*c == '/') return (char *) name;
}
size_t l = (size_t)(c - name);
char *ret = malloc(l + 3);
if (NULL == ret) {
JANET_OUT_OF_MEMORY;
}
ret[0] = '.';
ret[1] = '/';
memcpy(ret + 2, name, l + 3);
return ret;
}
JanetModule janet_native(const char *name, const uint8_t **error) { JanetModule janet_native(const char *name, const uint8_t **error) {
Clib lib = load_clib(name); char *processed_name = get_processed_name(name);
Clib lib = load_clib(processed_name);
JanetModule init; JanetModule init;
JanetModconf getter; JanetModconf getter;
if (name != processed_name) free(processed_name);
if (!lib) { if (!lib) {
*error = janet_cstring(error_clib()); *error = janet_cstring(error_clib());
return NULL; return NULL;

View File

@ -376,6 +376,13 @@ static Janet cfun_typed_array_new(int32_t argc, Janet *argv) {
if (argc > 3) if (argc > 3)
offset = janet_getsize(argv, 3); offset = janet_getsize(argv, 3);
if (argc > 4) { if (argc > 4) {
int32_t blen;
const uint8_t *bytes;
if (janet_bytes_view(argv[4], &bytes, &blen)) {
buffer = janet_abstract(&janet_ta_buffer_type, sizeof(JanetTArrayBuffer));
ta_buffer_init(buffer, (size_t) blen);
memcpy(buffer->data, bytes, blen);
} else {
if (!janet_checktype(argv[4], JANET_ABSTRACT)) { if (!janet_checktype(argv[4], JANET_ABSTRACT)) {
janet_panicf("bad slot #%d, expected ta/view|ta/buffer, got %v", janet_panicf("bad slot #%d, expected ta/view|ta/buffer, got %v",
4, argv[4]); 4, argv[4]);
@ -393,6 +400,7 @@ static Janet cfun_typed_array_new(int32_t argc, Janet *argv) {
4, argv[4]); 4, argv[4]);
} }
} }
}
JanetTArrayView *view = janet_tarray_view(type, size, stride, offset, buffer); JanetTArrayView *view = janet_tarray_view(type, size, stride, offset, buffer);
return janet_wrap_abstract(view); return janet_wrap_abstract(view);
} }