Skip to content

Commit

Permalink
AIX compilation fix for io classes (#3275)
Browse files Browse the repository at this point in the history
Summary:
in AIX OS ,as fileno is defined as C macro,   we get the compilation error during preprocessing step.

In file included from /ranjit/Faiss/faiss/faiss/invlists/InvertedListsIOHook.h:10:
/ranjit/Faiss/faiss/faiss/impl/io.h:35:17: error: expected member name or ';' after declaration specifiers
   35 |     virtual int fileno();
      |     ~~~~~~~~~~~ ^
/usr/include/stdio.h:517:30: note: expanded from macro 'fileno'
  517 | #define fileno(__p)     ((__p)->_file)

Pull Request resolved: #3275

Reviewed By: algoriddle

Differential Revision: D54944388

Pulled By: mdouze

fbshipit-source-id: 40c4314de93547778ac274281245ff59e3a18b6d
  • Loading branch information
ranjitsastra authored and facebook-github-bot committed Mar 15, 2024
1 parent dafdff1 commit e99ad12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 12 additions & 4 deletions faiss/impl/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ namespace faiss {
* IO functions
***********************************************************************/

int IOReader::fileno() {
int IOReader::filedescriptor() {
FAISS_THROW_MSG("IOReader does not support memory mapping");
}

int IOWriter::fileno() {
int IOWriter::filedescriptor() {
FAISS_THROW_MSG("IOWriter does not support memory mapping");
}

Expand Down Expand Up @@ -85,8 +85,12 @@ size_t FileIOReader::operator()(void* ptr, size_t size, size_t nitems) {
return fread(ptr, size, nitems, f);
}

int FileIOReader::fileno() {
int FileIOReader::filedescriptor() {
#ifdef _AIX
return fileno(f);
#else
return ::fileno(f);
#endif
}

FileIOWriter::FileIOWriter(FILE* wf) : f(wf) {}
Expand Down Expand Up @@ -116,8 +120,12 @@ size_t FileIOWriter::operator()(const void* ptr, size_t size, size_t nitems) {
return fwrite(ptr, size, nitems, f);
}

int FileIOWriter::fileno() {
int FileIOWriter::filedescriptor() {
#ifdef _AIX
return fileno(f);
#else
return ::fileno(f);
#endif
}

/***********************************************************************
Expand Down
8 changes: 4 additions & 4 deletions faiss/impl/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct IOReader {
virtual size_t operator()(void* ptr, size_t size, size_t nitems) = 0;

// return a file number that can be memory-mapped
virtual int fileno();
virtual int filedescriptor();

virtual ~IOReader() {}
};
Expand All @@ -45,7 +45,7 @@ struct IOWriter {
virtual size_t operator()(const void* ptr, size_t size, size_t nitems) = 0;

// return a file number that can be memory-mapped
virtual int fileno();
virtual int filedescriptor();

virtual ~IOWriter() noexcept(false) {}
};
Expand Down Expand Up @@ -73,7 +73,7 @@ struct FileIOReader : IOReader {

size_t operator()(void* ptr, size_t size, size_t nitems) override;

int fileno() override;
int filedescriptor() override;
};

struct FileIOWriter : IOWriter {
Expand All @@ -88,7 +88,7 @@ struct FileIOWriter : IOWriter {

size_t operator()(const void* ptr, size_t size, size_t nitems) override;

int fileno() override;
int filedescriptor() override;
};

/*******************************************************
Expand Down

0 comments on commit e99ad12

Please sign in to comment.