[xsde-users] variable length member : suggestion for "_present
(bool x)" methods
Ivan Le Lann
ivan.lelann at free.fr
Fri Sep 10 10:22:45 EDT 2010
Hi Boris,
I hope I do not bother you with all my comments!
----- "Boris Kolpackov" <boris at codesynthesis.com> a écrit :
>
> Two problems with this suggestion:
>
> 1. When exceptions are disabled
I definitely overlooked the exception point.
"_present (bool)" could be switch to void/error, but that's quite ugly.
> 2. The more serious problem is the fact that the newly created object
> (bar in the code above) is itself uninitialized. Since it is var-
> length, it will most likely contain members that need
> initialization
> (e.g., a string member when STL is disabled). So the patch only
> postpones the problem for a little while:
>
> f.bar ().baz (); // ok
> f.bar ().baz ().str () // segfault
>
Please let me stress that my point is not to avoid all segfaults.
It is to be able to write the same code for fix/var elements,
as much as possible.
I am focusing on "_present" but as you suggest,
there might be other harder cases to harmonize, like simple accessors.
While "_prevent(false)" is ok, since it deallocates on non-null pointer,
"_present(true)" is not since it does not allocate on null pointer .
Two solutions to adapt my suggestion :
1) change the return type of _present(bool) to void/error
2) isolate new behavior in a "void/error _check_present()"
>Maybe not generate _present(bool) for var-length members at all?
You don't end with var/fix independant code, but at least,
this is compile time error. I consider it a better way.
This is the exact opposite of what I suggested, though! :-D
As for elements accessors without "_present" flag,
I indeed see no obvious solution that would fit with "no exception" support.
Ivan
More information about the xsde-users
mailing list