Skip to content

[libc] Define MB_LEN_MAX in limits.h #102246

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

Merged
merged 2 commits into from
Aug 7, 2024
Merged

[libc] Define MB_LEN_MAX in limits.h #102246

merged 2 commits into from
Aug 7, 2024

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Aug 6, 2024

Summary:
This is supposed to define the maximum bytes required to store a char in
any locale. There's some question about what this should be set to. I
believe because the proposed solution for locale.h is to only support
the default locale, we should do what musl does and set it to 4
which covers up to UTF-32.

Fixes #79358

Summary:
This is supposed to define the maximum bytes required to store a char in
any locale. There's some question about what this should be set to. I
believe because the proposed solution for `locale.h` is to only support
the default locale, we should do what `musl` does and set it to `4`
which covers up to UTF-32.

Fixes llvm#79358
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
This is supposed to define the maximum bytes required to store a char in
any locale. There's some question about what this should be set to. I
believe because the proposed solution for locale.h is to only support
the default locale, we should do what musl does and set it to 4
which covers up to UTF-32.

Fixes #79358


Full diff: https://github.com/llvm/llvm-project/pull/102246.diff

1 Files Affected:

  • (modified) libc/include/llvm-libc-macros/limits-macros.h (+3-6)
diff --git a/libc/include/llvm-libc-macros/limits-macros.h b/libc/include/llvm-libc-macros/limits-macros.h
index 456487e603b25..066896c73119f 100644
--- a/libc/include/llvm-libc-macros/limits-macros.h
+++ b/libc/include/llvm-libc-macros/limits-macros.h
@@ -19,12 +19,9 @@
 #endif // __CHAR_BIT__
 #endif // CHAR_BIT
 
-// TODO: https://github.com/llvm/llvm-project/issues/79358
-//   Define MB_LEN_MAX if missing.
-//     clang: MB_LEN_MAX = 1 -
-// https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/limits.h#L64
-//     glibc: MB_LEN_MAX = 16 -
-// https://github.com/bminor/glibc/blob/master/include/limits.h#L32
+#ifndef MB_LEN_MAX
+#define MB_LEN_MAX 4
+#endif // MB_LEN_MAX
 
 // *_WIDTH macros
 

// glibc: MB_LEN_MAX = 16 -
// https://github.com/bminor/glibc/blob/master/include/limits.h#L32
#ifndef MB_LEN_MAX
#define MB_LEN_MAX 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding comments about the rationale of the value, in case the assumption is changed in the future?

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jhuber6 jhuber6 merged commit b209eda into llvm:main Aug 7, 2024
6 checks passed
@jhuber6 jhuber6 deleted the MB_LEN_MAX branch September 23, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc] Investigate the correct value for MB_LEN_MAX in limits.h header
4 participants