Thread: Serialization problem

  1. #16
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    There were minor errors in the load() and store() methods Body.
    and if its implemented in serialize.cpp file the compiler was bypassing it and making the serialize.o
    Code:
    The Exception Classes had some constructor related error. (fixed)
    srzFStream.read((char*)obj, sizeof(obj)); Here the casting was wrong
    Changed to srzFStream.read(reinterpret_cast<char*>(&obj), sizeof(obj));
    so at the time of linking it was not getting the whole methods. and thats why as I've already told nm and objdump was not showing the existance of load() and store() in the serialization class.
    and thats why It was not even firing those errors in serialize.cpp while making serialize.o
    If I put all in serialize.h or make it inline function it shows me up those Errors and when I fix it It Compiles.
    I thought My evil days were at an end ehen It got compiled.
    But nope.
    after I execute it. it shut me off with this error.
    Code:
    *** glibc detected *** double free or corruption (fasttop): 0x0804f008 ***
    /bin/sh: line 1:  1420 Aborted                 ./srz
    Here is the New Project archived http://rapidshare.com/files/129808229/srz.tar.gz.html
    the executable reacives SIGABRT Signal.
    while debuging I notice some Wired thing.
    Code:
    1. How Can a Program reacieve SIGABRT on the last line of main() return EXIT_SUCCESS; (which evalutes to return 0)
    2. why the programm is not abort() ing on uncaught Exceptions. 
    Its getting failedToWrite Exception on store() but still Continuing Processing ?? (I observed this while debuging)
    I thing you've noticed there is not try catch Block in main() so it should call terminate() and then abort() on uncaught Exception
    But what the glibc is Screwing here ??
    even if I catch teh exceptions in main() the glic error is fired.
    srz.cpp http://pastebin.com/f7c3e8a19
    Code:
    //main() function
    int main(int argc, char *argv[]){
    	string x="Neel Basu";
    	string y;
    	try{
    		Serialization<string>::store(x, "/home/neel/Desktop/name.srl");
    	}catch(SerializationException ex){
    		cout<<ex.getErrMsg()<<endl;
    	}
    	try{
    		y=Serialization<string>::load("/home/neel/Desktop/name.srl");
    	}catch(SerializationException ex){
    		cout<<ex.getErrMsg()<<endl;
    	}
      return EXIT_SUCCESS;
    }
    Its worth to mention that It has created the name.srl file with nothing in it (4B long)
    Code:
    0000:0000 | 14 D0 04 08                                           | .&#208;..
    which has no relation with the string Object that was meant to be serialized
    Last edited by noobcpp; 07-15-2008 at 01:24 AM.

  2. #17
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    One more wired thing I've noticed. is that
    http://pastebin.com/f5ac284aa
    Code:
    int main(int argc, char *argv[]){
    	string x="Neel Basu";
    	string y;
    	Serialization<int> tst;//Instanciate a Dummy Object
    	try{
    		Serialization<string>::store(x, "/home/neel/Desktop/name.srl");//Line 51
    	}catch(SerializationException ex){
    		cout<<ex.getErrMsg()<<endl;
    	}
    	try{
    		y=Serialization<string>::load("/home/neel/Desktop/name.srl");//Line 52
    	}catch(SerializationException ex){
    		cout<<ex.getErrMsg()<<endl;
    	}
      return EXIT_SUCCESS;
    }
    When I Instanciate the Serialization Class It Fires Errors at Link time saying.
    Code:
    /home/neel/dev.cpp/srz/src/srz.cpp:38: undefined reference to `Serialization<int>::Serialization()'
    /home/neel/dev.cpp/srz/src/srz.cpp:49: undefined reference to `Serialization<int>::~Serialization()'
    /home/neel/dev.cpp/srz/src/srz.cpp:49: undefined reference to `Serialization<int>::~Serialization()
    The new Serialization Class (which is stored in the srchive) Contains Constructors and Destructors.

  3. #18
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The most common way that I know of to get those sorts of linker errors is to declare a method in a class but forget to define it, i.e.:
    Code:
    class type {
    public:
        type();
    };
    
    //type::type() {}
    You can solve this by putting a function body in for those constructors and destructors, either separately or inline.
    Code:
    class type {
    public:
        type() {}  // inline body
    };
    That's assuming I've guessed correctly, of course.

    1. How Can a Program reacieve SIGABRT on the last line of main() return EXIT_SUCCESS; (which evalutes to return 0)
    By performing an illegal operation of some sort (or perhaps throwing an exception) inside a destructor. I think this is probably what's happening; it would explain why uncaught exceptions don't appear to be printed. As the stack was unwound, all local variables would have to be destructed before abort() was called. And if one of those variables has an error in its destructor . . . .

    Code:
    cout<<ex.getErrMsg()<<endl;
    Suggestion: why not use something like this?
    Code:
    ostream &operator<< (ostream &o, SerializationException &e) {
        o << e.getErrMsg();
        return o;
    }
    Then you can just go:
    Code:
    cout << ex << endl;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM

Tags for this Thread