diff options
author | Adrian Thurston <thurston@colm.net> | 2017-02-01 17:26:11 +0700 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2017-02-01 17:26:11 +0700 |
commit | 13afe74c75f5af3caabfeddcbaad473ca744ad79 (patch) | |
tree | 0a48bbbe93dc15b6e5f8f6e631c0a31fbe93391d | |
parent | 1298b7c88908cabbc87413d579f59e41c613d945 (diff) | |
download | colm-13afe74c75f5af3caabfeddcbaad473ca744ad79.tar.gz |
allow program args to be passed in with lengths
In this mode we can pass in binary data.
-rw-r--r-- | src/bytecode.c | 15 | ||||
-rw-r--r-- | src/colm.h | 3 | ||||
-rw-r--r-- | src/program.c | 8 | ||||
-rw-r--r-- | src/program.h | 1 |
4 files changed, 20 insertions, 7 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 85ffe6ab..a4edb100 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -331,23 +331,25 @@ static void downref_locals( program_t *prg, tree_t ***psp, } } -static tree_t *construct_arg0( program_t *prg, int argc, const char **argv ) +static tree_t *construct_arg0( program_t *prg, int argc, const char **argv, const int *argl ) { tree_t *arg0 = 0; if ( argc > 0 ) { - head_t *head = colm_string_alloc_pointer( prg, argv[0], strlen(argv[0]) ); + size_t len = argl != 0 ? argl[0] : strlen(argv[0]); + head_t *head = colm_string_alloc_pointer( prg, argv[0], len ); arg0 = construct_string( prg, head ); colm_tree_upref( arg0 ); } return arg0; } -static list_t *construct_argv( program_t *prg, int argc, const char **argv ) +static list_t *construct_argv( program_t *prg, int argc, const char **argv, const int *argl ) { list_t *list = (list_t*)colm_construct_generic( prg, prg->rtd->argv_generic_id ); int i; for ( i = 1; i < argc; i++ ) { - head_t *head = colm_string_alloc_pointer( prg, argv[i], strlen(argv[i]) ); + size_t len = argl != 0 ? argl[i] : strlen(argv[i]); + head_t *head = colm_string_alloc_pointer( prg, argv[i], len ); tree_t *arg = construct_string( prg, head ); colm_tree_upref( arg ); @@ -428,6 +430,7 @@ tree_t *colm_run_func( struct colm_program *prg, int frame_id, /* Make the arguments available to the program. */ prg->argc = 0; prg->argv = 0; + prg->argl = 0; Execution execution; memset( &execution, 0, sizeof(execution) ); @@ -3809,7 +3812,7 @@ again: debug( prg, REALM_BYTECODE, "IN_LOAD_ARG0 %lu\n", field ); /* tree_t comes back upreffed. */ - tree_t *tree = construct_arg0( prg, prg->argc, prg->argv ); + tree_t *tree = construct_arg0( prg, prg->argc, prg->argv, prg->argl ); tree_t *prev = colm_struct_get_field( prg->global, tree_t*, field ); colm_tree_downref( prg, sp, prev ); colm_struct_set_field( prg->global, tree_t*, field, tree ); @@ -3820,7 +3823,7 @@ again: read_half( field ); debug( prg, REALM_BYTECODE, "IN_LOAD_ARGV %lu\n", field ); - list_t *list = construct_argv( prg, prg->argc, prg->argv ); + list_t *list = construct_argv( prg, prg->argc, prg->argv, prg->argl ); colm_struct_set_field( prg->global, list_t*, field, list ); break; } @@ -118,6 +118,9 @@ void colm_set_debug( struct colm_program *prg, long active_realm ); /* Run a top-level colm program. */ void colm_run_program( struct colm_program *prg, int argc, const char **argv ); +/* Run a top-level colm program, with argument lengths (allows binary data). */ +void colm_run_program2( struct colm_program *prg, int argc, const char **argv, const int *argl ); + /* Run a single exported colm function. */ struct colm_tree *colm_run_func( struct colm_program *prg, int frame_id, const char **params, int param_count ); diff --git a/src/program.c b/src/program.c index 0d806779..1fabf479 100644 --- a/src/program.c +++ b/src/program.c @@ -201,7 +201,7 @@ program_t *colm_new_program( struct colm_sections *rtd ) return prg; } -void colm_run_program( program_t *prg, int argc, const char **argv ) +void colm_run_program2( program_t *prg, int argc, const char **argv, const int *argl ) { if ( prg->rtd->root_code_len == 0 ) return; @@ -209,6 +209,7 @@ void colm_run_program( program_t *prg, int argc, const char **argv ) /* Make the arguments available to the program. */ prg->argc = argc; prg->argv = argv; + prg->argl = argl; Execution execution; memset( &execution, 0, sizeof(execution) ); @@ -221,6 +222,11 @@ void colm_run_program( program_t *prg, int argc, const char **argv ) prg->argv = 0; } +void colm_run_program( program_t *prg, int argc, const char **argv ) +{ + colm_run_program2( prg, argc, argv, 0 ); +} + static void colm_clear_heap( program_t *prg, tree_t **sp ) { struct colm_struct *hi = prg->heap.head; diff --git a/src/program.h b/src/program.h index 0013c061..1dbff78d 100644 --- a/src/program.h +++ b/src/program.h @@ -126,6 +126,7 @@ struct colm_program int argc; const char **argv; + const int *argl; unsigned char ctx_dep_parsing; struct colm_sections *rtd; |