Skip to content

Feat: Rewritten Windows Bindings - #5

Open
Mahasvan wants to merge 36 commits into
mainfrom
feat/win-bindings-new
Open

Feat: Rewritten Windows Bindings#5
Mahasvan wants to merge 36 commits into
mainfrom
feat/win-bindings-new

Conversation

@Mahasvan

@Mahasvan Mahasvan commented Aug 1, 2026

Copy link
Copy Markdown
Owner

No description provided.

Comment on lines +21 to +23
typedef struct {
char values[WMI_MAX_FIELDS][WMI_FIELD_LEN];
} WmiRow;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This could be turned into a typedef without being encapsulated in a struct. Is there a specific reason for it to stay inside of a struct?

Also, I think you meant to do char values[WMI_FIELD_LEN][WMI_MAX_FIELDS]

Comment thread src/hwprobe/interops/win/src/wmi.cpp
Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment on lines +47 to +48
static void VariantToUtf8Slot(VARIANT &vt, char *dst, int dst_size) {
if (dst_size <= 0) return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general, to avoid having to check for negative numbers (especially if talking about a parameter indicating size), you can use unsigned integer types: unsigned int dst_size

The caller is also then forced to ensure the passed value is 100% a positive integer.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The check dst_size <= 0 already handles both cases in one comparison. Switching to unsigned wouldn't force callers to pass positive values in C (negative ints silently wrap to huge unsigned values, which is worse), and it would require changing the header, the ctypes binding, and all callers for no functional benefit. The current int is consistent with the rest of the ABI (WMI_FIELD_LEN, WMI_MAX_FIELDS are all int-typed).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah yeah, I forgot about that. We could technically use -Werror with -Wsign-conversion and -Wconversion to at least mark when these cases of wrapping are happening, but if you think it's not worth the change, then OK, can mark this as resolved.

Comment thread src/hwprobe/interops/win/include/wmi.h
Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment on lines +79 to +88
// VT_BSTR fast path.
if (bstr) {
int len = WideCharToMultiByte(CP_UTF8, 0, bstr, -1, nullptr, 0, nullptr, nullptr);
if (len > 0) {
if (len > dst_size) len = dst_size;
WideCharToMultiByte(CP_UTF8, 0, bstr, -1, dst, len, nullptr, nullptr);
dst[dst_size - 1] = '\0';
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it just be easier to move this into the initial if condition block?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

apparently not, according to claude

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not? It seems to be doing the exact same thing when analyzing control flow?

Comment thread src/hwprobe/interops/win/src/wmi.cpp
Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment thread src/hwprobe/interops/win/bindings/wmi.py
Comment thread src/hwprobe/interops/win/src/gpu_info.cpp Outdated
Comment thread src/hwprobe/interops/win/src/gpu_info.cpp Outdated
Comment thread src/hwprobe/interops/win/src/gpu_info.cpp Outdated

@kernel-dev kernel-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general I'd like to assert a few points:

  • General utility/common header functionality would be a nice addition, some methods are re-used or have the potential for re-usability. Defining macros and such in private scopes is OK as long as they stay only in that scope. Otherwise, they should be moved to a common file as well.
  • Graceful handling of Win32/COM API calls should be implemented, i.e. the suggested changes for WideCharToMultiByte(...) second call, which is meant to allocate data to the buffer, does have the potential to fail; we should react appropriately to this.
  • We should strive to type data as explicitly as possible, i.e. don't use int solely in place where unsigned int fits better. For readability or ease sake, we can define typedefs like typedef unsigned int uint;
  • Even for our internal bindings etc. - we should still devise a system for statuses. It'll be helpful for both the backend and frontend to understand why exactly some call failed if it failed. And that way, we can also design our ABI to be as concise and feature-complete as possible.

Comment thread src/hwprobe/core/windows/graphics.py Outdated
Comment thread src/hwprobe/interops/win/include/display_info.h

// ---- wide -> UTF-8 ----

static std::string WideToUtf8(const wchar_t *src) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could move this to a common utilities file, seems like it's used throughout the bindings frequently (along with any other functions you might have in mind)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

fair enough tbh, ill refactor in a bit

Comment thread src/hwprobe/core/windows/network.py
Comment thread src/hwprobe/core/windows/network.py Outdated
Comment thread src/hwprobe/interops/win/bindings/display_info.py
Comment thread src/hwprobe/interops/win/include/display_info.h

@kernel-dev kernel-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For some reason I couldn't add to my previous review, so I published that one and now it let me 😄

Comment thread src/hwprobe/core/windows/cpu.py Outdated
Comment thread src/hwprobe/interops/win/include/gpu_info.h
@kernel-dev kernel-dev added the enhancement New feature or request label Aug 1, 2026

@Mahasvan Mahasvan left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Thanks for the review @kernel-dev, much appreciated.

Comment thread src/hwprobe/interops/win/bindings/wmi.py
Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment on lines +47 to +48
static void VariantToUtf8Slot(VARIANT &vt, char *dst, int dst_size) {
if (dst_size <= 0) return;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The check dst_size <= 0 already handles both cases in one comparison. Switching to unsigned wouldn't force callers to pass positive values in C (negative ints silently wrap to huge unsigned values, which is worse), and it would require changing the header, the ctypes binding, and all callers for no functional benefit. The current int is consistent with the rest of the ABI (WMI_FIELD_LEN, WMI_MAX_FIELDS are all int-typed).

Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment thread src/hwprobe/interops/win/src/wmi.cpp Outdated
Comment on lines +79 to +88
// VT_BSTR fast path.
if (bstr) {
int len = WideCharToMultiByte(CP_UTF8, 0, bstr, -1, nullptr, 0, nullptr, nullptr);
if (len > 0) {
if (len > dst_size) len = dst_size;
WideCharToMultiByte(CP_UTF8, 0, bstr, -1, dst, len, nullptr, nullptr);
dst[dst_size - 1] = '\0';
}
}
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

apparently not, according to claude

Comment thread src/hwprobe/interops/win/src/wmi.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants