1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 23:36:00 +02:00

Fixes from macOS, first working build

This commit is contained in:
Brian Fiete 2019-10-15 17:27:09 -07:00
parent 2e84b4229c
commit 67ee302451
19 changed files with 237 additions and 107 deletions

View file

@ -27,6 +27,8 @@
#include <cxxabi.h>
#include <random>
#include <mach-o/dyld.h>
USING_NS_BF;
@ -293,6 +295,48 @@ static Array<CrashInfoFunc> gCrashInfoFuncs;
static String gCmdLine;
static String gExePath;
typedef struct _Unwind_Context _Unwind_Context; // opaque
typedef enum {
_URC_NO_REASON = 0,
_URC_OK = 0,
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
_URC_FATAL_PHASE2_ERROR = 2,
_URC_FATAL_PHASE1_ERROR = 3,
_URC_NORMAL_STOP = 4,
_URC_END_OF_STACK = 5,
_URC_HANDLER_FOUND = 6,
_URC_INSTALL_CONTEXT = 7,
_URC_CONTINUE_UNWIND = 8,
_URC_FAILURE = 9
} _Unwind_Reason_Code;
typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *, void *);
extern "C" _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
extern "C" uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
static String gUnwindExecStr;
static int gUnwindIdx = 0;
static _Unwind_Reason_Code UnwindHandler(struct _Unwind_Context* context, void* ref)
{
gUnwindIdx++;
if (gUnwindIdx < 2)
return _URC_NO_REASON;
dl_info dyldInfo;
void* addr = (void*)_Unwind_GetIP(context);
gUnwindExecStr += StrFormat(" %p", addr);
return _URC_NO_REASON;
}
static bool FancyBacktrace()
{
gUnwindExecStr += StrFormat("atos -p %d", getpid());
_Unwind_Backtrace(&UnwindHandler, NULL);
return system(gUnwindExecStr.c_str()) == 0;
}
static void Crashed()
{
//
@ -315,18 +359,21 @@ static void Crashed()
fprintf(stderr, "%s", debugDump.c_str());
}
void* array[64];
size_t size;
char** strings;
size_t i;
if (!FancyBacktrace())
{
void* array[64];
size_t size;
char** strings;
size_t i;
size = backtrace(array, 64);
strings = backtrace_symbols(array, size);
size = backtrace(array, 64);
strings = backtrace_symbols(array, size);
for (i = 0; i < size; i++)
fprintf(stderr, "%s\n", strings[i]);
for (i = 0; i < size; i++)
fprintf(stderr, "%s\n", strings[i]);
free(strings);
free(strings);
}
exit(1);
}
@ -372,11 +419,12 @@ BFP_EXPORT void BFP_CALLTYPE BfpSystem_Init(int version, BfpSystemInitFlags flag
}
BFP_EXPORT void BFP_CALLTYPE BfpSystem_SetCommandLine(int argc, char** argv)
{
{
char* relPath = argv[0];
char* cwd = getcwd(NULL, 0);
gExePath = GetAbsPath(relPath, cwd);
free(cwd);
for (int i = 0; i < argc; i++)
@ -501,6 +549,19 @@ BFP_EXPORT void BFP_CALLTYPE BfpSystem_GetCommandLine(char* outStr, int* inOutSt
BFP_EXPORT void BFP_CALLTYPE BfpSystem_GetExecutablePath(char* outStr, int* inOutStrSize, BfpSystemResult* outResult)
{
//printf("Setting BfpSystem_GetExecutablePath %s %p\n", gExePath.c_str(), &gExePath);
if (gExePath.IsEmpty())
{
char path[4096];
uint32_t size = sizeof(path);
if (_NSGetExecutablePath(path, &size) == 0)
gExePath = path;
// When when running with a './file', we end up with an annoying '/./' in our path
gExePath.Replace("/./", "/");
}
TryStringOut(gExePath, outStr, inOutStrSize, (BfpResult*)outResult);
}
@ -1101,6 +1162,8 @@ BFP_EXPORT bool BFP_CALLTYPE BfpThread_WaitFor(BfpThread* thread, int waitMS)
return true;
}
if (thread == NULL)
BF_FATAL("Invalid thread with non-infinite wait");
return BfpEvent_WaitFor(thread->mDoneEvent, waitMS);
}
@ -1505,12 +1568,14 @@ BFP_EXPORT BfpFile* BFP_CALLTYPE BfpFile_Create(const char* inName, BfpFileCreat
if ((createFlags & BfpFileCreateFlag_Pipe) != 0)
{
name = "/tmp/" + name;
if ((createKind == BfpFileCreateKind_CreateAlways) ||
(createKind == BfpFileCreateKind_CreateIfNotExists))
{
for (int pass = 0; pass < 2; pass++)
{
int result = mknod(name.c_str(), S_IFIFO | ALLPERMS, 0);
int result = mknod(name.c_str(), S_IFIFO | 0666, 0);
if (result == 0)
break;
@ -1821,10 +1886,20 @@ BFP_EXPORT void BFP_CALLTYPE BfpFile_Copy(const char* oldPath, const char* newPa
return;
}
fd_to = open(newPath, O_WRONLY | O_CREAT | O_EXCL, 0666);
int flags = O_WRONLY | O_CREAT;
if (copyKind == BfpFileCopyKind_IfNotExists)
flags |= O_EXCL;
fd_to = open(newPath, flags, 0666);
if (fd_to < 0)
{
OUTRESULT(BfpFileResult_AlreadyExists);
if (errno == EEXIST)
{
OUTRESULT(BfpFileResult_AlreadyExists);
goto out_error;
}
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}

View file

@ -58,8 +58,6 @@ typedef int16_t int16;
typedef int8_t int8;
typedef unsigned int uint;
#define BF_PLATFORM_LINUX
#define BF_PLATFORM_NAME "BF_PLATFORM_LINUX"
//#define BF_PLATFORM_SDL
#define NOP
@ -67,13 +65,8 @@ typedef unsigned int uint;
//#define BF_NOTHROW noexcept
#define BF_NOTHROW
#ifdef BF64
typedef int64 intptr;
typedef uint64 uintptr;
#else
typedef int32 intptr;
typedef uint32 uintptr;
#endif
typedef intptr_t intptr;
typedef uintptr_t uintptr;
typedef wchar_t* BSTR;
typedef int HRESULT;
@ -85,6 +78,8 @@ typedef int32 LONG;
typedef pthread_key_t BFTlsKey;
typedef pthread_t BF_THREADID;
typedef pthread_t BF_THREADHANDLE;
#define BF_HAS_TLS_DECLSPEC
#define BF_TLS_DECLSPEC thread_local
//:int64 abs(int64 val);

View file

@ -5,6 +5,7 @@
#include "LinuxCommon.h"
#define BF_PLATFORM_LINUX
#define BF_PLATFORM_NAME "BF_PLATFORM_LINUX"
#define BF_IMPORT extern "C"

View file

@ -28,7 +28,6 @@
USING_NS_BF;
struct BfpPipeInfo
{
String mPipePath;
@ -431,7 +430,7 @@ BFP_EXPORT void BFP_CALLTYPE BfpSystem_Init(int version, BfpSystemInitFlags flag
}
BFP_EXPORT void BFP_CALLTYPE BfpSystem_SetCommandLine(int argc, char** argv)
{
{
char* relPath = argv[0];
char* cwd = getcwd(NULL, 0);
@ -1565,7 +1564,7 @@ BFP_EXPORT BfpFile* BFP_CALLTYPE BfpFile_Create(const char* inName, BfpFileCreat
{
for (int pass = 0; pass < 2; pass++)
{
int result = mknod(name.c_str(), S_IFIFO | ALLPERMS, 0);
int result = mknod(name.c_str(), S_IFIFO | 0666, 0);
if (result == 0)
break;
@ -1865,64 +1864,74 @@ BFP_EXPORT void BFP_CALLTYPE BfpFile_SetAttributes(const char* path, BfpFileAttr
BFP_EXPORT void BFP_CALLTYPE BfpFile_Copy(const char* oldPath, const char* newPath, BfpFileCopyKind copyKind, BfpFileResult* outResult)
{
int fd_to, fd_from;
char buf[4096];
ssize_t nread;
int fd_to, fd_from;
char buf[4096];
ssize_t nread;
fd_from = open(oldPath, O_RDONLY);
if (fd_from < 0)
{
OUTRESULT(BfpFileResult_NotFound);
return;
}
fd_from = open(oldPath, O_RDONLY);
if (fd_from < 0)
{
OUTRESULT(BfpFileResult_NotFound);
return;
}
fd_to = open(newPath, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd_to < 0)
{
OUTRESULT(BfpFileResult_AlreadyExists);
goto out_error;
}
int flags = O_WRONLY | O_CREAT;
if (copyKind == BfpFileCopyKind_IfNotExists)
flags |= O_EXCL;
while (nread = read(fd_from, buf, sizeof buf), nread > 0)
{
char *out_ptr = buf;
ssize_t nwritten;
fd_to = open(newPath, flags, 0666);
if (fd_to < 0)
{
if (errno == EEXIST)
{
OUTRESULT(BfpFileResult_AlreadyExists);
goto out_error;
}
do {
nwritten = write(fd_to, out_ptr, nread);
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}
if (nwritten >= 0)
{
nread -= nwritten;
out_ptr += nwritten;
}
else if (errno != EINTR)
{
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}
} while (nread > 0);
}
while (nread = read(fd_from, buf, sizeof buf), nread > 0)
{
char *out_ptr = buf;
ssize_t nwritten;
if (nread == 0)
{
if (close(fd_to) < 0)
{
fd_to = -1;
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}
close(fd_from);
do {
nwritten = write(fd_to, out_ptr, nread);
/* Success! */
OUTRESULT(BfpFileResult_Ok);
return;
}
if (nwritten >= 0)
{
nread -= nwritten;
out_ptr += nwritten;
}
else if (errno != EINTR)
{
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}
} while (nread > 0);
}
if (nread == 0)
{
if (close(fd_to) < 0)
{
fd_to = -1;
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}
close(fd_from);
/* Success! */
OUTRESULT(BfpFileResult_Ok);
return;
}
out_error:
close(fd_from);
if (fd_to >= 0)
close(fd_to);
close(fd_from);
if (fd_to >= 0)
close(fd_to);
}
BFP_EXPORT void BFP_CALLTYPE BfpFile_Rename(const char* oldPath, const char* newPath, BfpFileResult* outResult)

View file

@ -55,8 +55,6 @@ typedef int16_t int16;
typedef int8_t int8;
typedef unsigned int uint;
#define BF_PLATFORM_LINUX
#define BF_PLATFORM_NAME "BF_PLATFORM_LINUX"
//#define BF_PLATFORM_SDL
#define NOP

View file

@ -5,7 +5,8 @@
#include "../darwin/DarwinCommon.h"
#include <string>
#define BF_PLATFORM_OSX
#define BF_PLATFORM_MACOS
#define BF_PLATFORM_NAME "BF_PLATFORM_MACOS"
#define BF_IMPORT extern "C"