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{ {@autoreleasepool{
CGRect cgFrame = {{frame.x, frame.y}, {frame.w, frame.h}}; CGRect cgFrame = {{frame.x, frame.y}, {frame.w, frame.h}};
// dispatch_async(dispatch_get_main_queue(), [CATransaction begin];
// ^{ [CATransaction setDisableActions:YES];
[CATransaction begin]; [surface->layer.caLayer setFrame: cgFrame];
[CATransaction setDisableActions:YES]; [CATransaction commit];
[surface->layer.caLayer setFrame: cgFrame];
[CATransaction commit];
// });
}} }}
bool mg_osx_surface_get_hidden(mg_surface_data* surface) bool mg_osx_surface_get_hidden(mg_surface_data* surface)
@ -2222,27 +2218,44 @@ int mp_alert_popup(const char* title,
uint32 count, uint32 count,
const char** options) const char** options)
{ {
@autoreleasepool __block int result = 0;
{
NSWindow *keyWindow = [NSApp keyWindow];
NSAlert* alert = [[NSAlert alloc] init]; dispatch_block_t block = ^{
NSString* string; @autoreleasepool
for(int i=count-1;i>=0;i--)
{ {
string = [[NSString alloc] initWithUTF8String:options[i]]; NSWindow *keyWindow = [NSApp keyWindow];
[alert addButtonWithTitle:string];
[string release];
}
string = [[NSString alloc] initWithUTF8String:message];
[alert setMessageText:string];
[string release];
[alert setAlertStyle:NSAlertStyleWarning]; NSAlert* alert = [[NSAlert alloc] init];
int result = count - ([alert runModal]-NSAlertFirstButtonReturn) - 1; NSString* string;
[keyWindow makeKeyWindow]; for(int i=count-1;i>=0;i--)
return(result); {
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: * @revision:
* *
*****************************************************************/ *****************************************************************/
#include<stdarg.h>
#include<string.h> #include<string.h>
#include"debug_log.h" #include"debug_log.h"
#include"platform_varg.h"
static const char* LOG_HEADINGS[LOG_LEVEL_COUNT] = { static const char* LOG_HEADINGS[LOG_LEVEL_COUNT] = {
"Error", "Error",
"Warning", "Warning",

View File

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