How do I get Boost.Serialization to work with PhysicsFS - serialization

I would like to use PhysFS in conjunction with Boost.Serialization. I found an implementation here which uses Boost.Iostreams to create a PhysFS file stream. It works for basic operations, buy if I try ti use it with Boost.Serialization, I get the following error during runtime:
/usr/include/boost/iostreams/detail/optional.hpp:55: T& boost::iostreams::detail::optional<T>::operator*() [with T = boost::iostreams::detail::concept_adapter<PhysFS::FileDevice>]: Assertion `initialized_' failed.
Aborted
here is an example of the code.
PhysFS::init(argv[0]);
PhysFS::setWriteDir(".");
PhysFS::FileStream ofs("test.xml", PhysFS::OM_WRITE);
boost::archive::xml_oarchive xml(ofs);
vec2 vec(3.1415, 2.5);
xml << BOOST_SERIALIZATION_NVP(vec);
ofs.close();
PhysFS::deinit();
Is there any way to get a working file stream wrapper for PhysFS that will work with libraries like Boost.Serialization?

My mistake was calling ofs.close(), and also calling PhysFS::deinit before the destruction of ofs.

Related

debugging vxworks loadModule failure

I have a VxWorks Image Project project without a File-System on MPC5200B, using DIAB tool-chain.
I need to dynamically load a module from flash.
I allocated memory on my stack char myTemporaryModuleData[MAX_MODULE_SIZE]
and filled it with the module data from Flash.
(checked that the binary data is intact)
then i create a memDevice('/mem/mem01', myTemporaryModuleData, moduleReadLength)
open the psuedo-stream int fdModuleData = open("/mem/mem01", O_RDONLY, 777);
when i run int mId = loadModule(fdModuleData, LOAD_ALL_SYMBOLS);
did not see anything in the console after running loadModule();
but mId = 0 which indicates failure :(.
getErrno() returned 0x3D0004 (S_objLib_OBJ_TIMEOUT)
NOTE: it didn't take long at all to fail => timeout?
i tried replacing the module with a simple void foo() { printf(...); } module but still failes with same issue.
tried loading an .out instead of .o
unfortunately, nothing got me nowhere,
How can i know what caused it to fail? (log, last_error, anything i should check?)
FOUND IT.
Apparently, it was a mistake in the data read from the flash.
What I can contribute is that 'loadModule()' from memDrv device is possible and working.

unable to use f_read() and f_lseek() in Fatfs

I'm trying to connect to a 2GB sd card class 6 with stm32f091cctx MCU via SPI. Using fatFs library ver. R0.13a I'm able to mount the drive and open the file with f_mount and f_open functions. But when it comes to reading from file, it just freezes somewhere in f_read function. Also when I try to change the position of pointer with f_lseek, again it freezes. f_lseek works only when I write it as: f_lseek(&MyFile, 0).
This part of my code is as below:
if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
{
f_mount(&SDFatFs, (TCHAR const*)SDPath, 1);
f_open(&MyFile, "SAMPLE1.WAV", FA_READ);
f_lseek(&MyFile, 200);
f_read(&MyFile, rtext, 1000, (UINT*)&bytesread);
}
You are probably run out of heap size and go to HardFault exception.
You can increase HEAP size from CubeMX -> Project Setting or directly from **_startup.s file.
PS: Print something in HardFault_Handler and Error_Handler function to see when something goes wrong.

wx Widgets multiple errors in Windows 10

I have downloaded wxWidgets-3.0.2 and am trying to create a simple FRAME from the main program.
Unfortunately I am receiving multiple errors that are all to do with wxWidgets, NOT my code. This is odd as I am lead to believe wxWidgets should work.
Here are some of the errors I am getting:
*\msw\chkconf.h(19): Error! E080: col(10) "wxUSE_ACTIVEX must be defined."
\msw\chkconf.h(394): Error! E080: col(13) "wxUSE_DATAOBJ requires wxUSE_OLE"
\msw\chkconf.h(414): Error! E080: col(13) "wxMediaCtl requires wxActiveXContainer"
\chkconf.h(1630): Error! E080: col(13) "wxRearrangeCtrl requires wxCheckListBox"
\vector.h(197): Error! E148: col(71) access to private member 'reverse_iterator::m_ptr' is not allowed
\vector.h(187): Note! N392: col(21) definition: 'wxToolTip * * wxVector<wxToolTip *>::reverse_iterator::m_ptr'*
Why am I receiving these messages when wxWidgets is supposed to be ready to go?
Have you configured properly? If not try this link to configure on Windows. Also, you can try to use Linux. It is much easier to set up WxWidgets.
High level steps to installing wxWidgets:
Download ( you appear to have done this )
Build library ( I cannot tell if you have done this )
-OR-
Download binary built libraries if available for your compiler ( what compiler are you using - you haven't told us! )
Build one or two of the sample programs ( It really does not look like you have done this )
NOT UNTIL you have completed all these steps are you "ready to go"

yaml-0.2.7 GetNextDocument() hit assertion fail in Scanner::peek

yaml-cpp team and everyone,
Our product receives an unfixed size of json response from a cloud service provider. We currently used a buffer with 16KB initial size to receive it, then pass it to yaml parser(we are using yaml-0.2.7). We expect yaml parser to throw an exception if the json document is incomplete during parsing and we will double the size of the buffer.
Today, we hit an assertion which shows "Assertion failed: (!m_tokens.empty()), function peek, file .../yaml-cpp-0.2.7/src/scanner.cpp, line 41." when doing parser.GetNextDocument(doc). The json document was incomplete due to small receiving buffer.
After examining the buffer and doing some experiment, I found out if some characters are missing following a certain pattern, the assertion in scanner will be hit during GetNextDocument. Such as for '{"access": "abc"}', if the last '}' is missing, then the assertion will be hit. Same thing happens if it is '{"access":' or '{"access"'. It will not hit the assertion if it is '"{"access":"abc' (note abc does not have the trailing double quote).
Will it help if I upgrade to the latest 0.5.3 version? I looked at the source code and saw the same assertion in Scanner::peek function is still there.
Here is the source code of the function where assertion is hit:
Token& Scanner::peek() {
{
EnsureTokensInQueue();
/** THIS ONE GOT HIT **/
assert(!m_tokens.empty()); // should we be asserting here? I mean, we really just be checking
// if it's empty before peeking.
#if 0
static Token *pLast = 0;
if(pLast != &m_tokens.front())
std::cerr << "peek: " << m_tokens.front() << "\n";
pLast = &m_tokens.front();
#endif
return m_tokens.front();
}
Much appreciate for the help! :)
This is fixed in 0.5.3, although I'm not sure when precisely it was fixed. I added tests for your examples and they pass (by throwing exceptions) as expected.

Return key in process

The code was run as:
u = subprocess.Popen(['process','abc','def','','ghi','jkl'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
It doesn't work below due to an error occurred:
ValueError: I/O operation on closed file
I suggest you to try pexpect, it is far more well-suited for this tasks (actually, it is a tool built for these kind of tasks).
You can also browse througn examples and see what its usage looks like.