@@ -74,6 +74,7 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
7474 matches = function_pattern .finditer (header_content )
7575
7676 extern_declarations = []
77+ macro_definitions = []
7778 stub_functions = []
7879 pointer_initializations = []
7980 function_details_for_loader = []
@@ -90,9 +91,9 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
9091 if "void" in return_type :
9192 return_statement = " // No return value."
9293 elif "*" in return_type :
93- return_statement = " return NULL;"
94+ return_statement = f' return ( { return_type } )(&g_stub_memory);'
9495 else : # bool, int64_t, etc.
95- return_statement = " return 0 ;"
96+ return_statement = " return 1 ;"
9697
9798 stub_function = (
9899 f"// Stub for { function_name } \n "
@@ -105,6 +106,9 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
105106 declaration = f"extern { return_type } (*ptr_{ function_name } )({ cleaned_params_for_decl } );"
106107 extern_declarations .append (declaration )
107108
109+ macro = f'#define { function_name } ptr_{ function_name } '
110+ macro_definitions .append (macro )
111+
108112 pointer_init = f"{ return_type } (*ptr_{ function_name } )({ cleaned_params_for_decl } ) = &{ stub_name } ;"
109113 pointer_initializations .append (pointer_init )
110114
@@ -119,7 +123,8 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
119123 f .write (f"// Generated from { os .path .basename (header_file_path )} by { os .path .basename (sys .argv [0 ])} \n \n " )
120124 f .write (f"#ifndef { header_guard } \n " )
121125 f .write (f"#define { header_guard } \n \n " )
122-
126+ f .write ("#include <stdbool.h> // needed for bool type in pure C\n \n " )
127+
123128 f .write ("// --- Copied from original header ---\n " )
124129 f .write ("\n " .join (includes ) + "\n \n " )
125130 f .write ("" .join (typedefs ))
@@ -131,6 +136,8 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
131136 f .write ("// --- Function Pointer Declarations ---\n " )
132137 f .write ("// clang-format off\n " )
133138 f .write ("\n " .join (extern_declarations ))
139+ f .write ("\n \n " )
140+ f .write ("\n " .join (macro_definitions ))
134141 f .write ("\n // clang-format on\n " )
135142 f .write ("\n \n // --- Dynamic Loader Declaration for Windows ---\n " )
136143 f .write ("#if defined(_WIN32)\n " )
@@ -155,6 +162,7 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
155162 f .write (f'#include "{ INCLUDE_PREFIX } { os .path .basename (output_h_path )} "\n ' )
156163 f .write ('#include <stddef.h>\n \n ' )
157164 f .write ("// clang-format off\n \n " )
165+ f .write ("static void* g_stub_memory = NULL;\n \n " )
158166 f .write ("// --- Stub Function Definitions ---\n " )
159167 f .write ("\n \n " .join (stub_functions ))
160168 f .write ("\n \n \n // --- Function Pointer Initializations ---\n " )
0 commit comments