@@ -74,6 +74,7 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
74
74
matches = function_pattern .finditer (header_content )
75
75
76
76
extern_declarations = []
77
+ macro_definitions = []
77
78
stub_functions = []
78
79
pointer_initializations = []
79
80
function_details_for_loader = []
@@ -90,9 +91,9 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
90
91
if "void" in return_type :
91
92
return_statement = " // No return value."
92
93
elif "*" in return_type :
93
- return_statement = " return NULL;"
94
+ return_statement = f' return ( { return_type } )(&g_stub_memory);'
94
95
else : # bool, int64_t, etc.
95
- return_statement = " return 0 ;"
96
+ return_statement = " return 1 ;"
96
97
97
98
stub_function = (
98
99
f"// Stub for { function_name } \n "
@@ -105,6 +106,9 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
105
106
declaration = f"extern { return_type } (*ptr_{ function_name } )({ cleaned_params_for_decl } );"
106
107
extern_declarations .append (declaration )
107
108
109
+ macro = f'#define { function_name } ptr_{ function_name } '
110
+ macro_definitions .append (macro )
111
+
108
112
pointer_init = f"{ return_type } (*ptr_{ function_name } )({ cleaned_params_for_decl } ) = &{ stub_name } ;"
109
113
pointer_initializations .append (pointer_init )
110
114
@@ -119,7 +123,8 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
119
123
f .write (f"// Generated from { os .path .basename (header_file_path )} by { os .path .basename (sys .argv [0 ])} \n \n " )
120
124
f .write (f"#ifndef { header_guard } \n " )
121
125
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
+
123
128
f .write ("// --- Copied from original header ---\n " )
124
129
f .write ("\n " .join (includes ) + "\n \n " )
125
130
f .write ("" .join (typedefs ))
@@ -131,6 +136,8 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
131
136
f .write ("// --- Function Pointer Declarations ---\n " )
132
137
f .write ("// clang-format off\n " )
133
138
f .write ("\n " .join (extern_declarations ))
139
+ f .write ("\n \n " )
140
+ f .write ("\n " .join (macro_definitions ))
134
141
f .write ("\n // clang-format on\n " )
135
142
f .write ("\n \n // --- Dynamic Loader Declaration for Windows ---\n " )
136
143
f .write ("#if defined(_WIN32)\n " )
@@ -155,6 +162,7 @@ def generate_function_pointers(header_file_path, output_h_path, output_c_path):
155
162
f .write (f'#include "{ INCLUDE_PREFIX } { os .path .basename (output_h_path )} "\n ' )
156
163
f .write ('#include <stddef.h>\n \n ' )
157
164
f .write ("// clang-format off\n \n " )
165
+ f .write ("static void* g_stub_memory = NULL;\n \n " )
158
166
f .write ("// --- Stub Function Definitions ---\n " )
159
167
f .write ("\n \n " .join (stub_functions ))
160
168
f .write ("\n \n \n // --- Function Pointer Initializations ---\n " )
0 commit comments