bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash feature request: provide state data pointer and unset_func for


From: George
Subject: Re: Bash feature request: provide state data pointer and unset_func for dynamic variables
Date: Sat, 20 May 2017 04:00:36 -0400

On Fri, 2017-05-19 at 21:37 -0500, Eduardo Bustamante wrote:
> On Fri, May 19, 2017 at 12:08 PM,  <tetsujin@scope-eye.net> wrote:
> [...]
> > 
> > Anyway, I thought I'd float the idea and see if it might be a
> > possibility.
> Feel free to send patches.
> 
> Could you provide examples on how you expect this to be used? I'm
> having a hard time trying to understand how this will be used.
If there's a fair chance that the code change will actually be integrated into 
Bash, I'd be perfectly happy to write it myself and submit a patch.
I'm basically interested in this as a way to write loadable modules for the 
shell in C that can make data available to the user through shell
variables. The user then can manage that data and associated resources as part 
of the shell environment.
If I create a shell binding for a C library, functions in that library would 
use data from C data structures, and provide results in other C data
structures. To bind code like that to a dynamic interactive environment like 
the shell, it makes sense to use concepts from that environment (like
variables) to store and manage the data - but otherwise, internally, keep it 
stored in its C form. To make the library functionality usable in that
environment, the source data, intermediate data, and result data must be usable 
in that environment as well.
One of my short-term goals is a JSON library. There are already ways of working 
with JSON in the shell, of course, but my aim is to make one that's
very easy and comfortable in the context of the shell. In this case dynamic 
variables could be used to present pieces of JSON data being built or
deconstructed by the user. Within the shell the data would be visible as 
encoded JSON text, but under the hood, the library could skip re-parsing the
data each time it performs another operation with it, because the parsed 
representation is retained by the library as long as the variables reference
it.
Another goal I'm pursuing is a coprocess-like library for providing commands 
(actually requests issued to a coprocess) that maintain state between
successive invocations. For instance, starting a process to connect to a 
database, and then issuing different commands and queries to the database
without dropping and restarting the connection each time, or retrieving 
different individual fields from a large XML file without needing to re-parse
the source data each time a new query is issued. From the shell's perspective 
there are various resources that would need to be released when it is
time to dispose of the coprocess - the process ID, the file descriptors, 
buffered data received from the coprocess, the state of the protocol
governing the connection and any pending requests.
(Bash's coproc implementation is a bit broken 
(https://lists.gnu.org/archive/html/bug-bash/2016-04/msg00014.html) which is 
part of why I don't speak
of implementing this functionality on top of it)
That's basically the kind of stuff I have in mind. A few specific projects at 
present, and more generally I want loadable "built-in" libraries for the
shell to have the ability to produce "instance" data, and take advantage of the 
shell variable environment as a way for the user to access,
manipulate, and delete those instances of library-defined data and other 
"objects".


reply via email to

[Prev in Thread] Current Thread [Next in Thread]