From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27006 invoked from network); 12 Jun 2022 21:19:53 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Jun 2022 21:19:53 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1655068793; b=JUyKmY9XfAtSt3FHWKlkU4qIldMMK+hR/qJnfHDQYMoE+gL/7HkyA6Qj+nmMVBuKMGSsnsti4Q d8iMhjVNJfgrix5gh6dGibtPY8weB0GqCPlIuyggSsBJDBrBBDevN9qWHQY3hpM2evH3AotaRN gM618vPOQPL3UYV7sZ3UsfYIaPrp4kkgvjMxEjXQN6c3wap0iQCDbBI/FWRdizYTenhknyG5fl WF/IjOeWkCHsiqtlVNhPjdYUN0dhWmR+6oyubQsDqxg1H9rqX2myBAS16SDKz+Wo9L3P7j5yqs Kpk4AYDUWKtiip/oeEsm8jXMSVYlSVLvYbVuvxgKE0ppYA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f49.google.com) smtp.remote-ip=209.85.208.49; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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=1655068793; bh=0eGfpQYaquUJxgIomThoSK0qY8beF7BSpIsTPrSDG/8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=cS2YUW+D63T4BUuT4VV0K8JkFdfIpe9897xMCnFKYv4UJRD+PSVKHZVh9hTnXqOjoaSuYTTwp+ NEqCK09vnsBTEylEZ+e7MAGiK86361gdfQfrfrFHZsE5t67bpoE+1ym3gFawoYH5w6/HntgU/f xiZ8UlA33L2tylN56nFRkEVTne6lVDhutAAWMB2QDmKQdm1aPrEwuvFpsLJJ8BmVHoHBMJmHFv lFqXHu6N7W5/D/X0gCyZv99wurKeuUWExY68vyhoJp4Nv4pP08bYoaG5zu4Krmdl7ILKIMqxS2 ZbSqpV/EnEMIBigGo94DkcmAnugsmu2EQztDLGxnjm+XGg==; 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-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=XXU57HNDPIge4jHko+pc2gK9G7n23xfJOQMUopwYetc=; b=ijO58cOqJqBVaHvsKdODAqpGih jSbuNqWVPWjTAUYpDQ5Azugs6e7hPdyiej58nFUPJ4jQW4Nn0sfTr3gfbkm8lAxazcAmBoxEvXqXR X8pp3Hk9tsGh+SBX9dZ1hw5AT7DhdfHxzDgDnrqwvwHV95Ylxjp0bu0cjbzUJ1TWBuOLdjsLOxCd+ 3ex3mOnseBdBEGZw8F9yH07QnOBuZApvDK9ARTIuBvx7VOfmKMSGcrBSje9t+fENQR/RJhKHUC52E 6e2QLp8N1/m7yGpmbhLHMlB6h6n4wQB5HOaBFV8CBB+u55aUfA64o5B1FYTkQvlNEl5LBwiSzm2yj eDHIi4MA==; Received: from authenticated user by zero.zsh.org with local id 1o0Uzw-000OzE-6z; Sun, 12 Jun 2022 21:19:52 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f49.google.com) smtp.remote-ip=209.85.208.49; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f49.google.com ([209.85.208.49]:46963) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1o0Uze-000OfS-1a; Sun, 12 Jun 2022 21:19:34 +0000 Received: by mail-ed1-f49.google.com with SMTP id z7so4836987edm.13 for ; Sun, 12 Jun 2022 14:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=XXU57HNDPIge4jHko+pc2gK9G7n23xfJOQMUopwYetc=; b=LwEZZrXcfIO3QvJMVtN1VThbTr5KNjD3P3faKu0PjMQGnO/Yk4pNpatDqM8KgQ9+dB K9F3w1N8aGyWZ3xcHm5ZvNI5w+3/B+mmLKXxnczJX4eT04+QAnqscwBst76RiWhDDIAi GzGog9hZFZSjwGhiAsUSGTqpyPpCEUS9cvGbZrMtbpP/Exg7IEIe06mC9RXyV5JzIW1s gGAb4ntO6xDIlDWAhN4a8R+4pL6LEgyM8fY3f6JTDLvNZ24xWvN0q/WqSfRxf0vUm6pG bdA2dl/ZNSbGn3HbvvvhQ7JiQsXLd8UEGuRfulnPUx7xIQguZOns+e7Wvwxwcx5xlbpP MjSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=XXU57HNDPIge4jHko+pc2gK9G7n23xfJOQMUopwYetc=; b=gy2mHKoBA05UhueGq6i6WWrCZDQXiKeuX9WG7c8BnQ9pGRbNNzI5io4taTXMtnTcDs I31ECIj1nsk0uMTSiSVcxQ58AVu0oXEdz8QskEQK5jeoV7zEgqT3ZZmi7TqEM7fvjPBc i4GPO8LRX/HEbXgSEtZ4HLZPZYUh+8U6RfbSe/4wFrbs14ygpqAtijwvz4ddsw7Mdxug P++JacYIwY8Tye/fksyrVbxmYWFaO+5524qtEjKphqReWtDyQgPI0/edHp5SB497Juyg uT9x34kHrTNrBJ0xNMqzI4VMmcIlNyl1+Q/Cyn1UAyx1BWakNc7zrFuzA/B75iRJ4w/4 DQZw== X-Gm-Message-State: AOAM531K3zxz2GIYmRSg1UXebI6Y8hj5ZTc4uG+zeYwbNjWPEnSBuAgm lsj/wMj2u93lCQqv1DLVlk7kz+CYm5mMhhj606yTTKZnNkw= X-Google-Smtp-Source: ABdhPJwBl/BGKjLpMUXDLM1PBeziewpQaBvYN47EVdZ6Y1f/rtqnqNV+cmkZ/iC5sYYm+VlixoxWj4hkiUVH2s+mKXI= X-Received: by 2002:a50:eb91:0:b0:42d:c1d8:616a with SMTP id y17-20020a50eb91000000b0042dc1d8616amr63217321edr.219.1655068773334; Sun, 12 Jun 2022 14:19:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Sun, 12 Jun 2022 14:19:22 -0700 Message-ID: Subject: [PATCH] Re: zsh/db oddities To: Zsh hackers list Content-Type: multipart/mixed; boundary="00000000000050601705e146bac9" X-Seq: 50368 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: --00000000000050601705e146bac9 Content-Type: text/plain; charset="UTF-8" Returning to this 8+ months later ... On Mon, Sep 6, 2021 at 9:29 PM Bart Schaefer wrote: > > Open a database as a global and assign something to it: > [...] > Now start messing with the declaration in a function: > [...] > As soon as the tied parameter is declared local, the file has been > written, erasing all the existing values. This seems undesirable? > [...] > Untying the local destroys the global, too, and leaves the file as the > local wrote it. > [...] > I think the correct thing might be to prohibit changing the scope, > similar to what happens when an attempt is made to remove the readonly > attribute? > [...] > Re-ztie-ing the database file while it is still tied, is already > handled as an error. Looking into how this might be accomplished, I noticed this: #ifndef PM_UPTODATE #define PM_UPTODATE (1<<19) /* Parameter has up-to-date data (e.g. loaded from DB) */ #endif I don't think that's a safe choice of bitflag any more? That was introduced 2017-02-16, but the PM_ bit values were rearranged 2018-10-12 and bit 19 is now PM_LOCAL. That doesn't have any effect on the aforementioned behavior of "local"/"zuntie", but perhaps something like this is better? -#ifndef PM_UPTODATE -#define PM_UPTODATE (1<<19) /* Parameter has up-to-date data (e.g. loaded from DB) */ +#ifndef PM_UPTODATE /* Parameter has up-to-date data (e.g. loaded from DB) */ +#define PM_UPTODATE PM_DONTIMPORT_SUID /* Safe PM_ bit to re-use */ #endif Back on the original issue, the simplest way to fix this appears to be to declare the ztie'd parameters to be PM_SINGLE. % zmodload zsh/db/gdbm ztie -d db/gdbm -f sample.gdbm sampledb % () { local sampledb typeset +m sampledb } (anon):local:2: sampledb: can only have a single instance % Patch attached. Comments welcome. --00000000000050601705e146bac9 Content-Type: text/plain; charset="US-ASCII"; name="gdbm.txt" Content-Disposition: attachment; filename="gdbm.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_l4bt70ei0 ZGlmZiAtLWdpdCBhL1NyYy9Nb2R1bGVzL2RiX2dkYm0uYyBiL1NyYy9Nb2R1bGVzL2RiX2dkYm0u YwppbmRleCA3ZTExZWM5MzkuLjNmZWZkNDEyYiAxMDA2NDQKLS0tIGEvU3JjL01vZHVsZXMvZGJf Z2RibS5jCisrKyBiL1NyYy9Nb2R1bGVzL2RiX2dkYm0uYwpAQCAtMzQsOCArMzQsOCBAQAogI2lu Y2x1ZGUgImRiX2dkYm0ubWRoIgogI2luY2x1ZGUgImRiX2dkYm0ucHJvIgogCi0jaWZuZGVmIFBN X1VQVE9EQVRFCi0jZGVmaW5lIFBNX1VQVE9EQVRFICAgICAoMTw8MTkpIC8qIFBhc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