mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-25 06:40:58 -04:00
Solve non compatible 32/64bit file handle API
This commit is contained in:
parent
2a369cb785
commit
7d388c3090
5 changed files with 39 additions and 48 deletions
|
@ -160,18 +160,21 @@ void RsFileTree::recurs_buildFileTree(
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsFileTree::getDirectoryContent(
|
bool RsFileTree::getDirectoryContent(
|
||||||
std::string& name, std::vector<std::uintptr_t>& subdirs,
|
std::string& name, std::vector<uint64_t>& subdirs,
|
||||||
std::vector<FileData>& subfiles, std::uintptr_t index ) const
|
std::vector<FileData>& subfiles, uint64_t index_p ) const
|
||||||
{
|
{
|
||||||
if(index >= mDirs.size())
|
// Avoid warnings on Android armv7
|
||||||
return false ;
|
using sz_t = std::vector<FileData>::size_type;
|
||||||
|
sz_t index = static_cast<sz_t>(index_p);
|
||||||
|
|
||||||
|
if(index >= mDirs.size()) return false;
|
||||||
|
|
||||||
name = mDirs[index].name;
|
name = mDirs[index].name;
|
||||||
subdirs = mDirs[index].subdirs ;
|
subdirs = mDirs[index].subdirs ;
|
||||||
|
|
||||||
subfiles.clear() ;
|
subfiles.clear() ;
|
||||||
for(uint32_t i=0;i<mDirs[index].subfiles.size();++i)
|
for(sz_t i=0; i < mDirs[index].subfiles.size(); ++i)
|
||||||
subfiles.push_back(mFiles[mDirs[index].subfiles[i]]);
|
subfiles.push_back(mFiles[static_cast<sz_t>(mDirs[index].subfiles[i])]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,12 +345,12 @@ std::error_condition ftServer::requestFiles(
|
||||||
// Track how many time a directory have been explored
|
// Track how many time a directory have been explored
|
||||||
std::vector<uint32_t> dirsSeenCnt(dirsCount, 0);
|
std::vector<uint32_t> dirsSeenCnt(dirsCount, 0);
|
||||||
// <directory handle, parent path>
|
// <directory handle, parent path>
|
||||||
using StackEntry = std::tuple<std::uintptr_t, std::string>;
|
using StackEntry = std::tuple<uint64_t, std::string>;
|
||||||
std::deque<StackEntry> dStack = { std::make_tuple(0, basePath) };
|
std::deque<StackEntry> dStack = { std::make_tuple(0, basePath) };
|
||||||
|
|
||||||
const auto exploreDir = [&](const StackEntry& se)-> std::error_condition
|
const auto exploreDir = [&](const StackEntry& se)-> std::error_condition
|
||||||
{
|
{
|
||||||
std::uintptr_t dirHandle; std::string parentPath;
|
uint64_t dirHandle; std::string parentPath;
|
||||||
std::tie(dirHandle, parentPath) = se;
|
std::tie(dirHandle, parentPath) = se;
|
||||||
|
|
||||||
const auto& dirData = collection.mDirs[dirHandle];
|
const auto& dirData = collection.mDirs[dirHandle];
|
||||||
|
@ -843,7 +843,7 @@ bool ftServer::findChildPointer(void *ref, int row, void *& result, FileSearchFl
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftServer::requestDirDetails(
|
bool ftServer::requestDirDetails(
|
||||||
DirDetails &details, std::uintptr_t handle, FileSearchFlags flags )
|
DirDetails &details, uint64_t handle, FileSearchFlags flags )
|
||||||
{ return RequestDirDetails(reinterpret_cast<void*>(handle), details, flags); }
|
{ return RequestDirDetails(reinterpret_cast<void*>(handle), details, flags); }
|
||||||
|
|
||||||
int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags)
|
int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags)
|
||||||
|
@ -2249,7 +2249,7 @@ std::error_condition ftServer::dirDetailsToLink(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_condition ftServer::exportCollectionLink(
|
std::error_condition ftServer::exportCollectionLink(
|
||||||
std::string& link, std::uintptr_t handle, bool fragSneak,
|
std::string& link, uint64_t handle, bool fragSneak,
|
||||||
const std::string& baseUrl )
|
const std::string& baseUrl )
|
||||||
{
|
{
|
||||||
DirDetails tDirDet;
|
DirDetails tDirDet;
|
||||||
|
|
|
@ -225,7 +225,7 @@ public:
|
||||||
|
|
||||||
/// @see RsFiles
|
/// @see RsFiles
|
||||||
std::error_condition exportCollectionLink(
|
std::error_condition exportCollectionLink(
|
||||||
std::string& link, std::uintptr_t handle, bool fragSneak = false,
|
std::string& link, uint64_t handle, bool fragSneak = false,
|
||||||
const std::string& baseUrl = RsFiles::DEFAULT_FILES_BASE_URL
|
const std::string& baseUrl = RsFiles::DEFAULT_FILES_BASE_URL
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ public:
|
||||||
|
|
||||||
/// @see RsFiles::RequestDirDetails
|
/// @see RsFiles::RequestDirDetails
|
||||||
virtual bool requestDirDetails(
|
virtual bool requestDirDetails(
|
||||||
DirDetails &details, std::uintptr_t handle = 0,
|
DirDetails &details, uint64_t handle = 0,
|
||||||
FileSearchFlags flags = RS_FILE_HINTS_LOCAL );
|
FileSearchFlags flags = RS_FILE_HINTS_LOCAL );
|
||||||
|
|
||||||
virtual bool findChildPointer(void *ref, int row, void *& result, FileSearchFlags flags) ;
|
virtual bool findChildPointer(void *ref, int row, void *& result, FileSearchFlags flags) ;
|
||||||
|
|
|
@ -324,14 +324,14 @@ public:
|
||||||
|
|
||||||
/// Allow browsing the hierarchy
|
/// Allow browsing the hierarchy
|
||||||
bool getDirectoryContent(
|
bool getDirectoryContent(
|
||||||
std::string& name, std::vector<std::uintptr_t>& subdirs,
|
std::string& name, std::vector<uint64_t>& subdirs,
|
||||||
std::vector<FileData>& subfiles, std::uintptr_t handle = 0 ) const;
|
std::vector<FileData>& subfiles, uint64_t handle = 0 ) const;
|
||||||
|
|
||||||
struct DirData: RsSerializable
|
struct DirData: RsSerializable
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<std::uintptr_t> subdirs;
|
std::vector<uint64_t> subdirs;
|
||||||
std::vector<std::uintptr_t> subfiles;
|
std::vector<uint64_t> subfiles;
|
||||||
|
|
||||||
void serial_process(
|
void serial_process(
|
||||||
RsGenericSerializer::SerializeJob j,
|
RsGenericSerializer::SerializeJob j,
|
||||||
|
@ -735,7 +735,7 @@ public:
|
||||||
* @return false if error occurred, true otherwise
|
* @return false if error occurred, true otherwise
|
||||||
*/
|
*/
|
||||||
virtual bool requestDirDetails(
|
virtual bool requestDirDetails(
|
||||||
DirDetails &details, std::uintptr_t handle = 0,
|
DirDetails &details, uint64_t handle = 0,
|
||||||
FileSearchFlags flags = RS_FILE_HINTS_LOCAL ) = 0;
|
FileSearchFlags flags = RS_FILE_HINTS_LOCAL ) = 0;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -744,7 +744,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Kept for retrocompatibility, it was originally written for easier
|
* Kept for retrocompatibility, it was originally written for easier
|
||||||
* interaction with Qt. As soon as you can, you should prefer to use the
|
* interaction with Qt. As soon as you can, you should prefer to use the
|
||||||
* version of this methodn which take `std::uintptr_t handle` as paramether.
|
* version of this method which take `uint64_t handle` as paramether.
|
||||||
*/
|
*/
|
||||||
RS_DEPRECATED_FOR(requestDirDetails)
|
RS_DEPRECATED_FOR(requestDirDetails)
|
||||||
virtual int RequestDirDetails(
|
virtual int RequestDirDetails(
|
||||||
|
@ -927,7 +927,7 @@ public:
|
||||||
* @return error information if some error occurred, 0/SUCCESS otherwise
|
* @return error information if some error occurred, 0/SUCCESS otherwise
|
||||||
*/
|
*/
|
||||||
virtual std::error_condition exportCollectionLink(
|
virtual std::error_condition exportCollectionLink(
|
||||||
std::string& link, std::uintptr_t handle, bool fragSneak = false,
|
std::string& link, uint64_t handle, bool fragSneak = false,
|
||||||
const std::string& baseUrl = RsFiles::DEFAULT_FILES_BASE_URL ) = 0;
|
const std::string& baseUrl = RsFiles::DEFAULT_FILES_BASE_URL ) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -304,10 +304,16 @@ struct DirDetails : RsSerializable
|
||||||
type(DIR_TYPE_UNKNOWN), count(0), mtime(0), max_mtime(0) {}
|
type(DIR_TYPE_UNKNOWN), count(0), mtime(0), max_mtime(0) {}
|
||||||
|
|
||||||
|
|
||||||
|
/* G10h4ck do we still need to keep this as void* instead of uint64_t for
|
||||||
|
* retroshare-gui sake? */
|
||||||
void* parent;
|
void* parent;
|
||||||
|
|
||||||
int prow; /* parent row */
|
int prow; /* parent row */
|
||||||
|
|
||||||
|
/* G10h4ck do we still need to keep this as void* instead of uint64_t for
|
||||||
|
* retroshare-gui sake? */
|
||||||
void* ref;
|
void* ref;
|
||||||
|
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
RsPeerId id;
|
RsPeerId id;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -323,36 +329,18 @@ struct DirDetails : RsSerializable
|
||||||
|
|
||||||
/// @see RsSerializable
|
/// @see RsSerializable
|
||||||
void serial_process(RsGenericSerializer::SerializeJob j,
|
void serial_process(RsGenericSerializer::SerializeJob j,
|
||||||
RsGenericSerializer::SerializeContext& ctx)
|
RsGenericSerializer::SerializeContext& ctx) override
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
/* Enforce serialization as uint64_t because void* changes size
|
||||||
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
* depending (usually 4 bytes on 32bit arch and 8 bytes on 64bit archs)
|
||||||
#endif // defined(__GNUC__) && !defined(__clang__)
|
*/
|
||||||
|
uint64_t handle = reinterpret_cast<uint64_t>(ref);
|
||||||
// (Cyril) We have to do this because on some systems (MacOS) uintptr_t is unsigned long which is not well defined. It is always
|
|
||||||
// preferable to force type serialization to the correct size rather than letting the compiler choose for us.
|
|
||||||
// /!\ This structure cannot be sent over the network. The serialization would be inconsistent.
|
|
||||||
|
|
||||||
if(sizeof(ref) == 4)
|
|
||||||
{
|
|
||||||
std::uint32_t& handle(reinterpret_cast<std::uint32_t&>(ref));
|
|
||||||
RS_SERIAL_PROCESS(handle);
|
RS_SERIAL_PROCESS(handle);
|
||||||
std::uint32_t& parentHandle(reinterpret_cast<std::uint32_t&>(parent));
|
ref = reinterpret_cast<void*>(handle);
|
||||||
RS_SERIAL_PROCESS(parentHandle);
|
|
||||||
}
|
|
||||||
else if(sizeof(ref) == 8)
|
|
||||||
{
|
|
||||||
std::uint64_t& handle(reinterpret_cast<std::uint64_t&>(ref));
|
|
||||||
RS_SERIAL_PROCESS(handle);
|
|
||||||
std::uint64_t& parentHandle(reinterpret_cast<std::uint64_t&>(parent));
|
|
||||||
RS_SERIAL_PROCESS(parentHandle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << ": cannot serialize raw pointer of size " << sizeof(ref) << std::endl;
|
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
uint64_t parentHandle = reinterpret_cast<uint64_t>(parent);
|
||||||
# pragma GCC diagnostic pop
|
RS_SERIAL_PROCESS(parentHandle);
|
||||||
#endif // defined(__GNUC__) && !defined(__clang__)
|
parent = reinterpret_cast<void*>(parentHandle);
|
||||||
|
|
||||||
RS_SERIAL_PROCESS(prow);
|
RS_SERIAL_PROCESS(prow);
|
||||||
RS_SERIAL_PROCESS(type);
|
RS_SERIAL_PROCESS(type);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue