Skip to content

Windows BlocksRuntime #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_library(BlocksRuntime
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
target_sources(BlocksRuntime
PRIVATE
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/BlocksRuntime.def)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(BlocksRuntime
PRIVATE
BlocksRuntime_STATIC)
endif()
endif()
set_target_properties(BlocksRuntime
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE)
Expand Down
23 changes: 21 additions & 2 deletions src/BlocksRuntime/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@
#ifndef _Block_H_
#define _Block_H_

#if defined(_WIN32)
# if defined(BlocksRuntime_STATIC)
# define BLOCK_ABI
# else
# if defined(BlocksRuntime_EXPORTS)
# define BLOCK_ABI __declspec(dllexport)
# else
# define BLOCK_ABI __declspec(dllimport)
# endif
# endif
#else
# define BLOCK_ABI __attribute__((__visibility__("default")))
#endif

#if !defined(BLOCK_EXPORT)
# if defined(__cplusplus)
# define BLOCK_EXPORT extern "C" __attribute__((visibility("default")))
# define BLOCK_EXPORT extern "C" BLOCK_ABI
# else
# define BLOCK_EXPORT extern __attribute__((visibility("default")))
# define BLOCK_EXPORT extern BLOCK_ABI
# endif
#endif

Expand All @@ -38,8 +52,13 @@ BLOCK_EXPORT void _Block_object_assign(void *, const void *, const int);
BLOCK_EXPORT void _Block_object_dispose(const void *, const int);

// Used by the compiler. Do not use these variables yourself.
#if defined(_WIN32)
extern void * _NSConcreteGlobalBlock[32];
extern void * _NSConcreteStackBlock[32];
#else
BLOCK_EXPORT void * _NSConcreteGlobalBlock[32];
BLOCK_EXPORT void * _NSConcreteStackBlock[32];
#endif

#if __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions src/BlocksRuntime/BlocksRuntime.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LIBRARY BlocksRuntime
EXPORTS
_NSConcreteGlobalBlock CONSTANT
_NSConcreteStackBlock CONSTANT
20 changes: 13 additions & 7 deletions src/BlocksRuntime/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ We allocate space and export a symbol to be used as the Class for the on-stack a

We keep these in a separate file so that we can include the runtime code in test subprojects but not include the data so that compiled code that sees the data in libSystem doesn't get confused by a second copy. Somehow these don't get unified in a common block.
**********************/
#define BLOCK_EXPORT __attribute__((visibility("default")))
#include "Block.h"

BLOCK_EXPORT void * _NSConcreteStackBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteMallocBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteAutoBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteGlobalBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32] = { 0 };
#if defined(_WIN32)
void * _NSConcreteStackBlock[32] = { 0 };
void * _NSConcreteGlobalBlock[32] = { 0 };
#else
BLOCK_ABI void * _NSConcreteStackBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteGlobalBlock[32] = { 0 };
#endif

BLOCK_ABI void * _NSConcreteMallocBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteAutoBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteFinalizingBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteWeakBlockVariable[32] = { 0 };