-
Notifications
You must be signed in to change notification settings - Fork 799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the creation of SAFEARRAY(VT_RECORD) from a sequence of COM Records #2317
Conversation
of COM Records and the possibility to use instances of this type as COM Record fields.
To progress this PR I have the same questions as in #2310 (comment) |
Now that I have managed to compile the C++ PyComTest server-dll with Visual Studio 2022 as stated in #2310 (comment) I will try to implement a similar test case for this PR, if this makes sense. |
I've added the method The test case has been added to If the changes of commit 78be16b are reverted, the test fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems great too, thanks. Please add a changelog entry when you fix the conflicts.
is_record_item = PyRecord_Check(obItemCheck); | ||
} | ||
// If the sequence elements are PyRecord objects we do NOT package | ||
// them as VARIANT elements but put them directly into the SAFEARRAY. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mildly surprised this check doesn't need to be deeper in PyCom_SAFEARRAYFromPyObject
- are nested arrays of these a thing? But this still looks fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid point. To be honest I didn't open this Pandora's box because my use case doesn't require nested arrays.
Not sure how common they are.
I'm dealing with an engineering application that publishes round about 2000 COM methods and while the majority requires [in, out] Record pointers only 2 of them (unfortunately quite important ones) require plain Safearrays of Recods as parameters.
and the possibility to use instances of this type as COM Record fields.
This PR addresses the following issue.
Given a COM interface that defines a COM Record of the following type in the IDL-file:
where the
T_RECORD_B
is another COM Record type with fields of just simple types,there is currently no way to assign the required SAFEARRAY instance to the
array_of_records
field of aT_RECORD_A
instance.The following code successfully creates all record instances.
However, assigning to the
array_of_records
field of theT_RECORD_A
instance raises an exception:This happens because the code is currently creating a SAFEARRAY(VT_VARIANT) with VARIANT elements of type VT_RECORD while the COM-server expects a SAFEARRAY(VT_RECORD), i.e. COM Record elements.
The modifications of the code implement the required logic to create a SAFEARRAY(VT_RECORD) and assign this as the value to a Record field.
To retrieve the value of such a Record field, the existing code of the
getattro
method in PyRecord.cpp was fixed.I'm wondering if the code in the else block starting at line 500:
was ever tested or used because I cannot see how it could have worked.