review fix

This commit is contained in:
irving ou 2025-07-05 18:42:26 -04:00
parent 83da59a85e
commit b2f731cf68
4 changed files with 3 additions and 159 deletions

View file

@ -1,105 +0,0 @@
// <auto-generated/> by Diplomat
#pragma warning disable 0105
using System;
using System.Runtime.InteropServices;
using Devolutions.IronRdp.Diplomat;
#pragma warning restore 0105
namespace Devolutions.IronRdp;
#nullable enable
public partial class OptionalString: IDisposable
{
private unsafe Raw.OptionalString* _inner;
/// <summary>
/// Creates a managed <c>OptionalString</c> from a raw handle.
/// </summary>
/// <remarks>
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free).
/// <br/>
/// This constructor assumes the raw struct is allocated on Rust side.
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction.
/// </remarks>
public unsafe OptionalString(Raw.OptionalString* handle)
{
_inner = handle;
}
public bool IsSome()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("OptionalString");
}
bool retVal = Raw.OptionalString.IsSome(_inner);
return retVal;
}
}
/// <returns>
/// A <c>OptionalString</c> allocated on Rust side.
/// </returns>
public static OptionalString New(string value)
{
unsafe
{
byte[] valueBuf = DiplomatUtils.StringToUtf8(value);
nuint valueBufLength = (nuint)valueBuf.Length;
fixed (byte* valueBufPtr = valueBuf)
{
Raw.OptionalString* retVal = Raw.OptionalString.New(valueBufPtr, valueBufLength);
return new OptionalString(retVal);
}
}
}
/// <returns>
/// A <c>OptionalString</c> allocated on Rust side.
/// </returns>
public static OptionalString NewEmpty()
{
unsafe
{
Raw.OptionalString* retVal = Raw.OptionalString.NewEmpty();
return new OptionalString(retVal);
}
}
/// <summary>
/// Returns the underlying raw handle.
/// </summary>
public unsafe Raw.OptionalString* AsFFI()
{
return _inner;
}
/// <summary>
/// Destroys the underlying object immediately.
/// </summary>
public void Dispose()
{
unsafe
{
if (_inner == null)
{
return;
}
Raw.OptionalString.Destroy(_inner);
_inner = null;
GC.SuppressFinalize(this);
}
}
~OptionalString()
{
Dispose();
}
}

View file

@ -1,31 +0,0 @@
// <auto-generated/> by Diplomat
#pragma warning disable 0105
using System;
using System.Runtime.InteropServices;
using Devolutions.IronRdp.Diplomat;
#pragma warning restore 0105
namespace Devolutions.IronRdp.Raw;
#nullable enable
[StructLayout(LayoutKind.Sequential)]
public partial struct OptionalString
{
private const string NativeLib = "DevolutionsIronRdp";
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OptionalString_is_some", ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static unsafe extern bool IsSome(OptionalString* self);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OptionalString_new", ExactSpelling = true)]
public static unsafe extern OptionalString* New(byte* value, nuint valueSz);
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OptionalString_new_empty", ExactSpelling = true)]
public static unsafe extern OptionalString* NewEmpty();
[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OptionalString_destroy", ExactSpelling = true)]
public static unsafe extern void Destroy(OptionalString* self);
}

View file

@ -53,6 +53,9 @@ namespace Devolutions.IronRdp.src
public override void Flush()
{
// No need. the third parameter of SendAsync is set to true, which means the frame is sent immediately.
// Also, this method is not called in practice ever somehow.
// However, since it's not blocking any functionality, we can leave it empty.
}
// Not supported

View file

@ -102,27 +102,4 @@ pub mod ffi {
self.0.ok_or_else(|| "value is None".into())
}
}
#[diplomat::opaque]
pub struct OptionalString(pub(crate) Option<String>);
impl OptionalString {
pub fn is_some(&self) -> bool {
self.0.is_some()
}
pub fn new(value: &str) -> Box<OptionalString> {
Box::new(OptionalString(Some(value.to_owned())))
}
pub fn new_empty() -> Box<OptionalString> {
Box::new(OptionalString(None))
}
}
}
impl From<&ffi::OptionalString> for Option<String> {
fn from(value: &ffi::OptionalString) -> Self {
value.0.clone()
}
}