Bug 1440207 - Part 5: Disable UniqueFileHandle for RUST_BINDGEN, r=emilio,glandium

Apparently rust bindgen uses a hack which assumes all specializations of
`UniquePtr` have the basic layout and use a pointer member with an empty
deleter.

This incorrect assumption unfortunately comes up for UniqueFileHandle,
which replaces the pointer type using the deleter with a file handle
helper type.

As this fails to build with RUST_BINDGEN, this patch takes the same
approach as bug 1802320, and just disables building these types when
building headers for bindgen.

This does not fix the general issue of bindgen making incorrect
assumptions about the layout of UniquePtr with non-default deleters.
Ideally, all non-default deleters should be made opaque.

Differential Revision: https://phabricator.services.mozilla.com/D223628
This commit is contained in:
Nika Layzell
2024-10-01 22:21:52 +00:00
parent 8c8d95ef61
commit 46df2b8625

View File

@@ -93,6 +93,7 @@ struct FreePolicy {
void operator()(const void* ptr) { free(const_cast<void*>(ptr)); }
};
#if !defined(RUST_BINDGEN)
# if defined(XP_WIN)
// Can't include <windows.h> to get the actual definition of HANDLE
// because of namespace pollution.
@@ -162,6 +163,7 @@ struct FileHandleDeleter {
using receiver = FileHandleType;
MFBT_API void operator()(FileHandleHelper aHelper);
};
#endif
#if defined(XP_DARWIN) && !defined(RUST_BINDGEN)
struct MachPortHelper {
@@ -215,6 +217,7 @@ struct MachPortSetDeleter {
template <typename T>
using UniqueFreePtr = UniquePtr<T, detail::FreePolicy<T>>;
#if !defined(RUST_BINDGEN)
// A RAII class for the OS construct used for open files and similar
// objects: a file descriptor on Unix or a handle on Windows.
using UniqueFileHandle =
@@ -227,6 +230,7 @@ inline UniqueFileHandle DuplicateFileHandle(const UniqueFileHandle& aFile) {
return DuplicateFileHandle(aFile.get());
}
# endif
#endif
#if defined(XP_DARWIN) && !defined(RUST_BINDGEN)
// A RAII class for a Mach port that names a send right.