fix mmap error in OSX

pull/392/head
Matthijs Douze 2018-04-04 15:18:42 +02:00
parent 3bdc5abeaf
commit 3b56a79f45
1 changed files with 7 additions and 4 deletions

View File

@ -233,19 +233,20 @@ void OnDiskInvertedLists::prefetch_lists (const long *list_nos, int n) const
void OnDiskInvertedLists::do_mmap ()
{
const char *rw_flags = read_only ? "r" : "rw+";
const char *rw_flags = read_only ? "r" : "r+";
int prot = read_only ? PROT_READ : PROT_WRITE | PROT_READ;
FILE *f = fopen (filename.c_str(), rw_flags);
FAISS_THROW_IF_NOT_FMT (f, "could not open %s in mode %s: %s",
filename.c_str(), rw_flags, strerror(errno));
ptr = (uint8_t*)mmap (nullptr, totsize,
uint8_t * ptro = (uint8_t*)mmap (nullptr, totsize,
prot, MAP_SHARED, fileno (f), 0);
FAISS_THROW_IF_NOT_FMT (ptr != MAP_FAILED,
FAISS_THROW_IF_NOT_FMT (ptro != MAP_FAILED,
"could not mmap %s: %s",
filename.c_str(),
strerror(errno));
ptr = ptro;
fclose (f);
}
@ -334,6 +335,8 @@ OnDiskInvertedLists::OnDiskInvertedLists (
OnDiskInvertedLists::OnDiskInvertedLists ():
InvertedLists (0, 0),
totsize (0),
ptr (nullptr),
read_only (false),
locks (new LockLevels ()),
pf (new OngoingPrefetch (this))