Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -168,11 +168,10 @@ OFLocking.h \ OFMessagePackRepresentation.h \ OFSerialization.h \ OFTLSSocket.h \ ObjFW.h \ - block.h \ macros.h \ objfw-defs.h \ platform.h \ ${USE_INCLUDES_ATOMIC} Index: src/OFBlock.h ================================================================== --- src/OFBlock.h +++ src/OFBlock.h @@ -13,12 +13,10 @@ * file. */ #import "OFObject.h" -#import "block.h" - OF_ASSUME_NONNULL_BEGIN /** * @class OFBlock OFBlock.h ObjFW/OFBlock.h * @@ -38,7 +36,39 @@ @end OF_SUBCLASSING_RESTRICTED @interface OFMallocBlock: OFBlock @end + +#ifdef __cplusplus +extern "C" { +#endif +extern void *_Block_copy(const void *); +extern void _Block_release(const void *); + +# if defined(OF_WINDOWS) && \ + (defined(OF_NO_SHARED) || defined(OF_COMPILING_OBJFW)) +/* + * Clang has implicit declarations for these, but they are dllimport. When + * compiling ObjFW itself or using it as a static library, these need to be + * dllexport. Interestingly, this still works when using it as a shared library. + */ +extern __declspec(dllexport) struct objc_class _NSConcreteStackBlock; +extern __declspec(dllexport) struct objc_class _NSConcreteGlobalBlock; +extern __declspec(dllexport) void _Block_object_assign(void *, const void *, + const int); +extern __declspec(dllexport) void _Block_object_dispose(const void *, + const int); +# endif +#ifdef __cplusplus +} +#endif + +#ifndef Block_copy +# define Block_copy(...) \ + ((__typeof__(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) +#endif +#ifndef Block_release +# define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) +#endif OF_ASSUME_NONNULL_END Index: src/OFBlock.m ================================================================== --- src/OFBlock.m +++ src/OFBlock.m @@ -33,14 +33,27 @@ #endif #ifdef OF_HAVE_THREADS # import "mutex.h" #endif -typedef struct of_block_byref_t of_block_byref_t; -struct of_block_byref_t { +struct block { + Class isa; + int flags; + int reserved; + void (*invoke)(void *block, ...); + struct { + unsigned long reserved; + unsigned long size; + void (*_Nullable copy_helper)(void *dest, void *src); + void (*_Nullable dispose_helper)(void *src); + const char *signature; + } *descriptor; +}; + +struct byref { Class isa; - of_block_byref_t *forwarding; + struct byref *forwarding; int flags; int size; void (*byref_keep)(void *dest, void *src); void (*byref_dispose)(void *); }; @@ -74,11 +87,11 @@ sizeof(_NSConcreteStackBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteStackBlock = { &_NSConcreteStackBlock_metaclass, (Class)(void *)"OFBlock", - "OFStackBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), + "OFStackBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct block), NULL, NULL }; static struct objc_class _NSConcreteGlobalBlock_metaclass = { Nil, Nil, "OFGlobalBlock", 8, OBJC_CLASS_INFO_METACLASS, @@ -85,11 +98,11 @@ sizeof(_NSConcreteGlobalBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteGlobalBlock = { &_NSConcreteGlobalBlock_metaclass, (Class)(void *)"OFBlock", - "OFGlobalBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), + "OFGlobalBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct block), NULL, NULL }; static struct objc_class _NSConcreteMallocBlock_metaclass = { Nil, Nil, "OFMallocBlock", 8, OBJC_CLASS_INFO_METACLASS, @@ -96,11 +109,11 @@ sizeof(_NSConcreteMallocBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteMallocBlock = { &_NSConcreteMallocBlock_metaclass, (Class)(void *)"OFBlock", - "OFMallocBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), + "OFMallocBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct block), NULL, NULL }; static struct { unsigned long unknown; @@ -161,14 +174,14 @@ #endif void * _Block_copy(const void *block_) { - of_block_literal_t *block = (of_block_literal_t *)block_; + struct block *block = (struct block *)block_; if ([(id)block isMemberOfClass: (Class)&_NSConcreteStackBlock]) { - of_block_literal_t *copy; + struct block *copy; if ((copy = malloc(block->descriptor->size)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException *) @@ -201,11 +214,11 @@ } void _Block_release(const void *block_) { - of_block_literal_t *block = (of_block_literal_t *)block_; + struct block *block = (struct block *)block_; if (object_getClass((id)block) != (Class)&_NSConcreteMallocBlock) return; #ifdef OF_HAVE_ATOMIC_OPS @@ -242,19 +255,19 @@ if (src_ == NULL) return; switch (flags) { case OF_BLOCK_FIELD_IS_BLOCK: - *(of_block_literal_t **)dst_ = _Block_copy(src_); + *(struct block **)dst_ = _Block_copy(src_); break; case OF_BLOCK_FIELD_IS_OBJECT: if (!(flags_ & OF_BLOCK_BYREF_CALLER)) *(id *)dst_ = [(id)src_ retain]; break; case OF_BLOCK_FIELD_IS_BYREF:; - of_block_byref_t *src = (of_block_byref_t *)src_; - of_block_byref_t **dst = (of_block_byref_t **)dst_; + struct byref *src = (struct byref *)src_; + struct byref **dst = (struct byref **)dst_; src = src->forwarding; if ((src->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { if ((*dst = malloc(src->size)) == NULL) { @@ -327,11 +340,11 @@ case OF_BLOCK_FIELD_IS_OBJECT: if (!(flags_ & OF_BLOCK_BYREF_CALLER)) [(id)object_ release]; break; case OF_BLOCK_FIELD_IS_BYREF:; - of_block_byref_t *object = (of_block_byref_t *)object_; + struct byref *object = (struct byref *)object_; object = object->forwarding; #ifdef OF_HAVE_ATOMIC_OPS if ((of_atomic_int_dec(&object->flags) & @@ -461,11 +474,11 @@ } - (unsigned int)retainCount { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) - return ((of_block_literal_t *)self)->flags & + return ((struct block *)self)->flags & OF_BLOCK_REFCOUNT_MASK; return OF_RETAIN_COUNT_MAX; } Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -28,11 +28,10 @@ #include #include #include #include -#include "block.h" #include "macros.h" #include "once.h" /* * Some versions of MinGW require to be included before @@ -1314,12 +1313,14 @@ #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END + +#include "OFBlock.h" #ifdef __OBJC__ # import "OFObject+KeyValueCoding.h" # import "OFObject+Serialization.h" #endif #endif DELETED src/block.h Index: src/block.h ================================================================== --- src/block.h +++ src/block.h @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2008-2021 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#ifndef OBJFW_BLOCK_H -#define OBJFW_BLOCK_H - -#include "macros.h" - -OF_ASSUME_NONNULL_BEGIN - -typedef struct of_block_literal_t { -#ifdef __OBJC__ - Class isa; -#else - void *isa; -#endif - int flags; - int reserved; - void (*invoke)(void *block, ...); - struct of_block_descriptor_t { - unsigned long reserved; - unsigned long size; - void (*_Nullable copy_helper)(void *dest, void *src); - void (*_Nullable dispose_helper)(void *src); - const char *signature; - } *descriptor; -} of_block_literal_t; - -#ifdef __cplusplus -extern "C" { -#endif -extern void *_Block_copy(const void *); -extern void _Block_release(const void *); - -# if defined(OF_WINDOWS) && \ - (defined(OF_NO_SHARED) || defined(OF_COMPILING_OBJFW)) -/* - * Clang has implicit declarations for these, but they are dllimport. When - * compiling ObjFW itself or using it as a static library, these need to be - * dllexport. Interestingly, this still works when using it as a shared library. - */ -extern __declspec(dllexport) struct objc_class _NSConcreteStackBlock; -extern __declspec(dllexport) struct objc_class _NSConcreteGlobalBlock; -extern __declspec(dllexport) void _Block_object_assign(void *, const void *, - const int); -extern __declspec(dllexport) void _Block_object_dispose(const void *, - const int); -# endif -#ifdef __cplusplus -} -#endif - -#ifndef Block_copy -# define Block_copy(...) \ - ((__typeof__(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) -#endif -#ifndef Block_release -# define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) -#endif - -OF_ASSUME_NONNULL_END - -#endif