Make xpj*.cpp compile against Mozilla's jni.h on Solaris (where jlong is

apparently a struct rather than "long long").


git-svn-id: svn://10.0.0.236/trunk@46650 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
frankm%eng.sun.com
1999-09-09 22:38:04 +00:00
parent 7eefa4b809
commit a998b6acf2
5 changed files with 113 additions and 17 deletions

View File

@@ -36,6 +36,32 @@
extern "C" {
#endif
/* Because not all platforms convert jlong to "long long"
*
* NOTE: this code was cut&pasted from xpj_XPCMethod.cpp, with tweaks.
* Normally I wouldn't do this, but my reasons are:
*
* 1. My alternatives were to put it in xpjava.h or xpjava.cpp
* I'd like to take stuff *out* of xpjava.h, and putting it
* in xpjava.cpp would preclude inlining.
*
* 2. How we map proxies to XPCOM objects is an implementation
* detail, which may change in the future (e.g. an index
* into a proxy table). Thus ToPtr/ToJLong is only of
* interest to those objects that stuff pointers into jlongs.
*
* 3. This allows adaptations to each implementation, for
* type safety (e.g. ToPtr returning nsISupports*).
*
* -- frankm, 99.09.09
*/
static inline nsISupports* ToPtr(jlong l) {
int result;
jlong_L2I(result, l);
return (nsISupports *)result;
}
JNIEXPORT jboolean JNICALL
Java_org_mozilla_xpcom_XPComUtilities_initialize(JNIEnv *env, jclass cls)
{
@@ -145,7 +171,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPComUtilities_RegisterComponent
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPComUtilities_AddRef
(JNIEnv *env, jclass cls, jlong ref)
{
((nsISupports *)ref)->AddRef();
(ToPtr(ref))->AddRef();
}
/*
@@ -156,7 +182,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPComUtilities_AddRef
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPComUtilities_Release
(JNIEnv *env, jclass cls, jlong ref)
{
((nsISupports *)ref)->Release();
(ToPtr(ref))->Release();
}
/*
@@ -193,7 +219,7 @@ JNIEXPORT void JNICALL
return;
}
nsISupports* true_this = (nsISupports *)ref;
nsISupports* true_this = ToPtr(ref);
//true_this->AddRef();
res = XPTC_InvokeByIndex(true_this,

View File

@@ -45,6 +45,36 @@ jclass classXPCMethod = NULL;
extern "C" {
#endif
/* Because not all platforms convert jlong to "long long"
*
* NOTE: this code was cut&pasted to other places, with tweaks.
* Normally I wouldn't do this, but my reasons are:
*
* 1. My alternatives were to put it in xpjava.h or xpjava.cpp
* I'd like to take stuff *out* of xpjava.h, and putting it
* in xpjava.cpp would preclude inlining.
*
* 2. How we represent methods in Java is an implementation
* detail, which may change in the future; this entire class
* may disappear in favor of normal Java reflection, or change
* drastically. Thus ToPtr/ToJLong is only of interest to those
* objects that encode pointers as jlongs, which is kind of a
* kludge to begin with.
*
* -- frankm, 99.09.09
*/
static inline jlong ToJLong(const void *p) {
jlong result;
jlong_I2L(result, (int)p);
return result;
}
static inline void* ToPtr(jlong l) {
int result;
jlong_L2I(result, l);
return (void *)result;
}
/*
* Class: XPCMethod
* Method: init
@@ -117,7 +147,7 @@ JNIEXPORT jint JNICALL
env->SetLongField(self,
XPCMethod_infoptr_ID,
(jlong)mi);
ToJLong(mi));
env->SetIntField(self,
XPCMethod_count_ID,
@@ -130,11 +160,11 @@ JNIEXPORT jint JNICALL
env->SetLongField(self,
XPCMethod_frameptr_ID,
(jlong)variantPtr);
ToJLong(variantPtr));
#else
env->SetLongField(self,
XPCMethod_frameptr_ID,
(jlong)0);
ToJLong(NULL));
#endif
// Return offset
@@ -150,7 +180,7 @@ JNIEXPORT void JNICALL
Java_org_mozilla_xpcom_XPCMethod_destroyPeer(JNIEnv *env,
jobject self, jlong peer) {
nsXPTCVariant *variantPtr = (nsXPTCVariant *)peer;
nsXPTCVariant *variantPtr = (nsXPTCVariant *)ToPtr(peer);
delete [] variantPtr;
}
@@ -169,9 +199,9 @@ JNIEXPORT jint JNICALL Java_org_mozilla_xpcom_XPCMethod_getParameterType
return -1;
}
else {
jlong ptrval = env->GetLongField(self, XPCMethod_infoptr_ID);
const nsXPTMethodInfo *mi =
(const nsXPTMethodInfo *)env->GetLongField(self,
XPCMethod_infoptr_ID);
(const nsXPTMethodInfo *)ToPtr(ptrval);
return mi->GetParam(index).GetType().TagPart();
}
}
@@ -207,8 +237,9 @@ JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPCMethod_invoke
nsXPTCVariant variantArray[paramcount];
#ifdef USE_PARAM_TEMPLATE
jlong ptrval = env->GetLongField(self, XPCMethod_frameptr_ID);
nsXPTCVariant *paramTemplate =
(nsXPTCVariant *)env->GetLongField(self, XPCMethod_frameptr_ID);
(nsXPTCVariant *)ToPtr(ptrval);
memcpy(variantArray, paramTemplate, paramcount * sizeof(nsXPTCVariant));
// Fix pointers
@@ -219,11 +250,11 @@ JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPCMethod_invoke
}
}
#else
jlong ptrval = env->GetLongField(self, XPCMethod_infoptr_ID);
const nsXPTMethodInfo *mi =
(const nsXPTMethodInfo *)env->GetLongField(self,
XPCMethod_infoptr_ID);
(const nsXPTMethodInfo *)ToPtr(ptrval);
BuildParamsForMethodInfo(mi, variantArray);
#endif;
#endif
res = JArrayToVariant(env, paramcount, variantArray, params);

View File

@@ -30,6 +30,35 @@
#define ID_FIELD_NAME "nsidptr"
#define ID_FIELD_TYPE "J"
/* Because not all platforms convert jlong to "long long"
*
* NOTE: this code was cut&pasted from xpj_XPCMethod.cpp, with tweaks.
* Normally I wouldn't do this, but my reasons are:
*
* 1. My alternatives were to put it in xpjava.h or xpjava.cpp
* I'd like to take stuff *out* of xpjava.h, and putting it
* in xpjava.cpp would preclude inlining.
*
* 2. How we represent nsIDs in Java is an implementation
* detail, which may change in the future (e.g. placing the
* whole value in the Java obj, not just a pointer to heap
* memory). Thus ToPtr/ToJLong is only of interest to those
* objects that stuff pointers into jlongs.
*
* -- frankm, 99.09.09
*/
static inline jlong ToJLong(const void *p) {
jlong result;
jlong_I2L(result, (int)p);
return result;
}
static inline void* ToPtr(jlong l) {
int result;
jlong_L2I(result, l);
return (void *)result;
}
/********************** ID **************************/
jobject ID_NewJavaID(JNIEnv *env, const nsIID* iid) {
@@ -53,7 +82,7 @@ nsID *ID_GetNative(JNIEnv *env, jobject self) {
jlong nsidptr = env->GetLongField(self, nsidptrID);
return (nsID *)nsidptr;
return (nsID *)ToPtr(nsidptr);
}
void ID_SetNative(JNIEnv *env, jobject self, nsID *id) {
@@ -62,7 +91,7 @@ void ID_SetNative(JNIEnv *env, jobject self, nsID *id) {
assert(env->IsInstanceOf(self, clazz));
jlong nsidptr = (jlong)id;
jlong nsidptr = ToJLong(id);
env->SetLongField(self, nsidptrID, nsidptr);
}
@@ -75,8 +104,8 @@ jboolean ID_IsEqual(JNIEnv *env, jobject self, jobject other) {
assert(env->IsInstanceOf(self, clazz));
if (other != NULL && env->IsInstanceOf(other, clazz)) {
nsID *selfid = (nsID *)env->GetLongField(self, nsidptrID);
nsID *otherid = (nsID *)env->GetLongField(other, nsidptrID);
nsID *selfid = (nsID *)ToPtr(env->GetLongField(self, nsidptrID));
nsID *otherid = (nsID *)ToPtr(env->GetLongField(other, nsidptrID));
if (selfid != NULL && otherid != NULL) {
result = selfid->Equals(*otherid);

View File

@@ -727,6 +727,7 @@ nsresult InitXPCOM() {
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);
#if 0
// XXX Remove when allocator autoregisters
cerr << "Registering Allocator" << endl;
@@ -741,6 +742,7 @@ nsresult InitXPCOM() {
cerr << "Failed to register allocator, res = " << res << endl;
return res;
}
#endif
// Get InterfaceInfoManager

View File

@@ -15,6 +15,10 @@
#include "nsISupports.h"
#include "xptcall.h"
#ifdef __cplusplus
extern "C" {
#endif
extern nsresult InitXPCOM();
extern jboolean InitJavaCaches(JNIEnv *env);
@@ -67,3 +71,7 @@ extern nsID* ID_GetNative(JNIEnv *env, jobject self);
extern void ID_SetNative(JNIEnv *env, jobject self, nsID* id);
extern jboolean ID_IsEqual(JNIEnv *env, jobject self, jobject other);
#ifdef __cplusplus
}
#endif