Overview
Comment: | Blocks can be used like normal ObjC objects now. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ccf87e1ffbf53cf7f06228411bca545d |
User & Date: | js on 2010-09-06 20:27:41 |
Other Links: | manifest | tags |
Context
2010-09-06
| ||
20:51 | Add missing definitions of Block_{copy,release} to OFBlock.h. check-in: 3f655d43f6 user: js tags: trunk | |
20:27 | Blocks can be used like normal ObjC objects now. check-in: ccf87e1ffb user: js tags: trunk | |
15:39 | Add flags for blocks to objfw-config. check-in: cc3239f5f7 user: js tags: trunk | |
Changes
Modified configure.ac from [4c20212f8e] to [81303923b2].
︙ | ︙ | |||
71 72 73 74 75 76 77 | AC_DEFINE(OF_HAVE_BLOCKS, 1, [Compiler support for blocks]) AC_SUBST(BLOCKS_FLAGS, "-fblocks") AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ]) | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | AC_DEFINE(OF_HAVE_BLOCKS, 1, [Compiler support for blocks]) AC_SUBST(BLOCKS_FLAGS, "-fblocks") AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ]) AC_CHECK_FUNC(_Block_copy,, AC_SUBST(OFBLOCK_M, "OFBlock.m")) AC_CHECK_HEADERS([objfw-rt.h objc/objc.h]) test x"$ac_cv_header_objfw_rt_h" = x"yes" && objc_runtime="ObjFW-RT" if test x"$ac_cv_header_objc_objc_h" = x"yes"; then dnl TODO: This is ugly. Let's think of a better check. |
︙ | ︙ |
Modified extra.mk.in from [278e8d8f53] to [9812258b7a].
1 2 3 4 5 6 7 8 | OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_LIB_MAJOR = 2 OBJFW_LIB_MINOR = 0 OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} ASPRINTF_M = @ASPRINTF_M@ ATOMIC_H = @ATOMIC_H@ | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_LIB_MAJOR = 2 OBJFW_LIB_MINOR = 0 OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} ASPRINTF_M = @ASPRINTF_M@ ATOMIC_H = @ATOMIC_H@ OBJC_PROPERTIES_M = @OBJC_PROPERTIES_M@ OBJC_SYNC_M = @OBJC_SYNC_M@ OFBLOCK_M = @OFBLOCK_M@ OFPLUGIN_M = @OFPLUGIN_M@ OFPLUGINTESTS_M = @OFPLUGINTESTS_M@ OFTHREAD_M = @OFTHREAD_M@ OFTHREADTESTS_M = @OFTHREADTESTS_M@ PROPERTIESTESTS_M = @PROPERTIESTESTS_M@ REEXPORT_LIBOBJC = @REEXPORT_LIBOBJC@ TESTPLUGIN = @TESTPLUGIN@ |
︙ | ︙ |
Modified src/Makefile from [2ddb212bf2] to [35ed01a7f4].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | include ../extra.mk LIB = ${OBJFW_SHARED_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} STATIC_LIB = ${OBJFW_STATIC_LIB} SRCS = OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFConstString.m \ OFDataArray.m \ OFDictionary.m \ OFExceptions.m \ OFFile.m \ OFHash.m \ OFEnumerator.m \ OFList.m \ | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | include ../extra.mk LIB = ${OBJFW_SHARED_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} STATIC_LIB = ${OBJFW_STATIC_LIB} SRCS = OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFConstString.m \ ${OFBLOCK_M} \ OFDataArray.m \ OFDictionary.m \ OFExceptions.m \ OFFile.m \ OFHash.m \ OFEnumerator.m \ OFList.m \ |
︙ | ︙ | |||
50 51 52 53 54 55 56 | objfw-defs.h \ ${THREADING_H} SRCS += ${ASPRINTF_M} \ iso_8859_15.m \ windows_1252.m \ ${OBJC_PROPERTIES_M} \ | | < | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | objfw-defs.h \ ${THREADING_H} SRCS += ${ASPRINTF_M} \ iso_8859_15.m \ windows_1252.m \ ${OBJC_PROPERTIES_M} \ ${OBJC_SYNC_M} include ../buildsys.mk CPPFLAGS += -I.. LD = ${OBJC} LDFLAGS += ${REEXPORT_LIBOBJC} |
Added src/OFBlock.h version [31cbc5c2b5].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | /* * Copyright (c) 2008 - 2010 * Jonathan Schleifer <js@webkeks.org> * * 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 included in * the packaging of this file. */ #import "objfw-defs.h" #ifdef OF_OBJFW_RUNTIME # import <objfw-rt.h> #else # import <objc/objc.h> #endif typedef struct __of_block_literal { Class isa; int flags; int reserved; void (*invoke)(void *, ...); struct __of_block_descriptor { unsigned long reserved; unsigned long size; void (*copy_helper)(void *dest, void *src); void (*dispose_helper)(void *src); const char *signature; } *descriptor; } of_block_literal_t; typedef struct __of_block_byref { Class isa; struct __of_block_byref *forwarding; int flags; int size; void (*byref_keep)(void *dest, void *src); void (*byref_dispose)(void*); } of_block_byref_t; enum { OF_BLOCK_HAS_COPY_DISPOSE = (1 << 25), OF_BLOCK_HAS_CTOR = (1 << 26), OF_BLOCK_IS_GLOBAL = (1 << 28), OF_BLOCK_HAS_STRET = (1 << 29), OF_BLOCK_HAS_SIGNATURE = (1 << 30), }; enum { OF_BLOCK_FIELD_IS_OBJECT = 3, OF_BLOCK_FIELD_IS_BLOCK = 7, OF_BLOCK_FIELD_IS_BYREF = 8, OF_BLOCK_FIELD_IS_WEAK = 16, OF_BLOCK_BYREF_CALLER = 128, }; @interface OFBlock { Class isa; } - copy; - (void)release; - autorelease; @end |
Added src/OFBlock.m version [ef0cae1828].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /* * Copyright (c) 2008 - 2010 * Jonathan Schleifer <js@webkeks.org> * * 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 included in * the packaging of this file. */ #include "config.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #import "OFBlock.h" #import "OFAutoreleasePool.h" struct objc_abi_class { struct objc_abi_class *metaclass; const char *superclass, *name; unsigned long version, info, instance_size; void *ivars, *methodlist, *dtable, *subclass_list, *sibling_class; void *protocols, *gc_object_type; long abi_version; void *ivar_offsets, *properties; }; enum objc_abi_class_info { OBJC_CLASS_INFO_CLASS = 0x01, OBJC_CLASS_INFO_METACLASS = 0x02 }; extern void __objc_exec_class(void*); /* Begin of ObjC module */ static struct objc_abi_class _NSConcreteStackBlock_metaclass = { &_NSConcreteStackBlock_metaclass, "OFBlock", "_NSConcreteStackBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(struct objc_class), NULL, NULL }; struct objc_abi_class _NSConcreteStackBlock = { &_NSConcreteStackBlock_metaclass, "OFBlock", "_NSConcreteStackBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), NULL, NULL }; static struct objc_abi_class _NSConcreteGlobalBlock_metaclass = { &_NSConcreteGlobalBlock_metaclass, "OFBlock", "_NSConcreteGlobalBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(struct objc_class), NULL, NULL }; struct objc_abi_class _NSConcreteGlobalBlock = { &_NSConcreteGlobalBlock_metaclass, "OFBlock", "_NSConcreteGlobalBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), NULL, NULL }; static struct objc_abi_class _NSConcreteMallocBlock_metaclass = { &_NSConcreteMallocBlock_metaclass, "OFBlock", "_NSConcreteMallocBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(struct objc_class), NULL, NULL }; struct objc_abi_class _NSConcreteMallocBlock = { &_NSConcreteMallocBlock_metaclass, "OFBlock", "_NSConcreteMallocBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), NULL, NULL }; static struct { unsigned int unknown; struct objc_abi_selector *sel_refs; uint16_t cls_def_cnt, cat_def_cnt; void *defs[4]; } symtab = { 0, NULL, 3, 0, { &_NSConcreteStackBlock, &_NSConcreteGlobalBlock, &_NSConcreteMallocBlock, NULL }}; static struct { unsigned long version, size; const char *name; void *symtab; } module = { 8, sizeof(module), NULL, &symtab }; static void __attribute__((constructor)) __objc_gnu_init() { __objc_exec_class(&module); } /* Emd of ObjC module */ of_block_literal_t* Block_copy(of_block_literal_t *block) { if (block->isa == (Class)&_NSConcreteStackBlock) { of_block_literal_t *copy; if ((copy = malloc(block->descriptor->size)) == NULL) { fputs("Not enough memory to copy block!\n", stderr); exit(1); } memcpy(copy, block, block->descriptor->size); copy->isa = (Class)&_NSConcreteMallocBlock; copy->reserved++; if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE) block->descriptor->copy_helper(copy, block); return copy; } if (block->isa == (Class)&_NSConcreteMallocBlock) block->reserved++; return block; } void Block_release(of_block_literal_t *block) { if (block->isa != (Class)&_NSConcreteMallocBlock) return; if (--block->reserved == 0) { if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE) block->descriptor->dispose_helper(block); free(block); } } void _Block_object_assign(void *dst, void *src, int flags) { flags &= OF_BLOCK_FIELD_IS_BLOCK | OF_BLOCK_FIELD_IS_OBJECT | OF_BLOCK_FIELD_IS_BYREF; switch (flags) { case OF_BLOCK_FIELD_IS_BLOCK: *(of_block_literal_t**)dst = Block_copy(src); break; case OF_BLOCK_FIELD_IS_OBJECT: *(id*)dst = [(id)src retain]; break; case OF_BLOCK_FIELD_IS_BYREF:; of_block_byref_t *src_ = src; of_block_byref_t **dst_ = dst; if ((src_->flags & ~OF_BLOCK_HAS_COPY_DISPOSE) == 0) { if ((*dst_ = malloc(src_->size)) == NULL) { fputs("Not enough memory for block " "variables!\n", stderr); exit(1); } if (src_->forwarding == src) src_->forwarding = *dst_; memcpy(*dst_, src_, src_->size); if (src_->size >= sizeof(of_block_byref_t)) src_->byref_keep(*dst_, src_); } else *dst_ = src_; (*dst_)->flags++; break; } } void _Block_object_dispose(void *obj, int flags) { flags &= OF_BLOCK_FIELD_IS_BLOCK | OF_BLOCK_FIELD_IS_OBJECT | OF_BLOCK_FIELD_IS_BYREF; switch (flags) { case OF_BLOCK_FIELD_IS_BLOCK: Block_release(obj); break; case OF_BLOCK_FIELD_IS_OBJECT: [(id)obj release]; break; case OF_BLOCK_FIELD_IS_BYREF:; of_block_byref_t *obj_ = obj; if ((--obj_->flags & ~OF_BLOCK_HAS_COPY_DISPOSE) == 0) { if (obj_->size >= sizeof(of_block_byref_t)) obj_->byref_dispose(obj_); free(obj_); } break; } } static Class autoreleasepool = Nil; @implementation OFBlock - copy { return (id)Block_copy((of_block_literal_t*)self); } - (void)release { Block_release((of_block_literal_t*)self); } - autorelease { /* * Cache OFAutoreleasePool since class lookups are expensive with the * GNU runtime. */ if (autoreleasepool == Nil) autoreleasepool = [OFAutoreleasePool class]; [autoreleasepool addObjectToTopmostPool: self]; return self; } @end |
Modified src/ObjFW.h from [816eccd8cc] to [b6d3c640b8].
︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import "objfw-defs.h" #import "OFObject.h" #import "OFExceptions.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFDataArray.h" #import "OFArray.h" | > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import "objfw-defs.h" #import "OFObject.h" #import "OFBlock.h" #import "OFExceptions.h" #import "OFAutoreleasePool.h" #import "OFString.h" #import "OFDataArray.h" #import "OFArray.h" |
︙ | ︙ |
Deleted src/block.m version [576dbf7c91].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |