Ghost: Make special user directory query thread safe

Similar to e0ff7731e0.

Noticed a data race when working on blender/blender!130543, which calls
this function from a thread. Make this thread safe by avoiding returning
of static memory, instead use an optional `std::string`.

Pull Request: https://projects.blender.org/blender/blender/pulls/141083
This commit is contained in:
Julian Eisel
2025-06-27 15:16:35 +02:00
committed by Julian Eisel
parent 52caedb19e
commit 4b2d60a2c3
10 changed files with 71 additions and 37 deletions

View File

@@ -8,6 +8,9 @@
#pragma once
#include <optional>
#include <string>
#include "GHOST_Types.h"
GHOST_DECLARE_HANDLE(GHOST_SystemPathsHandle);
@@ -46,9 +49,9 @@ extern const char *GHOST_getUserDir(int version, const char *versionstr);
/**
* Determine a special ("well known") and easy to reach user directory.
* \return Unsigned char string pointing to user directory (eg `~/Documents/`).
* \return If successfull, a string containing the user directory path (eg `~/Documents/`).
*/
extern const char *GHOST_getUserSpecialDir(GHOST_TUserSpecialDirTypes type);
extern std::optional<std::string> GHOST_getUserSpecialDir(GHOST_TUserSpecialDirTypes type);
/**
* Determine the directory in which the binary file is found.