Skip to content

[io] read versioned class from file even if in-memory-class is unversioned #18660

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions io/io/src/TBufferFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3618,9 +3618,10 @@ Int_t TBufferFile::ReadClassBuffer(const TClass *cl, void *pointer, const TClass
// (tracking) was not enabled. So let's create the StreamerInfo if it is the
// one for the current version, otherwise let's complain ...
// We could also get here when reading a file prior to the introduction of StreamerInfo.
// We could also get here if there old class version was '1' and the new class version is higher than 1
// We could also get here if the old class version was '1' and the new class version is higher than 1
// We could also get here if the stored-in-file class version was '3' and the current-in-memory class version is not defined
// AND the checksum is the same.
if (v2file || version == cl->GetClassVersion() || version == 1 ) {
if (v2file || version == cl->GetClassVersion() || version == 1 || (version > 0 && cl->GetClassVersion() == -1) ) {
R__LOCKGUARD(gInterpreterMutex);

// We need to check if another thread did not get here first
Expand Down
34 changes: 34 additions & 0 deletions roottest/root/io/evolution/versions/execROOT5306.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "TInterpreter.h"
#include "TFile.h"

#ifndef SUBCLASS_HH
#define SUBCLASS_HH
class MySubClass
{
public:
int id;
};
#endif
#ifdef __ROOTCLING__
#pragma link C++ class MySubClass+;
#endif

// https://its.cern.ch/jira/browse/ROOT-5306
int execROOT5306()
{
// Original file was generated as:
// .L MySubClass.cxx+
// TFile f("/tmp/mysub.root", "RECREATE");
// MySubClass msc;
// msc.id = 33;
// f.WriteObjectAny(&msc, "MySubClass", "msc");
// f.Close();
// with MySubClass.cxx containing: class MySubClass { public: int id; ClassDef(MySubClass, 3) };
TFile f("mysub.root", "READ");
auto msc = f.Get<MySubClass>("msc");
if (msc->id != 33) {
printf("Error: id is %d vs 33\n", msc->id);
return 3;
}
return 0;
}
3 changes: 3 additions & 0 deletions roottest/root/io/evolution/versions/execROOT5306.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Processing execROOT5306.cxx+...
(int) 0
Binary file added roottest/root/io/evolution/versions/mysub.root
Binary file not shown.
Loading