Skip to content

Conversation

@cpz
Copy link
Contributor

@cpz cpz commented May 11, 2025

Updated GetMemAlloc in IMemAlloc.h to use __declspec(dllimport) for proper external linkage. Improved SDK generation in startup.cpp by adding support for dumping enums and classes from global type scopes.

Note: Dumping the GlobalTypeScope is essential because it may include classes that are not explicitly registered within any specific module. This ensures complete coverage of all relevant types during SDK generation.

Updated `GetMemAlloc` in `IMemAlloc.h` to use `__declspec(dllimport)` for proper external linkage. Improved SDK generation in `startup.cpp` by adding support for dumping enums and classes from global type scopes.
@cpz cpz requested a review from es3n1n May 11, 2025 11:55
@es3n1n es3n1n changed the title feature: Enhance memory allocation and SDK generation feat: Enhance memory allocation and SDK generation May 11, 2025
auto type_scopes = sdk::g_schema->GetTypeScopes();
assert(type_scopes.Count() > 0 && "sdk is outdated");


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

}

// @note: @es3n1n: Obtaining type scopes and generating sdk
const auto type_scopes = sdk::g_schema->GetTypeScopes();
Copy link
Collaborator

@es3n1n es3n1n May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove const?

Comment on lines +92 to +104
const auto global_scope = sdk::g_schema->GlobalTypeScope();
auto current_enums = global_scope->GetEnumBindings();
for (auto el : current_enums.GetElements()) {
auto& dump{dumped_modules.emplace(el->m_pszModule, unique_module_dump{}).first->second};
dump.enums.emplace(el->m_pszName, el);
}

auto current_classes = global_scope->GetClassBindings();
for (auto el : current_classes.GetElements()) {
auto& dump{dumped_modules.emplace(el->m_pszModule, unique_module_dump{}).first->second};
dump.classes.emplace(el->m_pszName, el);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of code repetition here. How about making a lambda that takes a pointer to CSchemaSystemTypeScope and does this processing so that we can just call lambda in the loop and for the global scope?

};

extern IMemAlloc* GetMemAlloc();
extern "C" __declspec(dllimport) IMemAlloc* GetMemAlloc();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__declspec is a microsoft-specific attribute. This code would not work on linux.

Would really love to put this under a macro, but for now we have only one use case so we can just inline it.

Suggested change
extern "C" __declspec(dllimport) IMemAlloc* GetMemAlloc();
#if defined(_WIN64) || defined(_WIN32)
extern "C" __declspec(dllimport) IMemAlloc* GetMemAlloc();
#else
extern "C" IMemAlloc* GetMemAlloc();
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants