fix bug 119387. Add a non-allocating IID version of the frequently used getIIDForParam method. r=dbradley sr=jst

This commit is contained in:
jband%netscape.com 2002-01-14 20:02:14 +00:00
parent 80007341d2
commit 66c9536fcc
6 changed files with 65 additions and 104 deletions

View File

@ -2015,8 +2015,7 @@ private:
uint16 methodIndex, uint16 methodIndex,
const nsXPTType& type, const nsXPTType& type,
nsXPTCMiniVariant* params, nsXPTCMiniVariant* params,
JSBool* iidIsOwned, nsID* result);
nsID** result);
void CleanupPointerArray(const nsXPTType& datum_type, void CleanupPointerArray(const nsXPTType& datum_type,
JSUint32 array_count, JSUint32 array_count,

View File

@ -713,20 +713,17 @@ nsXPCWrappedJSClass::GetInterfaceTypeFromParam(JSContext* cx,
uint16 methodIndex, uint16 methodIndex,
const nsXPTType& type, const nsXPTType& type,
nsXPTCMiniVariant* nativeParams, nsXPTCMiniVariant* nativeParams,
JSBool* iidIsOwned, nsID* result)
nsID** result)
{ {
uint8 type_tag = type.TagPart(); uint8 type_tag = type.TagPart();
nsID* iid;
if(type_tag == nsXPTType::T_INTERFACE) if(type_tag == nsXPTType::T_INTERFACE)
{ {
if(NS_FAILED(GetInterfaceInfo()-> if(NS_SUCCEEDED(GetInterfaceInfo()->
GetIIDForParam(methodIndex, &param, &iid))) GetIIDForParamNoAlloc(methodIndex, &param, result)))
{ {
return JS_FALSE; return JS_TRUE;
} }
*iidIsOwned = JS_TRUE;
} }
else if(type_tag == nsXPTType::T_INTERFACE_IS) else if(type_tag == nsXPTType::T_INTERFACE_IS)
{ {
@ -743,15 +740,23 @@ nsXPCWrappedJSClass::GetInterfaceTypeFromParam(JSContext* cx,
arg_type.TagPart() == nsXPTType::T_IID) arg_type.TagPart() == nsXPTType::T_IID)
{ {
if(arg_param.IsOut()) if(arg_param.IsOut())
iid = *((nsID**)nativeParams[argnum].val.p); {
nsID** p = (nsID**) nativeParams[argnum].val.p;
if(!p || !*p)
return JS_FALSE;
*result = **p;
}
else else
iid = (nsID*) nativeParams[argnum].val.p; {
*iidIsOwned = JS_FALSE; nsID* p = (nsID*) nativeParams[argnum].val.p;
if(!p)
return JS_FALSE;
*result = *p;
}
return JS_TRUE;
} }
} }
return JS_FALSE;
*result = iid;
return iid ? JS_TRUE : JS_FALSE;
} }
void void
@ -813,8 +818,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
JSErrorReporter older; JSErrorReporter older;
JSBool success; JSBool success;
JSBool readyToDoTheCall = JS_FALSE; JSBool readyToDoTheCall = JS_FALSE;
nsID* conditional_iid = nsnull; nsID param_iid;
JSBool iidIsOwned = JS_FALSE;
uint8 outConversionFailedIndex; uint8 outConversionFailedIndex;
JSObject* obj; JSObject* obj;
const char* name = info->GetName(); const char* name = info->GetName();
@ -1055,7 +1059,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
if(datum_type.IsInterfacePointer() && if(datum_type.IsInterfacePointer() &&
!GetInterfaceTypeFromParam(cx, info, param, methodIndex, !GetInterfaceTypeFromParam(cx, info, param, methodIndex,
datum_type, nativeParams, datum_type, nativeParams,
&iidIsOwned, &conditional_iid)) &param_iid))
goto pre_call_clean_up; goto pre_call_clean_up;
if(isArray || isSizedString) if(isArray || isSizedString)
@ -1070,7 +1074,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
{ {
if(!XPCConvert::NativeArray2JS(ccx, &val, (const void**)&pv->val, if(!XPCConvert::NativeArray2JS(ccx, &val, (const void**)&pv->val,
datum_type, conditional_iid, datum_type, &param_iid,
array_count, obj, nsnull)) array_count, obj, nsnull))
goto pre_call_clean_up; goto pre_call_clean_up;
} }
@ -1085,18 +1089,9 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
else else
{ {
if(!XPCConvert::NativeData2JS(ccx, &val, &pv->val, type, if(!XPCConvert::NativeData2JS(ccx, &val, &pv->val, type,
conditional_iid, obj, nsnull)) &param_iid, obj, nsnull))
goto pre_call_clean_up; goto pre_call_clean_up;
} }
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
} }
if(param.IsOut()) if(param.IsOut())
@ -1174,16 +1169,6 @@ pre_call_clean_up:
*((void**)p) = nsnull; *((void**)p) = nsnull;
} }
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
if(!readyToDoTheCall) if(!readyToDoTheCall)
goto done; goto done;
@ -1432,27 +1417,17 @@ pre_call_clean_up:
if(type_tag == nsXPTType::T_INTERFACE) if(type_tag == nsXPTType::T_INTERFACE)
{ {
if(NS_FAILED(GetInterfaceInfo()->GetIIDForParam(methodIndex, &param, if(NS_FAILED(GetInterfaceInfo()->
&conditional_iid))) GetIIDForParamNoAlloc(methodIndex, &param,
&param_iid)))
HANDLE_OUT_CONVERSION_FAILURE HANDLE_OUT_CONVERSION_FAILURE
iidIsOwned = JS_TRUE;
} }
else if(type.IsPointer() && !param.IsShared() && !param.IsDipper()) else if(type.IsPointer() && !param.IsShared() && !param.IsDipper())
useAllocator = JS_TRUE; useAllocator = JS_TRUE;
if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type, if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type,
useAllocator, conditional_iid, nsnull)) useAllocator, &param_iid, nsnull))
HANDLE_OUT_CONVERSION_FAILURE HANDLE_OUT_CONVERSION_FAILURE
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
} }
// if any params were dependent, then we must iterate again to convert them. // if any params were dependent, then we must iterate again to convert them.
@ -1503,7 +1478,7 @@ pre_call_clean_up:
{ {
if(!GetInterfaceTypeFromParam(cx, info, param, methodIndex, if(!GetInterfaceTypeFromParam(cx, info, param, methodIndex,
datum_type, nativeParams, datum_type, nativeParams,
&iidIsOwned, &conditional_iid)) &param_iid))
HANDLE_OUT_CONVERSION_FAILURE HANDLE_OUT_CONVERSION_FAILURE
} }
else if(type.IsPointer() && !param.IsShared()) else if(type.IsPointer() && !param.IsShared())
@ -1522,7 +1497,7 @@ pre_call_clean_up:
if(!XPCConvert::JSArray2Native(ccx, (void**)&pv->val, val, if(!XPCConvert::JSArray2Native(ccx, (void**)&pv->val, val,
array_count, array_count, array_count, array_count,
datum_type, datum_type,
useAllocator, conditional_iid, useAllocator, &param_iid,
nsnull)) nsnull))
HANDLE_OUT_CONVERSION_FAILURE HANDLE_OUT_CONVERSION_FAILURE
} }
@ -1538,20 +1513,10 @@ pre_call_clean_up:
else else
{ {
if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type, if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type,
useAllocator, conditional_iid, useAllocator, &param_iid,
nsnull)) nsnull))
HANDLE_OUT_CONVERSION_FAILURE HANDLE_OUT_CONVERSION_FAILURE
} }
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
} }
} }
@ -1608,9 +1573,6 @@ done:
if(sp) if(sp)
js_FreeStack(cx, mark); js_FreeStack(cx, mark);
if(conditional_iid && iidIsOwned)
nsMemory::Free((void*)conditional_iid);
if(cx) if(cx)
{ {
JS_SetErrorReporter(cx, older); JS_SetErrorReporter(cx, older);

View File

@ -1537,7 +1537,7 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx,
uint8 paramIndex, uint8 paramIndex,
const nsXPTType& datum_type, const nsXPTType& datum_type,
nsXPTCVariant* dispatchParams, nsXPTCVariant* dispatchParams,
nsID** result) nsID* result)
{ {
uint8 argnum; uint8 argnum;
nsresult rv; nsresult rv;
@ -1547,7 +1547,7 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx,
if(type_tag == nsXPTType::T_INTERFACE) if(type_tag == nsXPTType::T_INTERFACE)
{ {
rv = ifaceInfo->GetIIDForParam(vtblIndex, &paramInfo, result); rv = ifaceInfo->GetIIDForParamNoAlloc(vtblIndex, &paramInfo, result);
if(NS_FAILED(rv)) if(NS_FAILED(rv))
return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx); return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx);
} }
@ -1564,9 +1564,10 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx,
if(!arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_IID) if(!arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_IID)
return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx); return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx);
if(!(*result = (nsID*) nsMemory::Clone(dispatchParams[argnum].val.p, nsID* p = (nsID*) dispatchParams[argnum].val.p;
sizeof(nsID)))) if(!p)
return ReportOutOfMemory(ccx); return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx);
*result = *p;
} }
return JS_TRUE; return JS_TRUE;
} }
@ -1621,7 +1622,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
uint8 paramCount; uint8 paramCount;
jsval src; jsval src;
nsresult invokeResult; nsresult invokeResult;
nsID* conditional_iid = nsnull; nsID param_iid;
uintN err; uintN err;
nsIXPCSecurityManager* sm; nsIXPCSecurityManager* sm;
JSBool foundDependentParam; JSBool foundDependentParam;
@ -1832,25 +1833,19 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
} }
if(type_tag == nsXPTType::T_INTERFACE && if(type_tag == nsXPTType::T_INTERFACE &&
NS_FAILED(ifaceInfo->GetIIDForParam(vtblIndex, &paramInfo, NS_FAILED(ifaceInfo->GetIIDForParamNoAlloc(vtblIndex, &paramInfo,
&conditional_iid))) &param_iid)))
{ {
ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, i, ccx); ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, i, ccx);
goto done; goto done;
} }
if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type, if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type,
useAllocator, conditional_iid, &err)) useAllocator, &param_iid, &err))
{ {
ThrowBadParam(err, i, ccx); ThrowBadParam(err, i, ccx);
goto done; goto done;
} }
if(conditional_iid)
{
nsMemory::Free((void*)conditional_iid);
conditional_iid = nsnull;
}
} }
// if any params were dependent, then we must iterate again to convert them. // if any params were dependent, then we must iterate again to convert them.
@ -1940,7 +1935,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
if(datum_type.IsInterfacePointer() && if(datum_type.IsInterfacePointer() &&
!GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo, !GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo,
vtblIndex, i, datum_type, vtblIndex, i, datum_type,
dispatchParams, &conditional_iid)) dispatchParams, &param_iid))
goto done; goto done;
if(isArray || isSizedString) if(isArray || isSizedString)
@ -1959,7 +1954,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
array_count, array_capacity, array_count, array_capacity,
datum_type, datum_type,
useAllocator, useAllocator,
conditional_iid, &err)) &param_iid, &err))
{ {
// XXX need exception scheme for arrays to indicate bad element // XXX need exception scheme for arrays to indicate bad element
ThrowBadParam(err, i, ccx); ThrowBadParam(err, i, ccx);
@ -1983,19 +1978,13 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
else else
{ {
if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type, if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type,
useAllocator, conditional_iid, useAllocator, &param_iid,
&err)) &err))
{ {
ThrowBadParam(err, i, ccx); ThrowBadParam(err, i, ccx);
goto done; goto done;
} }
} }
if(conditional_iid)
{
nsMemory::Free((void*)conditional_iid);
conditional_iid = nsnull;
}
} }
} }
@ -2065,13 +2054,13 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
if(datum_type.IsInterfacePointer() && if(datum_type.IsInterfacePointer() &&
!GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo, !GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo,
vtblIndex, i, datum_type, dispatchParams, vtblIndex, i, datum_type, dispatchParams,
&conditional_iid)) &param_iid))
goto done; goto done;
if(isArray) if(isArray)
{ {
if(!XPCConvert::NativeArray2JS(ccx, &v, (const void**)&dp->val, if(!XPCConvert::NativeArray2JS(ccx, &v, (const void**)&dp->val,
datum_type, conditional_iid, datum_type, &param_iid,
array_count, ccx.GetCurrentJSObject(), array_count, ccx.GetCurrentJSObject(),
&err)) &err))
{ {
@ -2094,7 +2083,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
else else
{ {
if(!XPCConvert::NativeData2JS(ccx, &v, &dp->val, datum_type, if(!XPCConvert::NativeData2JS(ccx, &v, &dp->val, datum_type,
conditional_iid, &param_iid,
ccx.GetCurrentJSObject(), &err)) ccx.GetCurrentJSObject(), &err))
{ {
ThrowBadParam(err, i, ccx); ThrowBadParam(err, i, ccx);
@ -2118,11 +2107,6 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
goto done; goto done;
} }
} }
if(conditional_iid)
{
nsMemory::Free((void*)conditional_iid);
conditional_iid = nsnull;
}
} }
retval = JS_TRUE; retval = JS_TRUE;
@ -2186,9 +2170,6 @@ done:
} }
} }
if(conditional_iid)
nsMemory::Free((void*)conditional_iid);
if(dispatchParams && dispatchParams != paramBuffer) if(dispatchParams && dispatchParams != paramBuffer)
delete [] dispatchParams; delete [] dispatchParams;

View File

@ -129,5 +129,9 @@ interface nsIInterfaceInfo : nsISupports
PRBool isFunction(); PRBool isFunction();
PRBool hasAncestor(in nsIIDPtr iid); PRBool hasAncestor(in nsIIDPtr iid);
[notxpcom] nsresult getIIDForParamNoAlloc(in PRUint16 methodIndex,
[const] in nsXPTParamInfoPtr param,
out nsIID iid);
}; };

View File

@ -463,6 +463,19 @@ xptiInterfaceEntry::GetIIDForParam(uint16 methodIndex,
return entry->GetIID(iid); return entry->GetIID(iid);
} }
nsresult
xptiInterfaceEntry::GetIIDForParamNoAlloc(PRUint16 methodIndex,
const nsXPTParamInfo * param,
nsIID *iid)
{
xptiInterfaceEntry* entry;
nsresult rv = GetEntryForParam(methodIndex, param, &entry);
if(NS_FAILED(rv))
return rv;
*iid = entry->mIID;
return NS_OK;
}
// this is a private helper // this is a private helper
nsresult nsresult
xptiInterfaceEntry::GetTypeInArray(const nsXPTParamInfo* param, xptiInterfaceEntry::GetTypeInArray(const nsXPTParamInfo* param,

View File

@ -629,6 +629,7 @@ public:
nsresult GetIIDShared(const nsIID * *iid); nsresult GetIIDShared(const nsIID * *iid);
nsresult IsFunction(PRBool *_retval); nsresult IsFunction(PRBool *_retval);
nsresult HasAncestor(const nsIID * iid, PRBool *_retval); nsresult HasAncestor(const nsIID * iid, PRBool *_retval);
nsresult GetIIDForParamNoAlloc(PRUint16 methodIndex, const nsXPTParamInfo * param, nsIID *iid);
////////////////////// //////////////////////
@ -721,6 +722,7 @@ public:
NS_IMETHOD GetIIDShared(const nsIID * *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDShared(iid); } NS_IMETHOD GetIIDShared(const nsIID * *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDShared(iid); }
NS_IMETHOD IsFunction(PRBool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->IsFunction(_retval); } NS_IMETHOD IsFunction(PRBool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->IsFunction(_retval); }
NS_IMETHOD HasAncestor(const nsIID * iid, PRBool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->HasAncestor(iid, _retval); } NS_IMETHOD HasAncestor(const nsIID * iid, PRBool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->HasAncestor(iid, _retval); }
NS_IMETHOD GetIIDForParamNoAlloc(PRUint16 methodIndex, const nsXPTParamInfo * param, nsIID *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDForParamNoAlloc(methodIndex, param, iid); }
public: public:
xptiInterfaceInfo(xptiInterfaceEntry* entry); xptiInterfaceInfo(xptiInterfaceEntry* entry);