diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index ebb66a3cf7fc5e1e5bbe43fc2a21a89c229e53d6..41e6b72f91354931069443e9bf0b492b4f8dc7ee 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -3976,7 +3976,9 @@ public: //! returns true if the object is associated with currently opened file. CV_WRAP virtual bool isOpened() const; //! closes the file and releases all the memory buffers - CV_WRAP virtual string release(); + CV_WRAP virtual void release(); + //! closes the file, releases all the memory buffers and returns the text string + CV_WRAP_AS(releaseAndGetString) virtual void release(CV_OUT string& buf); //! returns the first element of the top-level mapping CV_WRAP FileNode getFirstTopLevelNode() const; diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index a02c1864ae8aa9692125b8f12948b595aa9992ae..7d1d5865c6a903336abaaa5e7b0b0cbcd781cc0e 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -5154,19 +5154,25 @@ bool FileStorage::isOpened() const return !fs.empty() && fs.obj->is_opened; } -string FileStorage::release() +void FileStorage::release() { - string buf; - - if( fs.obj && fs.obj->outbuf ) - icvClose(fs.obj, &buf); - fs.release(); structs.clear(); state = UNDEFINED; - return buf; } +void FileStorage::release(string& buf) +{ + if( fs.obj && fs.obj->outbuf ) + icvClose(fs.obj, &buf); + else + buf.clear(); + + fs.release(); + structs.clear(); + state = UNDEFINED; +} + FileNode FileStorage::root(int streamidx) const { return isOpened() ? FileNode(fs, cvGetRootFileNode(fs, streamidx)) : FileNode(); diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index a74a7fb7af18b91d603feffdb1d74e9016734594..150bdd1cdd9d1c0521b289a9b48b678bb8d2c02c 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -180,7 +180,8 @@ protected: fs.writeObj("test_graph",graph); CvGraph* graph2 = (CvGraph*)cvClone(graph); - string content = fs.release(); + string content; + fs.release(content); if(!fs.open(mem ? content : filename, FileStorage::READ + (mem ? FileStorage::MEMORY : 0))) {