8041498: Remove npt library
Get rid of npt library and move utf-related code to share/backend Reviewed-by: sla
This commit is contained in:
parent
d4988ce66f
commit
c201595a62
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
#
|
#
|
||||||
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -320,7 +319,6 @@ ifeq ($(OPENJDK_TARGET_OS), aix)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
$(eval $(call SetupJVMTIDemo,hprof, java_crw_demo, \
|
$(eval $(call SetupJVMTIDemo,hprof, java_crw_demo, \
|
||||||
-I$(JDK_TOPDIR)/src/share/npt -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt \
|
|
||||||
$(BUILD_LIBHPROF_AIX_EXTRA_CFLAGS), C, \
|
$(BUILD_LIBHPROF_AIX_EXTRA_CFLAGS), C, \
|
||||||
-ldl, ws2_32.lib winmm.lib, -lsocket -lnsl, -lpthread, $(BUILD_LIBHPROF_AIX_EXTRA_SRC)))
|
-ldl, ws2_32.lib winmm.lib, -lsocket -lnsl, -lpthread, $(BUILD_LIBHPROF_AIX_EXTRA_SRC)))
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -526,30 +526,3 @@ else ifeq ($(OPENJDK_TARGET_OS), aix)
|
|||||||
BUILD_LIBRARIES += $(JDK_OUTPUTDIR)/objs/libjli_static.a
|
BUILD_LIBRARIES += $(JDK_OUTPUTDIR)/objs/libjli_static.a
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
##########################################################################################
|
|
||||||
|
|
||||||
$(eval $(call SetupNativeCompilation,BUILD_LIBNPT, \
|
|
||||||
LIBRARY := npt, \
|
|
||||||
OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
|
|
||||||
SRC := $(JDK_TOPDIR)/src/share/npt $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt, \
|
|
||||||
LANG := C, \
|
|
||||||
OPTIMIZATION := LOW, \
|
|
||||||
CFLAGS := $(CFLAGS_JDKLIB) \
|
|
||||||
-I$(JDK_TOPDIR)/src/share/npt \
|
|
||||||
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt, \
|
|
||||||
MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libnpt/mapfile-vers, \
|
|
||||||
LDFLAGS := $(LDFLAGS_JDKLIB) \
|
|
||||||
$(call SET_SHARED_LIBRARY_ORIGIN), \
|
|
||||||
LDFLAGS_macosx := -liconv, \
|
|
||||||
LDFLAGS_SUFFIX_windows := -export:nptInitialize -export:nptTerminate, \
|
|
||||||
LDFLAGS_SUFFIX_solaris := -lc, \
|
|
||||||
VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
|
|
||||||
RC_FLAGS := $(RC_FLAGS) \
|
|
||||||
-D "JDK_FNAME=npt.dll" \
|
|
||||||
-D "JDK_INTERNAL_NAME=npt" \
|
|
||||||
-D "JDK_FTYPE=0x2L", \
|
|
||||||
OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libnpt, \
|
|
||||||
DEBUG_SYMBOLS := true))
|
|
||||||
|
|
||||||
BUILD_LIBRARIES += $(BUILD_LIBNPT)
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -147,8 +147,6 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJDWP, \
|
|||||||
CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) -DJDWP_LOGGING \
|
CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) -DJDWP_LOGGING \
|
||||||
-I$(JDK_TOPDIR)/src/share/transport/export \
|
-I$(JDK_TOPDIR)/src/share/transport/export \
|
||||||
-I$(JDK_TOPDIR)/src/share/back/export \
|
-I$(JDK_TOPDIR)/src/share/back/export \
|
||||||
-I$(JDK_TOPDIR)/src/share/npt \
|
|
||||||
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt \
|
|
||||||
-I$(JDK_TOPDIR)/src/share/back \
|
-I$(JDK_TOPDIR)/src/share/back \
|
||||||
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/back \
|
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/back \
|
||||||
-I$(JDK_OUTPUTDIR)/gensrc_jdwp_headers, \
|
-I$(JDK_OUTPUTDIR)/gensrc_jdwp_headers, \
|
||||||
@ -158,6 +156,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJDWP, \
|
|||||||
LDFLAGS_SUFFIX_linux := $(LIBDL), \
|
LDFLAGS_SUFFIX_linux := $(LIBDL), \
|
||||||
LDFLAGS_SUFFIX_solaris := $(LIBDL) -lc, \
|
LDFLAGS_SUFFIX_solaris := $(LIBDL) -lc, \
|
||||||
LDFLAGS_SUFFIX_windows := $(LDFLAGS_JDKLIB_SUFFIX), \
|
LDFLAGS_SUFFIX_windows := $(LDFLAGS_JDKLIB_SUFFIX), \
|
||||||
|
LDFLAGS_SUFFIX_macosx := -liconv, \
|
||||||
VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
|
VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
|
||||||
RC_FLAGS := $(RC_FLAGS) \
|
RC_FLAGS := $(RC_FLAGS) \
|
||||||
-D "JDK_FNAME=jdwp.dll" \
|
-D "JDK_FNAME=jdwp.dll" \
|
||||||
@ -340,8 +339,6 @@ BUILD_LIBRARIES += $(BUILD_LIBMANAGEMENT)
|
|||||||
|
|
||||||
BUILD_LIBHPROF_SRC := $(JDK_TOPDIR)/src/share/demo/jvmti/hprof $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/demo/jvmti/hprof
|
BUILD_LIBHPROF_SRC := $(JDK_TOPDIR)/src/share/demo/jvmti/hprof $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/demo/jvmti/hprof
|
||||||
BUILD_LIBHPROF_CFLAGS := -I$(JDK_TOPDIR)/src/share/demo/jvmti/hprof \
|
BUILD_LIBHPROF_CFLAGS := -I$(JDK_TOPDIR)/src/share/demo/jvmti/hprof \
|
||||||
-I$(JDK_TOPDIR)/src/share/npt \
|
|
||||||
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt \
|
|
||||||
-I$(JDK_TOPDIR)/src/share/demo/jvmti/java_crw_demo
|
-I$(JDK_TOPDIR)/src/share/demo/jvmti/java_crw_demo
|
||||||
|
|
||||||
ifeq ($(OPENJDK_TARGET_OS), aix)
|
ifeq ($(OPENJDK_TARGET_OS), aix)
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
#
|
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
|
||||||
# under the terms of the GNU General Public License version 2 only, as
|
|
||||||
# published by the Free Software Foundation. Oracle designates this
|
|
||||||
# particular file as subject to the "Classpath" exception as provided
|
|
||||||
# by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
#
|
|
||||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
# version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
# accompanied this code).
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License version
|
|
||||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
#
|
|
||||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
# or visit www.oracle.com if you need additional information or have any
|
|
||||||
# questions.
|
|
||||||
#
|
|
||||||
|
|
||||||
# Define public interface.
|
|
||||||
|
|
||||||
SUNWprivate_1.1 {
|
|
||||||
global:
|
|
||||||
nptInitialize;
|
|
||||||
nptTerminate;
|
|
||||||
local:
|
|
||||||
*;
|
|
||||||
};
|
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -127,8 +127,6 @@ PROFILE_3_JRE_LIB_FILES := \
|
|||||||
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)jsdt.diz \
|
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)jsdt.diz \
|
||||||
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)management$(SHARED_LIBRARY_SUFFIX) \
|
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)management$(SHARED_LIBRARY_SUFFIX) \
|
||||||
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)management.diz \
|
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)management.diz \
|
||||||
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)npt$(SHARED_LIBRARY_SUFFIX) \
|
|
||||||
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)npt.diz \
|
|
||||||
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)prefs$(SHARED_LIBRARY_SUFFIX) \
|
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)prefs$(SHARED_LIBRARY_SUFFIX) \
|
||||||
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)sctp$(SHARED_LIBRARY_SUFFIX) \
|
$(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)sctp$(SHARED_LIBRARY_SUFFIX) \
|
||||||
jvm.hprof.txt \
|
jvm.hprof.txt \
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -202,8 +202,6 @@ Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
|
|||||||
jint jvmtiCompileTimeMajorVersion;
|
jint jvmtiCompileTimeMajorVersion;
|
||||||
jint jvmtiCompileTimeMinorVersion;
|
jint jvmtiCompileTimeMinorVersion;
|
||||||
jint jvmtiCompileTimeMicroVersion;
|
jint jvmtiCompileTimeMicroVersion;
|
||||||
char *boot_path = NULL;
|
|
||||||
char npt_lib[MAXPATHLEN];
|
|
||||||
|
|
||||||
/* See if it's already loaded */
|
/* See if it's already loaded */
|
||||||
if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) {
|
if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) {
|
||||||
@ -268,24 +266,6 @@ Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
|
|||||||
forceExit(1); /* Kill entire process, no core dump wanted */
|
forceExit(1); /* Kill entire process, no core dump wanted */
|
||||||
}
|
}
|
||||||
|
|
||||||
JVMTI_FUNC_PTR(gdata->jvmti, GetSystemProperty)
|
|
||||||
(gdata->jvmti, (const char *)"sun.boot.library.path",
|
|
||||||
&boot_path);
|
|
||||||
|
|
||||||
dbgsysBuildLibName(npt_lib, sizeof(npt_lib), boot_path, NPT_LIBNAME);
|
|
||||||
/* Npt and Utf function init */
|
|
||||||
NPT_INITIALIZE(npt_lib, &(gdata->npt), NPT_VERSION, NULL);
|
|
||||||
jvmtiDeallocate(boot_path);
|
|
||||||
if (gdata->npt == NULL) {
|
|
||||||
ERROR_MESSAGE(("JDWP: unable to initialize NPT library"));
|
|
||||||
return JNI_ERR;
|
|
||||||
}
|
|
||||||
gdata->npt->utf = (gdata->npt->utfInitialize)(NULL);
|
|
||||||
if (gdata->npt->utf == NULL) {
|
|
||||||
ERROR_MESSAGE(("JDWP: UTF function initialization failed"));
|
|
||||||
return JNI_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse input options */
|
/* Parse input options */
|
||||||
if (!parseOptions(options)) {
|
if (!parseOptions(options)) {
|
||||||
/* No message necessary, should have been printed out already */
|
/* No message necessary, should have been printed out already */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -47,6 +47,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "utf_util.h"
|
||||||
#include "proc_md.h"
|
#include "proc_md.h"
|
||||||
|
|
||||||
/* Maximim length of a message */
|
/* Maximim length of a message */
|
||||||
@ -70,13 +71,8 @@ vprint_message(FILE *fp, const char *prefix, const char *suffix,
|
|||||||
len = (int)strlen((char*)utf8buf);
|
len = (int)strlen((char*)utf8buf);
|
||||||
|
|
||||||
/* Convert to platform encoding (ignore errors, dangerous area) */
|
/* Convert to platform encoding (ignore errors, dangerous area) */
|
||||||
if (gdata->npt != NULL) {
|
(void)utf8ToPlatform(utf8buf, len, pbuf, MAX_MESSAGE_LEN);
|
||||||
(void)(gdata->npt->utf8ToPlatform)(gdata->npt->utf,
|
|
||||||
utf8buf, len, pbuf, MAX_MESSAGE_LEN);
|
|
||||||
} else {
|
|
||||||
/* May be called before NPT is initialized so don't fault */
|
|
||||||
strncpy(pbuf, (char*)utf8buf, len);
|
|
||||||
}
|
|
||||||
(void)fprintf(fp, "%s%s%s", prefix, pbuf, suffix);
|
(void)fprintf(fp, "%s%s%s", prefix, pbuf, suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "utf_util.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "inStream.h"
|
#include "inStream.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
@ -379,15 +380,12 @@ inStream_readString(PacketInputStream *stream)
|
|||||||
string[length] = '\0';
|
string[length] = '\0';
|
||||||
|
|
||||||
/* This is Standard UTF-8, convert to Modified UTF-8 if necessary */
|
/* This is Standard UTF-8, convert to Modified UTF-8 if necessary */
|
||||||
new_length = (gdata->npt->utf8sToUtf8mLength)
|
new_length = utf8sToUtf8mLength((jbyte*)string, length);
|
||||||
(gdata->npt->utf, (jbyte*)string, length);
|
|
||||||
if ( new_length != length ) {
|
if ( new_length != length ) {
|
||||||
char *new_string;
|
char *new_string;
|
||||||
|
|
||||||
new_string = jvmtiAllocate(new_length+1);
|
new_string = jvmtiAllocate(new_length+1);
|
||||||
(gdata->npt->utf8sToUtf8m)
|
utf8sToUtf8m((jbyte*)string, length, (jbyte*)new_string, new_length);
|
||||||
(gdata->npt->utf, (jbyte*)string, length,
|
|
||||||
(jbyte*)new_string, new_length);
|
|
||||||
jvmtiDeallocate(string);
|
jvmtiDeallocate(string);
|
||||||
return new_string;
|
return new_string;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "utf_util.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "outStream.h"
|
#include "outStream.h"
|
||||||
#include "inStream.h"
|
#include "inStream.h"
|
||||||
@ -307,8 +308,7 @@ outStream_writeString(PacketOutputStream *stream, char *string)
|
|||||||
} else {
|
} else {
|
||||||
jint new_length;
|
jint new_length;
|
||||||
|
|
||||||
new_length = (gdata->npt->utf8mToUtf8sLength)
|
new_length = utf8mToUtf8sLength((jbyte*)string, length);
|
||||||
(gdata->npt->utf, (jbyte*)string, length);
|
|
||||||
if ( new_length == length ) {
|
if ( new_length == length ) {
|
||||||
(void)outStream_writeInt(stream, length);
|
(void)outStream_writeInt(stream, length);
|
||||||
error = writeBytes(stream, (jbyte *)string, length);
|
error = writeBytes(stream, (jbyte *)string, length);
|
||||||
@ -316,9 +316,7 @@ outStream_writeString(PacketOutputStream *stream, char *string)
|
|||||||
char *new_string;
|
char *new_string;
|
||||||
|
|
||||||
new_string = jvmtiAllocate(new_length+1);
|
new_string = jvmtiAllocate(new_length+1);
|
||||||
(gdata->npt->utf8mToUtf8s)
|
utf8mToUtf8s((jbyte*)string, length, (jbyte*)new_string, new_length);
|
||||||
(gdata->npt->utf, (jbyte*)string, length,
|
|
||||||
(jbyte*)new_string, new_length);
|
|
||||||
(void)outStream_writeInt(stream, new_length);
|
(void)outStream_writeInt(stream, new_length);
|
||||||
error = writeBytes(stream, (jbyte *)new_string, new_length);
|
error = writeBytes(stream, (jbyte *)new_string, new_length);
|
||||||
jvmtiDeallocate(new_string);
|
jvmtiDeallocate(new_string);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "utf_util.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
#include "debugLoop.h"
|
#include "debugLoop.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
@ -65,8 +66,7 @@ printLastError(jdwpTransportEnv *t, jdwpTransportError err)
|
|||||||
len = (int)strlen(msg);
|
len = (int)strlen(msg);
|
||||||
maxlen = len+len/2+2; /* Should allow for plenty of room */
|
maxlen = len+len/2+2; /* Should allow for plenty of room */
|
||||||
utf8msg = (jbyte*)jvmtiAllocate(maxlen+1);
|
utf8msg = (jbyte*)jvmtiAllocate(maxlen+1);
|
||||||
(void)(gdata->npt->utf8FromPlatform)(gdata->npt->utf,
|
(void)utf8FromPlatform(msg, len, utf8msg, maxlen);
|
||||||
msg, len, utf8msg, maxlen);
|
|
||||||
utf8msg[maxlen] = 0;
|
utf8msg[maxlen] = 0;
|
||||||
}
|
}
|
||||||
if (rv == JDWPTRANSPORT_ERROR_NONE) {
|
if (rv == JDWPTRANSPORT_ERROR_NONE) {
|
||||||
@ -110,8 +110,7 @@ loadTransportLibrary(const char *libdir, const char *name)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = (int)strlen(libdir);
|
len = (int)strlen(libdir);
|
||||||
(void)(gdata->npt->utf8ToPlatform)(gdata->npt->utf,
|
(void)utf8ToPlatform((jbyte*)libdir, len, buf, (int)sizeof(buf));
|
||||||
(jbyte*)libdir, len, buf, (int)sizeof(buf));
|
|
||||||
plibdir = buf;
|
plibdir = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,8 +391,7 @@ launch(char *command, char *name, char *address)
|
|||||||
/* Convert commandLine from UTF-8 to platform encoding */
|
/* Convert commandLine from UTF-8 to platform encoding */
|
||||||
len = (int)strlen(commandLine);
|
len = (int)strlen(commandLine);
|
||||||
buf = jvmtiAllocate(len*3+3);
|
buf = jvmtiAllocate(len*3+3);
|
||||||
(void)(gdata->npt->utf8ToPlatform)(gdata->npt->utf,
|
(void)utf8ToPlatform((jbyte*)commandLine, len, buf, len*3+3);
|
||||||
(jbyte*)commandLine, len, buf, len*3+3);
|
|
||||||
|
|
||||||
/* Exec commandLine */
|
/* Exec commandLine */
|
||||||
rc = dbgsysExec(buf);
|
rc = dbgsysExec(buf);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,117 +23,25 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Misc functions for conversion of Unicode and UTF-8 and platform encoding */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
|
||||||
#include "utf.h"
|
#include "utf_util.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* Error handler
|
/* Error and assert macros */
|
||||||
*/
|
#define UTF_ERROR(m) utfError(__FILE__, __LINE__, m)
|
||||||
void
|
#define UTF_ASSERT(x) ( (x)==0 ? UTF_ERROR("ASSERT ERROR " #x) : (void)0 )
|
||||||
utfError(char *file, int line, char *message)
|
|
||||||
{
|
// Platform independed part
|
||||||
|
|
||||||
|
static void utfError(char *file, int line, char *message) {
|
||||||
(void)fprintf(stderr, "UTF ERROR [\"%s\":%d]: %s\n", file, line, message);
|
(void)fprintf(stderr, "UTF ERROR [\"%s\":%d]: %s\n", file, line, message);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert UTF-8 to UTF-16
|
|
||||||
* Returns length or -1 if output overflows.
|
|
||||||
*/
|
|
||||||
int JNICALL
|
|
||||||
utf8ToUtf16(struct UtfInst *ui, jbyte *utf8, int len, unsigned short *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
int outputLen;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
UTF_ASSERT(utf8);
|
|
||||||
UTF_ASSERT(len>=0);
|
|
||||||
UTF_ASSERT(output);
|
|
||||||
UTF_ASSERT(outputMaxLen>0);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
outputLen = 0;
|
|
||||||
while ( i<len ) {
|
|
||||||
unsigned code, x, y, z;
|
|
||||||
|
|
||||||
if ( outputLen >= outputMaxLen ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
x = (unsigned char)utf8[i++];
|
|
||||||
code = x;
|
|
||||||
if ( (x & 0xE0)==0xE0 ) {
|
|
||||||
y = (unsigned char)utf8[i++];
|
|
||||||
z = (unsigned char)utf8[i++];
|
|
||||||
code = ((x & 0xF)<<12) + ((y & 0x3F)<<6) + (z & 0x3F);
|
|
||||||
} else if ( (x & 0xC0)==0xC0 ) {
|
|
||||||
y = (unsigned char)utf8[i++];
|
|
||||||
code = ((x & 0x1F)<<6) + (y & 0x3F);
|
|
||||||
}
|
|
||||||
output[outputLen++] = code;
|
|
||||||
}
|
|
||||||
return outputLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert UTF-16 to UTF-8 Modified
|
|
||||||
* Returns length or -1 if output overflows.
|
|
||||||
*/
|
|
||||||
int JNICALL
|
|
||||||
utf16ToUtf8m(struct UtfInst *ui, unsigned short *utf16, int len, jbyte *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int outputLen;
|
|
||||||
|
|
||||||
UTF_ASSERT(utf16);
|
|
||||||
UTF_ASSERT(len>=0);
|
|
||||||
UTF_ASSERT(output);
|
|
||||||
UTF_ASSERT(outputMaxLen>0);
|
|
||||||
|
|
||||||
outputLen = 0;
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
unsigned code;
|
|
||||||
|
|
||||||
code = utf16[i];
|
|
||||||
if ( code >= 0x0001 && code <= 0x007F ) {
|
|
||||||
if ( outputLen + 1 >= outputMaxLen ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
output[outputLen++] = code;
|
|
||||||
} else if ( code == 0 || ( code >= 0x0080 && code <= 0x07FF ) ) {
|
|
||||||
if ( outputLen + 2 >= outputMaxLen ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
output[outputLen++] = ((code>>6) & 0x1F) | 0xC0;
|
|
||||||
output[outputLen++] = (code & 0x3F) | 0x80;
|
|
||||||
} else if ( code >= 0x0800 && code <= 0xFFFF ) {
|
|
||||||
if ( outputLen + 3 >= outputMaxLen ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
output[outputLen++] = ((code>>12) & 0x0F) | 0xE0;
|
|
||||||
output[outputLen++] = ((code>>6) & 0x3F) | 0x80;
|
|
||||||
output[outputLen++] = (code & 0x3F) | 0x80;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output[outputLen] = 0;
|
|
||||||
return outputLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
int JNICALL
|
|
||||||
utf16ToUtf8s(struct UtfInst *ui, unsigned short *utf16, int len, jbyte *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
return -1; /* FIXUP */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine length of this Standard UTF-8 in Modified UTF-8.
|
/* Determine length of this Standard UTF-8 in Modified UTF-8.
|
||||||
* Validation is done of the basic UTF encoding rules, returns
|
* Validation is done of the basic UTF encoding rules, returns
|
||||||
* length (no change) when errors are detected in the UTF encoding.
|
* length (no change) when errors are detected in the UTF encoding.
|
||||||
@ -141,56 +49,54 @@ utf16ToUtf8s(struct UtfInst *ui, unsigned short *utf16, int len, jbyte *output,
|
|||||||
* Note: Accepts Modified UTF-8 also, no verification on the
|
* Note: Accepts Modified UTF-8 also, no verification on the
|
||||||
* correctness of Standard UTF-8 is done. e,g, 0xC080 input is ok.
|
* correctness of Standard UTF-8 is done. e,g, 0xC080 input is ok.
|
||||||
*/
|
*/
|
||||||
int JNICALL
|
int JNICALL utf8sToUtf8mLength(jbyte *string, int length) {
|
||||||
utf8sToUtf8mLength(struct UtfInst *ui, jbyte *string, int length)
|
int newLength;
|
||||||
{
|
int i;
|
||||||
int newLength;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
newLength = 0;
|
newLength = 0;
|
||||||
for ( i = 0 ; i < length ; i++ ) {
|
for ( i = 0 ; i < length ; i++ ) {
|
||||||
unsigned byte;
|
unsigned byte;
|
||||||
|
|
||||||
byte = (unsigned char)string[i];
|
byte = (unsigned char)string[i];
|
||||||
if ( (byte & 0x80) == 0 ) { /* 1byte encoding */
|
if ( (byte & 0x80) == 0 ) { /* 1byte encoding */
|
||||||
newLength++;
|
newLength++;
|
||||||
if ( byte == 0 ) {
|
if ( byte == 0 ) {
|
||||||
newLength++; /* We gain one byte in length on NULL bytes */
|
newLength++; /* We gain one byte in length on NULL bytes */
|
||||||
}
|
}
|
||||||
} else if ( (byte & 0xE0) == 0xC0 ) { /* 2byte encoding */
|
} else if ( (byte & 0xE0) == 0xC0 ) { /* 2byte encoding */
|
||||||
/* Check encoding of following bytes */
|
/* Check encoding of following bytes */
|
||||||
if ( (i+1) >= length || (string[i+1] & 0xC0) != 0x80 ) {
|
if ( (i+1) >= length || (string[i+1] & 0xC0) != 0x80 ) {
|
||||||
break; /* Error condition */
|
break; /* Error condition */
|
||||||
}
|
}
|
||||||
i++; /* Skip next byte */
|
i++; /* Skip next byte */
|
||||||
newLength += 2;
|
newLength += 2;
|
||||||
} else if ( (byte & 0xF0) == 0xE0 ) { /* 3byte encoding */
|
} else if ( (byte & 0xF0) == 0xE0 ) { /* 3byte encoding */
|
||||||
/* Check encoding of following bytes */
|
/* Check encoding of following bytes */
|
||||||
if ( (i+2) >= length || (string[i+1] & 0xC0) != 0x80
|
if ( (i+2) >= length || (string[i+1] & 0xC0) != 0x80
|
||||||
|| (string[i+2] & 0xC0) != 0x80 ) {
|
|| (string[i+2] & 0xC0) != 0x80 ) {
|
||||||
break; /* Error condition */
|
break; /* Error condition */
|
||||||
}
|
|
||||||
i += 2; /* Skip next two bytes */
|
|
||||||
newLength += 3;
|
|
||||||
} else if ( (byte & 0xF8) == 0xF0 ) { /* 4byte encoding */
|
|
||||||
/* Check encoding of following bytes */
|
|
||||||
if ( (i+3) >= length || (string[i+1] & 0xC0) != 0x80
|
|
||||||
|| (string[i+2] & 0xC0) != 0x80
|
|
||||||
|| (string[i+3] & 0xC0) != 0x80 ) {
|
|
||||||
break; /* Error condition */
|
|
||||||
}
|
|
||||||
i += 3; /* Skip next 3 bytes */
|
|
||||||
newLength += 6; /* 4byte encoding turns into 2 3byte ones */
|
|
||||||
} else {
|
|
||||||
break; /* Error condition */
|
|
||||||
}
|
}
|
||||||
|
i += 2; /* Skip next two bytes */
|
||||||
|
newLength += 3;
|
||||||
|
} else if ( (byte & 0xF8) == 0xF0 ) { /* 4byte encoding */
|
||||||
|
/* Check encoding of following bytes */
|
||||||
|
if ( (i+3) >= length || (string[i+1] & 0xC0) != 0x80
|
||||||
|
|| (string[i+2] & 0xC0) != 0x80
|
||||||
|
|| (string[i+3] & 0xC0) != 0x80 ) {
|
||||||
|
break; /* Error condition */
|
||||||
|
}
|
||||||
|
i += 3; /* Skip next 3 bytes */
|
||||||
|
newLength += 6; /* 4byte encoding turns into 2 3byte ones */
|
||||||
|
} else {
|
||||||
|
break; /* Error condition */
|
||||||
}
|
}
|
||||||
if ( i != length ) {
|
}
|
||||||
/* Error in finding new length, return old length so no conversion */
|
if ( i != length ) {
|
||||||
/* FIXUP: ERROR_MESSAGE? */
|
/* Error in finding new length, return old length so no conversion */
|
||||||
return length;
|
/* FIXUP: ERROR_MESSAGE? */
|
||||||
}
|
return length;
|
||||||
return newLength;
|
}
|
||||||
|
return newLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert Standard UTF-8 to Modified UTF-8.
|
/* Convert Standard UTF-8 to Modified UTF-8.
|
||||||
@ -199,9 +105,7 @@ utf8sToUtf8mLength(struct UtfInst *ui, jbyte *string, int length)
|
|||||||
* Note: Accepts Modified UTF-8 also, no verification on the
|
* Note: Accepts Modified UTF-8 also, no verification on the
|
||||||
* correctness of Standard UTF-8 is done. e,g, 0xC080 input is ok.
|
* correctness of Standard UTF-8 is done. e,g, 0xC080 input is ok.
|
||||||
*/
|
*/
|
||||||
void JNICALL
|
void JNICALL utf8sToUtf8m(jbyte *string, int length, jbyte *newString, int newLength) {
|
||||||
utf8sToUtf8m(struct UtfInst *ui, jbyte *string, int length, jbyte *newString, int newLength)
|
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@ -263,9 +167,7 @@ utf8sToUtf8m(struct UtfInst *ui, jbyte *string, int length, jbyte *newString, in
|
|||||||
* Note: No validation is made that this is indeed Modified UTF-8 coming in.
|
* Note: No validation is made that this is indeed Modified UTF-8 coming in.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int JNICALL
|
int JNICALL utf8mToUtf8sLength(jbyte *string, int length) {
|
||||||
utf8mToUtf8sLength(struct UtfInst *ui, jbyte *string, int length)
|
|
||||||
{
|
|
||||||
int newLength;
|
int newLength;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -330,9 +232,7 @@ utf8mToUtf8sLength(struct UtfInst *ui, jbyte *string, int length)
|
|||||||
* Note: No validation is made that this is indeed Modified UTF-8 coming in.
|
* Note: No validation is made that this is indeed Modified UTF-8 coming in.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void JNICALL
|
void JNICALL utf8mToUtf8s(jbyte *string, int length, jbyte *newString, int newLength) {
|
||||||
utf8mToUtf8s(struct UtfInst *ui, jbyte *string, int length, jbyte *newString, int newLength)
|
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@ -394,107 +294,247 @@ utf8mToUtf8s(struct UtfInst *ui, jbyte *string, int length, jbyte *newString, in
|
|||||||
newString[j] = 0;
|
newString[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================================= */
|
#ifdef _WIN32
|
||||||
|
// Microsoft Windows specific part
|
||||||
|
|
||||||
#ifdef COMPILE_WITH_UTF_TEST /* Test program */
|
#include <windows.h>
|
||||||
|
|
||||||
/*
|
static UINT getCodepage() {
|
||||||
* Convert any byte array into a printable string.
|
LANGID langID;
|
||||||
* Returns length or -1 if output overflows.
|
LCID localeID;
|
||||||
*/
|
TCHAR strCodePage[7]; // ANSI code page id
|
||||||
static int
|
|
||||||
bytesToPrintable(struct UtfInst *ui, char *bytes, int len, char *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
int outputLen;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
UTF_ASSERT(bytes);
|
static UINT intCodePage = -1;
|
||||||
UTF_ASSERT(len>=0);
|
|
||||||
UTF_ASSERT(output);
|
|
||||||
UTF_ASSERT(outputMaxLen>=0);
|
|
||||||
|
|
||||||
outputLen = 0;
|
if (intCodePage == -1) {
|
||||||
for ( i=0; i<len ; i++ ) {
|
// Firts call, get codepage from the os
|
||||||
unsigned byte;
|
langID = LANGIDFROMLCID(GetUserDefaultLCID());
|
||||||
|
localeID = MAKELCID(langID, SORT_DEFAULT);
|
||||||
byte = bytes[i];
|
if (GetLocaleInfo(localeID, LOCALE_IDEFAULTANSICODEPAGE,
|
||||||
if ( byte <= 0x7f && isprint(byte) && !iscntrl(byte) ) {
|
strCodePage, sizeof(strCodePage)/sizeof(TCHAR)) > 0 ) {
|
||||||
if ( outputLen + 1 >= outputMaxLen ) {
|
intCodePage = atoi(strCodePage);
|
||||||
return -1;
|
}
|
||||||
}
|
else {
|
||||||
output[outputLen++] = (char)byte;
|
intCodePage = GetACP();
|
||||||
} else {
|
|
||||||
if ( outputLen + 4 >= outputMaxLen ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
(void)sprintf(output+outputLen,"\\x%02x",byte);
|
|
||||||
outputLen += 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output[outputLen] = 0;
|
|
||||||
return outputLen;
|
return intCodePage;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
/*
|
||||||
test(void)
|
* Get wide string (assumes len>0)
|
||||||
{
|
*/
|
||||||
static char *strings[] = {
|
static WCHAR* getWideString(UINT codePage, char* str, int len, int *pwlen) {
|
||||||
"characters",
|
int wlen;
|
||||||
"abcdefghijklmnopqrstuvwxyz",
|
WCHAR* wstr;
|
||||||
"0123456789",
|
|
||||||
"!@#$%^&*()_+=-{}[]:;",
|
|
||||||
NULL };
|
|
||||||
int i;
|
|
||||||
struct UtfInst *ui;
|
|
||||||
|
|
||||||
ui = utfInitialize(NULL);
|
/* Convert the string to WIDE string */
|
||||||
|
wlen = MultiByteToWideChar(codePage, 0, str, len, NULL, 0);
|
||||||
|
*pwlen = wlen;
|
||||||
|
if (wlen <= 0) {
|
||||||
|
UTF_ERROR(("Can't get WIDE string length"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
wstr = (WCHAR*)malloc(wlen * sizeof(WCHAR));
|
||||||
|
if (wstr == NULL) {
|
||||||
|
UTF_ERROR(("Can't malloc() any space"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (MultiByteToWideChar(codePage, 0, str, len, wstr, wlen) == 0) {
|
||||||
|
UTF_ERROR(("Can't get WIDE string"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return wstr;
|
||||||
|
}
|
||||||
|
|
||||||
i = 0;
|
/*
|
||||||
while ( strings[i] != NULL ) {
|
* Convert UTF-8 to a platform string
|
||||||
char *str;
|
*/
|
||||||
#define MAX 1024
|
int JNICALL utf8ToPlatform(jbyte *utf8, int len, char* output, int outputMaxLen) {
|
||||||
char buf0[MAX];
|
int wlen;
|
||||||
char buf1[MAX];
|
int plen;
|
||||||
char buf2[MAX];
|
WCHAR* wstr;
|
||||||
unsigned short buf3[MAX];
|
UINT codepage;
|
||||||
int len1;
|
|
||||||
int len2;
|
|
||||||
int len3;
|
|
||||||
|
|
||||||
str = strings[i];
|
UTF_ASSERT(utf8);
|
||||||
|
UTF_ASSERT(output);
|
||||||
|
UTF_ASSERT(outputMaxLen > len);
|
||||||
|
|
||||||
(void)bytesToPrintable(ui, str, (int)strlen(str), buf0, 1024);
|
/* Zero length is ok, but we don't need to do much */
|
||||||
|
if ( len == 0 ) {
|
||||||
len1 = utf8FromPlatform(ui, str, (int)strlen(str), (jbyte*)buf1, 1024);
|
output[0] = 0;
|
||||||
|
return 0;
|
||||||
UTF_ASSERT(len1==(int)strlen(str));
|
|
||||||
|
|
||||||
len3 = utf8ToUtf16(ui, (jbyte*)buf1, len1, (jchar*)buf3, 1024);
|
|
||||||
|
|
||||||
UTF_ASSERT(len3==len1);
|
|
||||||
|
|
||||||
len1 = utf16ToUtf8m(ui, (jchar*)buf3, len3, (jbyte*)buf1, 1024);
|
|
||||||
|
|
||||||
UTF_ASSERT(len1==len3);
|
|
||||||
UTF_ASSERT(strcmp(str, buf1) == 0);
|
|
||||||
|
|
||||||
len2 = utf8ToPlatform(ui, (jbyte*)buf1, len1, buf2, 1024);
|
|
||||||
|
|
||||||
UTF_ASSERT(len2==len1);
|
|
||||||
UTF_ASSERT(strcmp(str, buf2) == 0);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utfTerminate(ui, NULL);
|
/* Get WIDE string version (assumes len>0) */
|
||||||
|
wstr = getWideString(CP_UTF8, (char*)utf8, len, &wlen);
|
||||||
|
if ( wstr == NULL ) {
|
||||||
|
// Can't allocate WIDE string
|
||||||
|
goto just_copy_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert WIDE string to MultiByte string */
|
||||||
|
codepage = getCodepage();
|
||||||
|
plen = WideCharToMultiByte(codepage, 0, wstr, wlen,
|
||||||
|
output, outputMaxLen, NULL, NULL);
|
||||||
|
free(wstr);
|
||||||
|
if (plen <= 0) {
|
||||||
|
// Can't convert WIDE string to multi-byte
|
||||||
|
goto just_copy_bytes;
|
||||||
|
}
|
||||||
|
output[plen] = '\0';
|
||||||
|
return plen;
|
||||||
|
|
||||||
|
just_copy_bytes:
|
||||||
|
(void)memcpy(output, utf8, len);
|
||||||
|
output[len] = 0;
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/*
|
||||||
main(int argc, char **argv)
|
* Convert Platform Encoding to UTF-8.
|
||||||
{
|
*/
|
||||||
test();
|
int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputMaxLen) {
|
||||||
return 0;
|
int wlen;
|
||||||
|
int plen;
|
||||||
|
WCHAR* wstr;
|
||||||
|
UINT codepage;
|
||||||
|
|
||||||
|
UTF_ASSERT(str);
|
||||||
|
UTF_ASSERT(output);
|
||||||
|
UTF_ASSERT(outputMaxLen > len);
|
||||||
|
|
||||||
|
/* Zero length is ok, but we don't need to do much */
|
||||||
|
if ( len == 0 ) {
|
||||||
|
output[0] = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get WIDE string version (assumes len>0) */
|
||||||
|
codepage = getCodepage();
|
||||||
|
wstr = getWideString(codepage, str, len, &wlen);
|
||||||
|
if ( wstr == NULL ) {
|
||||||
|
goto just_copy_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert WIDE string to UTF-8 string */
|
||||||
|
plen = WideCharToMultiByte(CP_UTF8, 0, wstr, wlen,
|
||||||
|
(char*)output, outputMaxLen, NULL, NULL);
|
||||||
|
free(wstr);
|
||||||
|
if (plen <= 0) {
|
||||||
|
UTF_ERROR(("Can't convert WIDE string to multi-byte"));
|
||||||
|
goto just_copy_bytes;
|
||||||
|
}
|
||||||
|
output[plen] = '\0';
|
||||||
|
return plen;
|
||||||
|
|
||||||
|
just_copy_bytes:
|
||||||
|
(void)memcpy(output, str, len);
|
||||||
|
output[len] = 0;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
// *NIX specific part
|
||||||
|
|
||||||
|
#include <iconv.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <langinfo.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
typedef enum {TO_UTF8, FROM_UTF8} conv_direction;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do iconv() conversion.
|
||||||
|
* Returns length or -1 if output overflows.
|
||||||
|
*/
|
||||||
|
static int iconvConvert(conv_direction drn, char *bytes, size_t len, char *output, size_t outputMaxLen) {
|
||||||
|
|
||||||
|
static char *codeset = 0;
|
||||||
|
iconv_t func;
|
||||||
|
size_t bytes_converted;
|
||||||
|
size_t inLeft, outLeft;
|
||||||
|
char *inbuf, *outbuf;
|
||||||
|
|
||||||
|
UTF_ASSERT(bytes);
|
||||||
|
UTF_ASSERT(output);
|
||||||
|
UTF_ASSERT(outputMaxLen > len);
|
||||||
|
|
||||||
|
/* Zero length is ok, but we don't need to do much */
|
||||||
|
if ( len == 0 ) {
|
||||||
|
output[0] = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codeset == NULL && codeset != (char *) -1) {
|
||||||
|
// locale is not initialized, do it now
|
||||||
|
if (setlocale(LC_ALL, "") != NULL) {
|
||||||
|
// nl_langinfo returns ANSI_X3.4-1968 by default
|
||||||
|
codeset = (char*)nl_langinfo(CODESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codeset == NULL) {
|
||||||
|
// Not able to intialize process locale from platform one.
|
||||||
|
codeset = (char *) -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codeset == (char *) -1) {
|
||||||
|
// There was an error during initialization, so just bail out
|
||||||
|
goto just_copy_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
func = (drn == TO_UTF8) ? iconv_open(codeset, "UTF-8") : iconv_open("UTF-8", codeset);
|
||||||
|
if (func == (iconv_t) -1) {
|
||||||
|
// Requested charset combination is not supported, conversion couldn't be done.
|
||||||
|
// make sure we will not try it again
|
||||||
|
codeset = (char *) -1;
|
||||||
|
goto just_copy_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// perform conversion
|
||||||
|
inbuf = bytes;
|
||||||
|
outbuf = output;
|
||||||
|
inLeft = len;
|
||||||
|
outLeft = outputMaxLen;
|
||||||
|
|
||||||
|
bytes_converted = iconv(func, (void*)&inbuf, &inLeft, &outbuf, &outLeft);
|
||||||
|
if (bytes_converted == (size_t) -1 || bytes_converted == 0 || inLeft != 0) {
|
||||||
|
// Input string is invalid, not able to convert entire string
|
||||||
|
// or some other iconv error happens.
|
||||||
|
iconv_close(func);
|
||||||
|
goto just_copy_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
iconv_close(func);
|
||||||
|
// Overwrite bytes_converted with value of actually stored bytes
|
||||||
|
bytes_converted = outputMaxLen-outLeft;
|
||||||
|
output[bytes_converted] = 0;
|
||||||
|
return bytes_converted;
|
||||||
|
|
||||||
|
|
||||||
|
just_copy_bytes:
|
||||||
|
(void)memcpy(output, bytes, len);
|
||||||
|
output[len] = 0;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert UTF-8 to Platform Encoding.
|
||||||
|
* Returns length or -1 if output overflows.
|
||||||
|
*/
|
||||||
|
int JNICALL utf8ToPlatform(jbyte *utf8, int len, char *output, int outputMaxLen) {
|
||||||
|
return iconvConvert(FROM_UTF8, (char*)utf8, len, output, outputMaxLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert Platform Encoding to UTF-8.
|
||||||
|
* Returns length or -1 if output overflows.
|
||||||
|
*/
|
||||||
|
int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputMaxLen) {
|
||||||
|
return iconvConvert(TO_UTF8, str, len, (char*) output, outputMaxLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,11 +23,18 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _UTF_MD_H
|
#ifndef _utf_util_h_
|
||||||
#define _UTF_MD_H
|
#define _utf_util_h_
|
||||||
|
|
||||||
struct UtfInst {
|
#include "jni.h"
|
||||||
unsigned int platformCodePage;
|
|
||||||
};
|
|
||||||
|
int JNICALL utf8sToUtf8mLength(jbyte *string, int length);
|
||||||
|
void JNICALL utf8sToUtf8m(jbyte *string, int length, jbyte *newString, int newLength);
|
||||||
|
int JNICALL utf8mToUtf8sLength(jbyte *string, int length);
|
||||||
|
void JNICALL utf8mToUtf8s(jbyte *string, int length, jbyte *newString, int newLength);
|
||||||
|
|
||||||
|
int JNICALL utf8ToPlatform(jbyte *utf8, int len, char* output, int outputMaxLen);
|
||||||
|
int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputMaxLen);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -53,9 +53,6 @@
|
|||||||
#include "error_messages.h"
|
#include "error_messages.h"
|
||||||
#include "debugInit.h"
|
#include "debugInit.h"
|
||||||
|
|
||||||
/* Get access to Native Platform Toolkit functions */
|
|
||||||
#include "npt.h"
|
|
||||||
|
|
||||||
/* Definition of a CommonRef tracked by the backend for the frontend */
|
/* Definition of a CommonRef tracked by the backend for the frontend */
|
||||||
typedef struct RefNode {
|
typedef struct RefNode {
|
||||||
jlong seqNum; /* ID of reference, also key for hash table */
|
jlong seqNum; /* ID of reference, also key for hash table */
|
||||||
@ -123,9 +120,6 @@ typedef struct {
|
|||||||
|
|
||||||
unsigned log_flags;
|
unsigned log_flags;
|
||||||
|
|
||||||
/* The Native Platform Toolkit access */
|
|
||||||
NptEnv *npt;
|
|
||||||
|
|
||||||
/* Common References static data */
|
/* Common References static data */
|
||||||
jrawMonitorID refLock;
|
jrawMonitorID refLock;
|
||||||
jlong nextSeqNum;
|
jlong nextSeqNum;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -67,10 +67,6 @@
|
|||||||
#include "classfile_constants.h"
|
#include "classfile_constants.h"
|
||||||
#include "jvm_md.h"
|
#include "jvm_md.h"
|
||||||
|
|
||||||
#ifndef SKIP_NPT
|
|
||||||
#include "npt.h" /* To get NptEnv for doing character conversions */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Macros to extract the upper and lower 32 bits of a jlong */
|
/* Macros to extract the upper and lower 32 bits of a jlong */
|
||||||
|
|
||||||
#define jlong_high(a) ((jint)((a)>>32))
|
#define jlong_high(a) ((jint)((a)>>32))
|
||||||
@ -207,9 +203,6 @@ typedef struct {
|
|||||||
|
|
||||||
jvmtiEnv *jvmti; /* JVMTI env for this session */
|
jvmtiEnv *jvmti; /* JVMTI env for this session */
|
||||||
JavaVM *jvm; /* JavaVM* for this session */
|
JavaVM *jvm; /* JavaVM* for this session */
|
||||||
#ifndef SKIP_NPT
|
|
||||||
NptEnv *npt; /* NptEnv* for this session, see npt.h */
|
|
||||||
#endif
|
|
||||||
jint cachedJvmtiVersion; /* JVMTI version number */
|
jint cachedJvmtiVersion; /* JVMTI version number */
|
||||||
|
|
||||||
char *header; /* "JAVA PROFILE 1.0.[12]" */
|
char *header; /* "JAVA PROFILE 1.0.[12]" */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -740,16 +740,11 @@ parse_options(char *command_line_options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( gdata->utf8_output_filename != NULL ) {
|
if ( gdata->utf8_output_filename != NULL ) {
|
||||||
/* UTF-8 to platform encoding (fill in gdata->output_filename) */
|
// Don't attempt to convert output filename.
|
||||||
|
// If fileystem uses the same encoding as the rest of the OS it will work as is.
|
||||||
ulen = (int)strlen(gdata->utf8_output_filename);
|
ulen = (int)strlen(gdata->utf8_output_filename);
|
||||||
gdata->output_filename = (char*)HPROF_MALLOC(ulen*3+3);
|
gdata->output_filename = (char*)HPROF_MALLOC(ulen*3+3);
|
||||||
#ifdef SKIP_NPT
|
|
||||||
(void)strcpy(gdata->output_filename, gdata->utf8_output_filename);
|
(void)strcpy(gdata->output_filename, gdata->utf8_output_filename);
|
||||||
#else
|
|
||||||
(void)(gdata->npt->utf8ToPlatform)
|
|
||||||
(gdata->npt->utf, (jbyte*)gdata->utf8_output_filename, ulen,
|
|
||||||
gdata->output_filename, ulen*3+3);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By default we turn on gdata->alloc_sites and gdata->heap_dump */
|
/* By default we turn on gdata->alloc_sites and gdata->heap_dump */
|
||||||
@ -1949,7 +1944,6 @@ JNIEXPORT jint JNICALL
|
|||||||
Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
|
Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
|
||||||
{
|
{
|
||||||
char *boot_path = NULL;
|
char *boot_path = NULL;
|
||||||
char npt_lib[JVM_MAXPATHLEN];
|
|
||||||
|
|
||||||
/* See if it's already loaded */
|
/* See if it's already loaded */
|
||||||
if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) {
|
if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) {
|
||||||
@ -1970,24 +1964,6 @@ Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
|
|||||||
/* Get the JVMTI environment */
|
/* Get the JVMTI environment */
|
||||||
getJvmti();
|
getJvmti();
|
||||||
|
|
||||||
#ifndef SKIP_NPT
|
|
||||||
getSystemProperty("sun.boot.library.path", &boot_path);
|
|
||||||
/* Load in NPT library for character conversions */
|
|
||||||
md_build_library_name(npt_lib, sizeof(npt_lib), boot_path, NPT_LIBNAME);
|
|
||||||
if ( strlen(npt_lib) == 0 ) {
|
|
||||||
HPROF_ERROR(JNI_TRUE, "Could not find npt library");
|
|
||||||
}
|
|
||||||
jvmtiDeallocate(boot_path);
|
|
||||||
NPT_INITIALIZE(npt_lib, &(gdata->npt), NPT_VERSION, NULL);
|
|
||||||
if ( gdata->npt == NULL ) {
|
|
||||||
HPROF_ERROR(JNI_TRUE, "Cannot load npt library");
|
|
||||||
}
|
|
||||||
gdata->npt->utf = (gdata->npt->utfInitialize)(NULL);
|
|
||||||
if ( gdata->npt->utf == NULL ) {
|
|
||||||
HPROF_ERROR(JNI_TRUE, "Cannot initialize npt utf functions");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Lock needed to protect debug_malloc() code, which is not MT safe */
|
/* Lock needed to protect debug_malloc() code, which is not MT safe */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
gdata->debug_malloc_lock = createRawMonitor("HPROF debug_malloc lock");
|
gdata->debug_malloc_lock = createRawMonitor("HPROF debug_malloc lock");
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
README: For NPT Library.
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
To use this Native Platform Toolkit library, you need to add
|
|
||||||
-Isrc/share/npt and -I/src/${platform}/npt (platform is solaris or windows)
|
|
||||||
to your compilation lines.
|
|
||||||
|
|
||||||
To initialize/use the library:
|
|
||||||
|
|
||||||
#include "npt.h"
|
|
||||||
|
|
||||||
NptEnv *npt;
|
|
||||||
|
|
||||||
NPT_INITIALIZE(&npt, NPT_VERSION, NULL);
|
|
||||||
if (npt == NULL) {
|
|
||||||
FATAL_ERROR_MESSAGE(("Unable to gain access to Npt library"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To use the npt utf functions, they require initialization */
|
|
||||||
npt->utf = (npt->utfInitialize)(NULL);
|
|
||||||
if (npt->utf == NULL) {
|
|
||||||
FATAL_ERROR_MESSAGE(("Unable to gain access to Npt utf functions"));
|
|
||||||
}
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
/* After all uses is done, it can be terminated, however, if the
|
|
||||||
* process will be exiting anyway it isn't necessary, and if
|
|
||||||
* you have other threads running that might use these handles
|
|
||||||
* you will need to wait here until all those threads have terminated.
|
|
||||||
* So in general, termination can be a pain and slow your process
|
|
||||||
* termination down.
|
|
||||||
*/
|
|
||||||
(npt->utfTerminate)(npt->utf,NULL);
|
|
||||||
NPT_TERMINATE(&npt, NULL);
|
|
||||||
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "jni.h"
|
|
||||||
|
|
||||||
#include "npt.h"
|
|
||||||
|
|
||||||
#include "utf.h"
|
|
||||||
|
|
||||||
static int
|
|
||||||
version_check(char *version)
|
|
||||||
{
|
|
||||||
if ( version==NULL || strcmp(version, NPT_VERSION)!=0 ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
nptInitialize(NptEnv **pnpt, char *nptVersion, char *options)
|
|
||||||
{
|
|
||||||
NptEnv *npt;
|
|
||||||
|
|
||||||
(*pnpt) = NULL;
|
|
||||||
|
|
||||||
if ( version_check(nptVersion) ) {
|
|
||||||
NPT_ERROR("NPT version doesn't match");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
npt = (NptEnv*)calloc(sizeof(NptEnv), 1);
|
|
||||||
if ( npt == NULL ) {
|
|
||||||
NPT_ERROR("Cannot allocate calloc space for NptEnv*");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( options != NULL ) {
|
|
||||||
npt->options = strdup(options);
|
|
||||||
}
|
|
||||||
npt->utfInitialize = &utfInitialize;
|
|
||||||
npt->utfTerminate = &utfTerminate;
|
|
||||||
npt->utf8ToPlatform = &utf8ToPlatform;
|
|
||||||
npt->utf8FromPlatform = &utf8FromPlatform;
|
|
||||||
npt->utf8ToUtf16 = &utf8ToUtf16;
|
|
||||||
npt->utf16ToUtf8m = &utf16ToUtf8m;
|
|
||||||
npt->utf16ToUtf8s = &utf16ToUtf8s;
|
|
||||||
npt->utf8sToUtf8mLength = &utf8sToUtf8mLength;
|
|
||||||
npt->utf8sToUtf8m = &utf8sToUtf8m;
|
|
||||||
npt->utf8mToUtf8sLength = &utf8mToUtf8sLength;
|
|
||||||
npt->utf8mToUtf8s = &utf8mToUtf8s;
|
|
||||||
|
|
||||||
(*pnpt) = npt;
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
nptTerminate(NptEnv* npt, char *options)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* FIXUP: options? Check memory or something? */
|
|
||||||
if ( npt->options != NULL ) {
|
|
||||||
(void)free(npt->options);
|
|
||||||
}
|
|
||||||
(void)free(npt);
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Native Platform Toolkit */
|
|
||||||
|
|
||||||
#ifndef _NPT_H
|
|
||||||
#define _NPT_H
|
|
||||||
|
|
||||||
#define NPT_VERSION "0.0.0"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "jni.h"
|
|
||||||
|
|
||||||
#include "npt_md.h"
|
|
||||||
#include "utf.h"
|
|
||||||
|
|
||||||
#define NPT_ERROR(s) { (void)fprintf(stderr, "NPT ERROR: %s\n", s); exit(1); }
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
|
|
||||||
/* Used to save handle to our own dynamicly loaded library */
|
|
||||||
void *libhandle;
|
|
||||||
|
|
||||||
/* Copy of the options sent in at initialization */
|
|
||||||
char *options;
|
|
||||||
|
|
||||||
/* Can be used to save the UtfInst handle */
|
|
||||||
struct UtfInst *utf;
|
|
||||||
|
|
||||||
/* UTF interfaces, see utf.c */
|
|
||||||
struct UtfInst* (JNICALL *utfInitialize)
|
|
||||||
(char *options);
|
|
||||||
void (JNICALL *utfTerminate)
|
|
||||||
(struct UtfInst *utf, char *options);
|
|
||||||
int (JNICALL *utf8ToPlatform)
|
|
||||||
(struct UtfInst *utf, jbyte *utf8, int len,
|
|
||||||
char *output, int outputMaxLen);
|
|
||||||
int (JNICALL *utf8FromPlatform)
|
|
||||||
(struct UtfInst *utf, char *str, int len,
|
|
||||||
jbyte *output, int outputMaxLen);
|
|
||||||
int (JNICALL *utf8ToUtf16)
|
|
||||||
(struct UtfInst *utf, jbyte *utf8, int len,
|
|
||||||
jchar *output, int outputMaxLen);
|
|
||||||
int (JNICALL *utf16ToUtf8m)
|
|
||||||
(struct UtfInst *utf, jchar *utf16, int len,
|
|
||||||
jbyte *output, int outputMaxLen);
|
|
||||||
int (JNICALL *utf16ToUtf8s)
|
|
||||||
(struct UtfInst *utf, jchar *utf16, int len,
|
|
||||||
jbyte *output, int outputMaxLen);
|
|
||||||
int (JNICALL *utf8sToUtf8mLength)
|
|
||||||
(struct UtfInst *utf, jbyte *string, int length);
|
|
||||||
void (JNICALL *utf8sToUtf8m)
|
|
||||||
(struct UtfInst *utf, jbyte *string, int length,
|
|
||||||
jbyte *newString, int newLength);
|
|
||||||
int (JNICALL *utf8mToUtf8sLength)
|
|
||||||
(struct UtfInst *utf, jbyte *string, int length);
|
|
||||||
void (JNICALL *utf8mToUtf8s)
|
|
||||||
(struct UtfInst *utf, jbyte *string, int length,
|
|
||||||
jbyte *newString, int newLength);
|
|
||||||
|
|
||||||
} NptEnv;
|
|
||||||
|
|
||||||
/* Typedefs for the only 2 'extern' functions in npt library:
|
|
||||||
* nptInitialize and nptTerminate
|
|
||||||
* See NPT_INITIALIZE() and NPT_TERMINATE() in npt_md.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL nptInitialize
|
|
||||||
(NptEnv **pnpt, char *nptVersion, char *options);
|
|
||||||
typedef void (JNICALL *NptInitialize)
|
|
||||||
(NptEnv **pnpt, char *nptVersion, char *options);
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL nptTerminate
|
|
||||||
(NptEnv* npt, char *options);
|
|
||||||
typedef void (JNICALL *NptTerminate)
|
|
||||||
(NptEnv* npt, char *options);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Routines for various UTF conversions */
|
|
||||||
|
|
||||||
#ifndef _UTF_H
|
|
||||||
#define _UTF_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "jni.h"
|
|
||||||
#include "utf_md.h"
|
|
||||||
|
|
||||||
/* Use THIS_FILE when it is available. */
|
|
||||||
#ifndef THIS_FILE
|
|
||||||
#define THIS_FILE __FILE__
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Error and assert macros */
|
|
||||||
#define UTF_ERROR(m) utfError(THIS_FILE, __LINE__, m)
|
|
||||||
#define UTF_ASSERT(x) ( (x)==0 ? UTF_ERROR("ASSERT ERROR " #x) : (void)0 )
|
|
||||||
|
|
||||||
void utfError(char *file, int line, char *message);
|
|
||||||
|
|
||||||
struct UtfInst* JNICALL utfInitialize
|
|
||||||
(char *options);
|
|
||||||
void JNICALL utfTerminate
|
|
||||||
(struct UtfInst *ui, char *options);
|
|
||||||
int JNICALL utf8ToPlatform
|
|
||||||
(struct UtfInst *ui, jbyte *utf8,
|
|
||||||
int len, char *output, int outputMaxLen);
|
|
||||||
int JNICALL utf8FromPlatform
|
|
||||||
(struct UtfInst *ui, char *str, int len,
|
|
||||||
jbyte *output, int outputMaxLen);
|
|
||||||
int JNICALL utf8ToUtf16
|
|
||||||
(struct UtfInst *ui, jbyte *utf8, int len,
|
|
||||||
jchar *output, int outputMaxLen);
|
|
||||||
int JNICALL utf16ToUtf8m
|
|
||||||
(struct UtfInst *ui, jchar *utf16, int len,
|
|
||||||
jbyte *output, int outputMaxLen);
|
|
||||||
int JNICALL utf16ToUtf8s
|
|
||||||
(struct UtfInst *ui, jchar *utf16, int len,
|
|
||||||
jbyte *output, int outputMaxLen);
|
|
||||||
int JNICALL utf8sToUtf8mLength
|
|
||||||
(struct UtfInst *ui, jbyte *string, int length);
|
|
||||||
void JNICALL utf8sToUtf8m
|
|
||||||
(struct UtfInst *ui, jbyte *string, int length,
|
|
||||||
jbyte *new_string, int new_length);
|
|
||||||
int JNICALL utf8mToUtf8sLength
|
|
||||||
(struct UtfInst *ui, jbyte *string, int length);
|
|
||||||
void JNICALL utf8mToUtf8s
|
|
||||||
(struct UtfInst *ui, jbyte *string, int length,
|
|
||||||
jbyte *new_string, int new_length);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Native Platform Toolkit */
|
|
||||||
|
|
||||||
#ifndef _NPT_MD_H
|
|
||||||
#define _NPT_MD_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <jvm_md.h>
|
|
||||||
|
|
||||||
#define NPT_LIBNAME "npt"
|
|
||||||
|
|
||||||
#define NPT_INITIALIZE(path,pnpt,version,options) \
|
|
||||||
{ \
|
|
||||||
void *_handle; \
|
|
||||||
void *_sym; \
|
|
||||||
\
|
|
||||||
if ( (pnpt) == NULL ) NPT_ERROR("NptEnv* is NULL"); \
|
|
||||||
*(pnpt) = NULL; \
|
|
||||||
_handle = dlopen(path, RTLD_LAZY); \
|
|
||||||
if ( _handle == NULL ) NPT_ERROR("Cannot open library"); \
|
|
||||||
_sym = dlsym(_handle, "nptInitialize"); \
|
|
||||||
if ( _sym == NULL ) NPT_ERROR("Cannot find nptInitialize"); \
|
|
||||||
((NptInitialize)_sym)((pnpt), version, (options)); \
|
|
||||||
if ( (*(pnpt)) == NULL ) NPT_ERROR("Cannot initialize NptEnv"); \
|
|
||||||
(*(pnpt))->libhandle = _handle; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NPT_TERMINATE(npt,options) \
|
|
||||||
{ \
|
|
||||||
void *_handle; \
|
|
||||||
void *_sym; \
|
|
||||||
\
|
|
||||||
if ( (npt) == NULL ) NPT_ERROR("NptEnv* is NULL"); \
|
|
||||||
_handle = (npt)->libhandle; \
|
|
||||||
_sym = dlsym(_handle, "nptTerminate"); \
|
|
||||||
if ( _sym == NULL ) NPT_ERROR("Cannot find nptTerminate"); \
|
|
||||||
((NptTerminate)_sym)((npt), (options)); \
|
|
||||||
if ( _handle != NULL ) (void)dlclose(_handle); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,179 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <locale.h>
|
|
||||||
#include <langinfo.h>
|
|
||||||
#include <iconv.h>
|
|
||||||
|
|
||||||
#include "utf.h"
|
|
||||||
|
|
||||||
/* Global variables */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialize all utf processing.
|
|
||||||
*/
|
|
||||||
struct UtfInst *JNICALL
|
|
||||||
utfInitialize(char *options)
|
|
||||||
{
|
|
||||||
struct UtfInst *ui;
|
|
||||||
char *codeset;
|
|
||||||
|
|
||||||
ui = (struct UtfInst*)calloc(sizeof(struct UtfInst), 1);
|
|
||||||
ui->iconvToPlatform = (void *)-1;
|
|
||||||
ui->iconvFromPlatform = (void *)-1;
|
|
||||||
|
|
||||||
/* Set the locale from the environment */
|
|
||||||
(void)setlocale(LC_ALL, "");
|
|
||||||
|
|
||||||
/* Get the codeset name */
|
|
||||||
codeset = (char*)nl_langinfo(CODESET);
|
|
||||||
if ( codeset == NULL || codeset[0] == 0 ) {
|
|
||||||
return ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we don't need this, skip it */
|
|
||||||
if (strcmp(codeset, "UTF-8") == 0 || strcmp(codeset, "utf8") == 0 ) {
|
|
||||||
return ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open conversion descriptors */
|
|
||||||
ui->iconvToPlatform = iconv_open(codeset, "UTF-8");
|
|
||||||
if ( ui->iconvToPlatform == (void *)-1 ) {
|
|
||||||
UTF_ERROR("Failed to complete iconv_open() setup");
|
|
||||||
}
|
|
||||||
ui->iconvFromPlatform = iconv_open("UTF-8", codeset);
|
|
||||||
if ( ui->iconvFromPlatform == (void *)-1 ) {
|
|
||||||
UTF_ERROR("Failed to complete iconv_open() setup");
|
|
||||||
}
|
|
||||||
return ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Terminate all utf processing
|
|
||||||
*/
|
|
||||||
void JNICALL
|
|
||||||
utfTerminate(struct UtfInst *ui, char *options)
|
|
||||||
{
|
|
||||||
if ( ui->iconvFromPlatform != (void *)-1 ) {
|
|
||||||
(void)iconv_close(ui->iconvFromPlatform);
|
|
||||||
}
|
|
||||||
if ( ui->iconvToPlatform != (void *)-1 ) {
|
|
||||||
(void)iconv_close(ui->iconvToPlatform);
|
|
||||||
}
|
|
||||||
ui->iconvToPlatform = (void *)-1;
|
|
||||||
ui->iconvFromPlatform = (void *)-1;
|
|
||||||
(void)free(ui);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Do iconv() conversion.
|
|
||||||
* Returns length or -1 if output overflows.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
iconvConvert(iconv_t ic, char *bytes, int len, char *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
int outputLen = 0;
|
|
||||||
|
|
||||||
UTF_ASSERT(bytes);
|
|
||||||
UTF_ASSERT(len>=0);
|
|
||||||
UTF_ASSERT(output);
|
|
||||||
UTF_ASSERT(outputMaxLen>len);
|
|
||||||
|
|
||||||
output[0] = 0;
|
|
||||||
outputLen = 0;
|
|
||||||
|
|
||||||
if ( ic != (iconv_t)(void *)-1 ) {
|
|
||||||
int returnValue;
|
|
||||||
size_t inLeft;
|
|
||||||
size_t outLeft;
|
|
||||||
char *inbuf;
|
|
||||||
char *outbuf;
|
|
||||||
|
|
||||||
inbuf = bytes;
|
|
||||||
outbuf = output;
|
|
||||||
inLeft = len;
|
|
||||||
outLeft = outputMaxLen;
|
|
||||||
returnValue = iconv(ic, (void*)&inbuf, &inLeft, &outbuf, &outLeft);
|
|
||||||
if ( returnValue >= 0 && inLeft==0 ) {
|
|
||||||
outputLen = outputMaxLen-outLeft;
|
|
||||||
output[outputLen] = 0;
|
|
||||||
return outputLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Failed to do the conversion */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Just copy bytes */
|
|
||||||
outputLen = len;
|
|
||||||
(void)memcpy(output, bytes, len);
|
|
||||||
output[len] = 0;
|
|
||||||
return outputLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert UTF-8 to Platform Encoding.
|
|
||||||
* Returns length or -1 if output overflows.
|
|
||||||
*/
|
|
||||||
int JNICALL
|
|
||||||
utf8ToPlatform(struct UtfInst*ui, jbyte *utf8, int len, char *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
/* Negative length is an error */
|
|
||||||
if ( len < 0 ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Zero length is ok, but we don't need to do much */
|
|
||||||
if ( len == 0 ) {
|
|
||||||
output[0] = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return iconvConvert(ui->iconvToPlatform, (char*)utf8, len, output, outputMaxLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert Platform Encoding to UTF-8.
|
|
||||||
* Returns length or -1 if output overflows.
|
|
||||||
*/
|
|
||||||
int JNICALL
|
|
||||||
utf8FromPlatform(struct UtfInst*ui, char *str, int len, jbyte *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
/* Negative length is an error */
|
|
||||||
if ( len < 0 ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Zero length is ok, but we don't need to do much */
|
|
||||||
if ( len == 0 ) {
|
|
||||||
output[0] = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return iconvConvert(ui->iconvFromPlatform, str, len, (char*)output, outputMaxLen);
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _UTF_MD_H
|
|
||||||
#define _UTF_MD_H
|
|
||||||
|
|
||||||
struct UtfInst {
|
|
||||||
void *iconvToPlatform;
|
|
||||||
void *iconvFromPlatform;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Native Platform Toolkit */
|
|
||||||
|
|
||||||
#ifndef _NPT_MD_H
|
|
||||||
#define _NPT_MD_H
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#define NPT_LIBNAME "npt"
|
|
||||||
|
|
||||||
#define NPT_INITIALIZE(path,pnpt,version,options) \
|
|
||||||
{ \
|
|
||||||
void *_handle; \
|
|
||||||
void *_sym; \
|
|
||||||
\
|
|
||||||
if ( (pnpt) == NULL ) NPT_ERROR("NptEnv* is NULL"); \
|
|
||||||
*(pnpt) = NULL; \
|
|
||||||
_handle = LoadLibrary(path); \
|
|
||||||
if ( _handle == NULL ) NPT_ERROR("Cannot open library"); \
|
|
||||||
_sym = GetProcAddress(_handle, "nptInitialize"); \
|
|
||||||
if ( _sym == NULL ) NPT_ERROR("Cannot find nptInitialize"); \
|
|
||||||
((NptInitialize)_sym)((pnpt), version, (options)); \
|
|
||||||
if ( *(pnpt) == NULL ) NPT_ERROR("Cannot initialize NptEnv"); \
|
|
||||||
(*(pnpt))->libhandle = _handle; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NPT_TERMINATE(npt,options) \
|
|
||||||
{ \
|
|
||||||
void *_handle; \
|
|
||||||
void *_sym; \
|
|
||||||
\
|
|
||||||
if ( (npt) == NULL ) NPT_ERROR("NptEnv* is NULL"); \
|
|
||||||
_handle = (npt)->libhandle; \
|
|
||||||
if ( _handle == NULL ) NPT_ERROR("npt->libhandle is NULL"); \
|
|
||||||
_sym = GetProcAddress(_handle, "nptTerminate"); \
|
|
||||||
if ( _sym == NULL ) NPT_ERROR("Cannot find nptTerminate"); \
|
|
||||||
((NptTerminate)_sym)((npt), (options)); \
|
|
||||||
(void)FreeLibrary(_handle); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,172 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation. Oracle designates this
|
|
||||||
* particular file as subject to the "Classpath" exception as provided
|
|
||||||
* by Oracle in the LICENSE file that accompanied this code.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "utf.h"
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialize all utf processing.
|
|
||||||
*/
|
|
||||||
struct UtfInst * JNICALL
|
|
||||||
utfInitialize(char *options)
|
|
||||||
{
|
|
||||||
struct UtfInst *ui;
|
|
||||||
LANGID langID;
|
|
||||||
LCID localeID;
|
|
||||||
TCHAR strCodePage[7]; // ANSI code page id
|
|
||||||
|
|
||||||
ui = (struct UtfInst*)calloc(sizeof(struct UtfInst), 1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the code page for this locale
|
|
||||||
*/
|
|
||||||
langID = LANGIDFROMLCID(GetUserDefaultLCID());
|
|
||||||
localeID = MAKELCID(langID, SORT_DEFAULT);
|
|
||||||
if (GetLocaleInfo(localeID, LOCALE_IDEFAULTANSICODEPAGE,
|
|
||||||
strCodePage, sizeof(strCodePage)/sizeof(TCHAR)) > 0 ) {
|
|
||||||
ui->platformCodePage = atoi(strCodePage);
|
|
||||||
} else {
|
|
||||||
ui->platformCodePage = GetACP();
|
|
||||||
}
|
|
||||||
return ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Terminate all utf processing
|
|
||||||
*/
|
|
||||||
void JNICALL
|
|
||||||
utfTerminate(struct UtfInst *ui, char *options)
|
|
||||||
{
|
|
||||||
(void)free(ui);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get wide string (assumes len>0)
|
|
||||||
*/
|
|
||||||
static WCHAR*
|
|
||||||
getWideString(UINT codePage, char* str, int len, int *pwlen)
|
|
||||||
{
|
|
||||||
int wlen;
|
|
||||||
WCHAR* wstr;
|
|
||||||
|
|
||||||
/* Convert the string to WIDE string */
|
|
||||||
wlen = MultiByteToWideChar(codePage, 0, str, len, NULL, 0);
|
|
||||||
*pwlen = wlen;
|
|
||||||
if (wlen <= 0) {
|
|
||||||
UTF_ERROR(("Can't get WIDE string length"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
wstr = (WCHAR*)malloc(wlen * sizeof(WCHAR));
|
|
||||||
if (wstr == NULL) {
|
|
||||||
UTF_ERROR(("Can't malloc() any space"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (MultiByteToWideChar(codePage, 0, str, len, wstr, wlen) == 0) {
|
|
||||||
UTF_ERROR(("Can't get WIDE string"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return wstr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert UTF-8 to a platform string
|
|
||||||
*/
|
|
||||||
int JNICALL
|
|
||||||
utf8ToPlatform(struct UtfInst *ui, jbyte *utf8, int len, char* output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
int wlen;
|
|
||||||
int plen;
|
|
||||||
WCHAR* wstr;
|
|
||||||
|
|
||||||
/* Negative length is an error */
|
|
||||||
if ( len < 0 ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Zero length is ok, but we don't need to do much */
|
|
||||||
if ( len == 0 ) {
|
|
||||||
output[0] = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get WIDE string version (assumes len>0) */
|
|
||||||
wstr = getWideString(CP_UTF8, (char*)utf8, len, &wlen);
|
|
||||||
if ( wstr == NULL ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert WIDE string to MultiByte string */
|
|
||||||
plen = WideCharToMultiByte(ui->platformCodePage, 0, wstr, wlen,
|
|
||||||
output, outputMaxLen, NULL, NULL);
|
|
||||||
free(wstr);
|
|
||||||
if (plen <= 0) {
|
|
||||||
UTF_ERROR(("Can't convert WIDE string to multi-byte"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
output[plen] = '\0';
|
|
||||||
return plen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert Platform Encoding to UTF-8.
|
|
||||||
*/
|
|
||||||
int JNICALL
|
|
||||||
utf8FromPlatform(struct UtfInst *ui, char *str, int len, jbyte *output, int outputMaxLen)
|
|
||||||
{
|
|
||||||
int wlen;
|
|
||||||
int plen;
|
|
||||||
WCHAR* wstr;
|
|
||||||
|
|
||||||
/* Negative length is an error */
|
|
||||||
if ( len < 0 ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Zero length is ok, but we don't need to do much */
|
|
||||||
if ( len == 0 ) {
|
|
||||||
output[0] = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get WIDE string version (assumes len>0) */
|
|
||||||
wstr = getWideString(ui->platformCodePage, str, len, &wlen);
|
|
||||||
if ( wstr == NULL ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert WIDE string to UTF-8 string */
|
|
||||||
plen = WideCharToMultiByte(CP_UTF8, 0, wstr, wlen,
|
|
||||||
(char*)output, outputMaxLen, NULL, NULL);
|
|
||||||
free(wstr);
|
|
||||||
if (plen <= 0) {
|
|
||||||
UTF_ERROR(("Can't convert WIDE string to multi-byte"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
output[plen] = '\0';
|
|
||||||
return plen;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user