|
Boost Users : |
Subject: Re: [Boost-users] revisiting casting a boost::shared_ptr to void*
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2014-07-30 03:23:45
On Wed, Jul 30, 2014 at 5:32 AM, Chris Cleeland <chris.cleeland_at_[hidden]>
wrote:
> In my case, the C API is stashing the value of the pointer in a container,
> and passing that pointer value as an argument to the registered callback
> function. That's it. The C code doesn't *do* anything with the pointer
> because it treats it as a void*.
>
Then it's a badly-designed C API I'm afraid...
SQLite introduced a bunch of _v2 APIs (e.g. [1]) specifically to add a
void(*xDestroy)(void*)
argument to some of its functions taking a void* user-data argument, to
address lifetime issues. That's C programming done right, which interfaces
just fine with C++ and shared_ptr and co.
The fact that one programs and designs APIs in C doesn't mean one shouldn't
care about lifetimes. My $0.02. --DD
[1] http://www.sqlite.org/capi3ref.html#sqlite3_create_module
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net