Skip to content

8354464: Additional cleanup setting up native.encoding #24607

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/java.base/share/native/libjava/System.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* questions.
*/

#include <assert.h>
#include <string.h>

#include "jni.h"
Expand Down Expand Up @@ -147,15 +148,9 @@ Java_jdk_internal_util_SystemProps_00024Raw_platformProperties(JNIEnv *env, jcla
PUTPROP(propArray, _line_separator_NDX, sprops->line_separator);

/* basic encoding properties, always non-NULL */
#ifdef MACOSX
/*
* Since sun_jnu_encoding is now hard-coded to UTF-8 on Mac, we don't
* want to use it to overwrite native.encoding
*/
assert(sprops->encoding != NULL);
assert(sprops->sun_jnu_encoding != NULL);
PUTPROP(propArray, _native_encoding_NDX, sprops->encoding);
#else
PUTPROP(propArray, _native_encoding_NDX, sprops->sun_jnu_encoding);
#endif
PUTPROP(propArray, _sun_jnu_encoding_NDX, sprops->sun_jnu_encoding);
Comment on lines 153 to 154
Copy link
Member

Choose a reason for hiding this comment

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

Since we now got rid of platform depenence here, would it make sense to perform non-null assertion in Java level here? I remember in the last PR we added assert in platform C code.

Copy link
Member

Choose a reason for hiding this comment

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

Java level -> Platform independent C level
Sorry

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Done.


/* encodings for standard streams, may be NULL */
Expand Down
4 changes: 0 additions & 4 deletions src/java.base/unix/native/libjava/java_props_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <stdio.h>
#include <ctype.h>
#endif
#include <assert.h>
#include <pwd.h>
#include <locale.h>
#ifndef ARCHPROPNAME
Expand Down Expand Up @@ -465,9 +464,6 @@ GetJavaProperties(JNIEnv *env)
sprops.sun_jnu_encoding = sprops.encoding;
#endif

assert(sprops.encoding != NULL);
assert(sprops.sun_jnu_encoding != NULL);

if (isatty(STDOUT_FILENO) == 1) {
sprops.stdout_encoding = sprops.encoding;
}
Expand Down
33 changes: 9 additions & 24 deletions src/java.base/windows/native/libjava/java_props_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "jni.h"
#include "jni_util.h"

#include <assert.h>
#include <windows.h>
#include <shlobj.h>
#include <objidl.h>
Expand All @@ -47,7 +46,7 @@

typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
static BOOL SetupI18nProps(LCID lcid, char** language, char** script, char** country,
char** variant, char** encoding);
char** variant);

#define PROPSIZE 9 // eight-letter + null terminator
#define SNAMESIZE 86 // max number of chars for LOCALE_SNAME is 85
Expand Down Expand Up @@ -167,7 +166,7 @@ getEncodingFromLangID(LANGID langID)
DllExport const char *
getJavaIDFromLangID(LANGID langID)
{
char * elems[5]; // lang, script, ctry, variant, encoding
char * elems[4]; // lang, script, ctry, variant
char * ret;
int index;

Expand All @@ -176,12 +175,12 @@ getJavaIDFromLangID(LANGID langID)
return NULL;
}

for (index = 0; index < 5; index++) {
for (index = 0; index < 4; index++) {
elems[index] = NULL;
}

if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
&(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) {
&(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]))) {

// there always is the "language" tag
strcpy(ret, elems[0]);
Expand All @@ -198,7 +197,7 @@ getJavaIDFromLangID(LANGID langID)
ret = NULL;
}

for (index = 0; index < 5; index++) {
for (index = 0; index < 4; index++) {
if (elems[index] != NULL) {
free(elems[index]);
}
Expand Down Expand Up @@ -263,7 +262,7 @@ cpu_isalist(void)

static BOOL
SetupI18nProps(LCID lcid, char** language, char** script, char** country,
char** variant, char** encoding) {
char** variant) {
/* script */
char tmp[SNAMESIZE];
*script = malloc(PROPSIZE);
Expand Down Expand Up @@ -320,11 +319,6 @@ SetupI18nProps(LCID lcid, char** language, char** script, char** country,
strcpy(*variant, "NY");
}

/* encoding */
*encoding = getEncodingInternal(lcid);
if (*encoding == NULL) {
return FALSE;
}
return TRUE;
}

Expand Down Expand Up @@ -640,7 +634,6 @@ GetJavaProperties(JNIEnv* env)
LCID userDefaultUILCID = MAKELCID(userDefaultUILang, SORTIDFROMLCID(userDefaultLCID));

{
char * display_encoding;
HANDLE hStdOutErr;

// Windows UI Language selection list only cares "language"
Expand All @@ -659,23 +652,18 @@ GetJavaProperties(JNIEnv* env)
&sprops.format_language,
&sprops.format_script,
&sprops.format_country,
&sprops.format_variant,
&sprops.encoding);
&sprops.format_variant);
SetupI18nProps(userDefaultUILCID,
&sprops.display_language,
&sprops.display_script,
&sprops.display_country,
&sprops.display_variant,
&display_encoding);

if (sprops.encoding == NULL) {
sprops.encoding = "UTF-8";
}
&sprops.display_variant);

sprops.sun_jnu_encoding = getEncodingInternal(0);
if (sprops.sun_jnu_encoding == NULL) {
sprops.sun_jnu_encoding = "UTF-8";
}
sprops.encoding = sprops.sun_jnu_encoding;

if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) {
// MS claims "Vista has built-in support for HKSCS-2004.
Expand All @@ -689,9 +677,6 @@ GetJavaProperties(JNIEnv* env)
sprops.sun_jnu_encoding = "MS950_HKSCS";
}

assert(sprops.encoding != NULL);
assert(sprops.sun_jnu_encoding != NULL);

hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdOutErr != INVALID_HANDLE_VALUE &&
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
Expand Down