Skip to content

Commit cfa4385

Browse files
committed
Update stub generation.
1 parent 7936e99 commit cfa4385

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

analytics/generate_windows_stubs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
100100
includes = re.findall(r"#include\s+<.*?>", header_content)
101101

102102
# Find all typedefs, including their documentation comments
103-
typedefs = re.findall(r"/\*\*(?:[\s\S]*?)\*/\s*typedef[\s\S]*?;\s*", header_content)
103+
typedefs = re.findall(r"(?:/\*\*(?:[\s\S]*?)\*/\s*)?typedef[\s\S]*?;\s*", header_content)
104104

105105
# --- Extract function prototypes ---
106106
function_pattern = re.compile(
@@ -127,7 +127,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
127127
if "void" in return_type:
128128
return_statement = " // No return value."
129129
elif "*" in return_type:
130-
return_statement = f' return ({return_type})(&g_stub_memory);'
130+
return_statement = f' return ({return_type})(&g_stub_memory[0]);'
131131
else: # bool, int64_t, etc.
132132
return_statement = " return 1;"
133133

@@ -203,7 +203,8 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
203203
f.write(f"// Generated from {os.path.basename(header_file_path)} by {os.path.basename(sys.argv[0])}\n\n")
204204
f.write(f'#include "{INCLUDE_PREFIX}{os.path.basename(output_h_path)}"\n\n')
205205
f.write('#include <stddef.h>\n\n')
206-
f.write("static void* g_stub_memory = NULL;\n\n")
206+
f.write("// A nice big chunk of stub memory that can be returned by stubbed Create methods.\n")
207+
f.write("static char g_stub_memory[256] = {0};\n\n")
207208
f.write("// clang-format off\n")
208209
f.write(f'\n// Number of Google Analytics functions expected to be loaded from the DLL.')
209210
f.write(f'\nconst int FirebaseAnalytics_DynamicFunctionCount = {len(function_details_for_loader)};\n\n');

analytics/src/analytics_desktop_dynamic.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
#include <stddef.h>
2020

21-
static void* g_stub_memory = NULL;
21+
// A nice big chunk of stub memory that can be returned by stubbed Create methods.
22+
static char g_stub_memory[256] = {0};
2223

2324
// clang-format off
2425

@@ -38,7 +39,7 @@ const int FirebaseAnalytics_KnownWindowsDllHashCount = 1;
3839
// --- Stub Function Definitions ---
3940
// Stub for GoogleAnalytics_Options_Create
4041
static GoogleAnalytics_Options* Stub_GoogleAnalytics_Options_Create() {
41-
return (GoogleAnalytics_Options*)(&g_stub_memory);
42+
return (GoogleAnalytics_Options*)(&g_stub_memory[0]);
4243
}
4344

4445
// Stub for GoogleAnalytics_Options_Destroy
@@ -48,7 +49,7 @@ static void Stub_GoogleAnalytics_Options_Destroy(GoogleAnalytics_Options* option
4849

4950
// Stub for GoogleAnalytics_Item_Create
5051
static GoogleAnalytics_Item* Stub_GoogleAnalytics_Item_Create() {
51-
return (GoogleAnalytics_Item*)(&g_stub_memory);
52+
return (GoogleAnalytics_Item*)(&g_stub_memory[0]);
5253
}
5354

5455
// Stub for GoogleAnalytics_Item_InsertInt
@@ -79,7 +80,7 @@ static void Stub_GoogleAnalytics_Item_Destroy(GoogleAnalytics_Item* item) {
7980

8081
// Stub for GoogleAnalytics_ItemVector_Create
8182
static GoogleAnalytics_ItemVector* Stub_GoogleAnalytics_ItemVector_Create() {
82-
return (GoogleAnalytics_ItemVector*)(&g_stub_memory);
83+
return (GoogleAnalytics_ItemVector*)(&g_stub_memory[0]);
8384
}
8485

8586
// Stub for GoogleAnalytics_ItemVector_InsertItem
@@ -94,7 +95,7 @@ static void Stub_GoogleAnalytics_ItemVector_Destroy(GoogleAnalytics_ItemVector*
9495

9596
// Stub for GoogleAnalytics_EventParameters_Create
9697
static GoogleAnalytics_EventParameters* Stub_GoogleAnalytics_EventParameters_Create() {
97-
return (GoogleAnalytics_EventParameters*)(&g_stub_memory);
98+
return (GoogleAnalytics_EventParameters*)(&g_stub_memory[0]);
9899
}
99100

100101
// Stub for GoogleAnalytics_EventParameters_InsertInt

analytics/src/analytics_desktop_dynamic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <stdbool.h>
2424
#include <stdint.h>
2525

26+
typedef struct GoogleAnalytics_Reserved_Opaque GoogleAnalytics_Reserved;
27+
2628
/**
2729
* @brief GoogleAnalytics_Options for initializing the Analytics SDK.
2830
* GoogleAnalytics_Options_Create() must be used to create an instance of this

0 commit comments

Comments
 (0)