[FEATURE] Process and thread locales for conventional C interfaces #86

Open
opened 2026-11-08 12:15:00 +01:00 by erikinkinen · 0 comments
Owner

Problem and motivation

The existing fourteen character calls use an explicit fixed C locale. Conventional C and POSIX consumers also need process locale selection, independent thread selection and locale objects. A process-global table indexed by thread-pointer values would not preserve thread generation or backing lifetime.

Proposed behavior and scope

Provide conventional ctype and locale-specific calls, <ctype.h> and <locale.h>, setlocale, localeconv, nl_langinfo/nl_langinfo_l, newlocale, duplocale, freelocale and uselocale. Support the C/POSIX and UTF-8 baseline profiles, category masks, environment precedence and explicit unsupported-locale errors. Keep required upstream source-use mapping as a separate acceptance obligation; this baseline does not claim every tool or language locale is supported.

The existing original ProcessRuntime embeds locale data and the genuine ThreadRuntime using its original heap and environment; the sole existing binding projects these actual fields. Genuine per-thread state holds an opaque current handle and a copied atomic profile, initially selecting the global locale. A checked current-encoding accessor serves conventional multibyte consumers. The coordinated thread-state extension owns initialization, generations and retirement; existing TCB reserved words are not reused.

Authority, security and reliability

Locale names, category bits and handles confer no native authority. No host locale database, environment lookup, service discovery or thread-pointer table is introduced. Original process, heap, thread image and locale-object lifetimes remain explicit. Invalid categories, missing locale data, allocation failure, foreign bindings and retired state fail before publication; failure preserves previous process/thread selection. Object mutation/free follows the documented C lifetime rules and actual original heap ownership.

Acceptance criteria

  • Implement the complete declared conventional ctype and locale interfaces with documented C layouts and calling contracts.
  • Preserve current process selection and independent current thread selection through actual initialized thread-state access.
  • Cover C/POSIX and UTF-8, byte/EOF cases, category composition, environment precedence and invalid or unsupported input.
  • Cover allocation failure atomicity, object duplication/free, thread replacement, original state withdrawal and concurrent readers.
  • Publish coherent native exports, original producer inputs, C/Rust controls and component/manual contracts.
  • Map the selected upstream consumers and retain any required native/guest adoption gates separately from host controls.

Alternatives and tradeoffs

Fixed-C aliases alone leave current-locale behavior incomplete. Hidden host TLS, pointer-indexed tables and reserved-word reuse would obscure lifetime and generation. The explicit runtime/state design adds a coordinated ABI prerequisite while keeping pure character operations free of native authority.

Tracking and rollout

Coordinate the original thread-runtime state extension first, then the locale runtime and conventional multibyte adapters. Preserve the existing explicit fixed-locale calls and caller-owned multibyte API. Update native producers and consumers together; source completion does not substitute for complete guest acceptance.

## Problem and motivation The existing fourteen character calls use an explicit fixed C locale. Conventional C and POSIX consumers also need process locale selection, independent thread selection and locale objects. A process-global table indexed by thread-pointer values would not preserve thread generation or backing lifetime. ## Proposed behavior and scope Provide conventional ctype and locale-specific calls, `<ctype.h>` and `<locale.h>`, `setlocale`, `localeconv`, `nl_langinfo`/`nl_langinfo_l`, `newlocale`, `duplocale`, `freelocale` and `uselocale`. Support the C/POSIX and UTF-8 baseline profiles, category masks, environment precedence and explicit unsupported-locale errors. Keep required upstream source-use mapping as a separate acceptance obligation; this baseline does not claim every tool or language locale is supported. The existing original ProcessRuntime embeds locale data and the genuine ThreadRuntime using its original heap and environment; the sole existing binding projects these actual fields. Genuine per-thread state holds an opaque current handle and a copied atomic profile, initially selecting the global locale. A checked current-encoding accessor serves conventional multibyte consumers. The coordinated thread-state extension owns initialization, generations and retirement; existing TCB reserved words are not reused. ## Authority, security and reliability Locale names, category bits and handles confer no native authority. No host locale database, environment lookup, service discovery or thread-pointer table is introduced. Original process, heap, thread image and locale-object lifetimes remain explicit. Invalid categories, missing locale data, allocation failure, foreign bindings and retired state fail before publication; failure preserves previous process/thread selection. Object mutation/free follows the documented C lifetime rules and actual original heap ownership. ## Acceptance criteria - [ ] Implement the complete declared conventional ctype and locale interfaces with documented C layouts and calling contracts. - [ ] Preserve current process selection and independent current thread selection through actual initialized thread-state access. - [ ] Cover C/POSIX and UTF-8, byte/EOF cases, category composition, environment precedence and invalid or unsupported input. - [ ] Cover allocation failure atomicity, object duplication/free, thread replacement, original state withdrawal and concurrent readers. - [ ] Publish coherent native exports, original producer inputs, C/Rust controls and component/manual contracts. - [ ] Map the selected upstream consumers and retain any required native/guest adoption gates separately from host controls. ## Alternatives and tradeoffs Fixed-C aliases alone leave current-locale behavior incomplete. Hidden host TLS, pointer-indexed tables and reserved-word reuse would obscure lifetime and generation. The explicit runtime/state design adds a coordinated ABI prerequisite while keeping pure character operations free of native authority. ## Tracking and rollout Coordinate the [original thread-runtime state extension](https://git.erikinkinen.fi/erix/lib-cstd/issues/85) first, then the locale runtime and conventional multibyte adapters. Preserve the existing explicit fixed-locale calls and caller-owned multibyte API. Update native producers and consumers together; source completion does not substitute for complete guest acceptance.
erikinkinen added this to the Alpha 1 milestone 2026-11-08 12:15:00 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
erix/lib-cstd#86
No description provided.