Skip to content

Commit

Permalink
Traktor: Added "nodiscard" to allocator interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Apr 30, 2024
1 parent 658fb2b commit bdf20d9
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion code/Core/Class/BoxedAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BoxedAllocator
Alloc::freeAlign(allocator.top());
}

BoxedType* alloc()
[[nodiscard]] BoxedType* alloc()
{
#if defined(T_BOXES_USE_MT_LOCK)
T_ANONYMOUS_VAR(Acquire< SpinLock >)(m_lock);
Expand Down
4 changes: 3 additions & 1 deletion code/Core/Class/CoreClassFactory1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Core/Io/Utf8Encoding.h"
#include "Core/Io/Utf16Encoding.h"
#include "Core/Io/Utf32Encoding.h"
#include "Core/Log/Log.h"
#include "Core/Serialization/DeepClone.h"
#include "Core/Serialization/DeepHash.h"
#include "Core/Settings/PropertyArray.h"
Expand Down Expand Up @@ -85,7 +86,8 @@ int64_t IStream_seek(IStream* self, int64_t origin, int64_t offset)

void FileSystem_setCurrentVolumeAndDirectory(FileSystem* self, const Path& directory)
{
self->setCurrentVolumeAndDirectory(directory);
if (!self->setCurrentVolumeAndDirectory(directory))
log::warning << L"Unable to set current volume and directory \"" << directory.getPathName() << L"\"." << Endl;
}

Path FileSystem_getCurrentVolumeAndDirectory(FileSystem* self)
Expand Down
2 changes: 1 addition & 1 deletion code/Core/Io/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class T_DLLCLASS FileSystem
* \param directory New current directory.
* \return True if successfully changed.
*/
bool setCurrentVolumeAndDirectory(const Path& directory);
[[nodiscard]] bool setCurrentVolumeAndDirectory(const Path& directory);

/*! Get current volume and directory.
*/
Expand Down
4 changes: 2 additions & 2 deletions code/Core/Memory/Alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class T_DLLCLASS Alloc
{
public:
/*! Allocate chunk of memory. */
static void* acquire(size_t size, const char* tag);
[[nodiscard]] static void* acquire(size_t size, const char* tag);

/*! Free chunk of memory. */
static void free(void* ptr);

/*! Allocate aligned chunk of memory. */
static void* acquireAlign(size_t size, size_t align, const char* tag);
[[nodiscard]] static void* acquireAlign(size_t size, size_t align, const char* tag);

/*! Free aligned chunk of memory. */
static void freeAlign(void* ptr);
Expand Down
2 changes: 1 addition & 1 deletion code/Core/Memory/BlockAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class T_DLLCLASS BlockAllocator

void* top() { return m_top; }

void* alloc();
[[nodiscard]] void* alloc();

bool free(void* p);

Expand Down
2 changes: 1 addition & 1 deletion code/Core/Memory/DebugAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DebugAllocator : public IAllocator

virtual ~DebugAllocator();

virtual void* alloc(size_t size, size_t align, const char* const tag) override final;
[[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final;

virtual void free(void* ptr) override final;

Expand Down
2 changes: 1 addition & 1 deletion code/Core/Memory/FastAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FastAllocator : public IAllocator

virtual ~FastAllocator();

virtual void* alloc(size_t size, size_t align, const char* const tag) override final;
[[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final;

virtual void free(void* ptr) override final;

Expand Down
2 changes: 1 addition & 1 deletion code/Core/Memory/IAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IAllocator
public:
virtual ~IAllocator() {}

virtual void* alloc(size_t size, size_t align, const char* const tag) = 0;
[[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) = 0;

virtual void free(void* ptr) = 0;
};
Expand Down
8 changes: 4 additions & 4 deletions code/Core/Memory/PoolAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class T_DLLCLASS PoolAllocator : public Object
* \param align Alignment of chunk.
* \return Pointer to chunk.
*/
void* alloc(uint32_t size, uint32_t align);
[[nodiscard]] void* alloc(uint32_t size, uint32_t align);

/*! Allocate object.
*
* \return Pointer to object.
*/
template < typename Type >
Type* alloc()
[[nodiscard]] Type* alloc()
{
void* ptr = alloc((uint32_t)sizeof(Type), (uint32_t)alignOf< Type >());
return new (ptr) Type();
Expand All @@ -85,7 +85,7 @@ class T_DLLCLASS PoolAllocator : public Object
* \return Pointer to first object.
*/
template < typename Type >
Type* alloc(uint32_t count)
[[nodiscard]] Type* alloc(uint32_t count)
{
if (!count)
return nullptr;
Expand All @@ -100,7 +100,7 @@ class T_DLLCLASS PoolAllocator : public Object
* \return Pointer to first object pointer.
*/
template < typename Type >
Type** allocArray(uint32_t count)
[[nodiscard]] Type** allocArray(uint32_t count)
{
if (!count)
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion code/Core/Memory/StdAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace traktor
class StdAllocator : public IAllocator
{
public:
virtual void* alloc(size_t size, size_t align, const char* const tag) override final;
[[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final;

virtual void free(void* ptr) override final;
};
Expand Down
6 changes: 3 additions & 3 deletions code/Core/Memory/SystemConstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ namespace traktor
{

template < typename T >
T* allocConstruct()
[[nodiscard]] T* allocConstruct()
{
void* p = Alloc::acquireAlign(sizeof(T), alignOf< T >(), "global");
return new (p) T();
}

template < typename T, typename A >
T* allocConstruct(A a)
[[nodiscard]] T* allocConstruct(A a)
{
void* p = Alloc::acquireAlign(sizeof(T), alignOf< T >(), "global");
return new (p) T(a);
}

template < typename T, typename A, typename B, typename C >
T* allocConstruct(A a, B b, C c)
[[nodiscard]] T* allocConstruct(A a, B b, C c)
{
void* p = Alloc::acquireAlign(sizeof(T), alignOf< T >(), "global");
return new (p) T(a, b, c);
Expand Down
2 changes: 1 addition & 1 deletion code/Core/Memory/TrackAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TrackAllocator : public IAllocator

virtual ~TrackAllocator();

virtual void* alloc(size_t size, size_t align, const char* const tag) override final;
[[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final;

virtual void free(void* ptr) override final;

Expand Down
6 changes: 4 additions & 2 deletions code/Editor/Build/App/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ int main(int argc, const char** argv)
const Path cwd = FileSystem::getInstance().getCurrentVolumeAndDirectory();

const Path executablePath = OS::getInstance().getExecutable().getPathOnly();
FileSystem::getInstance().setCurrentVolumeAndDirectory(executablePath);
if (!FileSystem::getInstance().setCurrentVolumeAndDirectory(executablePath))
return 1;

while (!FileSystem::getInstance().exist(L"LICENSE.txt"))
{
Expand All @@ -153,7 +154,8 @@ int main(int argc, const char** argv)
}

OS::getInstance().setEnvironment(L"TRAKTOR_HOME", FileSystem::getInstance().getCurrentVolumeAndDirectory().getPathNameOS());
FileSystem::getInstance().setCurrentVolumeAndDirectory(cwd);
if (!FileSystem::getInstance().setCurrentVolumeAndDirectory(cwd))
return 1;
}

std::wstring settingsFile = L"$(TRAKTOR_HOME)/resources/runtime/configurations/Traktor.Editor.config";
Expand Down
8 changes: 4 additions & 4 deletions code/Render/Context/RenderContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ class T_DLLCLASS RenderContext : public Object
virtual ~RenderContext();

/*! Allocate a unaligned block of memory from context's heap. */
void* alloc(uint32_t blockSize);
[[nodiscard]] void* alloc(uint32_t blockSize);

/*! Allocate a aligned block of memory from context's heap. */
void* alloc(uint32_t blockSize, uint32_t align);
[[nodiscard]] void* alloc(uint32_t blockSize, uint32_t align);

/*! Allocate object from context's heap. */
template < typename ObjectType, typename ... ArgumentTypes >
ObjectType* alloc(ArgumentTypes&& ... args)
[[nodiscard]] ObjectType* alloc(ArgumentTypes&& ... args)
{
void* object = alloc((uint32_t)sizeof(ObjectType), (uint32_t)alignOf< ObjectType >());
return new (object) ObjectType(std::forward< ArgumentTypes >(args) ...);
}

/*! Allocate named object from context's heap. */
template < typename ObjectType, typename ... ArgumentTypes >
ObjectType* allocNamed(const std::wstring_view& name, ArgumentTypes&& ... args)
[[nodiscard]] ObjectType* allocNamed(const std::wstring_view& name, ArgumentTypes&& ... args)
{
ObjectType* object = alloc< ObjectType, ArgumentTypes... >(std::forward< ArgumentTypes >(args) ...);
object->name = name;
Expand Down
3 changes: 2 additions & 1 deletion code/Ui/Theme/App/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR szCmdLine, int)
log::error << L"No LICENSE.txt file found." << Endl;
return 1;
}
FileSystem::getInstance().setCurrentVolumeAndDirectory(pwd);
if (!FileSystem::getInstance().setCurrentVolumeAndDirectory(pwd))
return 1;
}

const Path cwd = FileSystem::getInstance().getCurrentVolumeAndDirectory();
Expand Down

0 comments on commit bdf20d9

Please sign in to comment.