Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS 12.3 ARM64] /usr/bin/awk: towc: multibyte conversion failure on: '��@' #190

Open
killermoehre opened this issue May 1, 2022 · 12 comments

Comments

@killermoehre
Copy link

GNU bash, version 5.1.16(1)-release (aarch64-apple-darwin21.1.0)
ble.sh, version 0.4.0-devel3+d340233 (noarch)
bash-preexec (iterm2_shell_integration.sh), iterm2_shell_integration.sh (noarch) (integration: on)
locale: LANG=de_DE.UTF-8 LC_COLLATE=C LC_TERMINAL=iTerm2 LC_TERMINAL_VERSION=3.4.15
terminal: TERM=xterm-256color wcwidth=12.1-west/13.1-2+ri, xterm:95 (0;95;0)

So, I changed to a new MacBook with the AppleARM chip. If I do a on a path (or blesh tries by itself), the following error fragment are thrown.

$ /bin/ls /usr/bin/awk: towc: multibyte conversion failure on: '��@'

 input record number 9, file
 source line number 18
/usr/bin/awk: towc: multibyte conversion failure on: '��@'

 input record number 9, file
 source line number 18

Here is the "output" of /usr/bin/awk --version:

$ /usr/bin/awk --ve/usr/bin/awk: towc: multibyte conversion failure on: '��'

 input record number 31, file
 source line number 18
--versi/usr/bin/awk: towc: multibyte conversion failure on: '��'

 input record number 31, file
 source line number 18
--version/usr/bin/awk: towc: multibyte conversion failure on: '��'

 input record number 31, file
 source line number 18

awk version 20200816
@killermoehre
Copy link
Author

OK, was a problem on my side. My $PATH was not adjusted at the moment ble-attach run, so only the macOS inbuilt awk was available.

@akinomyoga
Copy link
Owner

The search for the error message finds two similar reports

The version format and another error message "input record number ... source line number ..." imply that this is a variant of nawk. However, the source code that contains the error message "towc: multibyte conversion failure on" does not seem to be found in GitHub or by Google. I guess the awk implementation is closed source.

@akinomyoga akinomyoga changed the title MacOS 12.3 ARM64: /usr/bin/awk: towc: multibyte conversion failure on: '��@' [MacOS 12.3 ARM64] /usr/bin/awk: towc: multibyte conversion failure on: '��@' May 3, 2022
@akinomyoga akinomyoga changed the title [MacOS 12.3 ARM64] /usr/bin/awk: towc: multibyte conversion failure on: '��@' [macOS 12.3 ARM64] /usr/bin/awk: towc: multibyte conversion failure on: '��@' May 3, 2022
@akinomyoga
Copy link
Owner

Thank you for the report. I'm not sure if I can fix or work around it soon, but I would like to keep it open so that other users can find it.

@akinomyoga akinomyoga reopened this May 3, 2022
@SuperSandro2000
Copy link

Maybe rename awk to gawk and force darwin users to get a recent GNU awk?

@akinomyoga
Copy link
Owner

@SuperSandro2000 Thank you for your comment! Yeah, I think that is the valid workaround. Currently, ble.sh selects the awk implementation here where the precedence is XPG4 awk (Solaris) > nawk > mawk > gawk > awk. I guess the macOS awk is only used when none of nawk, mawk, and gawk is found.

Nevertheless, if it is possible, I'd like to support the macOS awk.

@killermoehre
Copy link
Author

I can provide you the following data on a recent macOS 12.3.1

$ /usr/bin/awk --version
awk version 20200816
$ what /usr/bin/awk
/usr/bin/awk
	PROGRAM:awk  PROJECT:awk-32
	PROGRAM:awk  PROJECT:awk-32

The binary says that it's com.apple.awk and signed by Apple, Inc. Out of personal experience I know that there is no way to ask an awk implementation itself what operation it supports.

@akinomyoga
Copy link
Owner

Thank you for the information! I have searched for the string com.apple.awk and found the page opensource.apple.com/tarballs/awk where the source of macOS awk-27.40.1 can be downloaded. Unfortunately, the source of awk-27.40.1 doesn't seem to contain the error message "towc: multibyte conversion failure on".

@killermoehre
Copy link
Author

I asked in the Apple Developer Forums.

@akinomyoga
Copy link
Owner

akinomyoga commented May 7, 2022

I found the source code of awk-32 on GitHub. [ The GitHub code search for "towc: multibyte conversion failure on" initially didn't find anything, but after I searched for a shorter string "multibyte conversion failure", it somehow started to return results. Maybe the caching of the GitHub code search is related. ]

The source code contains the exact error message. Awk-32 seems to be the release version just coming after awk-27.40.1. The feature difference is explained here.

I have built it in Linux with the following modification

diff --git a/src/b.c b/src/b.c
index cfffcb9..fa03d40 100644
--- a/src/b.c
+++ b/src/b.c
@@ -31,7 +31,9 @@ THIS SOFTWARE.
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <xlocale.h>
+//#include <xlocale.h>
+#include <locale.h>
+typedef int wctype_t;
 #include <wchar.h>
 #include "awk.h"
 #include "awkgram.tab.h"
@@ -1256,6 +1258,7 @@ static int cclex(void) {
                                len = 1;
                                prestr += 2;

+#if 0
                                __collate_lookup_l(&collate_elem, &len, &prim1, &sec1, LC_GLOBAL_LOCALE);
                                DPRINTF("collate_elem: 0x%x p: %d s:%d\n", collate_elem, prim1, sec1);

@@ -1280,6 +1283,7 @@ static int cclex(void) {
                                                n++;
                                        }
                                }
+#endif
                        }
                } else if (wc == '\0') {
                        FATAL("nonterminated character class %.20s", lastre);

I thought maybe I can reproduce the problem using the obtained awk-32, but ble.sh seems to work with awk-32 without the error message on Linux. I'll later check the code again.

@akinomyoga
Copy link
Owner

@tessus Sorry, I think it's not your intention, but I used the VM to quickly check the behavior of the current /usr/bin/awk in macOS,

% bash --version
GNU bash, version 5.2.26(1)-release (x86_64-apple-darwin22.6.0)
% what /usr/bin/awk
/usr/bin/awk:
        PROGRAM:awk  PROJECT:awk-35
        PROGRAM:awk  PROJECT:awk-35
% head -c 32 /dev/urandom | awk '{print "hello"}'

In the past, awk-32 provided by macOS seemed to have issued error messages for some data not following the current character coding and failed without doing any actual processing. ble.sh wanted to use awk to process the output of Bash's builtin bind -p, in which some binary data is contained in the key sequence in older versions of Bash. I couldn't test it further for a long time because I didn't have access to macOS.

Now the awk version seems to be awk-35 and it doesn't seem to produce an error for binary data, though I'm not sure if the original problem is really related to the binary data.

@tessus
Copy link

tessus commented Feb 23, 2024

@akinomyoga don't worry about it. it is a dev test VM and you can use it for whatever tests you need. If it helps I can leave it running for a few weeks. You can even destroy it, and if you need it I can rollback to the point before you logged in for the first time. Just drop me a quick email if you need a rollback.

Btw, when I tried to install ble (via the make command) on the VM, ble complained that it wanted gawk. I did a sudo port install gawk and after that the install went through w/o a hitch.
You have root access. You can sudo port uninstall gawk for tests if you want.

@akinomyoga
Copy link
Owner

Thanks, by excluding /opt/local/bin from PATH, I can test the behavior without gawk. The error message doesn't seem to happen (though I added some workarounds by guess back then).

I also complied awk-32 from the source and tried it, but the error message doesn't seem to be reproduced by just head -c 4096 /dev/urandom | ./awk '{print "hello"}', etc. The error message might be specific to M1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants