zsh-workers
 help / color / mirror / code / Atom feed
From: vlkr1 <vlkr1@proton.me>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: How does zsh internally store and process variables?
Date: Sat, 27 Jan 2024 22:00:10 +0000	[thread overview]
Message-ID: <NiMjlpZnB4EgNmxh7Uv-4KJ9SgAs8OUvZv-AvH_sM4zr87dCd20KX4GnHqMvKPMFhMkb9pcRGpmgPnEPvrEywnF7OXWfMxfsR0QLmlHraOo=@proton.me> (raw)

[-- Attachment #1: Type: text/plain, Size: 1697 bytes --]

Hey there

I am helping revive with a rust crate/library (https://github.com/Diegovsky/zsh-module-rs) that allows rust programmers to make zsh modules, you know, the ones you load like zmodload zsh/modulename​.

One of the things that we are having trouble with are internal variables. We can use std::env::var("VARIABLE")​ to get environment variables, but only if they are exported by the shell. For example, you would have to run export ZSH_VERSION​ before it would show up, since rust's env::var()​ function was only designed to handle exported scalar environment variables.

We do have a way to make the shell do this, basically calling the zsh builtin eval​ to force it to export either these variables or dummy ones, and then running eval​ again to unset them, but this is a pretty janky hack -- what if the user had important data stored in the internal variable $YG76987HBHLUBHJ​, or what if they didn't really want to export PS1​? Then you end up looping eval​s to try and find empty vars to throw your 5KB associative array in, or just writing shell in a multiline string to run callbacks and the task is needlessly complex.

Anyways, we wanted to implement internal variable inspection, but was very confused trying to understand the code. We would like to know the following:

- how zsh handles its variables
- how its variables are exported (setenv?)
- If the keys and values are copied or expected to be leaked/alloccd with malloc by the caller

Could you help us out here?

"Don't believe everything you read on the internet just because there's a picture with a fancy quote next to it."- Abraham Lincoln

Sent with [Proton Mail](https://proton.me/) secure email.

[-- Attachment #2: Type: text/html, Size: 3727 bytes --]

             reply	other threads:[~2024-01-27 22:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-27 22:00 vlkr1 [this message]
2024-01-27 23:04 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='NiMjlpZnB4EgNmxh7Uv-4KJ9SgAs8OUvZv-AvH_sM4zr87dCd20KX4GnHqMvKPMFhMkb9pcRGpmgPnEPvrEywnF7OXWfMxfsR0QLmlHraOo=@proton.me' \
    --to=vlkr1@proton.me \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).