[C++-sig] using object constructor

Dave Hawkes daveh at cadlink.com
Fri Jun 21 19:56:35 CEST 2002


I noticed that new object class instances are usually created from function
returns with code like this:

    return
object((object::new_pyobject_reference*)PyObject_GetItem(target.ptr().get(),
key.ptr().get()));

The new_pyobject_reference is an incomplete class which seems to be used
just to prevent a raw PyObject* being used in the construction of an object.

If we want to start wrapping a significant number of functions to return
objects is this the best way to do it as it seems inherently unsafe as
almost any type of pointer return could be cast in this way.

Is there any reason why a new template class like borrowed but called
(possibly) new_pyobject was not used? That way we could get some additional
type safety from using new_pyobject<PyObject*> in the constructor definition
akin to the existing borrowed/null_ok definitions.

Thanks
Dave Hawkes










More information about the Cplusplus-sig mailing list