From: Dean M. B. <mik...@gm...> - 2011-02-01 22:28:04
|
On Wed, Feb 2, 2011 at 6:21 AM, Nelson, Erik - 2 <eri...@ba...> wrote: > Dean wrote: >> >> Why is copying into a string a problem in the first place? >> > > It's not... you were talking about the extensively documented problem of sending binary as 7-bit clear on the internet- that seems unrelated to whether or not the netlib container is a std::string or something else. > Right, so why are we talking about this again? :D > >> >>>> Erik wrote: >>>>> auto_ptr<MyObject> obj(new MyObject); >>>>> response << body(obj); > > Dean wrote: >> >> Uh oh, this is dangerous because the user can use the obj right >> after the data is passed to the response. > > Erik wrote: >>> Nope- the auto_ptr will be cleared when the ownership transfers to >>> the response, right? > > > Dean wrote: >> Well, after the `response << body(obj)` line, obj is still accessible >> to the user. It's not guaranteed that the user will do this line at >> the end of the handler body. > > Not so. obj is not accessible if ownership has been transferred to the response. Two auto_ptrs can't refer to the same object. > See this code: std::auto_ptr<Foo> f(new Foo); response << body(f); // which would never happen, if I can do anything about it... ;) f->bar(); // and here you get a segfault and angry users. ;) Which is exactly what I want to avoid if I can help it. :) -- Dean Michael Berris about.me/deanberris |