adding vargs and asserts for orca

This commit is contained in:
Martin Fouilleul 2023-04-18 10:43:52 +02:00
parent e9e9ab68c2
commit 0d6fb197fb
4 changed files with 65 additions and 29 deletions

View File

@ -1712,14 +1712,10 @@ void mg_osx_surface_set_frame(mg_surface_data* surface, mp_rect frame)
{@autoreleasepool{
CGRect cgFrame = {{frame.x, frame.y}, {frame.w, frame.h}};
// dispatch_async(dispatch_get_main_queue(),
// ^{
[CATransaction begin];
[CATransaction setDisableActions:YES];
[surface->layer.caLayer setFrame: cgFrame];
[CATransaction commit];
// });
[CATransaction begin];
[CATransaction setDisableActions:YES];
[surface->layer.caLayer setFrame: cgFrame];
[CATransaction commit];
}}
bool mg_osx_surface_get_hidden(mg_surface_data* surface)
@ -2222,27 +2218,44 @@ int mp_alert_popup(const char* title,
uint32 count,
const char** options)
{
@autoreleasepool
{
NSWindow *keyWindow = [NSApp keyWindow];
__block int result = 0;
NSAlert* alert = [[NSAlert alloc] init];
NSString* string;
for(int i=count-1;i>=0;i--)
dispatch_block_t block = ^{
@autoreleasepool
{
string = [[NSString alloc] initWithUTF8String:options[i]];
[alert addButtonWithTitle:string];
[string release];
}
string = [[NSString alloc] initWithUTF8String:message];
[alert setMessageText:string];
[string release];
NSWindow *keyWindow = [NSApp keyWindow];
[alert setAlertStyle:NSAlertStyleWarning];
int result = count - ([alert runModal]-NSAlertFirstButtonReturn) - 1;
[keyWindow makeKeyWindow];
return(result);
NSAlert* alert = [[NSAlert alloc] init];
NSString* string;
for(int i=count-1;i>=0;i--)
{
string = [[NSString alloc] initWithUTF8String:options[i]];
[alert addButtonWithTitle:string];
[string release];
}
string = [[NSString alloc] initWithUTF8String:title];
[alert setMessageText:string];
[string release];
string = [[NSString alloc] initWithUTF8String:message];
[alert setInformativeText:string];
[string release];
[alert setAlertStyle:NSAlertStyleWarning];
result = count - ([alert runModal]-NSAlertFirstButtonReturn) - 1;
[keyWindow makeKeyWindow];
}
};
if([NSThread isMainThread])
{
block();
}
else
{
dispatch_sync(dispatch_get_main_queue(), block);
}
return(result);
}

View File

@ -0,0 +1,22 @@
/************************************************************//**
*
* @file: platform_varg.h
* @author: Martin Fouilleul
* @date: 17/04/2023
*
*****************************************************************/
#ifndef __PLATFORM_VARG_H_
#define __PLATFORM_VARG_H_
#include"platform.h"
#if PLATFORM_ORCA
#define va_start __builtin_va_start
#define va_arg __builtin_va_arg
#define va_copy __builtin_va_copy
#define va_end __builtin_va_end
#else
#include<stdarg.h>
#endif
#endif //__PLATFORM_VARG_H_

View File

@ -6,10 +6,11 @@
* @revision:
*
*****************************************************************/
#include<stdarg.h>
#include<string.h>
#include"debug_log.h"
#include"platform_varg.h"
static const char* LOG_HEADINGS[LOG_LEVEL_COUNT] = {
"Error",
"Warning",

View File

@ -124,10 +124,10 @@ static inline u64 next_pow2_u64(u64 x)
#ifndef NO_ASSERT
#ifdef PLATFORM_ORCA
//TODO add a runtime-provided assert
extern void orca_assert(bool x);
extern int orca_assert(const char* file, const char* function, int line, const char* src, const char* msg);
#define _ASSERT_(x, msg) orca_assert(x)
#define ORCA_ASSERT(x, msg) ((x) || orca_assert(__FILE__, __FUNCTION__, __LINE__, #x, msg))
#define _ASSERT_(x, msg) ORCA_ASSERT(x, msg)
#else
#include<assert.h>
#define _ASSERT_(x, msg) assert(x && msg)