From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 5033724076 for ; Sun, 28 Jan 2024 00:05:32 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1706396732; b=Ue1G/Q1eAHPwQHEZ+cITgYGDDj5AA8toIiV9Lnci5hUsmLKRFLOWoXar5jdPDDWk6ICAZgx9n7 5erQCsME6M7Hmx621op7JG6yLgLtga2wqSjVqMBsEN0vF5/fdMNlM0jxHXyo26Oq/SrGubepjV KXPHkgqukUrPng97dAriJxBrlL9tiHJZkLawKMz8RNYoKSf3ZCpgwd97JLTvJQGbTPQveCbO5b UjrPlVaWr7qllRenQoS09bes8bR77lXZ35X1NG1oLoVKyTwsORn7T/3J9yXVcdACRQ6g8jyxiS +99YU+/MSpIY06b3o1DB+hjq/e8/xdKsamDEJrrz5G9KeA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1706396732; bh=JxFqSDLlKxe6wmNnMUBpMpoeCiSo1kN0+2sdB7FKpvI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=jRev1m6XVJa5bV5lZBnnWg9dXeAYZVYl4/Kcy8ZzU3pqY/HUQMUuruUqQrZFCuPWPc4wRW8SHb bZdLrwtpKwRzxIYNoe6/56F+eWR6uLE5r35rotTAn/V0HryoKnJIy9hn+e1N5SpNpCTzI3H5aR GqGf7RBRJDogVk9lkVru2/GBfRJEPnI0JFDhmWK1Pkh2KNyN2D1kY4Xm9pgPAjBkzbndkZf1gc F2qbmz5YG9YkJv9opb8zeJhb+b5SQ6Ewhsl5954113NVBkAR5hDR0k50HNz1KWOKnZ1Ml0Hj4j J20SUeYf1Wu64f9uNSmsamPQINrxXx5FVkyATa9Vup24PA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=TA/QKJ/h6/8xSdULuq9DDXaDEbHvWa5efwAI27h0fM0=; b=VqpSFpswY8WFlHcP6YLMAEXj5J KyqypwoRFb85DnRf+jLjm/tkrK9EMF1L16W9T/WC+AtVieEv6Bwb1By4ehXuLHznO+xsam0IBQOTx i9yMfDlDak7HBQQawJufBYP4VLxG571RNGfVdYaPE1OktKg86TVrhrZgq8DZQ6WyXRP5VJMzYvGMn JoVIcp5M6xpFlhOUV4ZJ7Bj3YgxAhfXEFQVDOJ152+nQi7koILmZfNnVZtNXjaOrciXC0rAyTuNyW L/p+Yq4PIi3e8wP0iln4SbgLsrEogrIimczQjc8b3pW89YC3qhSVIRwUN7AAdr7wH1EVbGEFHbJRu U2kV1qKQ==; Received: by zero.zsh.org with local id 1rTrjw-000F4J-HZ; Sat, 27 Jan 2024 23:05:32 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f50.google.com ([209.85.218.50]:49494) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rTrjb-000ElE-UB; Sat, 27 Jan 2024 23:05:14 +0000 Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a26f73732c5so148376166b.3 for ; Sat, 27 Jan 2024 15:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1706396711; x=1707001511; darn=zsh.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TA/QKJ/h6/8xSdULuq9DDXaDEbHvWa5efwAI27h0fM0=; b=fpuOU/PiZ0QygxiPUHX//69NNkaB8SX8OQfrSEL7atYAHbJOipKmMPp3l3iCxGcYUi vKIF5iLd+lm+wUH7PP2evPXiMNKkIotGaM7Tdob6xXDy/FaLrPFllJh+JN6uxCXBKjBy QB1VS9EbNT9qQDEMGiSHW7VxHMjcKrENyxmhRjV2SgcLdHmdtHUf1AIv8MsW3yx0TKN+ JmaFNIwADzUGykpe6Oo8M4tqDEgsh1uBOxKEu5DFx1OOuAu/gMZPSfe8f564UpY3kxJr otrp2UHB46uMntBFXG4roApA3VD6K0QlLyymkMcMF1f9LJ70wyzozzb3wvy+sk3kxXJD SA4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706396711; x=1707001511; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TA/QKJ/h6/8xSdULuq9DDXaDEbHvWa5efwAI27h0fM0=; b=d1nSftwtDjo4xwUN2v0DMr82mf2x/TNgbGhDvDbK3o5esqXJAGaUiXxouMUq9zeCqZ wjLL3Ivw5u9LvNe4GxFtDsWHmgtZPtTtV69do0xGbqqzilenK3xS6b6qKeCnib0M6Ycg 9/2IX3LX1dp4adnMVFmZFrkh+vJ1Q52Yz6ZAYvs+R9R3NB5KE3AzpveJxErGkL4IpGdy DZB6yu2Mv/hNZdjIHtxL2htr3vge60oH1aABAmEAXyiQxmersFGZI5j4kFOd3r9SE/JQ bSWN/u1gnx+9gBLgCdxsy5YdqkBkJwn2or8FP0UOMrwNMZZKDqWb0fckKcokG7CVDWnZ 11Kg== X-Gm-Message-State: AOJu0YzAdQYi521PgM22NfDCC1Nd8Qpb4LcMwfd1s0OmADeygDO3+w6t 5elJLDkAIMbmCPR0bIYQeosIPrlO1j/CiDp2mm7yRT+S8DHxS3wvbfQShxjvuYRUejimgec8kO0 QIkwTPOVn4EX75mP+JOHto617JnQ/1QZp5mO9 X-Google-Smtp-Source: AGHT+IHzm86tYl8LhSrnAUTtq0b8gcM7trvRlLo0CAHn5e+nyKwNYsgODrDaZI47Sgj3BfL9LufiFXCFy4xLYl12LG8= X-Received: by 2002:a17:906:b891:b0:a35:85d8:97e3 with SMTP id hb17-20020a170906b89100b00a3585d897e3mr114447ejb.65.1706396711297; Sat, 27 Jan 2024 15:05:11 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Sat, 27 Jan 2024 15:04:59 -0800 Message-ID: Subject: Re: How does zsh internally store and process variables? To: vlkr1 Cc: "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52506 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Sat, Jan 27, 2024 at 2:00=E2=80=AFPM vlkr1 wrote: > > One of the things that we are having trouble with are internal variables. Have you looked at Etc/zsh-development-guide in the zsh distribution? There's a section on "Parameters" and how modules should make use of them. It's mostly focused on how modules can add their own parameters rather than on how to access existing parameters, but the basics of the structures and accessors are all explained (albeit with pointers to zsh.h for structure definitions). As a side-effect of evolutionary development, zsh uses a single global pointer "paramtab" for most of the get/set functions, so it's not threading-safe code and signal handling has to be carefully managed. A second global pointer "realparamtab" points to the actual table for all the variables, so you'll see tests for "paramtab =3D=3D realparamtab" in various places. Internally, associative array key/value pairs are implemented as parameter tables, so paramtab may point to the internals of an associative array in some cases, where the associative array itself is contained in realparamtab (we don't presently allow them to nest). In the current development git head, the files Src/Modules/param_private.c and Src/Modules/ksh93.c may provide some useful coding hints, although neither is exactly what you're after. > how its variables are exported (setenv?) There's a preprocessor definitions for HAVE_PUTENV and USE_SET_UNSET_ENV. Primarily these apply in the zgetenv(), zputenv(), and delenv() functions defined in Src/params.c which are what you should call, but there are lower-level functions if you really need them or you can use #ifdef with those macros to choose the system library routines. > If the keys and values are copied or expected to be leaked/alloccd with m= alloc by the caller Keys are managed by the functions in Src/params.c, so you can pass constant strings e.g. as the first argument of setsparam() or the other parameter functions. String values (second parameter of setsparam()) should be allocated by the caller but are freed by Src/params.c when the value changes or is unset. Values represented by numeric types (int, float) are not memory-managed. String values also need to be "metafied". If you are copying them from another parameter, they are likely already metafied. If coming from user input or the like, use for example ztrdup_metafy() to allocate a metafied copy for setsparam().