TEST_F(MPoolTest, test1) { FileHandle f = createTmpFile(); const size_t pagesize = 4096; std::shared_ptr<MPOOL> mpool(new MPOOL(f, pagesize, 1)); pgno_t pgno; void* page = mpool->new_page(&pgno, 0); strncpy((char*)page, "hello world", pagesize); mpool->put_page(page, MPOOL_DIRTY); mpool->sync(); closeFile(f); }
bool GPT::compile(const list<string>& ifnames, bool genBinary){ bool success = false; stringstream s; if(!prologue(ifnames)) { return false; } string ofname = _outputfile; if(!_useOutputFile) { if(!genBinary) { ofname += ".asm"; } #ifdef WIN32 else { ofname += ".exe"; } #endif } try{ X86Walker x86(_stable); string asmsrc = x86.algoritmo(_astree); string ftmpname = createTmpFile(); ofstream fo; if(!genBinary) { //salva assembly code fo.open(ofname.c_str(), ios_base::out); if(!fo) { s << PACKAGE << ": não foi possível abrir o arquivo: \"" << ofname << "\"" << endl; GPTDisplay::self()->showError(s); goto bail; } fo << asmsrc; fo.close(); } else { //compile fo.open(ftmpname.c_str(), ios_base::out); if(!fo) { s << PACKAGE << ": erro ao processar arquivo temporário" << endl; GPTDisplay::self()->showError(s); goto bail; } fo << asmsrc; fo.close(); stringstream cmd; cmd << "nasm -O1 -fbin -o \"" << ofname << "\" " << ftmpname; if(system(cmd.str().c_str()) == -1) { s << PACKAGE << ": não foi possível invocar o nasm." << endl; GPTDisplay::self()->showError(s); goto bail; } #ifndef WIN32 cmd.str(""); cmd << "chmod +x " << ofname; system(cmd.str().c_str()); #endif } success = true; bail: if(ftmpname.length()>0) { unlink(ftmpname.c_str()); } return success; } catch(SymbolTableException& e) { s << PACKAGE << ": erro interno: " << e.getMessage() << endl; GPTDisplay::self()->showError(s); } }