diff --git a/scripts/templates/libapi.cpp.mako b/scripts/templates/libapi.cpp.mako index 2ec1b888..27add8c5 100644 --- a/scripts/templates/libapi.cpp.mako +++ b/scripts/templates/libapi.cpp.mako @@ -59,16 +59,56 @@ ${th.make_func_name(n, tags, obj)}( std::call_once(${x}_lib::context->initOnce, [flags]() { %if re.match("zes", n): result = ${x}_lib::context->Init(flags, true); -%else: - result = ${x}_lib::context->Init(flags, false); -%endif }); if( ${X}_RESULT_SUCCESS != result ) return result; + if(ze_lib::context->inTeardown) { + return ${X}_RESULT_ERROR_UNINITIALIZED; + } + + auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}; + if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) { + if(!ze_lib::context->isInitialized) + return ${X}_RESULT_ERROR_UNINITIALIZED; + else + return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); +} +%else: + result = ${x}_lib::context->Init(flags, false); + + if( ${X}_RESULT_SUCCESS != result ) + return result; + + if(ze_lib::context->inTeardown) { + return ${X}_RESULT_ERROR_UNINITIALIZED; + } + + auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}; + if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) { + if(!ze_lib::context->isInitialized) + return ${X}_RESULT_ERROR_UNINITIALIZED; + else + return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); + return result; + }); + + if(ze_lib::context->inTeardown) { + result = ${X}_RESULT_ERROR_UNINITIALIZED; + } + + return result; +} %endif +%else: if(ze_lib::context->inTeardown) { return ${X}_RESULT_ERROR_UNINITIALIZED; } @@ -83,6 +123,7 @@ ${th.make_func_name(n, tags, obj)}( return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); } +%endif %if 'condition' in obj: #endif // ${th.subt(n, tags, obj['condition'])} %endif diff --git a/scripts/templates/validation/valddi.cpp.mako b/scripts/templates/validation/valddi.cpp.mako index 51f46380..72eaf057 100644 --- a/scripts/templates/validation/valddi.cpp.mako +++ b/scripts/templates/validation/valddi.cpp.mako @@ -71,7 +71,7 @@ ${line} \ auto result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); %if generate_post_call: - if( result==${X}_RESULT_SUCCESS && context.enableHandleLifetime ){ + if( result == ${X}_RESULT_SUCCESS && context.enableHandleLifetime ){ %for i, item in enumerate(th.get_loader_epilogue(n, tags, obj, meta)): %if 'range' in item: for (size_t i = ${item['range'][0]}; ( nullptr != ${item['name']}) && (i < ${item['range'][1]}); ++i){