If that's not possible, isn't it typical to give the pointers an "identity" (store them in a class) to provide a GC-language with safety when wrapping a C API that seems to use a more affine/linear ownership system?
It seems to be undermining D's claims of safety if the "official" (widely published on the official blog) way to wrap C APIs is unsafe.
(Plus, at least the example code listings for the mixins, failure (returning NULL) of the C calls isn't checked.)
`URI` cannot be copied because the post-blit constructor is disabled. The default constructor is also disabled, so a "null" URI couldn't be created either.
You'll get no argument from me about not checking for failure though. Some asserts at least would be a good idea there.
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.
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.
It‘s clearly far from “official” recommendation. It’s more “an experience of one user” that can also be scrutinized.
(Also, just to be clear, I had a typo before: wildly -> widely.)
A blog entry with an experience of one user is just a blog entry with an experience of one user, and has exactly that much relevance, no matter where it is hosted. Where do you see that it was "peer reviewed" or that it is somehow or somewhere claimed to be a "recommended way" for anything at all?
You surely can't interpret your own belief (which is wrong) and claim that it's an "official" recommendation for "the way" something is to be done "in general" when writing D. It is just your own belief. You can only claim that you have subjectively and personally got that impression (that the post is more relevant than it is) but nothing more.
"Now and again, we’ll publish a post in which D users talk of their experiences with D, not about specific projects, but about the language itself. They’ll tell of things like their favorite features, why they use it, how it has changed the way they write code, or anything they’d like to say that expresses how they feel about programming in D."
Moreover, the article starts with "I initially started my research project using the Ada 2012 programming language (see my article “Experiences on Writing Ada Bindings for a C Library” in Ada User Journal, Volume 39, Number 1, March 2018)." "After some unsatisfying experiments with Java and Python, I settled on the D programming language."
It's obviously a D language beginner writing about his experiences. Showing his code. Which worked for him. Nothing wrong with that.