Skip to content

Commit

Permalink
win32: Add/update a handful of defines for Win32 without MinGW/Cygwin.
Browse files Browse the repository at this point in the history
* Thanks to Windows.h, BOOL must be an int on win32.
  • Loading branch information
DHowett committed Jan 22, 2018
1 parent 44988ee commit 6cd94b7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion legacy_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void *objc_atomic_malloc(size_t size)
return malloc(size);
}

#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_WINDOWS)
void *objc_valloc(size_t size)
{
return malloc(size);
Expand Down
3 changes: 2 additions & 1 deletion mutation.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "objc/runtime.h"
#include "visibility.h"

static void objc_enumeration_mutation_fallback(id object)
{
Expand All @@ -13,7 +14,7 @@ static void objc_enumeration_mutation_fallback(id object)
// This function is exported as a weak symbol to enable GNUstep or some other
// framework to replace it trivially. On platforms with linkers that cannot handle weak exports,
// the objc_enumeration_mutation hook is the preferred override point.
void __attribute__((weak)) objc_enumerationMutation(id obj)
void WEAK_EXPORT objc_enumerationMutation(id obj)
{
_objc_enumeration_mutation(obj);
}
Expand Down
4 changes: 4 additions & 0 deletions objc/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ typedef signed char BOOL;
# ifdef __vxwords
typedef int BOOL;
# else
# if defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
typedef int BOOL;

This comment has been minimized.

Copy link
@DHowett-MSFT

DHowett-MSFT Mar 4, 2018

@davidchisnall I wanted to get your take on this. For consumers who are both including Windows.h and using Objective-C we didn't have much choice but to make BOOL an int. I wanted to use a workaround like _WINBOOL (safewindows.h), but Windows.h consumers are pretty likely to want to use other windows headers that also assume an int BOOL.

This might be better expressed through a macro such as OBJC_BOOL_IS_INT (and on the windows side we could prevent linking together objects with two different definitions of BOOL)... but the problem remains.

Also, should __vxwords above actually be __vxworks? 🤷‍♂️

# else
typedef unsigned char BOOL;
# endif
# endif
# endif

Expand Down
2 changes: 1 addition & 1 deletion spinlock.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_WINDOWS)
#include <windows.h>
static unsigned sleep(unsigned seconds)
{
Expand Down
1 change: 1 addition & 0 deletions visibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

#define LIKELY(x) __builtin_expect(x, 1)
#define UNLIKELY(x) __builtin_expect(x, 0)
#define WEAK_EXPORT __attribute__((weak))

0 comments on commit 6cd94b7

Please sign in to comment.