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=-1.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,LONGWORDS, 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 7ADA12546A for ; Tue, 12 Mar 2024 05:14:05 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1710216845; b=D1P5hxxguG0xJcBB0SCLSYoFxTa6Z1ubuaIhLha2rqjIFwEhIjYsMcIHLhdVNF8bkpDsEopBos q6prZCQKgWZ0R0zbX8icIoh53CSjtbWYCa9u3OrWrsDLho7e19BvR2E8IVS6zdHyW2g2B4DGVy MG//UoONEBhCbTlH5pWdHjLUbJq7BTVjlL7M+8phQy9py8ak87JThU9UGDemX8J6wY29L8tXFT W4HnZKWiDXXMUkcTmS8UvEyfUT/b8S6x3tkU/urkBKVMQ1QhRAh5E5diRR4IQUORP3ieq2KwiF SKXpPfBO2U4WDa+iK1zo47S/YJVxWa2UUjx5lbBZKw+2Hw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f46.google.com) smtp.remote-ip=209.85.167.46; 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=1710216845; bh=X6a7tJ+5MwRlmXhUrIlSk13LtXvIlaxf78AxW3TFpc0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=YTnbAZyoSczc4dMyibssd6O7dRDfpnAgcY+2SgtyxmZfYSZFaInm8NJyp0YIt+XH7ajkp8wUjL IGPlosPT87cM3Lo5zsqTSxGFBMyz66lBwMYN8Jf+0luVjFWeWGyMn/IAj5QmqqbgIZlmxX3d7F twYxlqFggeYn6dVsq9roDngkLeToO5v8CJnyLdXcH12N1cYw/I+XJBSw5mM+3F9BW1ZLqbQLY4 PhwXhk4g5f97GhRP9knF5bbFP5pBT5AbAxXGoe0MkKwp5ewP8fGUY3wUIoQqL04ws4Py2gR3kk gyAS3X0BOdP3rJ4ZFNKQL1ZQWQ8FPTsh1YScdY1ybGYJzQ==; 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: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:In-Reply-To:References; bh=RbrILs4VCqO9HYaTFi79iHEjri9T6hGXvpnYROKel6I=; b=In3+HvQXbaI7cepCj0bcqO++ug ljMehq76B0phklJd4opHLD9dMf9hhqupX1uEaGc2cHC6Isrd2fE7q68fy/ReqF9v3dxxkRYa6XsP3 IhX2IUmsJDB4J393hX9Sv3Wqr4YcaiY+X/GRGp/cqGL22lrLaGeLKNJZoYaTeuLJfUZN8DtRVPu57 6TspTAD7ExYpbcBKpZxPPbfnz9vG0dDj3heHMEsq00Rx2qTJeStP05h1uV6MfE7an7qtLzwziHy/W xe810PtPXNIdGFhx9l6Be1KdJk7sfQ/WH5PCDaE5Dvk127dEXRZFclAZr+AlhuA/Nm1g6+MQ0hj0Z vSd5Y0FA==; Received: by zero.zsh.org with local id 1rjtWf-000ItM-1r; Tue, 12 Mar 2024 04:14:05 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f46.google.com) smtp.remote-ip=209.85.167.46; 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-lf1-f46.google.com ([209.85.167.46]:57682) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rjtWL-000IbQ-K6; Tue, 12 Mar 2024 04:13:46 +0000 Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-513b16bb739so1218394e87.3 for ; Mon, 11 Mar 2024 21:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1710216824; x=1710821624; darn=zsh.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=RbrILs4VCqO9HYaTFi79iHEjri9T6hGXvpnYROKel6I=; b=AD2GhaiUNCEMNf9xns8B26gJAXvL3tU6o/qjQPJuDPwT6VDglWTPKz00+hX2/+hjGH iA8vjbQu0uTPipechKXPMwbcVoOeQhs3BSbVjkIDEj/M3IOyiqUhWl0NkWVDQ+Cfo2S8 V81kBtupJogYhuWot/7f0NEsDYnWI5+CDrUIYKW76JNSZC1P7fdpE/GUjU4+J98FRgfx N3sPgIw/fFccxIW+y7Mn40vVvh2l131M3ZgI4OU2+oV68NvIsV4GJiAaHp6wqKPd8jsF 42NguCmMTBYU7V7SnJGCoAg5wFeyvW2My2q1imqk7vKc+HYTsUiq0iMC73DK/2CVopLB tbtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710216824; x=1710821624; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=RbrILs4VCqO9HYaTFi79iHEjri9T6hGXvpnYROKel6I=; b=YQqRKgUZlHV8kVe13948GCR9v2cbfIS8zQiby91ztjInTdRX32pXf2Yt07oxxR/HXs JjhkgUjFzjVQPL+Mctcdssnzm+B09TWhzLHwyht5FvzSOqHiE4PB1OHX9mIpgVUiLDiS 71nj+DJaKPsMOOqMa2BTs7fy+x9oaejqr6kwHNgyVBGRvf2oeOBnMP4soZ7l4x/0iMyn a4K6C+2k2PcyuLZgxvUmX72Ne52oggVwH+yQQ6fpo/gkalJZuGStwfedtY5H6liygEZj fMNJbwXagOeYJHwlWpLTKZ0wLq8kR3Es4jZOaHiDEnoVsiVkllnZTosRJxPLRswuNco7 QaPQ== X-Gm-Message-State: AOJu0YxhhHbrrKlS2isoqByFL3/Fy1sak4yKxcwiz/lgvWqBdqsQEqNE IGpWFET7/zW9oZI3C8DuNfmYlaaZirSw5QfO0aFGG+CC5AWtsueMnLHAAjHQenb7b2i53I1d9Ad bz3dHh6wQlMG3gTR8Hkd6Ce9FERWo4k3+taJ3R7aPUyPwIw1qqw== X-Google-Smtp-Source: AGHT+IEZ8rO+S/NIWwv9lJfdPRftjjKWcOlApNQWRs2BNSd4dPqj33f8JI4GQXosNEelfSGoppxDh9p7A0wQgmEdqls= X-Received: by 2002:a05:6512:e89:b0:513:201c:5dc6 with SMTP id bi9-20020a0565120e8900b00513201c5dc6mr6518597lfb.61.1710216823857; Mon, 11 Mar 2024 21:13:43 -0700 (PDT) MIME-Version: 1.0 From: Bart Schaefer Date: Mon, 11 Mar 2024 21:13:32 -0700 Message-ID: Subject: "typeset -p" and no_GLOBAL_EXPORT, other misc. To: Zsh hackers list Content-Type: multipart/mixed; boundary="00000000000047343206136ee2bc" X-Seq: 52728 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: --00000000000047343206136ee2bc Content-Type: text/plain; charset="UTF-8" I alluded to this on zsh-users. If you "emulate ksh" and then attempt "typeset -p" (especially "typeset -p -m") the results are somewhat unpredictable, but among the possible effects is that instead of printing parameter names/values, typeset instead attempts to create a local name for every existing global name. In part this invovles the GLOBAL_EXPORT option which is set by default in zsh mode. When it is unset, the PM_LOCAL flag is turned on in cases where it should not be, or at least in cases where typeset_single() doesn't know how to deal with it and bypasses the value printing code to fall through to the assignment / attribute modifying code. It doesn't actually succeed in doing anything at all, but if compiled with ZSH_DEBUG it spits out a lot of repetitions of BUG: -p not handled The doc for GLOBAL_EXPORT says: If this option is set, passing the -x flag to the builtins declare, float, integer, readonly and typeset (but not local) will also set the -g flag; hence parameters exported to the environment will not be made local to the enclosing function, unless they were already or the flag +g is given explicitly. If the option is unset, exported parameters will be made local in just the same way as any other parameter. The code that implements this is: if (!(OPT_ISSET(ops,'g') || OPT_ISSET(ops,'x') || OPT_ISSET(ops,'m')) || OPT_PLUS(ops,'g') || *name == 'l' || (!isset(GLOBALEXPORT) && !OPT_ISSET(ops,'g'))) on |= PM_LOCAL; If we unroll that and apply a little boolean algebra: if (*name == 'l' || OPT_PLUS(ops,'g')) on |= PM_LOCAL; else if (OPT_ISSET(ops,'g')) /* Do nothing */; /* Or strangely: on &= ~PM_LOCAL */ else if (!isset(GLOBALEXPORT)) on |= PM_LOCAL; else if (!(OPT_ISSET(ops,'x') || OPT_ISSET(ops,'m'))) on |= PM_LOCAL; This demonstrates that GLOBALEXPORT (when not set) affects a lot more than just the -x flag. In the "strangely" branch noted above, PM_LOCAL is often still set, but it's state doesn't seem to matter. Anyway, to make this almost match the doc, I can rearrange it to be: if (*name == 'l' || OPT_PLUS(ops,'g')) on |= PM_LOCAL; else { if (!(OPT_ISSET(ops,'x') || OPT_ISSET(ops,'m'))) on |= PM_LOCAL; else if (OPT_MINUS(ops,'x')) { if (isset(GLOBALEXPORT)) ops->ind['g'] = 1; else if (locallevel) on |= PM_LOCAL; } if (OPT_MINUS(ops,'g')) on &= ~PM_LOCAL; } This fixes most cases but it's still possible to generate the "BUG" message by explicitly enabling PM_LOCAL: % () { typeset -p +g -m \* } And in that case it somehow wipes out all the prompt-related parameters (PS1, PS2, etc.). The answer to that seems to be to never go past the "if (usepm)" branch in typeset_single() when the 'p' option is set, but that leaves cases that seem like they should work but where "usepm" is turned off too soon. So I've attempted to fix that too. The remaining thing, which I have not been able to fix, is the tangled meanings of [+|-][pgm] ... some combinations that it seems should display something display nothing, and some combinations display what seems like too much. This is because some decisions are made in bin_typeset() and others are deferred to typeset_single(). For example: % () { typeset +m f\* } array tied FIGNORE fignore array tied FPATH fpath undefined funcfiletrace undefined funcsourcetrace undefined funcstack undefined functions undefined functions_source undefined functrace But add -p and (trimming some long output): % () { typeset -p +m f\* } typeset -g -aT FIGNORE fignore=( ) typeset -g -aT FPATH fpath=( /usr/local/share/zsh/... ) That works exactly the same with -p -m which I guess is OK. However ... % () { local foo=bar; typeset -p -m f\* } typeset -g -aT FIGNORE fignore=( ) typeset -g -aT FPATH fpath=( /usr/local/share/zsh/... ) typeset foo=bar % () { local foo=bar; typeset -p +m f\* } typeset -g -aT FIGNORE fignore=( ) typeset foo=bar typeset -g -aT FPATH fpath=( /usr/local/share/zsh/... ) The order of printing changes between -/+ if there's a local that matches? Those two cases also don't matter for +p with either state of m, but then there's [+/-]g ... it seems like (inside a function where -g matters): typeset -p -g ... should print only globals and skip locals, but that doesn't happen. Also typeset +p +g ... should have the same effect, but it does something else. And typeset -p +g ... should print only locals, but it prints everything except in typeset -p +g -m ... which does print only locals, whereas typeset -p +g +m ... prints nothing. And you'd think that typeset +p -g ... would be the same as -p +g, but in fact it also prints everything (ignoring -m entirely), but becomes the same if +m is added. On top of this are differences between [-/+]m with and without a pattern argument. To even start fixing this mess, we'd have to explain what a function considers "local" and what "global". Are all "inherited" scopes global, so local is the current scope only? Gaah. Anyway the attached at least prevents munging the parameter space when the intention is only to display it. --00000000000047343206136ee2bc Content-Type: text/plain; charset="US-ASCII"; name="typeset+-pgm.txt" Content-Disposition: attachment; filename="typeset+-pgm.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_ltnuw3od0 ZGlmZiAtLWdpdCBhL1Rlc3QvRDEwbm9mb3JrLnp0c3QgYi9UZXN0L0QxMG5vZm9yay56dHN0Cmlu ZGV4IGQ2YTU1ODhkZi4uYjlhMmY5ZjM3IDEwMDY0NAotLS0gYS9UZXN0L0QxMG5vZm9yay56dHN0 CisrKyBiL1Rlc3QvRDEwbm9mb3JrLnp0c3QKQEAgLTcsNiArNyw4IEBACiAgIHB1cnIoKSB7IHBy aW50IC1yIC0tICIkQCIgfQogICBwdXJsKCkgeyBwcmludCAtcmwgLS0gIiRAIiB9CiAKKyAgc2V0 b3B0IGlnbm9yZWNsb3NlYnJhY2VzCisgIAogJXRlc3QKIAogICBSRVBMWT1PVVRFUgo= --00000000000047343206136ee2bc--