VirtualBox

Opened 9 years ago

Last modified 9 years ago

#14149 new defect

Trivial macro bug in SDK in bindings/c/include/VBoxCAPI_v4_3.h

Reported by: pwnall Owned by:
Component: other Version: VirtualBox 4.3.28
Keywords: api bindings vboxcapi Cc:
Guest type: all Host type: Linux

Description

The definition for the IVirtualBox_CreateMachine macro is missing the GroupSize parameter. It needs to have the parameter added, and then needs to forward it to CreateMachine.

Without this change, code that uses the macro won't compile.

Here's a diff, in case it helps.

diff a/bindings/c/include/VBoxCAPI_v4_3.h b/bindings/c/include/VBoxCAPI_v4_3.h
--- a/third_party/VirtualBoxSDK/sdk/bindings/c/include/VBoxCAPI_v4_3.h
+++ b/third_party/VirtualBoxSDK/sdk/bindings/c/include/VBoxCAPI_v4_3.h
@@ -4266,7 +4266,7 @@ struct IVirtualBoxVtbl
 #define IVirtualBox_get_GenericNetworkDrivers(p, aGenericNetworkDrivers) ((p)->lpVtbl->GetGenericNetworkDrivers(p, aGenericNetworkDrivers))
 #define IVirtualBox_GetGenericNetworkDrivers(p, aGenericNetworkDrivers) ((p)->lpVtbl->GetGenericNetworkDrivers(p, aGenericNetworkDrivers))
 #define IVirtualBox_ComposeMachineFilename(p, aName, aGroup, aCreateFlags, aBaseFolder, aFile) ((p)->lpVtbl->ComposeMachineFilename(p, aName, aGroup, aCreateFlags, aBaseFolder, aFile))
-#define IVirtualBox_CreateMachine(p, aSettingsFile, aName, aGroups, aOsTypeId, aFlags, aMachine) ((p)->lpVtbl->CreateMachine(p, aSettingsFile, aName, aGroups, aOsTypeId, aFlags, aMachine))
+#define IVirtualBox_CreateMachine(p, aSettingsFile, aName, aGroupSize, aGroups, aOsTypeId, aFlags, aMachine) ((p)->lpVtbl->CreateMachine(p, aSettingsFile, aName, aGroupSize, aGroups, aOsTypeId, aFlags, aMachine))
 #define IVirtualBox_OpenMachine(p, aSettingsFile, aMachine) ((p)->lpVtbl->OpenMachine(p, aSettingsFile, aMachine))
 #define IVirtualBox_RegisterMachine(p, aMachine) ((p)->lpVtbl->RegisterMachine(p, aMachine))
 #define IVirtualBox_FindMachine(p, aNameOrId, aMachine) ((p)->lpVtbl->FindMachine(p, aNameOrId, aMachine))

Change History (3)

comment:1 by pwnall, 9 years ago

IMedium_CreateBaseStorage (on line 11620) has the same problem. I've spotted a few more places with similar issues. Perhaps it's a code generator problem?

comment:2 by Klaus Espenlaub, 9 years ago

This is intentional code generator behavior, showing for every array parameter (i.e. many places in the generated header). If you follow the recommended way to pass such array parameters (see e.g. the sample code) then everything should work without warnings or trouble with the parameter count.

In the originally reported case you should be using something like

HRESULT rc = IVirtualBox_CreateMachine(vbox, "", "my VM", ComSafeArrayAsInParam(groupsSA), "Linux_64", ...);

The issue is that passing an array parameter uses a macro to generate the two values, and from the C preprocessor's perspective there is only one parameter (as the corresponding macro is expanded after the "parameter passing" from the preprocessor's perspective, not before, so the parameter count). The generated C code will have the "additional" parameters. If anyone has a better solution for such "parameter count changing macros", let me know. I do agree that the current solution isn't pretty, but it's the only way I found which allows using the same code both on Windows host (using COM, which has only one parameter for such arrays) and non-Windows host (using XPCOM, which needs two parameters for such arrays).

It seems to me that the core "problem" is passing empty arrays. I guess developers are tempted to take shortcuts (avoiding the extra variables and code effort for creating an empty array the proper way), and that's exposing this quirk. I wonder if it would be sufficient to introduce a macro which passes an empty array would be solving this quirk (one with expands to NULL on Windows and to 0, NULL elsewhere).

comment:3 by pwnall, 9 years ago

Ah, thanks so much for clarifying! I'll fix my bindings!

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use