Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

voidptr should be an unmanaged type #11424

Closed
krauthaufen opened this issue Apr 13, 2021 · 8 comments
Closed

voidptr should be an unmanaged type #11424

krauthaufen opened this issue Apr 13, 2021 · 8 comments
Labels
Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.

Comments

@krauthaufen
Copy link
Contributor

Currently F# does not treat voidptr as an unmanaged type.
Therefore types like nativeptr<voidptr>, etc. cause compiler errors.

However on IL level this works and C# libraries (e.g. Silk.NET.OpenGL) expose methods expecting this kind of argument (which currently can't be created in F# due the above)

Expected behavior

voidptr should be treated as an unmanaged type

Known workarounds

Sadly I couldn't come up with a workaround. If anyone has an idea I would be glad to hear it!

Related information

Tested on VS2019 with .NET5 and FSharp.Core 5.0.0

@zpodlovics
Copy link

The base library pointer types (e.g.: System.Int32*) including System.Void* are not a value types. So it seems that void** functionality is not yet available (as of dotnet/runtime#44968)

> System.Type.GetType("System.Int32*").IsValueType;;
val it : bool = false
> System.Type.GetType("System.Void*").IsValueType;;
val it : bool = false

however System.IntPtr is:

> System.Type.GetType("System.IntPtr").IsValueType;;
val it : bool = true

@krauthaufen
Copy link
Contributor Author

In F# nativeptr<int> is treated as an unmanaged type and i have a C# library here exposing a void** so this can't be entirely true...

@zpodlovics
Copy link

zpodlovics commented Apr 17, 2021

nativeptr is just s syntactic sugar around System.IntPtr (nativeint). What is missing is the System.Void (notice there is no pointer at the end) aka the void type in F#. However the integration will be challenging due the unit type mapping / overlap (e.g.: chkSystemVoidOnlyInTypeof does not seems to be accidental as it will allow only the typeof<System.Void> usage).

> typeof<nativeptr<int>>.FullName;;
val it : string = "System.IntPtr"
> typeof<System.Void>.IsValueType;;    
val it : bool = true

@krauthaufen
Copy link
Contributor Author

Okay then maybe just allow nativeptr<voidptr> (and still not allowing voidptr inside unmanaged structs/etc.) since it gets compiled to nativeint anyways? The Problem I'm currently facing is actually quite severe since there is a C# method I simply can't invoke from F# (expecting a nativeptr<voidptr>)
Any thoughts?

@zpodlovics
Copy link

You can always store an untyped pointer (nativeint) in the struct and have some helper methods / functions to map it to a proper type (worst case scenario is to call for an C# helper). What is the C# signature that you want to call (you can use simplified struct and some generic names)?

@krauthaufen
Copy link
Contributor Author

I didn't look at the source yet but the F# type hover shows me a nativeptr<voidptr> which seems to be impossible to produce from F#

@krauthaufen
Copy link
Contributor Author

I can certainly work around that using a micro C# library but nonetheless it would be great to see that fixed somewhen...
What's really ironic is, that I only want to pass a null pointer 😜

@KevinRansom KevinRansom added the Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. label Jul 14, 2021
@dsyme
Copy link
Contributor

dsyme commented Mar 3, 2022

This is by design for F# 6, so perhaps add a language suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
None yet
Development

No branches or pull requests

4 participants