zsh-workers
 help / color / mirror / code / Atom feed
* Bug: Unicode character of zsh module will become weird characters
@ 2024-05-11 13:40 Wu, Zhenyu
  2024-05-13  9:51 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Wu, Zhenyu @ 2024-05-11 13:40 UTC (permalink / raw)
  To: zsh-workers; +Cc: zsh-users

Excuse me:

Reproduce procedures:

```zsh
% git clone --depth=1 https://github.com/zsh-users/zsh
% cd zsh
% sed -i 's/strparam = ztrdup("example");/strparam = ztrdup("你好");/' Src/Modules/example.c
% autoreconf -vif
% ./configure
% make
```

Actual behavior:

```zsh
% zsh -f
laptop% module_path+=( $PWD/Src/Modules )
laptop% zmodload example
The example module has now been set up.
laptop% echo ${(q)exstr}
$'\344'$'\275'\好
laptop%
```

Expected behavior:

```zsh
% zsh -f
laptop% module_path+=( $PWD/Src/Modules )
laptop% zmodload example
The example module has now been set up.
laptop% echo ${(q)exstr}
你好
laptop%
```

Is it a bug? TIA!

-- 
Best Regards
Wu, Zhenyu


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug: Unicode character of zsh module will become weird characters
  2024-05-11 13:40 Bug: Unicode character of zsh module will become weird characters Wu, Zhenyu
@ 2024-05-13  9:51 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2024-05-13  9:51 UTC (permalink / raw)
  To: Wu, Zhenyu, zsh-workers

> On 11/05/2024 14:40 BST Wu, Zhenyu <wuzhenyu@ustc.edu> wrote:
> ```zsh
> % git clone --depth=1 https://github.com/zsh-users/zsh
> % cd zsh
> % sed -i 's/strparam = ztrdup("example");/strparam = ztrdup("你好");/' Src/Modules/example.c
> % autoreconf -vif
> % ./configure
> % make
> ```

I think The problem's actually here.  Zsh has a special encoding of
strings internally to avoid confusion between normal strings and
tokenised strings.  This is because special characters are mixed in with
normal characters in strings inside the code.  This system is known as
"metafication".  This means you have to be careful when creating strings
to be stored inside the system.  In fact, this is usually only a problem
if strings contain byte 0x80, so it can be a bit of a surprise when you
see it.

If you're doing normal input and output this should work automatically,
but you're updating the source code directly.  Try changing the line in
the example file to:

    strparam = metafy("你好", strlen("你好"), META_DUP);

and see if that works --- looks OK to me with a quick test.

cheers
pws


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-13  9:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-11 13:40 Bug: Unicode character of zsh module will become weird characters Wu, Zhenyu
2024-05-13  9:51 ` Peter Stephenson

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).