[#116016] [Ruby master Bug#20150] Memory leak in grapheme clusters — "peterzhu2118 (Peter Zhu) via ruby-core" <ruby-core@...>
Issue #20150 has been reported by peterzhu2118 (Peter Zhu).
7 messages
2024/01/04
[#116382] [Ruby master Feature#20205] Enable `frozen_string_literal` by default — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #20205 has been reported by byroot (Jean Boussier).
77 messages
2024/01/23
[ruby-core:116389] Re: [Ruby master Feature#19057] Hide implementation of `rb_io_t`.
From:
Eric Wong via ruby-core <ruby-core@...>
Date:
2024-01-24 01:03:00 UTC
List:
ruby-core #116389
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@ml.ruby-lang.org> wrote:
> I would be more worried about the C compiler, if the C
> compiler figures out a pointer is casted to "unrelated" struct
> types it might consider that as undefined behavior and do
> anything.
It's not undefined, every platform defines its own C ABI.
Any toolchain which ignores that ABI cannot interoperate at all
(which is fine for cases where you don't need interop)
Consider 1) how many languages/runtimes call C libraries.
Now consider 2) how many languages/libraries get called by C.
1 is common, 2 is rare and needs explicit instructions in
the non-C language (e.g. extern "C" in C++ headers).
gcc and clang generate objects from C which can safely be linked
by the others' linker. This isn't true for C++ at all.
FFI is completely dependent on a stable ABI.
> But I suspect that's explicitly not undefined behavior,
> because C has no notion of struct types being related or not,
> and there is likely tons of software using structs
> "inheriting/extending" another smaller struct.
>
> It might not explicitly be allowed either because I guess the
> fully correct way to do this is using a union of both structs,
> and not casting to a specific struct directly then.
FFI and Rust would not be able to use C libraries if the
C toolchain were told to violate its platform ABI.
Consider "struct sockaddr *" use in C standard library:
Functions like accept, connect, bind, getpeername, getsockname,
etc. all take a "struct sockaddr *" arg, but callers are expected
to allocate one of sockaddr_{in,in6,un,storage,...} to call them.
No unions are forced on a user for those sockaddr functions.
(I end up defining unions myself in what little C code I maintain,
but that's my choice for maintainability).
Same for POSIX fcntl locks, various ioctls, getsockopt/setsockopt,
or any other function which takes multiple struct types.
You can use FFI or syscall+pack/unpack on all of those
functions.
To make things more explicit, gcc and clang has
transparent_union which is intended to help document and
preserve ABI compatibility:
https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Common-Type-Attributes.html#index-transparent_005funion-type-attribute
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/