# How to undo \`unsafe\_string\` call

**URL:** https://discourse.julialang.org/t/how-to-undo-unsafe-string-call/130605
**Category:** General Usage
**Tags:** performance, strings
**Created:** [July 10, 2025, 11:30am UTC](https://discourse.julialang.org/t/how-to-undo-unsafe-string-call/130605 "2025-07-10T11:30:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)
#### Post date: [July 10, 2025, 11:30am UTC](https://discourse.julialang.org/t/how-to-undo-unsafe-string-call/130605/1 "2025-07-10T11:30:36Z")

</div>

I’m using a library (Instruments.jl) that does a bunch of `ccall`s to return a string.  
It does this by calling `unsafe_string(pointer(buf)) where buf isa Vector{UInt8}`.

Can I undo this call to `unsafe_string` to just get the `Vector{UInt8}` back?

I want to do this because the string is actually data that I want to `reinterpret`, so I really just want a way to `reinterpret` a string, since

```julia
julia> reinterpret(Float32, "asdf")
ERROR: ArgumentError: Source type for `reinterpret` must be isbits

```

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 10, 2025, 11:57am UTC](https://discourse.julialang.org/t/how-to-undo-unsafe-string-call/130605/2 "2025-07-10T11:57:09Z")

</div>

```julia
julia> s = "foo"
"foo"

julia> codeunits(s)
3-element Base.CodeUnits{UInt8, String}:
 0x66
 0x6f
 0x6f

```

might be what you want. Or something else depending on what you have available (like `unsafe_wrap`)
