summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2022-04-07fs: implement `fs.readfile()` and `fs.writefile()`Jo-Philipp Wich
The `fs.readfile()` and `fs.writefile()` functions allow efficient reading and writing of whole files, reducing the required boilerplace code compared to using the `open()`/`read()`/`write()`/`close()` API. - `fs.readfile()` takes two arguments; the path to open and an optional limit value. If limit is omitted, `null` or negative, the entire file contents are read, otherwise the specified amount of bytes. Returns the read file contents as string or `null` on error. - `fs.writefile()` takes three arguments; the path to open/create, the contents to write and an optional limit value. If limit is omitted, the entire content is written, otherwise just the specified amount of bytes. Non-string content arguments are internally converted to strings, `null` is treated as empty string. Returns the amount of bytes written or `null` on error. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31ci: debian: change path before attempting to invoke Git operationsJo-Philipp Wich
Fixes: dfaf05a ("ci: debian: automatically update changelog from Git tag") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31ci: debian: automatically update changelog from Git tagJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31ci: fix YAML syntax of Debian workflowJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31Merge pull request #64 from dangowrt/fs-dirname-fix-off-by-oneJo-Philipp Wich
fs: fix off-by-one in fs.dirname() function
2022-03-31Merge pull request #61 from jow-/debianJo-Philipp Wich
Debian package build
2022-03-31fs: fix off-by-one in fs.dirname() functionDaniel Golle
Make sure fs.dirname() doesn't truncate the last character of the returned path. Previously ucv_string_new_length was called with a length which no longer included the last character (which had just been tested not to be a '/' or '.' and hence broke the loop at that point). Signed-off-by: Daniel Golle <daniel@makrotopia.org> [testcase added] Signed-off-by: Paul Spooren <mail@aparcar.org> [testcase folded into this commit and fixed] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31.gitignore: fix overmatching patterns, blacklist cram .venvJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31build: remove legacy json-c checkJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31build: add polyfills for older libjson-c versionsJo-Philipp Wich
The libjson-c versions commonly shipped by Debian and Ubuntu lack unsigned 64bit integer support and a number of extended API functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31CI: build Debian packagePaul Spooren
Signed-off-by: Paul Spooren <mail@aparcar.org>
2022-03-31debian: Add package definitionPaul Spooren
This adds Debian packages for the ucode interpreter, the runtime library, development headers and extension modules. Fixes: #55 Signed-off-by: Paul Spooren <mail@aparcar.org> [split into multiple packages, pass SOVERSION to the build] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-31types: fix escape sequence encoding of high byte values in JSON stringsJo-Philipp Wich
Treat the char value as unsigned when testing its value to yield consistent results on both platforms with signed chars and those with unsigned chars by default (e.g. ARM ones). This also avoids encoding byte values > 127 as \uXXXX escape sequences, potentially breaking the strng contents. Fixes: #62 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-28Update README.mdJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-23build: fix symlink install targetJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-23treewide: replace some leftover "utpl" occurrences, update .gitignoreJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-22build: only stage ucc symlink if compile support is enabledJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-22Merge pull request #57 from jow-/uloop-task-supportJo-Philipp Wich
uloop: add support for tasks
2022-03-22Merge pull request #60 from jow-/time-functionsJo-Philipp Wich
lib: add date and time related functions
2022-03-22lib: add date and time related functionsJo-Philipp Wich
Add five new functions to deal with date calculation and timing: - localtime(), gmtime() - return a broken down calendar date and time specification from the given epoch (or now, if absent) in local and UTC time respectively - timelocal(), timegm() - the inverse operation for the former functions, taking a date and time specification (interpreted as local or UTC time respectively) and turning it into an epoch value - clock() - return the second and nanosecond values of the system clock, useful for time/performance measurements Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-22Merge pull request #59 from jow-/stdlib-function-getterJo-Philipp Wich
lib: provide API function to obtain stdlib function implementations
2022-03-22lib: provide API function to obtain stdlib function implementationsJo-Philipp Wich
Provide a new API function `uc_stdlib_function()` which allows to fetch the C implementation of the given named standard library function. This is useful for loadable modules or applications that embed ucode which want to reuse core functions such as `sprintf()`. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-21Merge pull request #58 from jow-/multicallJo-Philipp Wich
main: turn ucode into multicall executable
2022-03-21main: turn ucode into multicall executableJo-Philipp Wich
Turn the ucode executable into a multicall binary and select default flags based on the name it was invoked with. Introduce two new symlinks "ucc" and "utpl" which start ucode in compile and template mode respectively. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-21uloop: add support for tasksJo-Philipp Wich
Tasks are similar to processes but instead of executing a new process, an ucode function is invoked instead, running independently of the main process. Example usage: uloop.init(); let t = uloop.task( // program function function(pipe) { let input = pipe.receive(); pipe.send({ got_input: input }); return { result: true }; }, // parent recv function, invoked when task function calls pipe.send() function(res) { printf("Received output message: %.J\n", res); }, // parent send function, invoked when task function calls pipe.receive() function() { let input = { test: "Example" }; printf("Sending input message: %.J\n", input); return input; } ); uloop.run(); Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-21CI: build on macOSPaul Spooren
Build minimal version to detect compile issues. Signed-off-by: Paul Spooren <mail@aparcar.org>
2022-03-21Merge pull request #53 from jow-/string-format-argpos-supportJo-Philipp Wich
lib: add argument position support (`%m$`) to `sprintf()` and `printf()`
2022-03-20Merge pull request #52 from jow-/portability-fixesJo-Philipp Wich
Portability fixes for macOS
2022-03-20lib: add argument position support (`%m$`) to `sprintf()` and `printf()`Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15treewide: remove legacy json-c include directivesJo-Philipp Wich
We now include `json-c/json-c.h` on all supported environments. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15tests: 21_regex_literals: generalize syntax error test caseJo-Philipp Wich
Different libc implementations produce different syntax error messages on invalid regular expression patterns, so rework the test case to produce stable output across all environments. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15tests: 16_sort: fix logic flaw exposed on OS XJo-Philipp Wich
A typo in the custom order function of the test case caused the test case to yield differently sorted results on OS X, triggered by differences in the libc's `qsort()` implementation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15tests: run_tests.sh: pass dummy value to `-T` flagJo-Philipp Wich
Since OS X `getopt()` does not handle optional arguments, we need to always pass a value to `-T`. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15lib: disallow zero padding for %s formatsJo-Philipp Wich
Filter the zero padding `0` flag for `%s` formats to achieve constisten outputs on Linux and OS X systems. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15tests: run_tests.sh: use greadlink if availableJo-Philipp Wich
This ensures that GNU readlink is preferred over OS X own readlink when executing test cases. This is required due to lacking `-f` flag support on OS X. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15resolv: make OS X compatibleJo-Philipp Wich
OS X `socket()` does not support the `SOCK_NONBLOCK` or `SOCK_CLOEXEC` constants, so apply these flags using `fcntl()` after creating the socket. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15fs: avoid Linux specific sys/sysmacros.h include on OS XJo-Philipp Wich
It should be enough to include `sys/types.h` to obtain `major()` and `minor()` definitions on OS X, so avoid including the the Linux specific `sys/sysmacros.h` header in this case. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15uloop: use execvp() on OS XJo-Philipp Wich
Since `execvpe()` is a GNU extension, fall back to using `execve()` on OS X. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15lib: add naive sigtimedwait() stub for OS XJo-Philipp Wich
OS X does not implement `sigtimedwait()` used by `uc_system()` - add a simple implementation of it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15build: consolidate CMakeLists.txt and cover OS X deviationsJo-Philipp Wich
- Add OS X specific linker flags - Default disable Linux specific modules on OS X - Simplify json-c discovery - Fix uloop_timeout_remaining64() detection Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15include: add OS X compatible endian.h headerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-15include: rename include guards to avoid clashes with system headersJo-Philipp Wich
Identifiers starting with one or two underscores are reserved for system headers and toolchain implementations and should not appear in user code. Also on OS X, the ucode __TYPES_H_ guard clashes with the system types.h header. Rename all ucode header guards to avoid such clashes. Supersedes: #43 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-14Merge pull request #51 from jow-/nl80211-fixesJo-Philipp Wich
nl80211: add missing attributes and correct some attribute flags
2022-03-14Merge pull request #48 from jow-/cli-reworkJo-Philipp Wich
main: rework CLI frontend
2022-03-14nl80211: add missing attributes and correct some attribute flagsJo-Philipp Wich
Suggested-by: John Crispin <john@phrozen.org> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-14lib: adjust require(), render() and include() raw mode semanticsJo-Philipp Wich
- Let `require()` always evaluate the executed code in raw mode - Let `render()` always evaluate the executed code in template mode - Let `include()` inherit the raw mode semantics of the calling scope Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-14main: rework CLI frontendJo-Philipp Wich
- Change command line flags to be align better with those of other interpreters and with the gcc compiler, e.g. `-D` and `-U` to define and undefine globals, `-e` to execute script expression etc. - Pass only excess CLI arguments as `ARGV` to scripts, e.g. `ucode -e 'print("Hello world")' -- -x -y` would pass only `[ "-x", "-y" ]` as ARGV contents - Default to raw mode and introduce flag to enable template mode Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-14Merge pull request #50 from jow-/musl-empty-render-crashJo-Philipp Wich
lib: fix potential integer underflow on empty render output
2022-03-14lib: fix potential integer underflow on empty render outputJo-Philipp Wich
The current `uc_render()` implementation uses a `fseek()` call on the `open_memstream()` provided `FILE *` stream to reserve headroom for the `uc_string_t` header. The `fseek()` call alone does not guarantee that the underlying buffer length is updated on all libc implementations though. This may lead to an integer underflow later on when the `uc_string_t` header length is substracted from the buffer length after invoking a template that did not produce any output write operations. In such a case, a very large value is assigned to `ustr->length` leading to uninitialized or out-of-bounds memory accesses later on. Solve this issue by writing the header structure as data using `fwrite()` which should yield the expected behaviour on all libc environments. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-03-14Merge pull request #49 from jow-/vm-computed-prop-crashJo-Philipp Wich
vm: fix crash on object literals with non-string computed properties