зеркало из https://github.com/mozilla/gecko-dev.git
Properly handle [inout] string params when calling a Java method from XPCOM. Allocate enough space for PRUnichar string when returning to XPCOM.
This commit is contained in:
Родитель
2554d099dd
Коммит
09a89dd42d
|
@ -926,8 +926,6 @@ CallXPCOMMethod(JNIEnv *env, jclass that, jobject aJavaObject,
|
||||||
LOG("\t Param %d: ", i);
|
LOG("\t Param %d: ", i);
|
||||||
const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(i);
|
const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(i);
|
||||||
|
|
||||||
NS_ASSERTION(!paramInfo.IsDipper(), "Dipper!");
|
|
||||||
|
|
||||||
if (!paramInfo.IsRetval() && !paramInfo.IsDipper()) {
|
if (!paramInfo.IsRetval() && !paramInfo.IsDipper()) {
|
||||||
rv = SetupParams(env, env->GetObjectArrayElement(aParams, i), paramInfo,
|
rv = SetupParams(env, env->GetObjectArrayElement(aParams, i), paramInfo,
|
||||||
methodInfo, iinfo, aMethodIndex, params, params[i]);
|
methodInfo, iinfo, aMethodIndex, params, params[i]);
|
||||||
|
|
|
@ -297,6 +297,7 @@ nsJavaXPTCStub::CallMethod(PRUint16 aMethodIndex,
|
||||||
for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
|
for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
|
||||||
{
|
{
|
||||||
const nsXPTParamInfo ¶mInfo = aMethodInfo->GetParam(i);
|
const nsXPTParamInfo ¶mInfo = aMethodInfo->GetParam(i);
|
||||||
|
NS_ASSERTION(!paramInfo.IsDipper(), "Dipper!");
|
||||||
if (!paramInfo.IsRetval()) {
|
if (!paramInfo.IsRetval()) {
|
||||||
rv = SetupJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
|
rv = SetupJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
|
||||||
aParams[i], java_params[i], methodSig);
|
aParams[i], java_params[i], methodSig);
|
||||||
|
@ -582,16 +583,25 @@ nsJavaXPTCStub::SetupJavaParams(const nsXPTParamInfo &aParamInfo,
|
||||||
case nsXPTType::T_CHAR_STR:
|
case nsXPTType::T_CHAR_STR:
|
||||||
case nsXPTType::T_WCHAR_STR:
|
case nsXPTType::T_WCHAR_STR:
|
||||||
{
|
{
|
||||||
jobject str;
|
void* ptr = nsnull;
|
||||||
if (aVariant.val.p) {
|
if (!aParamInfo.IsOut()) {
|
||||||
|
ptr = aVariant.val.p;
|
||||||
|
} else if (aVariant.val.p) {
|
||||||
|
void** variant = NS_REINTERPRET_CAST(void**, aVariant.val.p);
|
||||||
|
ptr = *variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject str = nsnull;
|
||||||
|
if (ptr) {
|
||||||
if (tag == nsXPTType::T_CHAR_STR) {
|
if (tag == nsXPTType::T_CHAR_STR) {
|
||||||
str = mJavaEnv->NewStringUTF((const char*) aVariant.val.p);
|
str = mJavaEnv->NewStringUTF((const char*) ptr);
|
||||||
} else {
|
} else {
|
||||||
const PRUnichar* buf = (const PRUnichar*) aVariant.val.p;
|
const PRUnichar* buf = (const PRUnichar*) ptr;
|
||||||
str = mJavaEnv->NewString(buf, nsCRT::strlen(buf));
|
str = mJavaEnv->NewString(buf, nsCRT::strlen(buf));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
str = nsnull;
|
if (str == nsnull) {
|
||||||
|
str = mJavaEnv->NewStringUTF((const char*)"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aParamInfo.IsOut()) {
|
if (!aParamInfo.IsOut()) {
|
||||||
|
@ -1012,7 +1022,6 @@ nsJavaXPTCStub::FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
|
||||||
|
|
||||||
case nsXPTType::T_CHAR_STR:
|
case nsXPTType::T_CHAR_STR:
|
||||||
{
|
{
|
||||||
// XXX not sure how this should be handled
|
|
||||||
if (aParamInfo.IsOut()) {
|
if (aParamInfo.IsOut()) {
|
||||||
jstring str = nsnull;
|
jstring str = nsnull;
|
||||||
if (aParamInfo.IsRetval()) {
|
if (aParamInfo.IsRetval()) {
|
||||||
|
@ -1025,7 +1034,6 @@ nsJavaXPTCStub::FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
|
||||||
if (str) {
|
if (str) {
|
||||||
jboolean isCopy;
|
jboolean isCopy;
|
||||||
const char* char_ptr = mJavaEnv->GetStringUTFChars(str, &isCopy);
|
const char* char_ptr = mJavaEnv->GetStringUTFChars(str, &isCopy);
|
||||||
// XXX is this strdup right?
|
|
||||||
*((char **) aVariant.val.p) = strdup(char_ptr);
|
*((char **) aVariant.val.p) = strdup(char_ptr);
|
||||||
if (isCopy) {
|
if (isCopy) {
|
||||||
mJavaEnv->ReleaseStringUTFChars(str, char_ptr);
|
mJavaEnv->ReleaseStringUTFChars(str, char_ptr);
|
||||||
|
@ -1039,7 +1047,6 @@ nsJavaXPTCStub::FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
|
||||||
|
|
||||||
case nsXPTType::T_WCHAR_STR:
|
case nsXPTType::T_WCHAR_STR:
|
||||||
{
|
{
|
||||||
// XXX not sure how this should be handled
|
|
||||||
if (aParamInfo.IsOut()) {
|
if (aParamInfo.IsOut()) {
|
||||||
jstring str = nsnull;
|
jstring str = nsnull;
|
||||||
if (aParamInfo.IsRetval()) {
|
if (aParamInfo.IsRetval()) {
|
||||||
|
@ -1054,7 +1061,8 @@ nsJavaXPTCStub::FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
|
||||||
const jchar* wchar_ptr = mJavaEnv->GetStringChars(str, &isCopy);
|
const jchar* wchar_ptr = mJavaEnv->GetStringChars(str, &isCopy);
|
||||||
|
|
||||||
PRUint32 length = nsCRT::strlen(wchar_ptr);
|
PRUint32 length = nsCRT::strlen(wchar_ptr);
|
||||||
PRUnichar* string = (PRUnichar*) malloc(length + 1); // add one for null
|
PRUnichar* string = (PRUnichar*)
|
||||||
|
nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
|
||||||
memcpy(string, wchar_ptr, length * sizeof(PRUnichar));
|
memcpy(string, wchar_ptr, length * sizeof(PRUnichar));
|
||||||
string[length] = 0;
|
string[length] = 0;
|
||||||
*((PRUnichar **) aVariant.val.p) = string;
|
*((PRUnichar **) aVariant.val.p) = string;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче