Skip to content

Commit

Permalink
owners again
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Aug 8, 2017
1 parent 96ad380 commit 38e4d51
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
drkns 09.08.2017 00:11:01 +0000 - build 5003

1. Ещё раз о владельцах.

drkns 08.08.2017 20:27:34 +0000 - build 5002

1. 0003466: Зависание/падение по перерасходу памяти при добавлении новых столбцов панели без указания ширины
Expand Down
32 changes: 16 additions & 16 deletions far/common/smart_ptr.hpp
Expand Up @@ -40,8 +40,8 @@ class array_ptr: public conditional<array_ptr<T, StaticSize>>
MOVABLE(array_ptr);

array_ptr() noexcept:
m_Buffer(),
m_Size()
m_Size(),
m_IsStatic()
{
}

Expand All @@ -54,22 +54,22 @@ class array_ptr: public conditional<array_ptr<T, StaticSize>>
{
if (Size > StaticSize)
{
m_IsStatic = false;
m_DynamicBuffer.reset(Init? new T[Size]() : new T[Size]);
m_Buffer = m_DynamicBuffer.get();
}
else
{
m_IsStatic = true;
m_DynamicBuffer.reset();
m_Buffer = m_StaticBuffer;
}

m_Size = Size;
}

void reset() noexcept
{
m_IsStatic = false;
m_DynamicBuffer.reset();
m_Buffer = nullptr;
m_Size = 0;
}

Expand All @@ -80,31 +80,31 @@ class array_ptr: public conditional<array_ptr<T, StaticSize>>

bool operator!() const noexcept
{
return !m_Buffer;
return !m_IsStatic && !m_DynamicBuffer;
}

T* get() const noexcept
{
return m_Buffer;
return m_IsStatic? m_StaticBuffer.data() : m_DynamicBuffer.get();
}

T& operator*() const
{
assert(m_Size);
return *m_Buffer;
return *get();
}

T& operator[](size_t Index) const
{
assert(Index < m_Size);
return m_Buffer[Index];
return get()[Index];
}

private:
T* m_Buffer;
size_t m_Size;
mutable std::array<T, StaticSize> m_StaticBuffer;
std::unique_ptr<T[]> m_DynamicBuffer;
T m_StaticBuffer[StaticSize];
size_t m_Size;
bool m_IsStatic;
};

template<size_t Size = 1>
Expand All @@ -117,16 +117,16 @@ using wchar_t_ptr = wchar_t_ptr_n<1>;
using char_ptr = char_ptr_n<1>;


template<typename T>
class block_ptr: public char_ptr
template<typename T, size_t Size = 1>
class block_ptr: public char_ptr_n<Size>
{
public:
NONCOPYABLE(block_ptr);
MOVABLE(block_ptr);

using char_ptr::char_ptr;
using char_ptr_n<Size>::char_ptr_n;
block_ptr() = default;
decltype(auto) get() const noexcept {return reinterpret_cast<T*>(char_ptr::get());}
decltype(auto) get() const noexcept {return reinterpret_cast<T*>(char_ptr_n<Size>::get());}
decltype(auto) operator->() const noexcept { return get(); }
decltype(auto) operator*() const noexcept {return *get();}
};
Expand Down
33 changes: 16 additions & 17 deletions far/farwinapi.cpp
Expand Up @@ -50,15 +50,15 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace os
{
enum
template<typename buffer_type>
auto default_buffer()
{
default_buffer_size = MAX_PATH
};
return array_ptr<buffer_type, default_buffer_size>(default_buffer_size);
}

template<typename buffer_type, typename receiver, typename condition, typename assigner>
bool ApiDynamicReceiver(const receiver& Receiver, const condition& Condition, const assigner& Assigner)
bool ApiDynamicReceiver(buffer_type&& Buffer, const receiver& Receiver, const condition& Condition, const assigner& Assigner)
{
array_ptr<buffer_type, default_buffer_size> Buffer(default_buffer_size);
auto Size = Receiver(Buffer.get(), Buffer.size());

while (Condition(Size, Buffer.size()))
Expand All @@ -77,7 +77,8 @@ namespace os
template<typename T>
bool ApiDynamicStringReceiver(string& Destination, const T& Callable)
{
return ApiDynamicReceiver<wchar_t>(
return ApiDynamicReceiver(
default_buffer<wchar_t>(),
Callable,
[](size_t ReturnedSize, size_t AllocatedSize)
{
Expand All @@ -97,7 +98,8 @@ namespace os
template<typename T>
bool ApiDynamicErrorBasedStringReceiver(DWORD ExpectedErrorCode, string& Destination, const T& Callable)
{
return ApiDynamicReceiver<wchar_t>(
return ApiDynamicReceiver(
default_buffer<wchar_t>(),
Callable,
[&](size_t ReturnedSize, size_t AllocatedSize)
{
Expand Down Expand Up @@ -1765,24 +1767,21 @@ bool GetFileTimeSimple(const string &FileName, LPFILETIME CreationTime, LPFILETI

FAR_SECURITY_DESCRIPTOR GetFileSecurity(const string& Object, SECURITY_INFORMATION RequestedInformation)
{
FAR_SECURITY_DESCRIPTOR Result;
FAR_SECURITY_DESCRIPTOR Result(default_buffer_size);
NTPath NtObject(Object);
ApiDynamicReceiver<char>([&](char* Buffer, size_t Size)
ApiDynamicReceiver(Result, [&](SECURITY_DESCRIPTOR* Buffer, size_t Size)
{
DWORD LengthNeeded = 0;
if (!::GetFileSecurity(NtObject.data(), RequestedInformation, reinterpret_cast<SECURITY_DESCRIPTOR*>(Buffer), static_cast<DWORD>(Size), &LengthNeeded))
return size_t(0);
return LengthNeeded <= Size? Size : (size_t)LengthNeeded;
if (!::GetFileSecurity(NtObject.data(), RequestedInformation, Buffer, static_cast<DWORD>(Size), &LengthNeeded))
return static_cast<size_t>(LengthNeeded);
return Size;
},
[](size_t ReturnedSize, size_t AllocatedSize)
{
return ReturnedSize > AllocatedSize;
},
[&](const char* Buffer, size_t Size)
{
Result.reset(Size);
memcpy(Result.get(), Buffer, Size);
});
[](...){});

return Result;
}

Expand Down
7 changes: 6 additions & 1 deletion far/farwinapi.hpp
Expand Up @@ -37,6 +37,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace os
{
enum
{
default_buffer_size = MAX_PATH
};

namespace detail
{
template<class deleter>
Expand Down Expand Up @@ -150,7 +155,7 @@ namespace os
bool GetVolumePathNamesForVolumeName(const string& VolumeName, string& VolumePathNames);
bool GetFileTimeSimple(const string &FileName, LPFILETIME CreationTime, LPFILETIME LastAccessTime, LPFILETIME LastWriteTime, LPFILETIME ChangeTime);
void EnableLowFragmentationHeap();
using FAR_SECURITY_DESCRIPTOR = block_ptr<SECURITY_DESCRIPTOR>;
using FAR_SECURITY_DESCRIPTOR = block_ptr<SECURITY_DESCRIPTOR, default_buffer_size>;
FAR_SECURITY_DESCRIPTOR GetFileSecurity(const string& Object, SECURITY_INFORMATION RequestedInformation);
bool SetFileSecurity(const string& Object, SECURITY_INFORMATION RequestedInformation, const FAR_SECURITY_DESCRIPTOR& SecurityDescriptor);
bool DetachVirtualDisk(const string& Object, VIRTUAL_STORAGE_TYPE& VirtualStorageType);
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,5002)m4_dnl
m4_define(BUILD,5003)m4_dnl

0 comments on commit 38e4d51

Please sign in to comment.