mainThe GNU Bourne-Again SHell - Support: sr #110891, Dynamic variable values

 
 

sr #110891: Dynamic variable values

Submitter:  Dominik Kummer <domson>
Submitted:  Fri 23 Jun 2023 06:59:43 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  1 - Wish Status:  Postponed
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 13 Jul 2023 01:41:36 PM UTC, comment #4: 

yes I do. I am working on a json bash loadable to query and render json data via associative arrays. so there's no need for a shell interface like ksh93.

Thanks, I'll implement unset hook first. Usually further ideas come up during work, hopefully.

Btw what do you think about adding SHELL_VAR pointers to ARRAY and HASH_TABLE? So we can inject according 'sh_var_cell_func_t' (as proposed below) into 'array_reference' and 'assoc_reference'. Anyhow it feels a bit like a workaround though...

typedef struct hash_table {
  BUCKET_CONTENTS *bucket_array; / Where the data is kept. */
  SHELL_VAR var;                / To which variable does data belong. */
  int nbuckets; /* How many buckets does this table have. */
  int nentries; /* How many entries does this table have. */
} HASH_TABLE;

typedef struct array {
arrayind_t max_index;
arrayind_t num_elements;
#ifdef ALT_ARRAY_IMPLEMENTATION
arrayind_t first_index;
arrayind_t alloc_size;
struct array_element **elements;
#else
struct array_element *head;
struct array_element *lastref;
#endif
        SHELL_VAR var;                / To which variable does array belong. */
} ARRAY;

Dominik Kummer <domson>
Wed 12 Jul 2023 02:24:30 PM UTC, comment #3: 

It sounds like you have some pretty specific ideas already? You might start by adding an unset hook to the dynamic variable interface.

However, I'm not inclined to expose that interface to the shell programmer like ksh93 does.

Chet Ramey <chet>
Group administrator
Wed 12 Jul 2023 11:06:55 AM UTC, comment #2: 


comment #1:

> Thanks for the suggestion.


I'd be thankful for any architectural hint/direction so I can implement a proposing solution on my own and open a merge request.

Dominik Kummer <domson>
Thu 29 Jun 2023 08:26:59 PM UTC, comment #1: 

Thanks for the suggestion.

Chet Ramey <chet>
Group administrator
Fri 23 Jun 2023 06:59:43 PM UTC, original submission:  

Though the current interface in this regard is very useful there are situations where it is incomplete. Especially when dynamic variable cells shall be assigned on demand. For example $ echo ${a_configuration_json[key]}; or $ unset a_configuration_json[key]; could perform a query in /a/configuration.json by the given key without reading the whole file into memory at once.

Current interface functions are defined as

typedef struct variable sh_var_value_func_t PARAMS((struct variable ));
typedef struct variable sh_var_assign_func_t PARAMS((struct variable , char , arrayind_t, char ));

furthermore the following definition I'd consider more complete

typedef struct variable sh_var_value_func_t PARAMS((struct variable , char *, arrayind_t));
typedef struct variable sh_var_assign_func_t PARAMS((struct variable , char , arrayind_t, char ));
typedef struct variable sh_var_unassign_func_t PARAMS((struct variable , char *, arrayind_t));

but as far as I can judge the current architecture makes it uneasy to achieve a more specific assign function. That is because now assign function is called with every variable lookup in general, but not every single variable value (array, hash table) lookup. Which makes especially sense performance wise.

Therefore I'd suggest an additional interface looking something like

typedef struct variable sh_var_value_func_t PARAMS((struct variable ));
typedef struct variable sh_var_cell_func_t PARAMS((struct variable , char *, arrayind_t));
typedef struct variable sh_var_assign_func_t PARAMS((struct variable , char , arrayind_t, char ));
typedef struct variable sh_var_unassign_func_t PARAMS((struct variable , char *, arrayind_t));

A read function of type sh_var_cell_func_t could be called from within

extern char array_reference PARAMS((ARRAY , arrayind_t));

and

extern char assoc_reference PARAMS((HASH_TABLE , char *));

if SHELL_VAR* has an appropriate member assigned. The main problem I suspect here is that neither array_reference nor assoc_reference are aware of the current SHELL_VAR* to check either for the function assginment nor to pass SHELL_VAR* to sh_var_cell_func_t.

Unfortunately my current knowledge of bash architecture is insufficient to measure up further steps on my own.

Kind regards

Dominik Kummer

Dominik Kummer <domson>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by domson (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-06-29 chet StatusNone Postponed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code