about summary refs log tree commit diff
path: root/src/rustllvm/ExecutionEngineWrapper.cpp
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-06-14 22:46:50 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2014-06-29 21:15:26 +1000
commit2c9aada10cd9146138d76d182ccbd2a7627df204 (patch)
treeaaccf0ce04070f2b8cea5856ae6c3f81fb1f0dd0 /src/rustllvm/ExecutionEngineWrapper.cpp
parent6a3695d54f14491c39da7910082df9ba9c833b37 (diff)
downloadrust-2c9aada10cd9146138d76d182ccbd2a7627df204.tar.gz
rust-2c9aada10cd9146138d76d182ccbd2a7627df204.zip
c_str: add `.as_ptr` & `.as_mut_ptr` to replace `.with_[mut_]ref`.
These forms return the pointer directly, rather than the added
indirection, indentation, and inefficiencies of the closures in
`.with_ref` and `.with_mut_ref`. The two closure functions are
deprecated.

Replace

    foo(c_str.with_ref(|p| p))

    c_str.with_ref(|p| {
        foo(p);
        bar(p);
    })

with

    foo(c_str.as_ptr())

    let p = c_str.as_ptr();
    foo(p);
    bar(p);

This change does mean that one has to be careful to avoid writing `let p
= x.to_c_str().as_ptr();` since the `CString` will be freed at the end
of the statement. Previously, `with_ref` was used (and `as_ptr` avoided)
for this reason, but Rust has strongly moved away from closures to more
RAII-style code, and most uses of `.with_ref` where in the form
`.with_ref(|p| p)` anyway, that is, they were exactly `.as_ptr`.

[breaking-change]
Diffstat (limited to 'src/rustllvm/ExecutionEngineWrapper.cpp')
0 files changed, 0 insertions, 0 deletions