Remove code example

Undefined Behaviour
This commit is contained in:
pCYSl5EDgo 2023-03-13 21:31:41 +09:00 committed by GitHub
parent 5bb58158e6
commit e52c1ed45e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -902,48 +902,10 @@ csbindgen silently skips over any method with a non-generatable type. If you bui
Non-Generatable method: C variadic/variable arguments method Non-Generatable method: C variadic/variable arguments method
--- ---
csbindgen ignores C's variadic arguments because this feature is not stable both in C# and Rust. csbindgen doesn't handle C's variadic arguments, which causes undefined behaviors, because this feature is not stable both in C# and Rust.
There is a `__arglist` keyword for C's variadic arguments in C#. [`__arglist` has many problems except Windows environment.](https://github.com/dotnet/runtime/issues/48796) There is a `__arglist` keyword for C's variadic arguments in C#. [`__arglist` has many problems except Windows environment.](https://github.com/dotnet/runtime/issues/48796)
[There is an issue about C's variadic arguments in Rust.](https://github.com/rust-lang/rust/issues/44930) [There is an issue about C's variadic arguments in Rust.](https://github.com/rust-lang/rust/issues/44930)
```rust
extern "C"
{
pub fn use_varargs(a: VariableArgContainer);
pub fn add(left: usize, right: usize) -> usize;
pub fn add_varargs(left: usize, right: usize, ...) -> usize;
}
#[repr(C)]
pub struct VariableArgContainer {
pub add_varargs: extern "C" fn(left: usize, right: usize, ...) -> usize,
pub y: usize
}
```
```csharp
public static unsafe partial class NativeMethods
{
const string __DllName = "lib";
[DllImport(__DllName, EntryPoint = "use_varargs", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void use_varargs(VariableArgContainer a);
[DllImport(__DllName, EntryPoint = "add", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint add(nuint left, nuint right);
[DllImport(__DllName, EntryPoint = "add_varargs", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint add_varargs(nuint left, nuint right);
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct VariableArgContainer
{
public delegate* unmanaged[Cdecl]<nuint, nuint, nuint> add_varargs;
public nuint y;
}
```
License License
--- ---
This library is licensed under the MIT License. This library is licensed under the MIT License.