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

No-arg Ptr constructor. #30919

Merged
merged 4 commits into from
Feb 16, 2019
Merged

No-arg Ptr constructor. #30919

merged 4 commits into from
Feb 16, 2019

Conversation

malmaud
Copy link
Contributor

@malmaud malmaud commented Jan 31, 2019

Lets you write e.g. Ptr{Cvoid}() as a shorthand for Ptr{Cvoid}(0). Nice for when you're creating a bunch of pointers you're going to pass as references to C libraries to set so you don't care about the initial value.

base/boot.jl Outdated Show resolved Hide resolved
@ararslan ararslan added needs tests Unit tests are required for this change needs docs Documentation for this change is required needs news A NEWS entry is required for this change labels Jan 31, 2019
@maleadt
Copy link
Member

maleadt commented Feb 1, 2019

Nice for when you're creating a bunch of pointers you're going to pass as references to C libraries to set so you don't care about the initial value.

Isn't that what Ref is for? ie. Ref{T}()

@malmaud
Copy link
Contributor Author

malmaud commented Feb 1, 2019

I wanted to call a C function that sets an array of pointers,

ptrs_out = [Ptr{Cvoid}() for _ in 1:10]
ccall(..., (Ptr{Cvoid},), ptrs_out)

Even if there's a different way of doing that, it still seems to sensible to default pointers to C_NULL, doesn't it?

@ararslan
Copy link
Member

ararslan commented Feb 4, 2019

Looks like you'll need to rebase on master.

@ararslan ararslan removed needs docs Documentation for this change is required needs news A NEWS entry is required for this change needs tests Unit tests are required for this change labels Feb 4, 2019
@@ -8,6 +8,13 @@ memory is actually valid, or that it actually represents data of the specified t
"""
Ptr

"""
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fredrikekre should this have a compat annotation?

@fredrikekre fredrikekre added the needs compat annotation Add !!! compat "Julia x.y" to the docstring label Feb 17, 2019
@fredrikekre
Copy link
Member

Seems like this is causing

WARNING: Method definition (::Type{Ptr{T}})() where {T} in module Compiler at pointer.jl:16 overwritten in module Base at pointer.jl:16.

during sysimg build time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs compat annotation Add !!! compat "Julia x.y" to the docstring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants