mirror of
https://review.haiku-os.org/haiku
synced 2024-11-23 07:18:40 +01:00
userlandfs: use std::bitset for FSCapabilities
gcc 13 is confused by the custom bitset implementation, so use the C++ standard one instead. However, this results in including the C++ <string> header in kernel code. This doesn't work for gcc2, because of two problems: - That header includes a declaration of atomic_add that doesn't match the one in SupportsDefs.h (which can in some cases replace the function with a #define for an inline version). Adjust the header to use the be a problem because it creates a risk of circular inclusions. Standard C++ headers shouldn't depend on BeAPI ones. - It also leads to the inclusion of iostream which defined lock and unlock functions in the global namespace. We don't want these, and they are not part of the C++ standard, so just remove them. Ideally we could use std::hash for the GetHashCode implementation, but that doesn't work because it depends on an helper function that's in libstdc++, and we can't link that from kernel add-ons. Change-Id: Iee07280beb4dddf7a9b6160e37f3b816e4de89ae Reviewed-on: https://review.haiku-os.org/c/haiku/+/6663 Reviewed-by: Niels Sascha Reedijk <niels.reedijk@gmail.com> Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
parent
9aa43979f8
commit
899e0ef82b
@ -271,11 +271,6 @@ __asm__ ("__IO_clog")
|
|||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
extern istream& lock(istream& ins);
|
|
||||||
extern istream& unlock(istream& ins);
|
|
||||||
extern ostream& lock(ostream& outs);
|
|
||||||
extern ostream& unlock(ostream& outs);
|
|
||||||
|
|
||||||
struct Iostream_init { } ; // Compatibility hack for AT&T library.
|
struct Iostream_init { } ; // Compatibility hack for AT&T library.
|
||||||
|
|
||||||
inline ios& dec(ios& i)
|
inline ios& dec(ios& i)
|
||||||
|
@ -66,8 +66,10 @@ extern void __length_error (const char *);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __HAIKU__
|
#ifdef __HAIKU__
|
||||||
|
#ifndef atomic_add
|
||||||
extern "C" __haiku_int32 atomic_add(__haiku_int32* value,
|
extern "C" __haiku_int32 atomic_add(__haiku_int32* value,
|
||||||
__haiku_int32 addvalue);
|
__haiku_int32 addvalue);
|
||||||
|
#endif
|
||||||
#endif /* __HAIKU__ */
|
#endif /* __HAIKU__ */
|
||||||
|
|
||||||
template <class charT, class traits = string_char_traits<charT>,
|
template <class charT, class traits = string_char_traits<charT>,
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
|
|
||||||
enum client_fs_type {
|
enum client_fs_type {
|
||||||
@ -148,7 +150,7 @@ namespace UserlandFSUtil {
|
|||||||
|
|
||||||
template<const int CapabilityCount>
|
template<const int CapabilityCount>
|
||||||
struct FSCapabilitiesBase {
|
struct FSCapabilitiesBase {
|
||||||
uint8 capabilities[(CapabilityCount + 7) / 8];
|
std::bitset<CapabilityCount> capabilities;
|
||||||
|
|
||||||
inline void ClearAll();
|
inline void ClearAll();
|
||||||
|
|
||||||
@ -171,7 +173,7 @@ template<const int CapabilityCount>
|
|||||||
inline void
|
inline void
|
||||||
FSCapabilitiesBase<CapabilityCount>::ClearAll()
|
FSCapabilitiesBase<CapabilityCount>::ClearAll()
|
||||||
{
|
{
|
||||||
memset(capabilities, 0, sizeof(capabilities));
|
capabilities.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -183,11 +185,7 @@ FSCapabilitiesBase<CapabilityCount>::Set(uint32 capability, bool set)
|
|||||||
if (capability >= CapabilityCount)
|
if (capability >= CapabilityCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8 flag = uint8(1 << (capability % 8));
|
capabilities.set(capability, set);
|
||||||
if (set)
|
|
||||||
capabilities[capability / 8] |= flag;
|
|
||||||
else
|
|
||||||
capabilities[capability / 8] &= ~flag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -196,7 +194,10 @@ template<const int CapabilityCount>
|
|||||||
inline void
|
inline void
|
||||||
FSCapabilitiesBase<CapabilityCount>::Clear(uint32 capability)
|
FSCapabilitiesBase<CapabilityCount>::Clear(uint32 capability)
|
||||||
{
|
{
|
||||||
Set(capability, false);
|
if (capability >= CapabilityCount)
|
||||||
|
return;
|
||||||
|
|
||||||
|
capabilities.reset(capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -208,8 +209,7 @@ FSCapabilitiesBase<CapabilityCount>::Get(uint32 capability) const
|
|||||||
if (capability >= CapabilityCount)
|
if (capability >= CapabilityCount)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint8 flag = uint8(1 << (capability % 8));
|
return capabilities.test(capability);
|
||||||
return (capabilities[capability / 8] & flag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -218,12 +218,10 @@ template<const int CapabilityCount>
|
|||||||
inline uint32
|
inline uint32
|
||||||
FSCapabilitiesBase<CapabilityCount>::GetHashCode() const
|
FSCapabilitiesBase<CapabilityCount>::GetHashCode() const
|
||||||
{
|
{
|
||||||
uint32 hashCode = 0;
|
uint32 hash = 0;
|
||||||
int byteCount = sizeof(capabilities);
|
for (int i = 0; i < CapabilityCount; i++)
|
||||||
for (int i = 0; i < byteCount; i++)
|
hash ^= capabilities.test(i) << (i % 32);
|
||||||
hashCode = hashCode * 37 + capabilities[i];
|
return hash;
|
||||||
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -233,13 +231,7 @@ inline bool
|
|||||||
FSCapabilitiesBase<CapabilityCount>::operator==(
|
FSCapabilitiesBase<CapabilityCount>::operator==(
|
||||||
const FSCapabilitiesBase<CapabilityCount>& other) const
|
const FSCapabilitiesBase<CapabilityCount>& other) const
|
||||||
{
|
{
|
||||||
int byteCount = sizeof(capabilities);
|
return capabilities == other.capabilities;
|
||||||
for (int i = 0; i < byteCount; i++) {
|
|
||||||
if (capabilities[i] != other.capabilities[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -249,12 +241,7 @@ inline void
|
|||||||
FSCapabilitiesBase<CapabilityCount>::Dump() const
|
FSCapabilitiesBase<CapabilityCount>::Dump() const
|
||||||
{
|
{
|
||||||
D(
|
D(
|
||||||
char buffer[128];
|
PRINT(("FSCapabilities[%s]\n", capabilities.to_string().c_str()));
|
||||||
int byteCount = sizeof(capabilities);
|
|
||||||
for (int i = 0; i < byteCount; i++)
|
|
||||||
sprintf(buffer + 2 * i, "%02x", (int)capabilities[i]);
|
|
||||||
|
|
||||||
PRINT(("FSCapabilities[%s]\n", buffer));
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,5 +33,5 @@ SharedLibrary libuserlandfs_beos_kernel.so
|
|||||||
|
|
||||||
:
|
:
|
||||||
<nogrist>userlandfs_server
|
<nogrist>userlandfs_server
|
||||||
[ TargetLibsupc++ ] libbsd.so
|
[ TargetLibsupc++ ] [ TargetLibstdc++ ] libbsd.so
|
||||||
;
|
;
|
||||||
|
@ -36,7 +36,7 @@ SharedLibrary libuserlandfs_fuse.so
|
|||||||
FUSEVolume.cpp
|
FUSEVolume.cpp
|
||||||
mime_ext_table.c
|
mime_ext_table.c
|
||||||
:
|
:
|
||||||
<nogrist>userlandfs_server shared be [ TargetLibsupc++ ]
|
<nogrist>userlandfs_server shared be [ TargetLibsupc++ ] [ TargetLibstdc++ ]
|
||||||
;
|
;
|
||||||
|
|
||||||
SEARCH on [ FGristFiles mime_ext_table.c ]
|
SEARCH on [ FGristFiles mime_ext_table.c ]
|
||||||
|
@ -51,7 +51,7 @@ SharedLibrary libuserlandfs_haiku_kernel.so
|
|||||||
:
|
:
|
||||||
<nogrist>userlandfs_server
|
<nogrist>userlandfs_server
|
||||||
be # for BLocker only
|
be # for BLocker only
|
||||||
[ TargetLibsupc++ ]
|
[ TargetLibsupc++ ] [ TargetLibstdc++ ]
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user