cc-wrapper: simplify expandResponseParams parser#3
Conversation
0db0650 to
9ed1ef5
Compare
c41edf5 to
ba2757e
Compare
|
Looks very reasonable to me, and I like that you handle the whole argument list rather than one at a time - eliminating the need to loop over it in bash. I think it'd be a good idea to comment some of the trickier parts of this, in case anyone needs to come through this part of the codebase and fix or add functionality in the future. |
ba2757e to
bf403ee
Compare
|
I have added a docstring for |
There was a problem hiding this comment.
Can we use a State transitions[7][5] = [ [ .. ] .. ]? I think that would be cleaner.
There was a problem hiding this comment.
Unlike @ryantrinkle, I'm a bit less exited about forking regardless of whether there is a response file. But I can't think of any problems either, correctness-wise or bootstrapping-wise (it took me a second to realize that second part). I don't care to much, and you two outvote me, so lets keep it.
OTOH, great job with readarray and null deliminators. Huge fan of those :).
There was a problem hiding this comment.
I have changed this to only call expand-response-params when @FILE args are present.
Thank you!
There was a problem hiding this comment.
nit: EXIT_SUCCESS instead of 0.
There was a problem hiding this comment.
OK, but I wouldn't use EXIT_SUCCESS in my code unless I would also use EXIT_FAILURE.
There was a problem hiding this comment.
If argv[1] == 0 we'll free(0)
There was a problem hiding this comment.
This is correct, free is defined to do nothing on NULL.
There was a problem hiding this comment.
What does binding s achieve?
There was a problem hiding this comment.
append needs char *, whereas &c has type int * (because c needs to contain EOF which is not a char). It is also not correct to cast int * to char * because int * may point to a zero byte in the binary representation of the integer instead of the byte with the char.
There was a problem hiding this comment.
Ah! Thank you that explains it. (Would be good for a comment though... :))
There was a problem hiding this comment.
I'd rather add appendChar function than a comment about char s = c.
bf403ee to
4e3021a
Compare
Ericson2314
left a comment
There was a problem hiding this comment.
I'll let Ryan do the merge / comments galore as he pointed out would still be nice, but looks great re all my points.
I was also trying to think of one way to make the initial state explicit in the transition table, but completely forgot about C99 sparse array initialization syntax. Great trick!
There was a problem hiding this comment.
I don't think the explicit values are needed anymore?
There was a problem hiding this comment.
I could remove the numbers, but I still depend on their correspondence with transition columns, and C does not allow me to remove 5 from transitions[][5].
There was a problem hiding this comment.
Ah the columns, duh. Nevermind then!
There was a problem hiding this comment.
Hmm, I suppose both the old and new version should pass a -std=c99/-std=c11? Don't want some weirdness if somebody is bootstrapping with an impure stdenv.
There was a problem hiding this comment.
Done. BTW, I still don't understand why src is copied.
There was a problem hiding this comment.
Free free to try it with $src and investigate the error on Darwin! __FILE__ is only a guess.
There was a problem hiding this comment.
src was copied for my version because otherwise there would be a spurious reference in the binary to the source, which would be picked up by Nix. I'm pretty sure that's because of my use of assert, which probably uses __FILE__ as @Ericson2314 mentioned. If it doesn't cause trouble with yours, I see no reason to keep the cp around.
There was a problem hiding this comment.
What should I look for to recognize if there is a spurious reference or not? Does Nix refuse to install a derivation, or print a warning?
There was a problem hiding this comment.
It should fail with an error if there's a reference that isn't in allowedReferences/allowedRequisites. However, you might also just grep for /nix/store in the resulting binaries.
195c27b to
3def2b8
Compare
|
I have just pushed an update that modified |
9995856 to
f2ecf4a
Compare
There was a problem hiding this comment.
Could this be char * instead of void *?
There was a problem hiding this comment.
Done. I used void * because it is the interface of memcpy, but char * makes more sense for strings.
There was a problem hiding this comment.
Awesome! This is much easier for me to read.
f2ecf4a to
d7593dd
Compare
d7593dd to
2bc7b4e
Compare
|
If you strongly believe that some lines will benefit from additional comments, please point them out. Otherwise, this pull request seems ready for merge. |
|
@orivej Agreed! I'm doing some final testing now, and I'll merge ASAP. |
|
@orivej Unfortunately, this implementation seems to have a bug that prevents GHC from building. Specifically, when escaped quotes (of any kind) are inside of quotes (of any kind), they do not produce output. For example, this response file produces no output: However, it should produce a single argument with the value: Perhaps we should add some tests? |
|
@orivej Could you take a look at my fix for that issue and let me know what you think? |
|
Thank you, this is what I meant the code to do! |
… crash 1. Gnumeric has unbalanced XML tags in its doc translations. 2. itstool's XML error handler tries to print this error with context. 3. libxml2's context snipper treats the data as bytes, not UTF-8. 4. python3Packages.libxml2 casts the context to a UTF-8 Python string. 5. itstool dereferences a null pointer. This patch intervenes at #4. In https://bugzilla.gnome.org/show_bug.cgi?id=789714#c4 , upstream suggests that intervening at #3 would be better -- that each of the four copies of xmlParserPrintFileContextInternal() have four additional UTF-8 problems, one of which is that the caret indicator ought to count "unicode characters" not bytes. But to position a caret correctly, a character count is not sufficient -- this would need to use icu's BiDi logic (with fallback to doing something wrong when libxml2 is configured not to use icu) -- which makes a 'correct' fix a much larger project than this simple band-aid.
Without this change it segfaults when trying to play any media: $ jellyfinmediaplayer Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. libpng warning: iCCP: known incorrect sRGB profile Logging to /home/bf/.local/share/jellyfinmediaplayer/logs/jellyfinmediaplayer.log Cannot load libcuda.so.1 Segmentation fault (core dumped) The backtrace shows pipewire being at fault: $ coredumpctl debug [...] Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007f711428c9bb in core_event_demarshal_remove_id () from /nix/store/nhffrd7f15dhfbkwzgayq7hhzmdvdy19-pipewire-0.3.63-lib/lib/pipewire-0.3/libpipewire-module-protocol-native.so [Current thread is 1 (Thread 0x7f6ffdc87640 (LWP 1360949))] (gdb) bt #0 0x00007f711428c9bb in core_event_demarshal_remove_id () from /nix/store/nhffrd7f15dhfbkwzgayq7hhzmdvdy19-pipewire-0.3.63-lib/lib/pipewire-0.3/libpipewire-module-protocol-native.so #1 0x00007f711428886c in process_remote () from /nix/store/nhffrd7f15dhfbkwzgayq7hhzmdvdy19-pipewire-0.3.63-lib/lib/pipewire-0.3/libpipewire-module-protocol-native.so #2 0x00007f7114288e68 in on_remote_data () from /nix/store/nhffrd7f15dhfbkwzgayq7hhzmdvdy19-pipewire-0.3.63-lib/lib/pipewire-0.3/libpipewire-module-protocol-native.so #3 0x00007f7114310efe in loop_iterate () from /nix/store/nhffrd7f15dhfbkwzgayq7hhzmdvdy19-pipewire-0.3.63-lib/lib/spa-0.2/support/libspa-support.so #4 0x00007f71266fe7f2 in do_loop () from /nix/store/nhffrd7f15dhfbkwzgayq7hhzmdvdy19-pipewire-0.3.63-lib/lib/libpipewire-0.3.so.0 #5 0x00007f7128b08e86 in start_thread () from /nix/store/ayfr5l52xkqqjn3n4h9jfacgnchz1z7s-glibc-2.35-224/lib/libc.so.6 #6 0x00007f7128b8fce0 in clone3 () from /nix/store/ayfr5l52xkqqjn3n4h9jfacgnchz1z7s-glibc-2.35-224/lib/libc.so.6 (gdb) Standalone mpv doesn't segfault (when directly playing the underlying media files). I don't know why. Fixes: b97cda7 ("mpv-unwrapped: 0.34.1 -> 0.35.0") Fixes NixOS#205141 Ref jellyfin/jellyfin-desktop#341 (cherry picked from commit 3c528bc)
On my systems there is a path in the fonts list that looks like
/nix/store/<hash>-<font>.ttf. The previous code assumed that every font path
contains at least one more slash which isn't the case here.
The code matched on the / after the $out path of the derivation:
/nix/store/<hash>-<name>/share/X11/fonts/...
^
That slash only exists if the font lives in a subdirectory, which
isn't strictly required. In my case I've a few font files that are
located at /nix/store/<hash>-<name>.ttf and are assembled into a
folder as symlinks. (See example below)
Any attempt at calling realpath(3) on them (potentially recursively)
will result in the single file entry in the store being returned.
Whenever that font is being loaded flatpak segfaulted like so:
```
(gdb) bt
#0 0x00005583b3673763 in get_nix_closure ()
#1 0x00005583b3673711 in get_nix_closure ()
#2 0x00005583b36737dc in add_nix_store_symlink_targets ()
#3 0x00005583b36749a8 in add_font_path_args ()
#4 0x00005583b367b3f4 in flatpak_run_app ()
#5 0x00005583b35e4f08 in flatpak_builtin_run ()
#6 0x00005583b35a5970 in main ()
(gdb) x/5i $rip
=> 0x5583b3673763 <get_nix_closure+307>: movb $0x0,(%rax)
0x5583b3673766 <get_nix_closure+310>: call 0x5583b35a46a0 <g_hash_table_add@plt>
0x5583b367376b <get_nix_closure+315>: jmp 0x5583b3673699 <get_nix_closure+105>
0x5583b3673770 <get_nix_closure+320>: xor %edi,%edi
0x5583b3673772 <get_nix_closure+322>: lea 0x30475(%rip),%rsi # 0x5583b36a3bee
(gdb) x/s $rsi
0x5583e92d2180: "/nix/store/<hash>-A.ttf"
(gdb) print $rax
$1 = 0
```
RAX pointing to 0 here corresponds to the pointer `p` in the source
code. So the code attempted to dereference a null pointer as no further
slash (the return value of strchr(3)) could be found.
The modification in this commit ensures that we check for `p != 0` so
we don't run into this situation again.
Adding the path to the closure will still be done, even if no further
slash can be found, as that still points to a valid store path.
----
Nix code for custom fonts:
```nix
let
files = [
./A.ttf
./B.ttf
];
in
runCommandNoCC "custom-fonts" {} ''
mkdir -p $out/share/fonts/truetype
cd $out/share/fonts/truetype
${ lib.concatStringsSep "\n" (map (file: "ln -s ${file} ${baseNameOf file}") files)}
''
```
Import from https://github.com/orivej/expand-compiler-args/tree/ca9865a89eabee6282ed756a371825780f11fc25