MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor cprintf to return output as buffer instead of writing directly to stream

+40 -30
+1 -1
include/cli/cprintf.h
··· 3 3 4 4 #include <stdio.h> 5 5 #include <stddef.h> 6 + #include <stdbool.h> 6 7 7 8 extern bool io_no_color; 8 - 9 9 typedef struct program_t program_t; 10 10 11 11 program_t *cprintf_compile(const char *fmt);
+1 -1
include/runtime.h
··· 2 2 #define RUNTIME_H 3 3 4 4 #include "types.h" 5 - #include <argtable3.h> 5 + struct arg_file; 6 6 7 7 #define ANT_RUNTIME_CRYPTO_INIT (1u << 0) 8 8 #define CODE_ARENA_BLOCK_SIZE (64 * 1024)
+1 -2
libant/scripts/header.sh
··· 34 34 "utils.h:$INCLUDE_DIR/utils.h" 35 35 "runtime.h:$INCLUDE_DIR/runtime.h" 36 36 "esm/remote.h:$INCLUDE_DIR/esm/remote.h" 37 - "argtable3.h:$VENDOR_DIR/argtable-v3.3.0.116da6c/src/argtable3.h" 38 37 ) 39 38 40 39 for f in "$INCLUDE_DIR"/modules/*.h; do ··· 111 110 continue 112 111 fi 113 112 114 - if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|uv|argtable3|types|utarray|uthash|minicoro)\.h\> ]]; then 113 + if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|uv|types|utarray|uthash|minicoro)\.h\> ]]; then 115 114 continue 116 115 fi 117 116
+25 -16
src/cli/cprintf.c
··· 542 542 return vis; 543 543 } 544 544 545 - int cprintf_vm_exec(program_t *prog, FILE *stream, va_list ap) { 545 + typedef struct { 546 + char *data; 547 + size_t len; 548 + } vm_output_t; 549 + 550 + static vm_output_t cprintf_vm_run(program_t *prog, va_list ap) { 546 551 vm_regs_t regs = {0}; 547 552 548 553 size_t cap = 512, pos = 0; 549 554 char *out = malloc(cap); 550 - if (!out) return -1; 555 + if (!out) return (vm_output_t){ NULL, 0 }; 551 556 552 557 #define ENSURE(n) ({ \ 553 - while (pos + (n) + 1 > cap) { \ 554 - cap *= 2; out = realloc(out, cap); \ 555 - if (!out) return -1; \ 556 - }}) 558 + while (pos + (n) + 1 > cap) { \ 559 + cap *= 2; out = realloc(out, cap); \ 560 + if (!out) return (vm_output_t){ NULL, 0 }; \ 561 + }}) 557 562 558 563 #define OUT_STR(s, l) ({ ENSURE(l); memcpy(out+pos, s, l); pos += (l); }) 559 564 #define OUT_CSTR(s) ({ size_t _l = strlen(s); OUT_STR(s, _l); }) ··· 782 787 783 788 op_halt: { 784 789 out[pos] = '\0'; 785 - int ret = (int)fwrite(out, 1, pos, stream); 786 - free(out); return ret; 790 + return (vm_output_t){ out, pos }; 787 791 } 788 792 789 793 #undef ENSURE ··· 793 797 794 798 int cprintf_exec(program_t *prog, FILE *stream, ...) { 795 799 va_list ap; va_start(ap, stream); 796 - int ret = cprintf_vm_exec(prog, stream, ap); 800 + vm_output_t o = cprintf_vm_run(prog, ap); 801 + va_end(ap); if (!o.data) return -1; 802 + 803 + int ret = (int)fwrite(o.data, 1, o.len, stream); 804 + free(o.data); 797 805 798 - va_end(ap); 799 806 return ret; 800 807 } 801 808 802 809 int csprintf_inner(program_t *prog, char *buf, size_t size, ...) { 803 - FILE *f = fmemopen(buf, size, "w"); 804 - if (!f) return -1; 805 - 806 810 va_list ap; va_start(ap, size); 807 - int ret = cprintf_vm_exec(prog, f, ap); 811 + vm_output_t o = cprintf_vm_run(prog, ap); 812 + va_end(ap); if (!o.data) return -1; 813 + 814 + size_t copy = (o.len < size) ? o.len : size - 1; 815 + memcpy(buf, o.data, copy); 816 + buf[copy] = '\0'; 817 + free(o.data); 808 818 809 - va_end(ap); fclose(f); 810 - return ret; 819 + return (int)o.len; 811 820 }
+1
src/runtime.c
··· 6 6 #include <runtime.h> 7 7 #include <arena.h> 8 8 #include <uthash.h> 9 + #include <argtable3.h> 9 10 10 11 typedef struct { 11 12 const char *ptr;
+11 -10
vendor/argtable3.wrap
··· 1 1 [wrap-file] 2 - directory = argtable-v3.3.0.116da6c 3 - source_url = https://github.com/argtable/argtable3/releases/download/v3.3.0.116da6c/argtable-v3.3.0.116da6c.tar.gz 4 - source_filename = argtable-v3.3.0.116da6c.tar.gz 5 - source_hash = 21d653eaab4b9dede76ceb0cb4e8878cf5cadb48ef9180c6a4d1a5cef1549e65 6 - patch_filename = argtable3_3.3.0-1_patch.zip 7 - patch_url = https://wrapdb.mesonbuild.com/v2/argtable3_3.3.0-1/get_patch 8 - patch_hash = d08570286bcb991ebf0616e171bce86038edc3b6d90bf0aad17bcf49880d2c98 9 - source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/argtable3_3.3.0-1/argtable-v3.3.0.116da6c.tar.gz 10 - wrapdb_version = 3.3.0-1 2 + directory = argtable-v3.3.1 3 + source_url = https://github.com/argtable/argtable3/releases/download/v3.3.1/argtable-v3.3.1.tar.gz 4 + source_filename = argtable-v3.3.1.tar.gz 5 + source_hash = c08bca4b88ddb9234726b75455b3b1670d7c864d8daf198eaa7a3b4d41addf2c 6 + source_fallback_url = https://wrapdb.mesonbuild.com/v2/argtable3_3.3.1-1/get_source/argtable-v3.3.1.tar.gz 7 + patch_filename = argtable3_3.3.1-1_patch.zip 8 + patch_url = https://wrapdb.mesonbuild.com/v2/argtable3_3.3.1-1/get_patch 9 + patch_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/argtable3_3.3.1-1/argtable3_3.3.1-1_patch.zip 10 + patch_hash = 6bbe3bfd71536fd0dbf806eeaa8b20e721d3364d7d494e698c5a8f346bb778d2 11 + wrapdb_version = 3.3.1-1 11 12 12 13 [provide] 13 - argtable3 = argtable3_dep 14 + dependency_names = argtable3