summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2024-12-06main: pretty-print `-p` output by defaultJo-Philipp Wich
When outputting non-string expression results while running the cli interpreter using the `-p` flag, pretty-print the resulting JSON data for better readability. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-04types: ucv_resource_create(): rename `typename` parameter to `type`Jo-Philipp Wich
Since `typename` is a reserved word in C++ avoid using it to allow successful compilation with a C++ compiler. Fixes: #248 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02Merge pull request #247 from jow-/lib-use-sort-rJo-Philipp Wich
lib: utilize `ucv_array_sort_r()` and `ucv_object_sort_r()`
2024-12-02lib: utilize `ucv_array_sort_r()` and `ucv_object_sort_r()`Jo-Philipp Wich
Utilize the newly introduced sort functions to eliminate the global sort context usage. This change was originally part of PR #242 but got dropped during refactoring. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02Merge pull request #242 from IdWV/global-variablesJo-Philipp Wich
Removed all global variables from libucode for thread safety
2024-12-02vm: reset signals when freeing VMJo-Philipp Wich
When invoking `uc_vm_free()` on a VM with enabled `.setup_signal_handlers` configuration, reset system signal handlers back to their default actions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02types, vm: refactor usage of global variablesJo-Philipp Wich
Introduce an extensible private TLS context structure and use it within libucode to store global state such as active object iterators. This allows using libucode concurrently in multiple threads without unintentionally sharing global state among them. Also adjust the signal dispatching setup logic in `uc_vm_init()` to only enable signal handling if no other VM in the same thread already handles signals. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [squash commits, move signal handler vm pointer and object iterator list into common extensible TLS context, whitespace and naming adjustments, extended signal setup logic] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02types: introduce `ucv_array_sort_r()` and `ucv_object_sort_r()`Jo-Philipp Wich
Introduce two new functions for ordering arrays and object keys which utilize a different compare callback signature and allow passing a user provided pointer to the comparison callback. The main advantages of the `ucv_*_sort_r()` flavors are the ability to pass custom context to comparisons via the user data pointer and the invocation of the comparison callback with direct `uc_value_t *` pointers instead of opaque `const void *` arguments pointing to `uc_value_t *` or json-c internal `struct lh_entry *` pointers respectively. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [align naming and whitespace with the rest of the codebase, rename some variables for clarity, group sort related changes into two commits, drop constness from `uc_value_t *` compare function arguments] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-01Merge pull request #234 from IdWV/fsJo-Philipp Wich
lib: Removed global variables from module fs for thread safety
2024-12-01Merge pull request #232 from sebastianertz/lib-digestJo-Philipp Wich
lib: introduce digest library
2024-12-01digest: implement compile time option to exclude less common algorithmsJo-Philipp Wich
Introduce a new default enabled CMake option `DIGEST_SUPPORT_EXTENDED` which, when turned off, disables all but the most common md5, sha1 and sha256 alogirthms to reduce the library size. Also prefer statically linking libmd if possible. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-01ci: include libmd in MacOS CI buildsJo-Philipp Wich
This is needed for the upcoming digest library support. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-01lib: introduce digest librarySebastian Ertz
Signed-off-by: Sebastian Ertz <sebastian.ertz@gmx.de>
2024-11-29Merge pull request #246 from jow-/fix-upvalue-resolveJo-Philipp Wich
vm: resolve upvalues before pushing them onto the stack
2024-11-29types: resolve upvalue values in arrays and objectsJo-Philipp Wich
Some objects, such as wildcard module import namespace dictionaries may contain upvalue type values. Extend `ucv_key_get()` to transparently resolve such values before returning them to the caller in order to avoid increasing the refcount of the upvalue itself, leading to a memory leak later on when the VM indirectly dereferences it on upon `uc_vm_stack_push()`, loosing the upvalue object reference itself in the process. This long standing leak was discovered while fixing another upvalue related module import quirk. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-11-29vm: resolve upvalues before pushing them onto the stackJo-Philipp Wich
Commit e5fe6b1 ("treewide: refactor vector usage code") accidentially dropped the upvalue resolving logic from uc_vm_stack_push(), leading to unresolved upvalues leaking into the script execution context. Fixes: e5fe6b1 ("treewide: refactor vector usage code") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-11-29ci: drop OpenWrt tests for nowJo-Philipp Wich
The OpenWrt CI runs are broken and need to be redone. In order to unblock the PR pipeline, drop these tests for now to reintroduce fixed variants at a later point in time. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-24fs: eliminate the usage of global variablesIsaac de Wolff
Move last error code into a VM registry value and lookup resource types within the current VM context at call time, allowing the proper use of the fs module within multiple threads of a multithreaded application. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [turn err_return() back into a local macro, simplify uc_fs_error(), align whitespace style] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-24types: add ucv_resource_create() helperJo-Philipp Wich
Introduce a new inline convenience function ucv_resource_create() which simplifies creating resource values by resource type name by combining resource type lookup and resource value creation in one call. This function will be used in subsequent refactoring to eliminate global static variables. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [separated from original commit, move ucv_resource_create() into types.h] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-24Merge pull request #244 from nbd168/nl80211Jo-Philipp Wich
nl80211: add new attributes for multi-radio support
2024-10-23nl80211: add new attributes for multi-radio supportFelix Fietkau
- vif radio mask: used to assign vifs to specific radios - monitor skip_tx flag: do not pass locally transmitted packets on the monitor interface - radio antenna mask: radio specific part of the phy antenna mask Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-10-23nl80211: cover extended feature and EHT rate info attributesJo-Philipp Wich
These new attributes are required when dealing with WiFi 7 radios. Reported-by: John Crispin <john@phrozen.org> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-18Merge pull request #237 from sebastianertz/mathJo-Philipp Wich
lib: Removed global variables from module math for thread safety
2024-10-18Merge pull request #213 from jow-/improve-vector-macrosJo-Philipp Wich
utils: improve vector macros
2024-10-18math: removed global variable for thread safetySebastian Ertz
Signed-off-by: Sebastian Ertz <sebastian.ertz@gmx.de>
2024-10-18treewide: refactor vector usage codeJo-Philipp Wich
Utilize uc_vector_push() and uc_vector_foreach() where applicable. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-18utils: improve vector utilitiesJo-Philipp Wich
This commits introduces a number of new helper macros to deal with vectors and refactors the existing code for better resource utilization. The allocation strategy is changed from multiple of 8 to exponential growth by factor 1.5 in order to minimize the number of reallocations and potentially needed memory copies. The newly introduced macros are: - uc_vector_capacity(init_capacity, add_items) Derive the resulting vector capacity from the given item count and initial capacity. - uc_vector_extend(vector, add_items) Increase vector capacity by given amount of items, zero-initialize added capacity and return pointer to first new item past the current length. - uc_vector_reduce(vector, remove_items) Reduce vector capacity by given amount of items. - uc_vector_pop(vector) Return pointer to last element and decrement count, or NULL if the vector is empty. - uc_vector_foreach(vector, itervar) A for() loop wrapper to iterate vectors, providing an iter variable to the loop body. - uc_vector_foreach_reverse(vector, itervar) A for() loop wrapper to iterate vectors backwards, providing an iter variable to the loop body. The uc_vector_push() macro has been changed into a variadic macro which internally prefixes the argument list with a cast to the vector element type, allowing user to pass compound expressions like struct initializers in order to simplify adding elements: uc_vector_push(&my_collection, { .foo = 1, .bar = "qrx" }); Like uc_vector_pop(), the uc_vector_last() macro has been made safe to use on empty vectors, it'll now return NULL in this case. Finally the vector realloc logic was moved into static functions within the header file, allowing all vector using code of a compilation unit to share the reallocation, shrinking the size of libucode.so by 1-2KB as a side effect. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-18Merge pull request #241 from jow-/socket-local-fanout-declJo-Philipp Wich
socket: provide local definition of `struct fanout_args`
2024-10-17socket: provide local definition of `struct fanout_args`Jo-Philipp Wich
The `fanout_args` structure is a relatively recent addition to the kernel so provide a local definition for it, like we already do it for other like `timeval_old`. Fixes: #217 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-17Merge pull request #239 from jow-/safe-insert-during-obj-iterationJo-Philipp Wich
types: fix potential use after free on adding keys during iteration
2024-10-17Merge pull request #240 from jow-/stricter-number-conversionJo-Philipp Wich
vallist: more thoroughly check for trailing garbage after numeric string
2024-10-17types: fix potential use after free on adding keys during iterationJo-Philipp Wich
When keys are added to the object currently being iterated by a for loop, the insert operation might cause a hashtable resize with a subsequent memory reallocation and a different table base pointer, clobbering the entry pointers held by iterators pointing to the containing object of the resized table. In order to address this issue while keeping the iteration overhead low, extend the object key insert logic to check whether the insertion will trigger a reallocation and backup and restore the iterator pointers when needed. This slightly increases the size of the iterator states but the overhead for this should be neglectible as there'll only be a low amount of concurrently active iterations at any time. Fixes: #230 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-16vallist: more thoroughly check for trailing garbage after numeric stringJo-Philipp Wich
When converting numeric strings into numbers, ensure that only optional trailing whitespace follows and no other characters. Fixes: #231 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-24Merge pull request #226 from jow-/lexer-improvementsJo-Philipp Wich
Enhance lexer functionality and improve token reporting
2024-09-23lexer: make api functions publicJo-Philipp Wich
Make the lexer API functions `uc_lexer_init()`, `us_lexer_free()` and `uc_lexer_next_token()` public for use in loadable extensions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-23lexer: emit comment and template statement block tokensJo-Philipp Wich
Tweak the token stream reported by the lexer in order to make it more useful for alternative, non-compilation downstream parse processes such as code intelligence gathering within a language server implementation. - Instead of silently discarding source code comments in the lexing phase, emit TK_COMMENT tokens which is useful to e.g. parse type annotations and other structured information. - Do not silently discard TK_LSTM tokens but report them to downstream parsers instead. - Do not silently emit TK_RSTM tokens as TK_SCOL but report them as-is to downstrem parsers. - Adjust the byte code compiler to properly deal with the changed token reporting by discarding incoming TK_COMMENT and TK_LSTM tokens and by remapping read TK_RSTM tokens to the TK_SCOL type. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-23lexer: improve token position reportingJo-Philipp Wich
- Report end position for emitted tokens. This is required to reliably determine the token length, e.g. for downstream code intelligence use cases - Fix start offset of continued template literal string tokens. Previously the start offset of a literal string following a `${...}` placeholder expressions was shifted by one byte - Report proper start offset of `TK_LEXP` tokens. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-23Merge pull request #225 from ↵Jo-Philipp Wich
jow-/compiler-fix-keyword-property-labels-after-spread compiler: properly treat property names after spread expressions
2024-09-23Merge pull request #224 from jow-/lib-fs-readline-leakJo-Philipp Wich
fs: fix potential memory leak on i/o errors in .read()
2024-09-23compiler: properly treat property names after spread expressionsJo-Philipp Wich
Ensure that unquoted property names following spread expressions in object declaration literals are not treated as keywords. Prior to this fix, an expression such as `{ ...someobj, default: 1 }` would result in a compile time syntax error. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-23fs: fix potential memory leak on i/o errors in .read()Jo-Philipp Wich
Make sure to free the line buffer pointer when aborting a `getline()` / `getdelim()` based read operation on i/o errors. As an example, this issue could be triggered by receiving a broken pipe error while attempting to read a line from stdin. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-21Merge pull request #223 from jow-/nl80211-add-eht-attributesJo-Philipp Wich
nl80211: add EHT mac/phy capabilities
2024-09-21nl80211: add EHT mac/phy capabilitiesChad Monroe
Signed-off-by: Chad Monroe <chad@monroe.io>
2024-09-20Merge pull request #218 from jonasjelonek/add-ioctlJo-Philipp Wich
fs: add ioctl() file method
2024-09-20fs: add ioctl() file methodJonas Jelonek
implements ioctl() for a given file handle on Linux. Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
2024-09-20Merge pull request #221 from mikma/fix-getenvJo-Philipp Wich
lib: use copy of environ pointer in getenv()
2024-09-20lib: test if call to getenv() destroys environMikael Magnusson
Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
2024-09-20lib: use copy of environ pointer in getenv()Mikael Magnusson
Without this fix a call to getenv() without parameters destroys environ, and subsequent calls to getenv() (with or without parameter) return nothing. Fixes: #219 Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
2024-09-20ci: bump upload-artifact to v3Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-07-29Merge pull request #214 from jow-/ucode-test-runnerHEADmasterJo-Philipp Wich
tests: replace test runner shell script with ucode implementation