From c42242de8c5f3b98dfcfda74463e2e2bce0f47f1 Mon Sep 17 00:00:00 2001 From: freemin7 <25376460+freemin7@users.noreply.github.com> Date: Wed, 4 Jun 2025 23:49:13 +0200 Subject: [PATCH 1/6] If someone hacks on pointers they likely want to know that It took me a while to figure out how to do this and wished it would be documented here or in a similar place. --- base/pointer.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/base/pointer.jl b/base/pointer.jl index 72c567eaf2a85..4883b89b7e2fa 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -3,8 +3,9 @@ """ Ptr{T} -A memory address referring to data of type `T`. However, there is no guarantee that the -memory is actually valid, or that it actually represents data of the specified type. +A memory address referring to data of type `T`. Use [`reinterpret`](@ref) to get a pointer +with the same address but a different type. There is no guarantee that the memory is +actually valid, or that it actually represents data of the specified type. """ Ptr From 389aa6d3269af1106f758d9ff41ae78d23a0ce11 Mon Sep 17 00:00:00 2001 From: freemin7 <25376460+freemin7@users.noreply.github.com> Date: Wed, 4 Jun 2025 23:55:23 +0200 Subject: [PATCH 2/6] strip access white space --- base/pointer.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/pointer.jl b/base/pointer.jl index 4883b89b7e2fa..d37bfb67add44 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -4,8 +4,8 @@ Ptr{T} A memory address referring to data of type `T`. Use [`reinterpret`](@ref) to get a pointer -with the same address but a different type. There is no guarantee that the memory is -actually valid, or that it actually represents data of the specified type. +with the same address but a different type. There is no guarantee that the memory is +actually valid, or that it actually represents data of the specified type. """ Ptr From 3ffd9c320a2f7df71effdd9cd1e172411ef943b1 Mon Sep 17 00:00:00 2001 From: freemin7 <25376460+freemin7@users.noreply.github.com> Date: Fri, 6 Jun 2025 12:53:58 +0200 Subject: [PATCH 3/6] Elaborate on role of T in pointer type This information is based on a conversation in the Julia Slack internals channel. --- base/pointer.jl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/base/pointer.jl b/base/pointer.jl index d37bfb67add44..be2b081bf5ac2 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -3,9 +3,16 @@ """ Ptr{T} -A memory address referring to data of type `T`. Use [`reinterpret`](@ref) to get a pointer -with the same address but a different type. There is no guarantee that the memory is -actually valid, or that it actually represents data of the specified type. +A memory address referring to data of type `T`. However there is no guarantee that the +memory is actually valid, or that it actually represents data of the specified type. +Some operations like [`unsafe_load`](@ref) are only supported when T is an [`isbitstype`](@ref) +while [`unsafe_wrap`](@ref) also supports abstract types. +Use [`reinterpret`](@ref) to get a pointer with the same address but a different type. + +!!! warn + When T is an [`Union`](@ref) type, the pointer does not contain the necessary information + to reconstruct what elements in the array had which type. Such pointers can't be use to + retrieve any Julia objects. """ Ptr From 96b09dfded75993d53465298bdaa93a303ce70d1 Mon Sep 17 00:00:00 2001 From: freemin7 <25376460+freemin7@users.noreply.github.com> Date: Fri, 6 Jun 2025 20:31:24 +0200 Subject: [PATCH 4/6] Grammar tweak Co-authored-by: Lilith Orion Hafner --- base/pointer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/pointer.jl b/base/pointer.jl index be2b081bf5ac2..dd9815f04a64d 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -10,7 +10,7 @@ while [`unsafe_wrap`](@ref) also supports abstract types. Use [`reinterpret`](@ref) to get a pointer with the same address but a different type. !!! warn - When T is an [`Union`](@ref) type, the pointer does not contain the necessary information + When T is a [`Union`](@ref) type, the pointer does not contain the necessary information to reconstruct what elements in the array had which type. Such pointers can't be use to retrieve any Julia objects. """ From 7fde5bdc6b1a24a2fdc320339d45531d5aef04dd Mon Sep 17 00:00:00 2001 From: freemin7 <25376460+freemin7@users.noreply.github.com> Date: Fri, 6 Jun 2025 20:31:52 +0200 Subject: [PATCH 5/6] remove excess space Co-authored-by: Lilith Orion Hafner --- base/pointer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/pointer.jl b/base/pointer.jl index dd9815f04a64d..bf30e43e9a7f9 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -3,7 +3,7 @@ """ Ptr{T} -A memory address referring to data of type `T`. However there is no guarantee that the +A memory address referring to data of type `T`. However, there is no guarantee that the memory is actually valid, or that it actually represents data of the specified type. Some operations like [`unsafe_load`](@ref) are only supported when T is an [`isbitstype`](@ref) while [`unsafe_wrap`](@ref) also supports abstract types. From 436121d987978e4a433c1d8b24f3058190f6118a Mon Sep 17 00:00:00 2001 From: freemin7 <25376460+freemin7@users.noreply.github.com> Date: Fri, 6 Jun 2025 20:33:13 +0200 Subject: [PATCH 6/6] modify warning header Co-authored-by: Lilith Orion Hafner --- base/pointer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/pointer.jl b/base/pointer.jl index bf30e43e9a7f9..153daf2ca15a1 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -9,7 +9,7 @@ Some operations like [`unsafe_load`](@ref) are only supported when T is an [`isb while [`unsafe_wrap`](@ref) also supports abstract types. Use [`reinterpret`](@ref) to get a pointer with the same address but a different type. -!!! warn +!!! warning When T is a [`Union`](@ref) type, the pointer does not contain the necessary information to reconstruct what elements in the array had which type. Such pointers can't be use to retrieve any Julia objects.