[C++-sig] Re: Converting CString to/from std::string
Martin Blais
blais at iro.umontreal.ca
Wed Sep 24 23:11:20 CEST 2003
David Abrahams wrote:
> Martin Blais <blais at iro.umontreal.ca> writes:
>
>
> It's an interesting interface, the idea of using member function
> specialization to provide the functionality. The downside is that a
> failure to implement the member functions shows up only at runtime.
> If you left out the default implementations, you could get it to fail
> at link time, but I'd much rather see a solution that fails at compile
> time. It's easy enough to do.
well, the fact is you have a choice to specialize the method that uses
PyObject* or the one that uses/returns boost::python::object. whichever
one you decide to use the other one has to be defined (even if not
called i think, iirc that's a compiler-dependent behaviour, not sure).
> Another minor issue is that your converters force you to register
> conversions in both directions (not always desired), and only handle
> rvalue from-python conversions. That may be what most people want,
> most of the time... though I'm not sure.
i assumed that for that you would use the code you provide. i wonder if
we could split in two base classes and mixin.
> Well, it's got at least one serious problem:
>
>
>>template <class T>
>>void AutoConverter<T>::construct(
>> PyObject* obj_ptr,
>> python::converter::rvalue_from_python_stage1_data* data
>>)
>>{
>> // This should be exception-safe if the conversion fails (i.e. auto_ptr will
>> // take care of freeing memory.
>> std::auto_ptr<char> storage(
>> reinterpret_cast< python::converter::rvalue_from_python_storage<T>* >(
>> data
>> )->storage.bytes
>> );
>
>
> This whole statement is just wrong. You shouldn't be using
> reinterpret_cast (static_cast through void* or plain-old C-style cast
> will do) and you *definitely* shouldn't be trying to manage that
> memory with an auto_ptr. It's owned elsewhere.
you're so totally right, i screwed up, somehow i got into thinking about
the in-place allocation later on and i was mentally adding a call to a
user-provided function, thinking, it might raise an exception. (and i
had not written a test for the case where it fails yet).
thanks for your comments! :-)
cheers,
More information about the Cplusplus-sig
mailing list