-
-
Notifications
You must be signed in to change notification settings - Fork 9
Meta: Proper and friendly constructor/destructor support #244
Copy link
Copy link
Open
Labels
Area-OutputGenerationIssues concerning the process of generating output from BiohazrdIssues concerning the process of generating output from BiohazrdArea-TranslationIssues concerning the translation from libclang into BiohazrdIssues concerning the translation from libclang into BiohazrdBlocks-OpenCVBlocks-PhysXConcept-CorrectnessIssues concerning the correctness of the translation from an ABI perspectiveIssues concerning the correctness of the translation from an ABI perspectiveConcept-CppFeaturesIssues concerning unsupported C++ featuresIssues concerning unsupported C++ featuresConcept-CrossPlatformIssues concerning cross-platform supportIssues concerning cross-platform supportConcept-OutputFriendlinessIssues concerning the friendliness of using the Biohazrd outputIssues concerning the friendliness of using the Biohazrd outputConcept-OutputUsabilityIssues concerning whether or not the output from Biohazrd is actually usableIssues concerning whether or not the output from Biohazrd is actually usablePlatform-LinuxIssues specific to LinuxIssues specific to LinuxPlatform-WindowsIssues specific to WindowsIssues specific to WindowsTechDebt
Description
Metadata
Metadata
Assignees
Labels
Area-OutputGenerationIssues concerning the process of generating output from BiohazrdIssues concerning the process of generating output from BiohazrdArea-TranslationIssues concerning the translation from libclang into BiohazrdIssues concerning the translation from libclang into BiohazrdBlocks-OpenCVBlocks-PhysXConcept-CorrectnessIssues concerning the correctness of the translation from an ABI perspectiveIssues concerning the correctness of the translation from an ABI perspectiveConcept-CppFeaturesIssues concerning unsupported C++ featuresIssues concerning unsupported C++ featuresConcept-CrossPlatformIssues concerning cross-platform supportIssues concerning cross-platform supportConcept-OutputFriendlinessIssues concerning the friendliness of using the Biohazrd outputIssues concerning the friendliness of using the Biohazrd outputConcept-OutputUsabilityIssues concerning whether or not the output from Biohazrd is actually usableIssues concerning whether or not the output from Biohazrd is actually usablePlatform-LinuxIssues specific to LinuxIssues specific to LinuxPlatform-WindowsIssues specific to WindowsIssues specific to WindowsTechDebt
Up until now I've mostly ignored object construction/destruction because most libraries we've used with Biohazrd thus far have primarily had object lifetimes managed by the target library. (IE: Things are allocated and deallocated exclusively in native code.)
This isn't sustainable long-term, as many libraries (and even some aspects of libraries we already wrap) expect you to manage object lifetimes yourself.
At a high level, we need to support the following:
new()or usingdefault(T)when it would bypass the constructor. (These should be separate diagnostics.)operator newto allocate memory and then separately call the constructor.shouldDeleteparameter set to 1. (See Translation is incorrect for destructors on Microsoft ABI #243)Pinned<T>helper which basically lets you do this on the managed heap. Unfortunately .NET limitations meanTcannot contain managed references. (You can only really pin managed objects via an interior pointer and can't allocate them on the pinned heap.)It would also be nice if we could find a way to properly manage the above situations using
IDisposable. It's tricky in C# since we don't intrinsically know how the object was allocated like we do in C++.Dispose()/usingmakes sense for stack-allocated objects, but less so for heap-allocated ones. We don't want to accidentally mislead people into thinking they can/should callDispose()on heap-allocated objects and cause the destructor to be called without actually freeing memory. (Although if we don't permit allocating on the native heap -- IE: Only allow something likePinned<T>this becomes a non-issue I think?)Since C++ objects expect automatic destructor calls for stack-allocated objects, it might also be helpful to implement an analyzer to tell people to use
usingfor objects allocated on the stack from C#. It's pretty easy to accidentally miss this when porting code from C++ since it's implicit there.Additionally we need to investigate how virtual destructors affect any or all of the above.
The follow issues relate to this effort:
See also #163