1*3cab2bb3Spatrick /* 2*3cab2bb3Spatrick * Block.h 3*3cab2bb3Spatrick * 4*3cab2bb3Spatrick * Copyright 2008-2010 Apple, Inc. Permission is hereby granted, free of charge, 5*3cab2bb3Spatrick * to any person obtaining a copy of this software and associated documentation 6*3cab2bb3Spatrick * files (the "Software"), to deal in the Software without restriction, 7*3cab2bb3Spatrick * including without limitation the rights to use, copy, modify, merge, publish, 8*3cab2bb3Spatrick * distribute, sublicense, and/or sell copies of the Software, and to permit 9*3cab2bb3Spatrick * persons to whom the Software is furnished to do so, subject to the following 10*3cab2bb3Spatrick * conditions: 11*3cab2bb3Spatrick * 12*3cab2bb3Spatrick * The above copyright notice and this permission notice shall be included in 13*3cab2bb3Spatrick * all copies or substantial portions of the Software. 14*3cab2bb3Spatrick * 15*3cab2bb3Spatrick * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16*3cab2bb3Spatrick * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17*3cab2bb3Spatrick * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18*3cab2bb3Spatrick * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19*3cab2bb3Spatrick * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20*3cab2bb3Spatrick * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21*3cab2bb3Spatrick * SOFTWARE. 22*3cab2bb3Spatrick * 23*3cab2bb3Spatrick */ 24*3cab2bb3Spatrick 25*3cab2bb3Spatrick #ifndef _BLOCK_H_ 26*3cab2bb3Spatrick #define _BLOCK_H_ 27*3cab2bb3Spatrick 28*3cab2bb3Spatrick #if !defined(BLOCK_EXPORT) 29*3cab2bb3Spatrick # if defined(__cplusplus) 30*3cab2bb3Spatrick # define BLOCK_EXPORT extern "C" 31*3cab2bb3Spatrick # else 32*3cab2bb3Spatrick # define BLOCK_EXPORT extern 33*3cab2bb3Spatrick # endif 34*3cab2bb3Spatrick #endif 35*3cab2bb3Spatrick 36*3cab2bb3Spatrick #if defined(__cplusplus) 37*3cab2bb3Spatrick extern "C" { 38*3cab2bb3Spatrick #endif 39*3cab2bb3Spatrick 40*3cab2bb3Spatrick /* Create a heap based copy of a Block or simply add a reference to an existing one. 41*3cab2bb3Spatrick * This must be paired with Block_release to recover memory, even when running 42*3cab2bb3Spatrick * under Objective-C Garbage Collection. 43*3cab2bb3Spatrick */ 44*3cab2bb3Spatrick BLOCK_EXPORT void *_Block_copy(const void *aBlock); 45*3cab2bb3Spatrick 46*3cab2bb3Spatrick /* Lose the reference, and if heap based and last reference, recover the memory. */ 47*3cab2bb3Spatrick BLOCK_EXPORT void _Block_release(const void *aBlock); 48*3cab2bb3Spatrick 49*3cab2bb3Spatrick #if defined(__cplusplus) 50*3cab2bb3Spatrick } 51*3cab2bb3Spatrick #endif 52*3cab2bb3Spatrick 53*3cab2bb3Spatrick /* Type correct macros. */ 54*3cab2bb3Spatrick 55*3cab2bb3Spatrick #define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) 56*3cab2bb3Spatrick #define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) 57*3cab2bb3Spatrick 58*3cab2bb3Spatrick 59*3cab2bb3Spatrick #endif 60