Skip to content

Commit

Permalink
Split J9STR_CODE_PLATFORM into _PLATFORM_RAW and _PLATFORM_OMR_INTERNAL
Browse files Browse the repository at this point in the history
Issue: eclipse-omr#41
Signed-off-by: Peter Bain <[email protected]>
  • Loading branch information
youngar authored and pdbain-ibm committed Apr 1, 2016
1 parent edb7696 commit fc48a28
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 24 deletions.
18 changes: 9 additions & 9 deletions fvtest/porttest/omrstrTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ TEST(PortStrTest, str_convPlatTo8)

reportTestEntry(OMRPORTLIB, testName);
memset(outBuff, 0, sizeof(outBuff));
convertedStringLength = omrstr_convert(J9STR_CODE_PLATFORM, J9STR_CODE_MUTF8,
convertedStringLength = omrstr_convert(J9STR_CODE_PLATFORM_RAW, J9STR_CODE_MUTF8,
platformString, originalStringLength, outBuff, sizeof(outBuff));
if (convertedStringLength != expectedStringLength) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "buffer length wrong. Expected %d actual %d\n", expectedStringLength, convertedStringLength);
Expand All @@ -887,7 +887,7 @@ TEST(PortStrTest, str_convPlatTo8)
outputErrorMessage(PORTTEST_ERROR_ARGS, "Converted string wrong.");
}
/* test string length */
convertedStringLength = omrstr_convert(J9STR_CODE_PLATFORM, J9STR_CODE_MUTF8,
convertedStringLength = omrstr_convert(J9STR_CODE_PLATFORM_RAW, J9STR_CODE_MUTF8,
platformString, originalStringLength, NULL, 0);
if (convertedStringLength != expectedStringLength) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "buffer length wrong. Expected %d actual %d\n", expectedStringLength, convertedStringLength);
Expand Down Expand Up @@ -915,27 +915,27 @@ TEST(PortStrTest, str_convLongString)
longPlatformString[i] = (i % 127) + 1; /* stick to ASCII */
}
/* test string length */
mutf8StringLength = omrstr_convert(J9STR_CODE_PLATFORM, J9STR_CODE_MUTF8,
mutf8StringLength = omrstr_convert(J9STR_CODE_PLATFORM_RAW, J9STR_CODE_MUTF8,
longPlatformString, originalStringLength, NULL, 0);
if (mutf8StringLength < 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "Length calculation for modified UTF8 failed, error code %d\n", mutf8StringLength);
}
/* do the actual conversion */
mutf8StringLength = omrstr_convert(J9STR_CODE_PLATFORM, J9STR_CODE_MUTF8,
mutf8StringLength = omrstr_convert(J9STR_CODE_PLATFORM_RAW, J9STR_CODE_MUTF8,
longPlatformString, originalStringLength, mutf8Buff, sizeof(mutf8Buff));
if (mutf8StringLength < 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "Conversion to modified UTF8 failed, error code %d\n", mutf8StringLength);
}

/* test string length in the other direction */
returnStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
returnStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
mutf8Buff, mutf8StringLength, NULL, 0);
if (returnStringLength < 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "Length calculation for platform failed, error code %d\n", mutf8StringLength);
}

/* convert back and verify that it matches the original */
returnStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
returnStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
mutf8Buff, mutf8StringLength, returnBuff, sizeof(returnBuff));
if (returnStringLength < 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "Conversion to platform failed, error code %d\n", mutf8StringLength);
Expand Down Expand Up @@ -963,7 +963,7 @@ TEST(PortStrTest, str_convU8ToPlat)

reportTestEntry(OMRPORTLIB, testName);
memset(outBuff, 0, sizeof(outBuff));
convertedStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
convertedStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
utf8String, originalStringLength, outBuff, sizeof(outBuff));
if (convertedStringLength != expectedStringLength) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "buffer length wrong. Expected %d actual %d\n", originalStringLength, convertedStringLength);
Expand All @@ -972,7 +972,7 @@ TEST(PortStrTest, str_convU8ToPlat)
outputErrorMessage(PORTTEST_ERROR_ARGS, "Converted string wrong.");
}
/* test string length */
convertedStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
convertedStringLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
utf8String, originalStringLength, NULL, 0);
if (convertedStringLength != expectedStringLength) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "buffer length wrong. Expected %d actual %d\n", originalStringLength, convertedStringLength);
Expand Down Expand Up @@ -1115,7 +1115,7 @@ TEST(PortStrTest, str_convU8ToPlat_Null)

(void)memset(outBuff, '^', sizeof(outBuff)); /* initialize to non-zero */
convertedStringLength =
omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
inputString, inputStringLength, outBuff, sizeof(outBuff));

convertedStringTerminator = (uint32_t *)(outBuff + convertedStringLength);
Expand Down
4 changes: 2 additions & 2 deletions fvtest/porttest/testProcessHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ translateModifiedUtf8ToPlatform(OMRPortLibrary *portLibrary, const char *inBuffe
int32_t resultLength = 0;

*outBuffer = NULL;
bufferLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
bufferLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
inBuffer, inBufferSize, NULL, 0);
/* get the size of the platform string */

Expand All @@ -376,7 +376,7 @@ translateModifiedUtf8ToPlatform(OMRPortLibrary *portLibrary, const char *inBuffe
return OMRPORT_ERROR_STRING_MEM_ALLOCATE_FAILED;
}

resultLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
resultLength = omrstr_convert(J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
inBuffer, inBufferSize, result, bufferLength);
/* do the conversion */

Expand Down
18 changes: 17 additions & 1 deletion include_core/omrport.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ typedef struct J9ProcessorInfos {

/* omrstr_convert encodings. */
/* character set currently in effect */
#define J9STR_CODE_PLATFORM 1
#define J9STR_CODE_PLATFORM_RAW 1
/* modified UTF-8 */
#define J9STR_CODE_MUTF8 2
/* UTF-16 */
Expand All @@ -793,6 +793,22 @@ typedef struct J9ProcessorInfos {
/* Windows current thread ANSI code page */
#define J9STR_CODE_WINTHREADACP 8

#if defined(J9ZOS390)
/*
* OMR on z/OS translates the output of certain system calls such as getenv to ASCII using functions in atoe.c; see stdlib.h for a list.
* Use J9STR_CODE_PLATFORM_OMR_INTERNAL to when processing the output of these calls. Otherwise, use J9STR_CODE_PLATFORM_RAW.
*/
#define J9STR_CODE_PLATFORM_OMR_INTERNAL J9STR_CODE_LATIN1
#elif defined(WIN32)
/*
* Most system calls on Windows use the "wide" versions which return UTF-16, which OMR then converts to UTF-8.
*/
#define J9STR_CODE_PLATFORM_OMR_INTERNAL J9STR_CODE_UTF8
#else /* defined(WIN32) */
/* on other platforms the internal encoding is the actual operating system encoding */
#define J9STR_CODE_PLATFORM_OMR_INTERNAL J9STR_CODE_PLATFORM_RAW
#endif /* defined(J9ZOS390) */

#define UNICODE_REPLACEMENT_CHARACTER 0xFFFD
#define MAX_STRING_TERMINATOR_LENGTH 4
/* worst case terminating sequence: wchar or UTF-32 */
Expand Down
23 changes: 15 additions & 8 deletions port/common/omrstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ omrstr_printf(struct OMRPortLibrary *portLibrary, char *buf, uintptr_t bufLen, c
* @param[in] fromCode Input string encoding. Only the following encodings are allowed:
* J9STR_CODE_MUTF8 (Modified UTF-8)
* J9STR_CODE_WIDE (UTF-16)
* J9STR_CODE_PLATFORM (encoding used by the operating system)
* J9STR_CODE_LATIN1
* J9STR_CODE_PLATFORM_RAW (encoding used by the operating system)
* J9STR_CODE_PLATFORM_OMR_INTERNAL (encoding used by certain operating system calls)
* J9STR_CODE_WINTHREADACP, J9STR_CODE_WINDEFAULTACP (thread and default ANSI code page, Windows only)
* @param[in] toCode Output string encoding. Only the encodings listed above are allowed.
* @param[in] inBuffer Input text to be converted. May contain embedded null characters.
* @param[in] inBufferSize input string size in bytes, not including the terminating null.
Expand All @@ -227,11 +230,15 @@ omrstr_printf(struct OMRPortLibrary *portLibrary, char *buf, uintptr_t bufLen, c
* - OMRPORT_ERROR_STRING_UNSUPPORTED_ENCODING if the input or output encoding is not supported
* - OMRPORT_ERROR_STRING_MEM_ALLOCATE_FAILED if the port library could not allocate a working buffer
* The following translations are supported:
* platform to [wide, modified UTF-8]
* modified UTF-8 to [platform, wide]
* wide to [modified UTF-8, platform]
* ANSI code page to modified UTF-8 (Windows only)
* platform raw to [wide, modified UTF-8]
* modified UTF-8 to [platform raw, wide]
* [Latin-1, UTF-8] to modified UTF-8
* wide to [modified UTF-8, platform raw]
* [ISO Latin-1 (8859-1), UTF-8, Windows ANSI default and current code pages] to modified UTF-8
*
* @note J9STR_CODE_PLATFORM_OMR_INTERNAL is an alias for other encodings depending on the platform.
* @note J9STR_CODE_PLATFORM is deprecated. Use J9STR_CODE_PLATFORM_OMR_INTERNAL for results of system calls such as getenv (see stdlib.h) and
* @note J9STR_CODE_PLATFORM_RAW where the port library does not do implicit translation.
*/
#ifndef OS_ENCODING_CODE_PAGE
/* placeholder on non-Windows systems */
Expand All @@ -244,7 +251,7 @@ omrstr_convert(struct OMRPortLibrary *portLibrary, int32_t fromCode, int32_t toC
int32_t result = OMRPORT_ERROR_STRING_UNSUPPORTED_ENCODING;

switch (fromCode) {
case J9STR_CODE_PLATFORM: {
case J9STR_CODE_PLATFORM_RAW: {
switch (toCode) {
case J9STR_CODE_MUTF8:
result = convertPlatformToMutf8(portLibrary, OS_ENCODING_CODE_PAGE, inBuffer, inBufferSize, outBuffer, outBufferSize);
Expand Down Expand Up @@ -274,7 +281,7 @@ omrstr_convert(struct OMRPortLibrary *portLibrary, int32_t fromCode, int32_t toC
#endif
case J9STR_CODE_MUTF8: {
switch (toCode) {
case J9STR_CODE_PLATFORM:
case J9STR_CODE_PLATFORM_RAW:
result = convertMutf8ToPlatform(portLibrary, inBuffer, inBufferSize, outBuffer, outBufferSize);
break;
case J9STR_CODE_WIDE: {
Expand Down Expand Up @@ -319,7 +326,7 @@ omrstr_convert(struct OMRPortLibrary *portLibrary, int32_t fromCode, int32_t toC
break;
case J9STR_CODE_WIDE: {
switch (toCode) {
case J9STR_CODE_PLATFORM:
case J9STR_CODE_PLATFORM_RAW:
result = OMRPORT_ERROR_STRING_UNSUPPORTED_ENCODING;
break;
case J9STR_CODE_MUTF8: {
Expand Down
4 changes: 2 additions & 2 deletions port/unix/omrsyslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ get_conv_txt_num_bytes(struct OMRPortLibrary *portLibrary, const char *message)

const int32_t convRes =
portLibrary->str_convert(portLibrary, J9STR_CODE_MUTF8,
J9STR_CODE_PLATFORM, message, strlen(message),
J9STR_CODE_PLATFORM_RAW, message, strlen(message),
NULL, 0U);

if (0 < convRes) {
Expand Down Expand Up @@ -171,7 +171,7 @@ syslog_write(struct OMRPortLibrary *portLibrary, const char *buf, int priority)
*/
const int32_t convRes =
portLibrary->str_convert(portLibrary,
J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM,
J9STR_CODE_MUTF8, J9STR_CODE_PLATFORM_RAW,
buf, strlen(buf), lclMsg, lclMsgLen);

lclConvSuccess = (BOOLEAN)(convRes >= 0);
Expand Down
4 changes: 2 additions & 2 deletions port/zos390/omrgetjobid.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ omrget_jobid(struct OMRPortLibrary *portLibrary, char *jobid, uintptr_t length)

if (NULL != jsab_ptr) {
/* Job ID is JSABJBID field in JSAB control block. Convert from EBCDIC to internal UTF8 */
result = omrstr_convert(portLibrary, J9STR_CODE_PLATFORM, J9STR_CODE_MUTF8,
result = omrstr_convert(portLibrary, J9STR_CODE_PLATFORM_RAW, J9STR_CODE_MUTF8,
jsab_ptr->jsabjbid, sizeof(jsab_ptr->jsabjbid), jobid, length);
if (OMRPORT_ERROR_STRING_BUFFER_TOO_SMALL == result) {
/* return the number of bytes required to hold the converted text */
return omrstr_convert(portLibrary, J9STR_CODE_PLATFORM, J9STR_CODE_MUTF8,
return omrstr_convert(portLibrary, J9STR_CODE_PLATFORM_RAW, J9STR_CODE_MUTF8,
jsab_ptr->jsabjbid, sizeof(jsab_ptr->jsabjbid), NULL, 0);
}
}
Expand Down

0 comments on commit fc48a28

Please sign in to comment.