Skip to content

Commit

Permalink
made base grammar visible
Browse files Browse the repository at this point in the history
made changes in singleton.hpp to address running issue regarding test_dll_exported
fixed integer overflow so that UBAN tests pass
  • Loading branch information
robertramey committed Oct 12, 2018
1 parent 28c333c commit e1893dd
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 24 deletions.
6 changes: 2 additions & 4 deletions include/boost/archive/detail/iserializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ class iserializer : public basic_iserializer
virtual void destroy(/*const*/ void *address) const {
boost::serialization::access::destroy(static_cast<T *>(address));
}
protected:
// protected constructor since it's always created by singleton
public:
explicit iserializer() :
basic_iserializer(
boost::serialization::singleton<
Expand All @@ -133,7 +132,6 @@ class iserializer : public basic_iserializer
>::get_const_instance()
)
{}
public:
virtual BOOST_DLLEXPORT void load_object_data(
basic_iarchive & ar,
void *x,
Expand Down Expand Up @@ -307,7 +305,7 @@ class pointer_iserializer :
void * x,
const unsigned int file_version
) const BOOST_USED;
protected:
public:
// this should alway be a singleton so make the constructor protected
pointer_iserializer();
~pointer_iserializer();
Expand Down
2 changes: 1 addition & 1 deletion include/boost/archive/impl/basic_xml_grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace archive {
// XML grammar parsing

template<class CharType>
class basic_xml_grammar {
class BOOST_SYMBOL_VISIBLE basic_xml_grammar {
public:
// The following is not necessary according to DR45, but at least
// one compiler (Compaq C++ 6.5 in strict_ansi mode) chokes otherwise.
Expand Down
30 changes: 16 additions & 14 deletions include/boost/serialization/singleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,37 @@ class BOOST_SYMBOL_VISIBLE singleton_module :
public boost::noncopyable
{
private:
BOOST_DLLEXPORT static bool & get_lock() BOOST_USED {
BOOST_DLLEXPORT bool & get_lock() BOOST_USED {
static bool lock = false;
return lock;
}

public:
BOOST_DLLEXPORT static void lock(){
BOOST_DLLEXPORT void lock(){
get_lock() = true;
}
BOOST_DLLEXPORT static void unlock(){
BOOST_DLLEXPORT void unlock(){
get_lock() = false;
}
BOOST_DLLEXPORT static bool is_locked(){
BOOST_DLLEXPORT bool is_locked(){
return get_lock();
}
};

static inline singleton_module & get_singleton_module(){
static singleton_module m;
return m;
}

template <class T>
class singleton : public singleton_module
{
class singleton {
private:
// note presumption that T has a default constructor
static T & m_instance;
// include this to provoke instantiation at pre-execution time
static void use(T const *) {}
static void use(T const &) {}
static T & get_instance() {
// use a wrapper so that types T with protected constructors
// can be used
class singleton_wrapper : public T {};
static singleton_wrapper t;
static T t;

// refer to instance, causing it to be instantiated (and
// initialized at startup on working compilers)
Expand All @@ -130,18 +132,18 @@ class singleton : public singleton_module
// construct the instance at pre-execution time. This would prevent
// our usage/implementation of "locking" and introduce uncertainty into
// the sequence of object initializaition.
use(& m_instance);
use(m_instance);

return static_cast<T &>(t);
}

static bool & get_is_destroyed(){
static bool is_destroyed;
return is_destroyed;
}

public:
BOOST_DLLEXPORT static T & get_mutable_instance(){
BOOST_ASSERT(! is_locked());
BOOST_ASSERT(! get_singleton_module().is_locked());
return get_instance();
}
BOOST_DLLEXPORT static const T & get_const_instance(){
Expand Down
4 changes: 2 additions & 2 deletions test/A.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ A_DLL_DECL
A::A() :
b(true),
#ifndef BOOST_NO_INT64_T
f(std::rand() * std::rand()),
g(std::rand() * std::rand()),
f(static_cast<boost::int64_t>(std::rand()) * static_cast<boost::int64_t>(std::rand())),
g(static_cast<boost::uint64_t>(std::rand()) * static_cast<boost::uint64_t>(std::rand())),
#endif
l(static_cast<enum h>(std::rand() % 3)),
m(std::rand()),
Expand Down
4 changes: 2 additions & 2 deletions test/test_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ int test_main(int argc, char * argv[]);

int
main(int argc, char * argv[]){
boost::serialization::singleton_module::lock();
boost::serialization::get_singleton_module().lock();

int retval = 1;
BOOST_TRY{
Expand All @@ -209,7 +209,7 @@ main(int argc, char * argv[]){
}
BOOST_CATCH_END

boost::serialization::singleton_module::unlock();
boost::serialization::get_singleton_module().unlock();

int error_count = boost::report_errors();
if(error_count > 0)
Expand Down
85 changes: 84 additions & 1 deletion test/test_z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,92 @@ void f()
ar >> out;
}

int main(int argc, char* argv[])
{
return 0;
}

#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/detail/archive_serializer_map.hpp>
#include <boost/archive/impl/archive_serializer_map.ipp>
#include <boost/archive/impl/basic_xml_iarchive.ipp>
#include <boost/archive/impl/xml_iarchive_impl.ipp>
#include <boost/serialization/nvp.hpp>
#include <limits>
#include <fstream>

class xml_iarchive_nan :
public boost::archive::xml_iarchive_impl<xml_iarchive_nan>
{
protected:
friend class boost::archive::detail::interface_iarchive<xml_iarchive_nan>;
friend class boost::archive::detail::common_iarchive<xml_iarchive_nan>;
friend class boost::archive::basic_xml_iarchive<xml_iarchive_nan>;
friend class boost::archive::load_access;

using boost::archive::xml_iarchive_impl<xml_iarchive_nan>::load;
void load(double & t)
{
char c='0';
if(!is.fail())
{
c=is.peek();
if(c!='n')
{
boost::archive::xml_iarchive_impl<xml_iarchive_nan>::load(t);
}
else
{
char c1='0',c2='0';
is.get(c).get(c1).get(c2);
if(is.fail()||(!((c=='n')&&(c1=='a')&&(c2=='n'))))
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::input_stream_error));
else
t=std::numeric_limits<double>::quiet_NaN();
}
}
else
boost::serialization::throw_exception(
boost::archive::archive_exception(boost::archive::archive_exception::input_stream_error));
}

public:
xml_iarchive_nan(std::istream & is, unsigned int flags = 0) :
boost::archive::xml_iarchive_impl<xml_iarchive_nan>(is, flags)
{}
~xml_iarchive_nan(){};
};

BOOST_SERIALIZATION_REGISTER_ARCHIVE(xml_iarchive_nan)

namespace boost
{
namespace archive
{
template class detail::archive_serializer_map<xml_iarchive_nan>;
template class detail::interface_iarchive<xml_iarchive_nan>;
template class detail::common_iarchive<xml_iarchive_nan>;
template class basic_xml_iarchive<xml_iarchive_nan>;
template class xml_iarchive_impl<xml_iarchive_nan>;

}
}

int main(int argc, char** argv)
{
double value=0.0;
std::ifstream ifile("./somefile.xml");
xml_iarchive_nan ia(ifile);
ia>>BOOST_SERIALIZATION_NVP(value);
}

#endif

int main(int argc, char* argv[])
{
return 0;
return 0;
}

0 comments on commit e1893dd

Please sign in to comment.