Skip to content

locale_t etc are unusable #1055

@Hello71

Description

@Hello71
18:51 <Hello71> how do I check if a libc::locale_t is null?
18:52 <Hello71> it's just an enum, so I can't call is_null on it
18:52 <Hello71> as *const u8 == null? :/
18:53 <talchas> Hello71: you should never have a locale_t
18:53 <talchas> you should only ever have *const locale_t
18:53 <Hello71> then how do I use uselocale and newlocale and so on
18:53 <Hello71> those return locale_t, not *const locale_t
18:54 <Hello71> because C locale_t is really a pointer to a struct. it has to be, because (locale_t)0 is used everywhere
18:56 <talchas> hmm, that would be a bug in the libc crate then
18:56 <talchas> yeah, that's wildly incorrect
18:56 <talchas> having a value of enum Foo {} is UB
18:57 <Hello71> sounds about right
18:57 <Hello71> I don't like how POSIX likes to define x_ts as primitive types sometimes and structs other times and sometimes pointer types
18:58 <occultus> That means uselocale is completely uncalleable from safe code. Is newlocale actually bound?
18:58 <Hello71> actually I guess locale_t can be an integral type, but I'm willing to wager a guess that it's a pointer to struct everywhere
18:59 <talchas> occultus: yeah, it's just a bug in libc, and given that the current definition is 100% worthless it's probably safe to just change its definition of locale_t to something useful
19:00 <occultus> oh wait, newlocale is also uncallable becuase it takes a locale_t for base. heh.
19:02 <occultus> talchas: does it qualify as a bug or just not yet implemented?
19:04 <talchas> occultus: given that it's providing the type and fns, I'd call it a bug
19:13 <Hello71> https://github.com/rust-lang/libc/blob/master/src/fuchsia/mod.rs#L73 lmao
19:14 <Hello71> talchas, occultus: ^
19:14 <occultus> my guess is they just thought "if they're uninhabited nobody can use them, so nothing bad can happen"
19:14 <occultus> except that something bad does happen, people see them in the docs but can't use them
19:15 <talchas> Hello71: well, that's even just weighing in on whether you want *const empty_struct or *const empty_enum
19:16 <talchas> (ie, it probably wants to be struct DIR(()); or equivalent so that accidentally dereferencing a *const DIR is useless rather than UB)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions