Meta: Proper and friendly constructor/destructor support #244
Labels
Area-OutputGeneration
Issues concerning the process of generating output from Biohazrd
Area-Translation
Issues concerning the translation from libclang into Biohazrd
Blocks-OpenCV
Blocks-PhysX
Concept-Correctness
Issues concerning the correctness of the translation from an ABI perspective
Concept-CppFeatures
Issues concerning unsupported C++ features
Concept-CrossPlatform
Issues concerning cross-platform support
Concept-OutputFriendliness
Issues concerning the friendliness of using the Biohazrd output
Concept-OutputUsability
Issues concerning whether or not the output from Biohazrd is actually usable
Platform-Linux
Issues specific to Linux
Platform-Windows
Issues specific to Windows
TechDebt
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 new
to allocate memory and then separately call the constructor.shouldDelete
parameter 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 meanT
cannot 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()
/using
makes 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
using
for 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
The text was updated successfully, but these errors were encountered: