Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #423

Merged
merged 18 commits into from
Nov 20, 2017
Merged

Develop #423

merged 18 commits into from
Nov 20, 2017

Conversation

WSoptics
Copy link
Contributor

The second commit fixes many compiler warnings that GCC and Clang give when compiling with -Wconversion and -Wdocumentation.

@WSoptics
Copy link
Contributor Author

The third commit makes sure the specialization for std::vector<bool> is selected even when XMLInputArchive is used, for example, and uses copies in the range-based for loops since that's what std::vector<bool> returns.

@AzothAmmo
Copy link
Contributor

This is in addition to the feedback presented in #418, since these PRs seem to be related. This PR is against the develop branch so you can disregard that comment.

Since one of our targets is MSVC 2013, we can't use noexcept in general. We have a macro defined in cereal/macros.hpp that appropriately replaces noexcept when available, called CEREAL_NOEXCEPT.

@WSoptics
Copy link
Contributor Author

Thank you for your helpful feedback! I don't understand the last comment, we didn't add any noexcept, did we? Or do you mean we should have at some point?

@WSoptics
Copy link
Contributor Author

WSoptics commented Aug 11, 2017

@AzothAmmo I tried removing the unnecessary copies altogether and use std::move when appropriate in 1947a96. I'll rebase when everything is in order.

@WSoptics
Copy link
Contributor Author

Ah never mind, the noexcept was hidden in rapidxml.hpp :) I fixed it. Let's see what the AppVeyor build now says.

@AzothAmmo
Copy link
Contributor

I'll review this and likely merge either this weekend or early next week, pushing out a small release shortly thereafter with the other develop changes.

@WSoptics
Copy link
Contributor Author

Awesome, thank you!

@WSoptics
Copy link
Contributor Author

I added unit tests for shared_ptr<const T>.

Furthermore, I noticed std::unique_ptr<const T> suffered from the same problem. I added both unit tests and a fix for it. However, I believe the case of the user provided load_andor_construct is not tested. Since I don't know what this actually is, I do not feel competent to add a test.

@WSoptics
Copy link
Contributor Author

OK, one more thing that I noticed: std::decay was wrong here anyway. It would turn a std::shared_ptr<T*> into std::shared_ptr<T>. I fixed it to use std::remove_const, which I believe to be correct. I think now things look good.

@erichkeane
Copy link
Contributor

Are you sure you don't mean std::remove_cv instead of std::remove_const?

@WSoptics
Copy link
Contributor Author

I am not sure why volatile would have to be removed, but maybe I am missing something.

@erichkeane
Copy link
Contributor

std::decay does 3 things: Removes constant, removes volatile, and removes reference. I'm not sure why it would turn T* into T however...

I haven't looked closely at this component, but I presume that if we meant to remove const, we likely wanted to remove volatile, particularly since it has some pretty nasty performance/allocation gotchas.

@WSoptics
Copy link
Contributor Author

Sorry, I meant to write T& to T, not the pointer thing.

I am uncertain about volatile. It would seem that a user who uses volatile knows what they're doing and is aware of the adverse performance gotchas. Not sure about allocation issues though.

I'm also uncertain about removing references.

From what I can tell, boost::serialization does not remove references or volatile. However, the code is sufficiently complicated for me to be wrong here.

@erichkeane So maybe you can provide more reasoning as to why remove volatile and references.

@erichkeane
Copy link
Contributor

Ah, that makes more sense...
My biggest concern was that you switched from decay to remove_const in order to lose that T&->T conversion. I feared slightly that you were throwing the baby out with the bathwater:)

Volatile on some platforms requires different alignment requirements. Volatile in a shared_ptr requires a ton more OS loads, and hamstrings the optimizer. Additionally, we would end up generating an entirely new instance of the shared_ptr object in this case.

I'm OK either way, I just want to make sure this is a behavior change being made intentionally.

@AzothAmmo
Copy link
Contributor

Looks good overall and no errors for normal stuff with unique and shared pointers.

Testing with load_and_construct is currently not working, likely due to a type trait problem with const vs non-const.

This reminds me that this also needs to be tested with polymorphic types.

@WSoptics
Copy link
Contributor Author

@AzothAmmo will you take care of that? I am not sure what to do to be honest.

@AzothAmmo
Copy link
Contributor

Yes I'll take care of that when I merge this.

@AzothAmmo AzothAmmo added this to the v1.2.3 milestone Sep 7, 2017
@AzothAmmo
Copy link
Contributor

Still on my todo list to merge, been very busy lately; should hopefully get this done in the near future (along with anything else marked 1.2.3).

AzothAmmo added a commit that referenced this pull request Nov 6, 2017
Progress towards #448

Lots of warnings from g++7.2, these are addressed in #423 which hasn't been merged yet.
CMAKE can be cleaned up a bit - may put back in the ability to use older cmake and just throw errors as necessary,
otherwise just force people to use at least cmake 3.1
@AzothAmmo
Copy link
Contributor

Looking to merge this as a pre-req for #448. Almost have a solution for load and construct. Test case I was playing with is:

#include <fstream>
#include <iostream>
#include <cereal/cereal.hpp>
#include <cereal/access.hpp>

#include <cereal/archives/json.hpp>
#include <cereal/types/memory.hpp>

struct OneLA
{
  OneLA( int xx ) : x( xx ) {}

  int x;

  template <class Archive>
  void serialize( Archive & ar )
  { ar( x ); }

  template <class Archive, class T>
  static void load_and_construct( Archive & ar, cereal::construct<T> & construct )
  {
    int xx;
    ar( xx );
    construct( xx );
  }

  bool operator==( OneLA const & other ) const
  { return x == other.x; }
};

int main()
{
  std::stringstream ss;

  std::cerr << std::boolalpha;
  std::cerr << cereal::traits::has_member_load_and_construct<OneLA, cereal::JSONOutputArchive>::value << std::endl;
  std::cerr << cereal::traits::has_member_load_and_construct<const OneLA, cereal::JSONOutputArchive>::value << std::endl;

  {
    cereal::JSONOutputArchive ar( ss );
    auto b = std::make_shared<const OneLA>( 3 );
    ar( b );
  }

  std::cout << ss.str() << std::endl;

  {
    std::shared_ptr<const OneLA> b;

    {
      cereal::JSONInputArchive ar(ss);
      ar( b );
    }

    cereal::JSONOutputArchive ar2(std::cout);
    ar2( b );
  }
}

Requires changes in memory

-      std::shared_ptr<typename std::remove_const<T>::type> ptr(reinterpret_cast<T *>(new ST()),
-          [=]( T * t )
+      using NonConstT = typename std::remove_const<T>::type;
+      std::shared_ptr<NonConstT> ptr(reinterpret_cast<NonConstT *>(new ST()),
+          [=]( NonConstT * t )

Need to play with this more and get rid of the extra template parameter I added for load_and_contruct. Ideally we'll just strip away the const internally in all the right places.

@AzothAmmo AzothAmmo merged commit 11882b6 into USCiLab:develop Nov 20, 2017
AzothAmmo added a commit that referenced this pull request Nov 20, 2017
WSoptics pushed a commit to WSoptics/cereal that referenced this pull request Mar 15, 2018
Progress towards USCiLab#448

Lots of warnings from g++7.2, these are addressed in USCiLab#423 which hasn't been merged yet.
CMAKE can be cleaned up a bit - may put back in the ability to use older cmake and just throw errors as necessary,
otherwise just force people to use at least cmake 3.1
WSoptics pushed a commit to WSoptics/cereal that referenced this pull request Mar 23, 2018
Progress towards USCiLab#448

Lots of warnings from g++7.2, these are addressed in USCiLab#423 which hasn't been merged yet.
CMAKE can be cleaned up a bit - may put back in the ability to use older cmake and just throw errors as necessary,
otherwise just force people to use at least cmake 3.1
jrmadsen pushed a commit to jrmadsen/cereal that referenced this pull request Jul 7, 2019
Progress towards USCiLab#448

Lots of warnings from g++7.2, these are addressed in USCiLab#423 which hasn't been merged yet.
CMAKE can be cleaned up a bit - may put back in the ability to use older cmake and just throw errors as necessary,
otherwise just force people to use at least cmake 3.1
jrmadsen pushed a commit to jrmadsen/cereal that referenced this pull request Jul 7, 2019
Progress towards USCiLab#448

Lots of warnings from g++7.2, these are addressed in USCiLab#423 which hasn't been merged yet.
CMAKE can be cleaned up a bit - may put back in the ability to use older cmake and just throw errors as necessary,
otherwise just force people to use at least cmake 3.1
JerryRyan pushed a commit to JerryRyan/cereal that referenced this pull request Jan 6, 2020
Progress towards USCiLab#448

Lots of warnings from g++7.2, these are addressed in USCiLab#423 which hasn't been merged yet.
CMAKE can be cleaned up a bit - may put back in the ability to use older cmake and just throw errors as necessary,
otherwise just force people to use at least cmake 3.1
fryguy503 added a commit to wayfarershaven/server that referenced this pull request Jan 11, 2023
Cereal updated for work being done in another branch. This bump fixes some issues with the library. Tested

v1.3.1

Bug fixes and minor enhancements:
Fix typo in docs by @tankorsmash in Fix typo in docs USCiLab/cereal#597
Add MSVC 2019 to build, default ctor for static object by @AzothAmmo in Add MSVC 2019 to build, default ctor for static object USCiLab/cereal#593
Fix json.hpp compilation issue when int32_t is a long by @bblackham in Fix json.hpp compilation issue when int32_t is a long USCiLab/cereal#621
[cpp20] explicitly capture 'this' as copy by @lukaszgemborowski in [cpp20] explicitly capture 'this' as copy USCiLab/cereal#640
Fix rapidjson for Clang 10 by @groscoe2 in Fix rapidjson for Clang 10 USCiLab/cereal#645
Fixes to prevent clang-diagnostic errors by @johngladp in Fixes to prevent clang-diagnostic errors USCiLab/cereal#643
cleanup cmake files to be a little more moderen by @ClausKlein in cleanup cmake files to be a little more moderen USCiLab/cereal#659
GHSA-wgww-fh2f-c855: Store a copy of each serialized shared_ptr within the archive to prevent the shared_ptr to be freed to early. by @serpedon in CVE-2020-11105: Store a copy of each serialized shared_ptr within the archive to prevent the shared_ptr to be freed to early. USCiLab/cereal#667
add license files for components of cereal by @miartad in add license files for components of cereal USCiLab/cereal#676
Catch short documents in JSON input by @johnkeeping in Catch short documents in JSON input USCiLab/cereal#677
C++17: use inline globals for StaticObjects by @InBetweenNames in C++17: use inline globals for StaticObjects USCiLab/cereal#657
Use std::variant::emplace when loading by @kepler-5 in Use std::variant::emplace when loading USCiLab/cereal#699
Use std::optional::emplace() when loading non-empty optional by @kepler-5 in Use std::optional::emplace() when loading non-empty optional USCiLab/cereal#698
Fix itsNextName not clearing when not found + style change by @AzothAmmo in Fix itsNextName not clearing when not found + style change USCiLab/cereal#715
Update doctest to 2.4.6 + local fixes slated for upstream by @AzothAmmo in Update doctest to 2.4.6 + local fixes slated for upstream USCiLab/cereal#716
Fixed loading of std::vector by @Darred in Fixed loading of std::vector<bool> USCiLab/cereal#732
Update license to match BSD template by @AzothAmmo in Update license to match BSD template USCiLab/cereal#735
Update doctest to 2.4.7 by @AzothAmmo in Update doctest to 2.4.7 USCiLab/cereal#736
Use GNUInstallDirs instead of hard wiring install directories by @antonblanchard in Use GNUInstallDirs instead of hard wiring install directories USCiLab/cereal#710
This is not an exhaustive list of changes or individual contributions. See the closed issues or complete changelog for more information.
v1.3.0

New features include:

Deferred serialization for smart pointers (Stack overflow for large chains of shared_ptr (or smart pointers in general) USCiLab/cereal#185)
Initial support for C++17 standard library variant and optional (thanks to @arximboldi, Add serialization support for C++17 std::optional and std::variant USCiLab/cereal#448)
Support for std::atomic (thanks to @bluescarni, Implementation and testing of std::atomic serialization. USCiLab/cereal#277)
Fixes and enhancements include:

Vastly improved continuous integration testing (Appveyor updates + boost testing fixes USCiLab/cereal#568, Update Travis CI USCiLab/cereal#569)
Fixed several issues related to compilation on newer compilers (Fixing various compilation warnings USCiLab/cereal#579, Add fall through comments to json.hpp USCiLab/cereal#587, Fix warning unused private member itsValueItEnd USCiLab/cereal#515)
Fixed warnings with -Wconversion and -Wdocumentation (thanks to @WSoptics, Develop USCiLab/cereal#423)
Performance improvements for polymorphic serialization (PolymorphicVirtualCaster StaticObject instantiation takes a very long time at app startup USCiLab/cereal#354)
Minor fixes and enhancements include:

Fixed a bug related to CEREAL_REGISTER_DYNAMIC_INIT with shared libraries (thanks to @m2tm, Issue correctly using CEREAL_REGISTER_DYNAMIC_INIT USCiLab/cereal#523)
Avoid unnecessary undefined behavior with StaticObject (thanks to @erichkeane, Change StaticObject instance management to hopefully avoid UBSAN USCiLab/cereal#470)
New version.hpp file describes cereal version (detect cereal version at compile time / version.hpp USCiLab/cereal#444)
Ability to disable size=dynamic attribute in the XML archive (thanks to @hoensr, Add option to turn off the size=dynamic attributes of lists USCiLab/cereal#401)
Other Notes
The static checking for minimal serialization has been relaxed as there were many legitimate cases it was interfering with (thanks to @h-2, remove const check from load_minimal USCiLab/cereal#565)
The vs2013 directory has been removed in favor of generating solutions with CMake (Remove vs2013 directory USCiLab/cereal#574)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants