1.33 pointer to object serialization
Hi, I'm having trouble with serializing an object through a pointer to it. The code below works in 1.32, but in 1.33 it gives the errors below. I am using Mac OS X 10.4.2, gcc 4.0. I've had a look at the headers, but my template programming isn't good enough to make too much sense of them. It seems that there is a check to ensure T is not a pointer on line 549 of oserializer.hpp, which is the reason the static assert is failing? Is it correct that objects shouldn't be serializable by pointers to them, or not? Cheers Chris gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below g++ -o test test.cpp -lboost_serialization-d-1_33 /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = gps_position*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = gps_position*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = gps_position*, Archive = boost::archive::text_oarchive]' hash_test.cpp:130: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>' This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Ok, I've sice found some information on Object Tracking that suggests the Chris Coleman wrote:
Hi,
I'm having trouble with serializing an object through a pointer to it.
The code below works in 1.32, but in 1.33 it gives the errors below. I am using Mac OS X 10.4.2, gcc 4.0.
I've had a look at the headers, but my template programming isn't good enough to make too much sense of them. It seems that there is a check to ensure T is not a pointer on line 549 of oserializer.hpp, which is the reason the static assert is failing?
Is it correct that objects shouldn't be serializable by pointers to them, or not?
Cheers Chris
gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
g++ -o test test.cpp -lboost_serialization-d-1_33 /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = gps_position*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = gps_position*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = gps_position*, Archive = boost::archive::text_oarchive]' hash_test.cpp:130: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Tell me a little more about this. I presume that you've figured out what you want to do now. How did you come to a solution to your problem? Did the STATIC_ASSERT indicate some flawed code? or not? Did the information make sense. Note that I'm adding a short explanation of this situation to the manual regarding this. But the existence of the STATIC_ASSERT is still a source of disagreement. Robert Ramey Chris Coleman wrote:
Ok,
I've sice found some information on Object Tracking that suggests the
Chris Coleman wrote:
Hi,
I'm having trouble with serializing an object through a pointer to it.
The code below works in 1.32, but in 1.33 it gives the errors below. I am using Mac OS X 10.4.2, gcc 4.0.
I've had a look at the headers, but my template programming isn't good enough to make too much sense of them. It seems that there is a check to ensure T is not a pointer on line 549 of oserializer.hpp, which is the reason the static assert is failing?
Is it correct that objects shouldn't be serializable by pointers to them, or not?
Cheers Chris
gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
g++ -o test test.cpp -lboost_serialization-d-1_33 /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = gps_position*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = gps_position*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = gps_position*, Archive = boost::archive::text_oarchive]' hash_test.cpp:130: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Ok, I've since found some information on Object Tracking in another boost list that I missed previously. (apologies) This suggests the behaviour is now correct, and that 1.32 implementation was overly relaxed. As I understand it the << operator require a const reference to the object to be serialized inorder to prevent the same object being written or read, to or from an archive multiple times. So you can now no longer serialize a pointer to an object, even if its a const ptr? My solution has been to dereference the object as below, and it compiles and seems to work. However, I'm not convinced this is the correct way of doing things. oa << *memory->pull_slice(slice_id); ofs.close(); where pull_slice returns a const * to the object to be serialized. Is this best? Also, it's not really my place to say, but as a user it would probably be really useful if these changes were emphasised in the release notes or somewhere appropriate / obvious to avoid too people spamming the list with unnecessary questions as I have just done... <slopes of feeling stupid> Cheers Chris Chris Coleman wrote:
Hi,
I'm having trouble with serializing an object through a pointer to it.
The code below works in 1.32, but in 1.33 it gives the errors below. I am using Mac OS X 10.4.2, gcc 4.0.
I've had a look at the headers, but my template programming isn't good enough to make too much sense of them. It seems that there is a check to ensure T is not a pointer on line 549 of oserializer.hpp, which is the reason the static assert is failing?
Is it correct that objects shouldn't be serializable by pointers to them, or not?
Cheers Chris
gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
g++ -o test test.cpp -lboost_serialization-d-1_33 /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = gps_position*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = gps_position*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = gps_position*, Archive = boost::archive::text_oarchive]' hash_test.cpp:130: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
Why didn't your just change the above to?: const gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below Chris Coleman wrote:
Ok,
I've since found some information on Object Tracking in another boost list that I missed previously. (apologies) This suggests the behaviour is now correct, and that 1.32 implementation was overly relaxed.
As I understand it the << operator require a const reference to the object to be serialized inorder to prevent the same object being written or read, to or from an archive multiple times. So you can now no longer serialize a pointer to an object, even if its a const ptr?
My solution has been to dereference the object as below, and it compiles and seems to work. However, I'm not convinced this is the correct way of doing things.
oa << *memory->pull_slice(slice_id); ofs.close();
where pull_slice returns a const * to the object to be serialized. Is this best?
Also, it's not really my place to say, but as a user it would probably be really useful if these changes were emphasised in the release notes or somewhere appropriate / obvious to avoid too people spamming the list with unnecessary questions as I have just done... <slopes of feeling stupid>
Cheers Chris
Chris Coleman wrote:
Hi,
I'm having trouble with serializing an object through a pointer to it.
The code below works in 1.32, but in 1.33 it gives the errors below. I am using Mac OS X 10.4.2, gcc 4.0.
I've had a look at the headers, but my template programming isn't good enough to make too much sense of them. It seems that there is a check to ensure T is not a pointer on line 549 of oserializer.hpp, which is the reason the static assert is failing?
Is it correct that objects shouldn't be serializable by pointers to them, or not?
Cheers Chris
gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
g++ -o test test.cpp -lboost_serialization-d-1_33 /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = gps_position*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = gps_position*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = gps_position*, Archive = boost::archive::text_oarchive]' hash_test.cpp:130: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Robert Ramey wrote:
Why didn't your just change the above to?:
const gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
Ok, I'm obviously still missing something, because: oa << memory->pull_slice(slice_id); gives: zz_control.cpp:46: error: no match for 'operator<<' in 'oa << ((zz_memory*)((const zz_control*)this)->zz_control::memory)->zz_memory::pull_slice(slice_id)' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:84: note: candidates are: Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const zz_memory_slice*, Archive = boost::archive::text_oarchive] And: const zz_memory_slice* s = memory->pull_slice(slice_id); oa << s; gives: /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = const zz_memory_slice*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = const zz_memory_slice*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const zz_memory_slice*, Archive = boost::archive::text_oarchive]' zz_control.cpp:46: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>' Cheers Chris This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
What is zz_memory ? is it by any chance typedef for something else. Since it is a const but still being rejected, it would seem to marked "track_never". If not explicity so marked, it might be a typedef for some primitive like ? Robert Ramey Chris Coleman wrote:
Robert Ramey wrote:
Why didn't your just change the above to?:
const gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
Ok, I'm obviously still missing something, because:
oa << memory->pull_slice(slice_id);
gives:
zz_control.cpp:46: error: no match for 'operator<<' in 'oa << ((zz_memory*)((const zz_control*)this)->zz_control::memory)->zz_memory::pull_slice(slice_id)' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:84: note: candidates are: Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const zz_memory_slice*, Archive = boost::archive::text_oarchive]
And:
const zz_memory_slice* s = memory->pull_slice(slice_id); oa << s;
gives:
/usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = const zz_memory_slice*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = const zz_memory_slice*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const zz_memory_slice*, Archive = boost::archive::text_oarchive]' zz_control.cpp:46: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
Cheers Chris
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Robert Ramey wrote:
What is zz_memory ? is it by any chance typedef for something else. Since it is a const but still being rejected, it would seem to marked "track_never". If not explicity so marked, it might be a typedef for some primitive like ?
previously:
Why didn't your just change the above to?:
const gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
Ok, Going back to the gps_position example from the manual, http://www.boost.org/libs/serialization/doc/tutorial.html#simplecase If I change nothing other than what is below, then: const gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr; gives us: cqc$ g++ -o test.o -c test.cpp /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = const gps_position*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = const gps_position*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const gps_position*, Archive = boost::archive::text_oarchive]' test.cpp:43: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>' Also: gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr; and: gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << *g_ptr; Both result in a STATIC_ASSERT failure, with T = gps_position*, and gps_position respectively. The only case I can get to compile is: const gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << *g_ptr; In my code zz_memory is just a plain base class, its tracking is not changed, I have done some project wide searches for the tracking macros and none exist, however the gps example is totaly fundamental and still won't compile. Cheers Chris This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
const gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr;
Actually I believe the following will work. const gps_position * const g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr; I've come to agree although this is a correct rendition of my original intent it is a little tooooo obscure and I will look into alterhing this. Robert Ramey Chris Coleman wrote:
Robert Ramey wrote:
What is zz_memory ? is it by any chance typedef for something else. Since it is a const but still being rejected, it would seem to marked "track_never". If not explicity so marked, it might be a typedef for some primitive like ?
previously:
Why didn't your just change the above to?:
const gps_position* p_g = new gps_position(35, 59, 24.567f); oa << p_g; // causes the error's below
Ok,
Going back to the gps_position example from the manual, http://www.boost.org/libs/serialization/doc/tutorial.html#simplecase
If I change nothing other than what is below, then:
const gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr;
gives us:
cqc$ g++ -o test.o -c test.cpp /usr/local/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = const gps_position*]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = const gps_position*, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:85: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const gps_position*, Archive = boost::archive::text_oarchive]' test.cpp:43: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:560: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
Also:
gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr;
and:
gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << *g_ptr;
Both result in a STATIC_ASSERT failure, with T = gps_position*, and gps_position respectively.
The only case I can get to compile is:
const gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << *g_ptr;
In my code zz_memory is just a plain base class, its tracking is not changed, I have done some project wide searches for the tracking macros and none exist, however the gps example is totaly fundamental and still won't compile.
Cheers Chris
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Robert Ramey wrote:
Actually I believe the following will work.
const gps_position * const g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr;
Yep, thats done it. Thanks for your help. FWIW, I agree it is fairly obscure, since the obvious const * solution was my origional attempt at solving the error, and I probably wouldn't have arrived at this alone... Cheers Chris This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Actually, I've looked at this and decided that the default behavior for pointers should really be "track_never". That is addresses of addresses should not be stored. Also I'm changing the STATIC_ASSERT to a less drastic STATIC_WARNING Robert Ramey Chris Coleman wrote:
Robert Ramey wrote:
Actually I believe the following will work.
const gps_position * const g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr;
Yep, thats done it. Thanks for your help.
FWIW, I agree it is fairly obscure, since the obvious const * solution was my origional attempt at solving the error, and I probably wouldn't have arrived at this alone...
Cheers Chris
This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Robert Ramey wrote:
Actually, I've looked at this and decided that the default behavior for pointers should really be "track_never".
Err... I hope not for 1.33 release? That's a way too big change. Besides, I don't understand your motivation. Tracking pointers by default looks reasonable. - Volodya
This isn't the change that it first appears. This would mark the "address of an address" as not being tracked by default. I don't know how many people have serialized a pointer to a pointer and tracked it. It doesn't effect any of the tests and demos. Since pointers to objects are handled different than objects themselves, I expect this will only effect the library usage check. Vladimir Prus wrote:
Robert Ramey wrote:
Actually, I've looked at this and decided that the default behavior for pointers should really be "track_never".
Err... I hope not for 1.33 release? That's a way too big change. Besides, I don't understand your motivation. Tracking pointers by default looks reasonable.
- Volodya
Robert Ramey wrote:
const gps_position* g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr;
Actually I believe the following will work.
const gps_position * const g_ptr = new gps_position(35, 59, 24.567f); oa << g_ptr;
I've come to agree although this is a correct rendition of my original intent it is a little tooooo obscure and I will look into alterhing this.
Maybe, you can consider disabling the check altogether, after all? Here we have a situation where even you could not immediately figure out what's wrong. - Volodya
Hi List
I face an ugly linker error in my really simple program using boost 1.32 on
Linux SUSE9.3 and KDevelop
the line that causes the linker error is:
boost::archive::text_oarchive oa(cout);
error is:
cpptest.o(.gnu.linkonce.t._ZN5boost7archive18text_oarchive_implINS0_13text_oarchiveEED2Ev+0x51):/usr/local/include/boost/archive/text_oarchive.hpp:97:
undefined reference to
`boost::archive::basic_text_oprimitive<_STL::basic_ostream
participants (4)
-
Chris Coleman
-
Markus Ruettimann
-
Robert Ramey
-
Vladimir Prus