Created
March 2, 2018 17:36
-
-
Save wbbradley/46359327f6f9a5584714103a1192fcc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
type OwningBuffer C has | |
let raw *C | |
let length uint | |
def __finalize__(owning_buffer OwningBuffer any) | |
posix.free(owning_buffer.raw) | |
def OwningBuffer[T where T <: *?wchar](s T) (OwningBuffer wchar)? | |
return (s != null | |
? OwningBuffer(s, posix.wcslen(s)) | |
: null) | |
def OwningBuffer[T where T <: *?char](s T) (OwningBuffer char)? | |
return (s != null | |
? OwningBuffer(s, posix.strlen(s)) | |
: null) | |
def OwningBuffer(s *wchar) OwningBuffer wchar | |
return OwningBuffer(s, posix.wcslen(s)) | |
def OwningBuffer(s *char) OwningBuffer char | |
return OwningBuffer(s, posix.strlen(s)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment