Git Product home page Git Product logo

Comments (2)

rodrigocfd avatar rodrigocfd commented on June 18, 2024

WinSafe is designed to be interoperable with other libraries, so it has many escape hatches, like Handle::ptr and LocalFreeGuard::new. Indeed, I wrote that they are not meant to be used externally, but maybe it's an overconservative comment, because they can – that's why they're all pub. They must be unsafe, however, since they can easily trigger UB.

In your specific case, you can construct the HLOCAL and store the guard like this:

use winsafe::{self as w, prelude::*};

let pp: *mut std::ffi::c_void; // initialized somewhere

let my_handle = unsafe { w::HLOCAL::from_ptr(pp) };
let my_guard = unsafe { w::guard::LocalFreeGuard::new(my_handle) };

Or, if you just need to call LocalFree immediately:

use winsafe::{self as w, prelude::*};

let pp: *mut std::ffi::c_void; // initialized somewhere

let _ = unsafe { w::guard::LocalFreeGuard::new(w::HLOCAL::from_ptr(pp)) };

I will review the docs, and make it explicit that you can use those stuff to interop with other libraries.

Is this OK?

from winsafe.

Hawk777 avatar Hawk777 commented on June 18, 2024

Yeah, it’s just the comment that I was concerned about. I’m already doing exactly what you suggested in your first example. I agree that new should be unsafe. Thanks!

from winsafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.