Hacker News new | past | comments | ask | show | jobs | submit login

I think the use case for WithoutFinalise is for working with shared pointers (judging by the text).

In that case, if you're going to copy the pointer, you don't want to then free the memory, since you no longer know whether all copies have finished being used.

Having said, that, some kind of reference counting might be a safer strategy. It depends a bit on what the client code is up to.




If that's the case, I don't think it should be calling raptor_uri_copy, which allocates a whole new URI object (not just changing some reference counts). It could instead provide a "URI full_copy()" method that better models how the C API works.

Even then, it still isn't safe, because D doesn't (yet) seem to have the tools required to tie this sort of non-owning reference to the owning object, to avoid the dangling pointer problem mentioned in the article.


I'm not a D expert, but I think the raptor_uri_copy is called in dup() method of URIWithoutFinalize/URI, which is essentially the full_copy() method. The code says only URIWithoutFinalize() is shallow-copyable, and URIWithFinalize is not (see @disable this(this);).




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: