Skip to content

Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs #89463

Open

Description

@jtschuster

Marshal structs (which managed the out value) should be freed in the catch block if the method will return failure. Unmarshal structs (which manage the in value) should free in the assign out stage.

Activity

  1. ghost added
    untriaged
    on Jul 25, 2023
  2. self-assigned this
    on Jul 25, 2023
  3. removed
    untriaged
    on Jul 25, 2023
  4. changed the title [-]Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs. Marshal structs (which managed the out value) should be freed in the catch block if the method will return failure. Unmarshal structs (which manage the in value) should free in the assign out stage.[/-] [+]Different marshaller structs should be used for unmarshalling and marshalling elements in UnmanagedToManaged stubs[/+] on Jul 25, 2023
  5. jkoritzinsky commented on Jul 25, 2023

    @jkoritzinsky
    Member

    Using different stateful marshaller instances in the UnmanagedToManagedRef case concerns me a little bit, as that's a significant change in design. In particular, sometimes it's important to have the same unmanaged value returned (like a pointer to an object) if the managed object hasn't changed. The inverse scenario (ManagedToUnmanagedRef) definitely has this case for SafeHandles. I think we should (if possible) require marshaller authors to handle this scenario for UnmanagedToManagedRef-mode marshallers instead of using separate instances for the in and out.

    I could see a use case in saying "If there is no *Ref marshaller defined and no default, we will use the *In and *Out marshallers to provide the marshalling and handle the lifetime," but that would definitely be .NET 9 work.

  6. ghost added
    untriaged
    on Aug 3, 2023
  7. added this to the 9.0.0 milestone on Aug 3, 2023
  8. ghost removed
    untriaged
    on Aug 3, 2023
  9. modified the milestones: 9.0.0, Future on Aug 19, 2024
  10. dotnet-policy-service commented on Apr 13, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    No status

Relationships

None yet

Development

No branches or pull requests

Issue actions