From 66c9536fccb4d84ae962bfeaf5ecb3465abadb71 Mon Sep 17 00:00:00 2001 From: "jband%netscape.com" Date: Mon, 14 Jan 2002 20:02:14 +0000 Subject: [PATCH] fix bug 119387. Add a non-allocating IID version of the frequently used getIIDForParam method. r=dbradley sr=jst --- js/src/xpconnect/src/xpcprivate.h | 3 +- js/src/xpconnect/src/xpcwrappedjsclass.cpp | 96 ++++++------------- js/src/xpconnect/src/xpcwrappednative.cpp | 51 ++++------ .../xptinfo/public/nsIInterfaceInfo.idl | 4 + .../reflect/xptinfo/src/xptiInterfaceInfo.cpp | 13 +++ xpcom/reflect/xptinfo/src/xptiprivate.h | 2 + 6 files changed, 65 insertions(+), 104 deletions(-) diff --git a/js/src/xpconnect/src/xpcprivate.h b/js/src/xpconnect/src/xpcprivate.h index 26a38632ca4d..c5cd3c943edf 100644 --- a/js/src/xpconnect/src/xpcprivate.h +++ b/js/src/xpconnect/src/xpcprivate.h @@ -2015,8 +2015,7 @@ private: uint16 methodIndex, const nsXPTType& type, nsXPTCMiniVariant* params, - JSBool* iidIsOwned, - nsID** result); + nsID* result); void CleanupPointerArray(const nsXPTType& datum_type, JSUint32 array_count, diff --git a/js/src/xpconnect/src/xpcwrappedjsclass.cpp b/js/src/xpconnect/src/xpcwrappedjsclass.cpp index 3e2d3ccebd6b..0f041ad1f4ff 100644 --- a/js/src/xpconnect/src/xpcwrappedjsclass.cpp +++ b/js/src/xpconnect/src/xpcwrappedjsclass.cpp @@ -713,20 +713,17 @@ nsXPCWrappedJSClass::GetInterfaceTypeFromParam(JSContext* cx, uint16 methodIndex, const nsXPTType& type, nsXPTCMiniVariant* nativeParams, - JSBool* iidIsOwned, - nsID** result) + nsID* result) { uint8 type_tag = type.TagPart(); - nsID* iid; if(type_tag == nsXPTType::T_INTERFACE) { - if(NS_FAILED(GetInterfaceInfo()-> - GetIIDForParam(methodIndex, ¶m, &iid))) + if(NS_SUCCEEDED(GetInterfaceInfo()-> + GetIIDForParamNoAlloc(methodIndex, ¶m, result))) { - return JS_FALSE; + return JS_TRUE; } - *iidIsOwned = JS_TRUE; } else if(type_tag == nsXPTType::T_INTERFACE_IS) { @@ -743,15 +740,23 @@ nsXPCWrappedJSClass::GetInterfaceTypeFromParam(JSContext* cx, arg_type.TagPart() == nsXPTType::T_IID) { 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 - 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; } } - - *result = iid; - return iid ? JS_TRUE : JS_FALSE; + return JS_FALSE; } void @@ -813,8 +818,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex, JSErrorReporter older; JSBool success; JSBool readyToDoTheCall = JS_FALSE; - nsID* conditional_iid = nsnull; - JSBool iidIsOwned = JS_FALSE; + nsID param_iid; uint8 outConversionFailedIndex; JSObject* obj; const char* name = info->GetName(); @@ -1055,7 +1059,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex, if(datum_type.IsInterfacePointer() && !GetInterfaceTypeFromParam(cx, info, param, methodIndex, datum_type, nativeParams, - &iidIsOwned, &conditional_iid)) + ¶m_iid)) goto pre_call_clean_up; if(isArray || isSizedString) @@ -1070,7 +1074,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex, { if(!XPCConvert::NativeArray2JS(ccx, &val, (const void**)&pv->val, - datum_type, conditional_iid, + datum_type, ¶m_iid, array_count, obj, nsnull)) goto pre_call_clean_up; } @@ -1085,18 +1089,9 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex, else { if(!XPCConvert::NativeData2JS(ccx, &val, &pv->val, type, - conditional_iid, obj, nsnull)) + ¶m_iid, obj, nsnull)) goto pre_call_clean_up; } - if(conditional_iid) - { - if(iidIsOwned) - { - nsMemory::Free((void*)conditional_iid); - iidIsOwned = JS_FALSE; - } - conditional_iid = nsnull; - } } if(param.IsOut()) @@ -1174,16 +1169,6 @@ pre_call_clean_up: *((void**)p) = nsnull; } - if(conditional_iid) - { - if(iidIsOwned) - { - nsMemory::Free((void*)conditional_iid); - iidIsOwned = JS_FALSE; - } - conditional_iid = nsnull; - } - if(!readyToDoTheCall) goto done; @@ -1432,27 +1417,17 @@ pre_call_clean_up: if(type_tag == nsXPTType::T_INTERFACE) { - if(NS_FAILED(GetInterfaceInfo()->GetIIDForParam(methodIndex, ¶m, - &conditional_iid))) + if(NS_FAILED(GetInterfaceInfo()-> + GetIIDForParamNoAlloc(methodIndex, ¶m, + ¶m_iid))) HANDLE_OUT_CONVERSION_FAILURE - iidIsOwned = JS_TRUE; } else if(type.IsPointer() && !param.IsShared() && !param.IsDipper()) useAllocator = JS_TRUE; if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type, - useAllocator, conditional_iid, nsnull)) + useAllocator, ¶m_iid, nsnull)) 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. @@ -1503,7 +1478,7 @@ pre_call_clean_up: { if(!GetInterfaceTypeFromParam(cx, info, param, methodIndex, datum_type, nativeParams, - &iidIsOwned, &conditional_iid)) + ¶m_iid)) HANDLE_OUT_CONVERSION_FAILURE } else if(type.IsPointer() && !param.IsShared()) @@ -1522,7 +1497,7 @@ pre_call_clean_up: if(!XPCConvert::JSArray2Native(ccx, (void**)&pv->val, val, array_count, array_count, datum_type, - useAllocator, conditional_iid, + useAllocator, ¶m_iid, nsnull)) HANDLE_OUT_CONVERSION_FAILURE } @@ -1538,20 +1513,10 @@ pre_call_clean_up: else { if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type, - useAllocator, conditional_iid, + useAllocator, ¶m_iid, nsnull)) 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) js_FreeStack(cx, mark); - if(conditional_iid && iidIsOwned) - nsMemory::Free((void*)conditional_iid); - if(cx) { JS_SetErrorReporter(cx, older); diff --git a/js/src/xpconnect/src/xpcwrappednative.cpp b/js/src/xpconnect/src/xpcwrappednative.cpp index 371f7bdee197..3d0c6c3f061e 100644 --- a/js/src/xpconnect/src/xpcwrappednative.cpp +++ b/js/src/xpconnect/src/xpcwrappednative.cpp @@ -1537,7 +1537,7 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx, uint8 paramIndex, const nsXPTType& datum_type, nsXPTCVariant* dispatchParams, - nsID** result) + nsID* result) { uint8 argnum; nsresult rv; @@ -1547,7 +1547,7 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx, if(type_tag == nsXPTType::T_INTERFACE) { - rv = ifaceInfo->GetIIDForParam(vtblIndex, ¶mInfo, result); + rv = ifaceInfo->GetIIDForParamNoAlloc(vtblIndex, ¶mInfo, result); if(NS_FAILED(rv)) 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) return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx); - if(!(*result = (nsID*) nsMemory::Clone(dispatchParams[argnum].val.p, - sizeof(nsID)))) - return ReportOutOfMemory(ccx); + nsID* p = (nsID*) dispatchParams[argnum].val.p; + if(!p) + return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx); + *result = *p; } return JS_TRUE; } @@ -1621,7 +1622,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, uint8 paramCount; jsval src; nsresult invokeResult; - nsID* conditional_iid = nsnull; + nsID param_iid; uintN err; nsIXPCSecurityManager* sm; JSBool foundDependentParam; @@ -1832,25 +1833,19 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, } if(type_tag == nsXPTType::T_INTERFACE && - NS_FAILED(ifaceInfo->GetIIDForParam(vtblIndex, ¶mInfo, - &conditional_iid))) + NS_FAILED(ifaceInfo->GetIIDForParamNoAlloc(vtblIndex, ¶mInfo, + ¶m_iid))) { ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, i, ccx); goto done; } if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type, - useAllocator, conditional_iid, &err)) + useAllocator, ¶m_iid, &err)) { ThrowBadParam(err, i, ccx); 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. @@ -1940,7 +1935,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, if(datum_type.IsInterfacePointer() && !GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo, vtblIndex, i, datum_type, - dispatchParams, &conditional_iid)) + dispatchParams, ¶m_iid)) goto done; if(isArray || isSizedString) @@ -1959,7 +1954,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, array_count, array_capacity, datum_type, useAllocator, - conditional_iid, &err)) + ¶m_iid, &err)) { // XXX need exception scheme for arrays to indicate bad element ThrowBadParam(err, i, ccx); @@ -1983,19 +1978,13 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, else { if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type, - useAllocator, conditional_iid, + useAllocator, ¶m_iid, &err)) { ThrowBadParam(err, i, ccx); 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() && !GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo, vtblIndex, i, datum_type, dispatchParams, - &conditional_iid)) + ¶m_iid)) goto done; if(isArray) { if(!XPCConvert::NativeArray2JS(ccx, &v, (const void**)&dp->val, - datum_type, conditional_iid, + datum_type, ¶m_iid, array_count, ccx.GetCurrentJSObject(), &err)) { @@ -2094,7 +2083,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, else { if(!XPCConvert::NativeData2JS(ccx, &v, &dp->val, datum_type, - conditional_iid, + ¶m_iid, ccx.GetCurrentJSObject(), &err)) { ThrowBadParam(err, i, ccx); @@ -2118,11 +2107,6 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx, goto done; } } - if(conditional_iid) - { - nsMemory::Free((void*)conditional_iid); - conditional_iid = nsnull; - } } retval = JS_TRUE; @@ -2186,9 +2170,6 @@ done: } } - if(conditional_iid) - nsMemory::Free((void*)conditional_iid); - if(dispatchParams && dispatchParams != paramBuffer) delete [] dispatchParams; diff --git a/xpcom/reflect/xptinfo/public/nsIInterfaceInfo.idl b/xpcom/reflect/xptinfo/public/nsIInterfaceInfo.idl index a79b1260e521..80d832cdc6f5 100644 --- a/xpcom/reflect/xptinfo/public/nsIInterfaceInfo.idl +++ b/xpcom/reflect/xptinfo/public/nsIInterfaceInfo.idl @@ -129,5 +129,9 @@ interface nsIInterfaceInfo : nsISupports PRBool isFunction(); PRBool hasAncestor(in nsIIDPtr iid); + + [notxpcom] nsresult getIIDForParamNoAlloc(in PRUint16 methodIndex, + [const] in nsXPTParamInfoPtr param, + out nsIID iid); }; diff --git a/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp b/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp index 953b9345af2b..ba5a06f1dc89 100644 --- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp @@ -463,6 +463,19 @@ xptiInterfaceEntry::GetIIDForParam(uint16 methodIndex, 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 nsresult xptiInterfaceEntry::GetTypeInArray(const nsXPTParamInfo* param, diff --git a/xpcom/reflect/xptinfo/src/xptiprivate.h b/xpcom/reflect/xptinfo/src/xptiprivate.h index dac2ac587510..93b8366935b4 100644 --- a/xpcom/reflect/xptinfo/src/xptiprivate.h +++ b/xpcom/reflect/xptinfo/src/xptiprivate.h @@ -629,6 +629,7 @@ public: nsresult GetIIDShared(const nsIID * *iid); nsresult IsFunction(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 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 GetIIDForParamNoAlloc(PRUint16 methodIndex, const nsXPTParamInfo * param, nsIID *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDForParamNoAlloc(methodIndex, param, iid); } public: xptiInterfaceInfo(xptiInterfaceEntry* entry);