From 1f79cf92ac06ef465121108f25dc58c3ac976a5e Mon Sep 17 00:00:00 2001 From: Mike Jones Date: Mon, 20 May 2013 13:06:40 -0500 Subject: HWPF: Improve FAPI->TARG attribute mapping compile time type check Old code used to check that the user's data size was the same as the Targeting attribute, new code checks that the type is the same. Change-Id: Ia9d8050e9d71cecf567f549ffa74f0ed36358d76 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/4602 Tested-by: Jenkins Server Reviewed-by: Brian H. Horton Reviewed-by: Van H. Lee Reviewed-by: A. Patrick Williams III --- .../usr/hwpf/plat/fapiPlatAttributeService.H | 52 ++++++++++------------ 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'src/include/usr/hwpf') diff --git a/src/include/usr/hwpf/plat/fapiPlatAttributeService.H b/src/include/usr/hwpf/plat/fapiPlatAttributeService.H index 812ecb6fc..97c60b0de 100644 --- a/src/include/usr/hwpf/plat/fapiPlatAttributeService.H +++ b/src/include/usr/hwpf/plat/fapiPlatAttributeService.H @@ -70,23 +70,18 @@ namespace platAttrSvc { /** - * @brief Compile time check that a FAPI attribute is the same size as a - * TARGETING attribute when they are direct mapped + * @brief Compile time check that a variable is the same type as a Targeting + * attribute. * - * If the size is different then an undefined class is instantiated leading - * to a compile time failure else an empty inline function is optimized out - * by the compiler. + * Used when mapping a FAPI Attribute to a Targeting attribute to ensure that + * the type is correct, if not correct then this function will not be found + * and a compile error will result * - * @param[in] result of size comparison - * - * @return Pointer to Targeting Target + * @param[in] T Type of Targeting attribute + * @param[in] Reference to user's FAPI Attribute variable that must be of + * type T */ -class ErrorFapiTargSizeMismatch; -template void failIfFapiTargAttrSizeMismatch() -{ - ErrorFapiTargSizeMismatch(); -} -template <> inline void failIfFapiTargAttrSizeMismatch() {} +template void failIfTargTypeMismatch(T &) { } /** * @brief Gets a Targeting attribute, this is called by the macro that maps a @@ -463,29 +458,30 @@ fapi::ReturnCode fapiPlatGetPhaseRotatorData ( } // namespace fapi /** - * @brief Macro which directly maps a FAPI_ATTR_GET to a Targeting attr get + * @brief Macro that directly maps a FAPI_ATTR_GET to a Targeting attr get * - * Firstly there is a compile time check that the FAPI Attribute has the same - * size as the correpsonding TARGETING attribute, this is optimized out, then - * there is a single function call + * Firstly there is a compile time check that the user's VAL variable matches + * the Targeting attribute type, this is optimized out, then there is a + * single function call */ #define FAPI_PLAT_ATTR_SVC_GETMACRO_DIRECT(ID, PTARGET, VAL) \ - (fapi::platAttrSvc::failIfFapiTargAttrSizeMismatch::Type)>(), \ + (fapi::platAttrSvc::failIfTargTypeMismatch \ + ::Type>(VAL), \ fapi::platAttrSvc::getTargetingAttr(PTARGET, \ FAPI_PLAT_ATTR_SVC_MACRO_DIRECT_FAPI_##ID, sizeof(VAL), &(VAL))) + /** - * @brief Macro which directly maps a FAPI_ATTR_SET to a Targeting attr set + * @brief Macro that directly maps a FAPI_ATTR_SET to a Targeting attr set * - * Firstly there is a compile time check that the FAPI Attribute has the same - * size as the correpsonding TARGETING attribute, this is optimized out, then - * there is a single function call + * Firstly there is a compile time check that the user's VAL variable matches + * the Targeting attribute type, this is optimized out, then there is a + * single function call */ #define FAPI_PLAT_ATTR_SVC_SETMACRO_DIRECT(ID, PTARGET, VAL) \ - (fapi::platAttrSvc::failIfFapiTargAttrSizeMismatch::Type)>(), \ + (fapi::platAttrSvc::failIfTargTypeMismatch \ + ::Type>(VAL), \ fapi::platAttrSvc::setTargetingAttr(PTARGET, \ FAPI_PLAT_ATTR_SVC_MACRO_DIRECT_FAPI_##ID, sizeof(VAL), &(VAL))) -- cgit v1.2.3