├── Resources
├── English.lproj
│ └── InfoPlist.strings
├── PLBlockIMP-iOS-Tests-Info.plist
├── PLBlockIMP-iOSimulator-Tests-Info.plist
├── Tests-MacOSX-Info.plist
├── Info.plist
└── MainWindow.xib
├── Tools
├── README.txt
└── google-toolbox-for-mac-1-5-1
│ ├── UnitTesting
│ ├── GTMIPhoneUnitTestMain.m
│ ├── GTMIPhoneUnitTestDelegate.h
│ ├── GTMIPhoneUnitTestDelegate.m
│ ├── GTMSenTestCase.m
│ └── GTMSenTestCase.h
│ ├── ReleaseNotes.txt
│ ├── GTMDefines.h
│ └── COPYING
├── LICENSE
├── Source
├── PLBlockIMP.h
├── blockimp.h
├── ARM
│ ├── blockimp_arm.tramp
│ ├── blockimp_arm_stret.tramp
│ └── blockimp_arm64.tramp
├── x86_64
│ ├── blockimp_x86_64.tramp
│ └── blockimp_x86_64_stret.tramp
├── x86_32
│ ├── blockimp_x86_32.tramp
│ └── blockimp_x86_32_stret.tramp
├── trampoline_table.h
├── blockimp.c
├── blockimp_private.h
├── blockimp_tests.m
└── trampoline_table.c
├── README.md
└── Other Sources
└── gentramp.sh
/Resources/English.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/Tools/README.txt:
--------------------------------------------------------------------------------
1 | This directory contains externally maintained build and
2 | testing tools.
3 |
4 | google-toolbox-for-mac-1-5-1:
5 | Apache License 2.0.
6 |
7 | Provides iPhone unit testing.
8 | Downloaded from http://code.google.com/p/google-toolbox-for-mac/
9 |
10 | Modified as follows:
11 | - Patch GTM to remove use of private -[UIApplication terminate] API.
12 | - Patch GTM to not use the deprecated -[NSString stringWithCString:]
13 | - Remove all sources except for the iPhone unit test harness.
14 |
--------------------------------------------------------------------------------
/Resources/PLBlockIMP-iOS-Tests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.PLBlockIMPiOSTests
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | NSMainNibFile
20 | MainWindow
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Resources/PLBlockIMP-iOSimulator-Tests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.PLBlockIMPiOSTests
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | NSMainNibFile
20 | MainWindow
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Resources/Tests-MacOSX-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Resources/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.yourcompany.${PRODUCT_NAME:rfc1034Identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | NSPrincipalClass
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Author: Landon Fuller
2 |
3 | Copyright 2010-2011 Plausible Labs Cooperative, Inc.
4 | All rights reserved.
5 |
6 | Permission is hereby granted, free of charge,
7 | to any person obtaining a copy of this software and associated documentation
8 | files (the "Software"), to deal in the Software without restriction,
9 | including without limitation the rights to use, copy, modify, merge, publish,
10 | distribute, sublicense, and/or sell copies of the Software, and to permit
11 | persons to whom the Software is furnished to do so, subject to the following
12 | conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
24 |
--------------------------------------------------------------------------------
/Tools/google-toolbox-for-mac-1-5-1/UnitTesting/GTMIPhoneUnitTestMain.m:
--------------------------------------------------------------------------------
1 | //
2 | // GTMIPhoneUnitTestMain.m
3 | //
4 | // Copyright 2008 Google Inc.
5 | //
6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | // use this file except in compliance with the License. You may obtain a copy
8 | // of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 | // License for the specific language governing permissions and limitations under
16 | // the License.
17 | //
18 |
19 | #import "GTMDefines.h"
20 | #if !GTM_IPHONE_SDK
21 | #error GTMIPhoneUnitTestMain for iPhone only
22 | #endif
23 | #import
24 |
25 | // Creates an application that runs all tests from classes extending
26 | // SenTestCase, outputs results and test run time, and terminates right
27 | // afterwards.
28 | int main(int argc, char *argv[]) {
29 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
30 | int retVal = UIApplicationMain(argc, argv, nil, @"GTMIPhoneUnitTestDelegate");
31 | [pool release];
32 | return retVal;
33 | }
34 |
--------------------------------------------------------------------------------
/Source/PLBlockIMP.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Landon Fuller
3 | *
4 | * Copyright 2010-2011 Plausible Labs Cooperative, Inc.
5 | * All rights reserved.
6 | *
7 | * Permission is hereby granted, free of charge,
8 | * to any person obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without restriction,
10 | * including without limitation the rights to use, copy, modify, merge, publish,
11 | * distribute, sublicense, and/or sell copies of the Software, and to permit
12 | * persons to whom the Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | #pragma once
28 | #include "blockimp.h"
--------------------------------------------------------------------------------
/Tools/google-toolbox-for-mac-1-5-1/UnitTesting/GTMIPhoneUnitTestDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // GTMIPhoneUnitTestDelegate.h
3 | //
4 | // Copyright 2008 Google Inc.
5 | //
6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | // use this file except in compliance with the License. You may obtain a copy
8 | // of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 | // License for the specific language governing permissions and limitations under
16 | // the License.
17 | //
18 |
19 | #import
20 |
21 | // Application delegate that runs all test methods in registered classes
22 | // extending SenTestCase. The application is terminated afterwards.
23 | // You can also run the tests directly from your application by invoking
24 | // gtm_runTests and clean up, restore data, etc. before the application
25 | // terminates.
26 | @interface GTMIPhoneUnitTestDelegate : NSObject
27 | // Runs through all the registered classes and runs test methods on any
28 | // that are subclasses of SenTestCase. Prints results and run time to
29 | // the default output.
30 | - (BOOL)runTests;
31 | @end
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | PLBlockIMP
2 | -----------
3 |
4 |
5 | PLBlockIMP provides an open-source implementation of [imp_implementationWithBlock()](http://www.friday.com/bbum/2011/03/17/ios-4-3-imp_implementationwithblock/), using
6 | vm_remap()-based trampolines as described in [Implementing imp_implementationWithBlock](http://landonf.bikemonkey.org/code/objc/imp_implementationWithBlock.20110413.html).
7 |
8 | PLBlockIMP will generate a lightweight, high-performance function pointer trampoline that may be used to register a block as an Objective-C method implementation. Mac OS X 10.6+ and
9 | iOS 4.0+ are supported.
10 |
11 | Additionally, PLBlockIMP contains a generic trampoline allocator and set of generator scripts that may be used to implement custom trampoline pages on Mac OS X and iOS.
12 |
13 | PLBlockIMP is released under the MIT license.
14 |
15 | Sample Use
16 | -----------
17 |
18 | Use a block to add a new method to NSObject (based on Mike Ash's MABlockClosure example):
19 |
20 | int captured = 42;
21 | id block = ^(id self) { NSLog(@"captured is %d", captured); };
22 | block = [block copy];
23 | class_addMethod([NSObject class], @selector(my_printCaptured), pl_imp_implementationWithBlock(block), "v@:");
24 |
25 | Additionally, pl_imp_getBlock() may be used to fetch the block associated with an IMP trampoline, and pl_imp_removeBlock() to discard a trampoline
26 | and its associated block reference.
27 |
--------------------------------------------------------------------------------
/Source/blockimp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Landon Fuller
3 | *
4 | * Copyright 2010-2011 Plausible Labs Cooperative, Inc.
5 | * All rights reserved.
6 | *
7 | * Permission is hereby granted, free of charge,
8 | * to any person obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without restriction,
10 | * including without limitation the rights to use, copy, modify, merge, publish,
11 | * distribute, sublicense, and/or sell copies of the Software, and to permit
12 | * persons to whom the Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | #include
28 |
29 | extern IMP pl_imp_implementationWithBlock(void *block);
30 | extern void *pl_imp_getBlock(IMP anImp);
31 | extern BOOL pl_imp_removeBlock(IMP anImp);
--------------------------------------------------------------------------------
/Source/ARM/blockimp_arm.tramp:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # Copyright (c) 2010-2011, Plausible Labs Cooperative, Inc.
5 | # All Rights Reserved.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # ``Software''), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included
16 | # in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | # DEALINGS IN THE SOFTWARE.
26 | # -----------------------------------------------------------------------
27 |
28 | # Supported architectures
29 | check_architecture () {
30 | case "$1" in
31 | armv6)
32 | return 1
33 | ;;
34 | armv7)
35 | return 1
36 | ;;
37 | armv7s)
38 | return 1
39 | ;;
40 | *)
41 | return 0
42 | ;;
43 | esac
44 | }
45 |
46 | # Page size
47 | PAGE_SIZE="4096"
48 |
49 | # The name of this page
50 | PAGE_NAME=pl_blockimp_table_page
51 |
52 | # Prefix to be placed at the start of the trampoline page
53 | trampoline_prefix () {
54 | asm << 'EOF'
55 | _block_tramp_dispatch:
56 | # trampoline address+8 is in r12 -- calculate our config page address
57 | sub r12, #0x8
58 | sub r12, #0x1000
59 |
60 | # Set the 'self' argument as the second argument
61 | mov r1, r0
62 |
63 | # Load the block pointer as the first argument
64 | ldr r0, [r12]
65 |
66 | # Jump to the block pointer
67 | ldr pc, [r0, #0xc]
68 | EOF
69 | }
70 |
71 | # Generate a single trampoline
72 | trampoline () {
73 | asm << 'EOF'
74 | # Save pc+8, then jump to the shared prefix implementation
75 | mov r12, pc
76 | b _block_tramp_dispatch;
77 | EOF
78 | }
--------------------------------------------------------------------------------
/Source/ARM/blockimp_arm_stret.tramp:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # Copyright (c) 2010-2011, Plausible Labs Cooperative, Inc.
5 | # All Rights Reserved.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # ``Software''), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included
16 | # in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | # DEALINGS IN THE SOFTWARE.
26 | # -----------------------------------------------------------------------
27 |
28 | # Supported architectures
29 | check_architecture () {
30 | case "$1" in
31 | armv6)
32 | return 1
33 | ;;
34 | armv7)
35 | return 1
36 | ;;
37 | armv7s)
38 | return 1
39 | ;;
40 | *)
41 | return 0
42 | ;;
43 | esac
44 | }
45 |
46 | # Page size
47 | PAGE_SIZE="4096"
48 |
49 | # The name of this page
50 | PAGE_NAME=pl_blockimp_table_stret_page
51 |
52 | # Prefix to be placed at the start of the trampoline page
53 | trampoline_prefix () {
54 | asm << 'EOF'
55 | _block_tramp_dispatch:
56 | # trampoline address+8 is in r12 -- calculate our config page address
57 | sub r12, #0x8
58 | sub r12, #0x1000
59 |
60 | # Set the 'self' argument as the third argument
61 | mov r2, r1
62 |
63 | # Load the block pointer as the second argument
64 | ldr r1, [r12]
65 |
66 | # Jump to the block pointer
67 | ldr pc, [r1, #0xc]
68 | EOF
69 | }
70 |
71 | # Generate a single trampoline
72 | trampoline () {
73 | asm << 'EOF'
74 | # Save pc+8, then jump to the shared prefix implementation
75 | mov r12, pc
76 | b _block_tramp_dispatch;
77 | EOF
78 | }
--------------------------------------------------------------------------------
/Source/ARM/blockimp_arm64.tramp:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # Copyright (c) 2010-2013, Plausible Labs Cooperative, Inc.
5 | # All Rights Reserved.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # ``Software''), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included
16 | # in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | # DEALINGS IN THE SOFTWARE.
26 | # -----------------------------------------------------------------------
27 |
28 | # Supported architectures
29 | check_architecture () {
30 | case $1 in
31 | arm64)
32 | return 1
33 | ;;
34 | *)
35 | return 0
36 | ;;
37 | esac
38 | }
39 |
40 | # Page size
41 | PAGE_SIZE="16384"
42 |
43 | # The name of this page
44 | PAGE_NAME=pl_blockimp_table_page
45 |
46 | # Prefix to be placed at the start of the trampoline page
47 | trampoline_prefix () {
48 | asm << 'EOF'
49 | _block_tramp_dispatch:
50 | # trampoline address+8 is in lr -- calculate our config page address
51 | sub x12, lr, #0x8
52 | sub x12, x12, #0x4000
53 |
54 | # restore the link register
55 | mov lr, x13
56 |
57 | # Set the 'self' argument as the second argument
58 | mov x1, x0
59 |
60 | # Load the block pointer as the first argument
61 | ldr x0, [x12]
62 |
63 | # Jump to the block pointer
64 | ldr x13, [x0, #0x10]
65 | br x13
66 | EOF
67 | }
68 |
69 | # Generate a single trampoline
70 | trampoline () {
71 | asm << 'EOF'
72 | # Save lr, then jump to the shared prefix implementation
73 | mov x13, lr
74 | bl _block_tramp_dispatch;
75 | // pad out to 16 bytes (the size of our config entries)
76 | nop
77 | nop
78 | EOF
79 | }
--------------------------------------------------------------------------------
/Source/x86_64/blockimp_x86_64.tramp:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # Copyright (c) 2010-2011, Plausible Labs Cooperative, Inc.
5 | # All Rights Reserved.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # ``Software''), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included
16 | # in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | # DEALINGS IN THE SOFTWARE.
26 | # -----------------------------------------------------------------------
27 |
28 | # Supported architectures
29 | check_architecture () {
30 | case $1 in
31 | x86_64)
32 | return 1
33 | ;;
34 | *)
35 | return 0
36 | ;;
37 | esac
38 | }
39 |
40 | # Page size
41 | PAGE_SIZE="4096"
42 |
43 | # The name of this page
44 | PAGE_NAME=pl_blockimp_table_page
45 |
46 | # Prefix to be placed at the start of the trampoline page
47 | trampoline_prefix () {
48 | asm << 'EOF'
49 | _block_tramp_dispatch:
50 | pop %r11
51 | and $0xfffffffffffffff8, %r11 // truncate to the trampoline start (each is 8 bytes)
52 | sub $0x1000, %r11 // load the config location
53 |
54 | // Move 'self' to the second parameter, overwriting IMP
55 | movq %rdi, %rsi
56 |
57 | // Load the block reference from the config page, and move to the first parameter
58 | movq (%r11), %rdi
59 |
60 | // Jump to the block fptr
61 | jmp *0x10(%rdi)
62 | .align 4 // align the trampolines at 16 bytes (required for config page lookup and sizing)
63 | EOF
64 | }
65 |
66 | # Generate a single trampoline
67 | trampoline () {
68 | asm << 'EOF'
69 | // Call into the dispatcher, placing our return address on the stack.
70 | call _block_tramp_dispatch # 5 bytes
71 | .align 4 // align the trampolines at 16 bytes (required for config page lookup and sizing)
72 | EOF
73 | }
--------------------------------------------------------------------------------
/Source/x86_32/blockimp_x86_32.tramp:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # Copyright (c) 2010-2011, Plausible Labs Cooperative, Inc.
5 | # All Rights Reserved.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # ``Software''), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included
16 | # in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | # DEALINGS IN THE SOFTWARE.
26 | # -----------------------------------------------------------------------
27 |
28 | # Supported architectures
29 | check_architecture () {
30 | case $1 in
31 | i386)
32 | return 1
33 | ;;
34 | *)
35 | return 0
36 | ;;
37 | esac
38 | }
39 |
40 | # Page size
41 | PAGE_SIZE="4096"
42 |
43 | # The name of this page
44 | PAGE_NAME=pl_blockimp_table_page
45 |
46 | # Prefix to be placed at the start of the trampoline page
47 | trampoline_prefix () {
48 | asm << 'EOF'
49 | _block_tramp_dispatch:
50 | pop %eax
51 | andl $0xfffffff8, %eax // truncate to the trampoline start (each is 8 bytes)
52 | subl $0x1000, %eax // load the config location
53 |
54 | // Move 'self' to the second parameter, overwriting IMP
55 | movl 0x4(%esp), %ecx
56 | movl %ecx, 0x8(%esp)
57 |
58 | // Load the block reference from the config page, insert as the first parameter
59 | movl (%eax), %eax
60 | movl %eax, 0x4(%esp)
61 |
62 | // Jump to the block fptr
63 | jmp *0xc(%eax)
64 |
65 | .align 3 // align the trampolines at 8 bytes
66 |
67 | EOF
68 | }
69 |
70 | # Generate a single trampoline
71 | trampoline () {
72 | asm << 'EOF'
73 |
74 | # Call into the dispatcher, placing our return address on the stack.
75 | calll _block_tramp_dispatch # 5 bytes
76 | .align 3 // align the trampolines at 8 bytes
77 | EOF
78 | }
--------------------------------------------------------------------------------
/Source/x86_32/blockimp_x86_32_stret.tramp:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # Copyright (c) 2010-2011, Plausible Labs Cooperative, Inc.
5 | # All Rights Reserved.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # ``Software''), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included
16 | # in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | # DEALINGS IN THE SOFTWARE.
26 | # -----------------------------------------------------------------------
27 |
28 | # Supported architectures
29 | check_architecture () {
30 | case $1 in
31 | i386)
32 | return 1
33 | ;;
34 | *)
35 | return 0
36 | ;;
37 | esac
38 | }
39 |
40 | # Page size
41 | PAGE_SIZE="4096"
42 |
43 | # The name of this page
44 | PAGE_NAME=pl_blockimp_table_stret_page
45 |
46 | # Prefix to be placed at the start of the trampoline page
47 | trampoline_prefix () {
48 | asm << 'EOF'
49 | _block_tramp_dispatch:
50 | pop %eax
51 | andl $0xfffffff8, %eax // truncate to the trampoline start (each is 8 bytes)
52 | subl $0x1000, %eax // load the config location
53 |
54 | // Move 'self' to the third parameter, overwriting IMP
55 | movl 0x8(%esp), %ecx
56 | movl %ecx, 0xc(%esp)
57 |
58 | // Load the block reference from the config page, insert as the second parameter
59 | movl (%eax), %eax
60 | movl %eax, 0x8(%esp)
61 |
62 | // Jump to the block fptr
63 | jmp *0xc(%eax)
64 |
65 | .align 3 // align the trampolines at 8 bytes
66 | EOF
67 | }
68 |
69 | # Generate a single trampoline
70 | trampoline () {
71 | asm << 'EOF'
72 |
73 | # Call into the dispatcher, placing our return address on the stack.
74 | calll _block_tramp_dispatch # 5 bytes
75 | .align 3 // align the trampolines at 8 bytes
76 |
77 | EOF
78 | }
--------------------------------------------------------------------------------
/Source/x86_64/blockimp_x86_64_stret.tramp:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # Copyright (c) 2010-2011, Plausible Labs Cooperative, Inc.
5 | # All Rights Reserved.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # ``Software''), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included
16 | # in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | # DEALINGS IN THE SOFTWARE.
26 | # -----------------------------------------------------------------------
27 |
28 | # Supported architectures
29 | check_architecture () {
30 | case $1 in
31 | x86_64)
32 | return 1
33 | ;;
34 | *)
35 | return 0
36 | ;;
37 | esac
38 | }
39 |
40 | # Page size
41 | PAGE_SIZE="4096"
42 |
43 | # The name of this page
44 | PAGE_NAME=pl_blockimp_table_stret_page
45 |
46 | # Prefix to be placed at the start of the trampoline page
47 | trampoline_prefix () {
48 | asm << 'EOF'
49 | _block_tramp_dispatch:
50 | pop %r11
51 | and $0xfffffffffffffff8, %r11 // truncate to the trampoline start (each is 8 bytes)
52 | sub $0x1000, %r11 // load the config location
53 |
54 | // Move 'self' to the third parameter, overwriting IMP
55 | movq %rsi, %rdx
56 |
57 | // Load the block reference from the config page, and move to the second parameter
58 | movq (%r11), %rsi
59 |
60 | // Jump to the block fptr
61 | jmp *0x10(%rsi)
62 | .align 4 // align the trampolines at 16 bytes (required for config page lookup and sizing)
63 | EOF
64 | }
65 |
66 | # Generate a single trampoline
67 | trampoline () {
68 | asm << 'EOF'
69 | // Call into the dispatcher, placing our return address on the stack.
70 | call _block_tramp_dispatch # 5 bytes
71 | .align 4 // align the trampolines at 16 bytes (required for config page lookup and sizing)
72 | EOF
73 | }
--------------------------------------------------------------------------------
/Source/trampoline_table.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Landon Fuller
3 | *
4 | * Copyright 2010-2011 Plausible Labs Cooperative, Inc.
5 | * All rights reserved.
6 | *
7 | * Permission is hereby granted, free of charge,
8 | * to any person obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without restriction,
10 | * including without limitation the rights to use, copy, modify, merge, publish,
11 | * distribute, sublicense, and/or sell copies of the Software, and to permit
12 | * persons to whom the Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | #pragma once
28 |
29 | #ifdef PL_BLOCKIMP_PRIVATE
30 |
31 | #include
32 | #include
33 |
34 | typedef struct pl_trampoline_table pl_trampoline_table;
35 | typedef struct pl_trampoline pl_trampoline;
36 |
37 | /*
38 | * Trampoline table configuration
39 | */
40 | typedef struct pl_trampoline_table_config {
41 | /* The trampoline size */
42 | uint32_t trampoline_size;
43 |
44 | /* The page offset at which the trampolines are located. */
45 | uint32_t page_offset;
46 |
47 | /* The number of trampolines allocated per page. */
48 | uint32_t trampoline_count;
49 |
50 | /** The template code page. */
51 | void *template_page;
52 | } pl_trampoline_table_config;
53 |
54 | /*
55 | * A double-linked list of trampoline table entries.
56 | */
57 | struct pl_trampoline_table {
58 | /* Table configuration */
59 | pl_trampoline_table_config *config;
60 |
61 | /* Contigious writable and executable pages */
62 | vm_address_t data_page;
63 | vm_address_t trampoline_page;
64 |
65 | /* free list tracking */
66 | uint16_t free_count;
67 | pl_trampoline *free_list;
68 | pl_trampoline *free_list_pool;
69 |
70 | pl_trampoline_table *prev;
71 | pl_trampoline_table *next;
72 | };
73 |
74 | /*
75 | * A linked list of trampoline table entries.
76 | */
77 | struct pl_trampoline {
78 | /* The actual trampoline. */
79 | void *(*trampoline)();
80 |
81 | /** The table in which the entry is allocated. */
82 | pl_trampoline_table *table;
83 |
84 | /* Next entry in the trampoline list. */
85 | pl_trampoline *next;
86 | };
87 |
88 | pl_trampoline *pl_trampoline_alloc (pl_trampoline_table_config *config, pthread_mutex_t *lock, pl_trampoline_table **table_head);
89 | void pl_trampoline_free (pthread_mutex_t *lock, pl_trampoline_table **table_head, pl_trampoline *tramp);
90 | void *pl_trampoline_data_ptr (void *code_ptr);
91 |
92 | #endif /* PL_BLOCKIMP_PRIVATE */
--------------------------------------------------------------------------------
/Source/blockimp.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Landon Fuller
3 | *
4 | * Copyright 2010-2011 Plausible Labs Cooperative, Inc.
5 | * All rights reserved.
6 | *
7 | * Permission is hereby granted, free of charge,
8 | * to any person obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without restriction,
10 | * including without limitation the rights to use, copy, modify, merge, publish,
11 | * distribute, sublicense, and/or sell copies of the Software, and to permit
12 | * persons to whom the Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | #include "blockimp.h"
28 | #include "blockimp_private.h"
29 |
30 | #include "trampoline_table.h"
31 |
32 | #include
33 | #include
34 |
35 | /* The ARM64 ABI does not require (or support) the _stret objc_msgSend variant */
36 | #ifdef __arm64__
37 | #define STRET_TABLE_REQUIRED 0
38 | #define STRET_TABLE_CONFIG pl_blockimp_table_page_config
39 | #define STRET_TABLE blockimp_table
40 | #else
41 | #define STRET_TABLE_REQUIRED 1
42 | #define STRET_TABLE_CONFIG pl_blockimp_table_page_config
43 | #define STRET_TABLE blockimp_table_stret
44 | #endif
45 |
46 | #pragma mark Trampolines
47 |
48 | /* Global lock for our mutable state. Must be held when accessing the trampoline tables. */
49 | static pthread_mutex_t blockimp_lock = PTHREAD_MUTEX_INITIALIZER;
50 |
51 | /* Trampoline tables for objc_msgSend() dispatch. */
52 | static pl_trampoline_table *blockimp_table = NULL;
53 |
54 | #if STRET_TABLE_REQUIRED
55 | /* Trampoline tables for objc_msgSend_stret() dispatch. */
56 | static pl_trampoline_table *blockimp_table_stret = NULL;
57 | #endif /* STRET_TABLE_REQUIRED */
58 |
59 | /**
60 | *
61 | */
62 | IMP pl_imp_implementationWithBlock (void *block) {
63 | #if SUPPORT_APPLE_FALLBACK
64 | /* Prefer Apple's implementation */
65 | if (&imp_implementationWithBlock != NULL)
66 | return imp_implementationWithBlock(block);
67 | #endif
68 |
69 | /* Allocate the appropriate trampoline type. */
70 | pl_trampoline *tramp;
71 | struct Block_layout *bl = block;
72 | if (bl->flags & BLOCK_USE_STRET) {
73 | tramp = pl_trampoline_alloc(&STRET_TABLE_CONFIG, &blockimp_lock, &STRET_TABLE);
74 | } else {
75 | tramp = pl_trampoline_alloc(&pl_blockimp_table_page_config, &blockimp_lock, &blockimp_table);
76 | }
77 |
78 | /* Configure the trampoline */
79 | void **config = pl_trampoline_data_ptr(tramp->trampoline);
80 | config[0] = Block_copy(block);
81 | config[1] = tramp;
82 |
83 | /* Return the function pointer. */
84 | return (IMP) tramp->trampoline;
85 | }
86 |
87 | /**
88 | *
89 | */
90 | void *pl_imp_getBlock(IMP anImp) {
91 | #if SUPPORT_APPLE_FALLBACK
92 | /* Prefer Apple's implementation */
93 | if (&imp_getBlock != NULL) {
94 | return imp_getBlock(anImp);
95 | }
96 | #endif
97 |
98 | /* Fetch the config data and return the block reference. */
99 | void **config = pl_trampoline_data_ptr(anImp);
100 | return config[0];
101 | }
102 |
103 | /**
104 | *
105 | */
106 | BOOL pl_imp_removeBlock(IMP anImp) {
107 | #if SUPPORT_APPLE_FALLBACK
108 | /* Prefer Apple's implementation */
109 | if (&imp_removeBlock != NULL)
110 | return imp_removeBlock(anImp);
111 | #endif
112 |
113 | /* Fetch the config data */
114 | void **config = pl_trampoline_data_ptr(anImp);
115 | struct Block_layout *bl = config[0];
116 | pl_trampoline *tramp = config[1];
117 |
118 | /* Drop the trampoline allocation */
119 | if (bl->flags & BLOCK_USE_STRET) {
120 | pl_trampoline_free(&blockimp_lock, &STRET_TABLE, tramp);
121 | } else {
122 | pl_trampoline_free(&blockimp_lock, &blockimp_table, tramp);
123 | }
124 |
125 | /* Release the block */
126 | Block_release(config[0]);
127 |
128 | // TODO - what does this return value mean?
129 | return YES;
130 | }
--------------------------------------------------------------------------------
/Source/blockimp_private.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Private Block ABI Structures
3 | * Originally acquired frm PLBlocks and compiler_rt
4 | *
5 | * Copyright 2008 - 2009 Apple, Inc.
6 | * Copyright 2009 - 2011 Plausible Labs Cooperative, Inc.
7 | *
8 | * Permission is hereby granted, free of charge,
9 | * to any person obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without restriction,
11 | * including without limitation the rights to use, copy, modify, merge, publish,
12 | * distribute, sublicense, and/or sell copies of the Software, and to permit
13 | * persons to whom the Software is furnished to do so, subject to the following
14 | * conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be included in
17 | * all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | * SOFTWARE.
26 | *
27 | */
28 |
29 | #pragma once
30 |
31 | #if defined(__i386__)
32 | # include "blockimp_x86_32.h"
33 | # include "blockimp_x86_32_stret.h"
34 | #elif defined(__x86_64__)
35 | # include "blockimp_x86_64.h"
36 | # include "blockimp_x86_64_stret.h"
37 | #elif defined(__arm__)
38 | # include "blockimp_arm.h"
39 | # include "blockimp_arm_stret.h"
40 | #elif defined(__arm64__)
41 | # include "blockimp_arm64.h"
42 | #else
43 | # error Unknown Architecture
44 | #endif
45 |
46 | #pragma mark Fallback Support
47 |
48 | // if 1, we attempt to use Apple's official implementations
49 | #define SUPPORT_APPLE_FALLBACK 0
50 | #if SUPPORT_APPLE_FALLBACK
51 | extern IMP imp_implementationWithBlock(void *block) WEAK_IMPORT_ATTRIBUTE;
52 | extern void *imp_getBlock(IMP anImp) WEAK_IMPORT_ATTRIBUTE;
53 | extern BOOL imp_removeBlock(IMP anImp) WEAK_IMPORT_ATTRIBUTE;
54 | #endif
55 |
56 | /*
57 | * Block Flags
58 | */
59 | typedef enum {
60 | /** 16-bit block reference count. */
61 | BLOCK_REFCOUNT_MASK = (0xffff),
62 |
63 | BLOCK_NEEDS_FREE = (1 << 24),
64 | BLOCK_HAS_COPY_DISPOSE = (1 << 25),
65 |
66 | /** Helpers have C++ code. */
67 | BLOCK_HAS_CTOR = (1 << 26),
68 |
69 | BLOCK_IS_GC = (1 << 27),
70 | BLOCK_IS_GLOBAL = (1 << 28),
71 |
72 | /** Block returns its aggregate value in memory (ie, the block has a structure return type). */
73 | BLOCK_USE_STRET = (1 << 29),
74 | } block_flags_t;
75 |
76 |
77 | /*
78 | * Block field flags.
79 | */
80 | typedef enum {
81 | // see function implementation for a more complete description of these fields and combinations
82 | BLOCK_FIELD_IS_OBJECT = 3, // id, NSObject, __attribute__((NSObject)), block, ...
83 | BLOCK_FIELD_IS_BLOCK = 7, // a block variable
84 | BLOCK_FIELD_IS_BYREF = 8, // the on stack structure holding the __block variable
85 | BLOCK_FIELD_IS_WEAK = 16, // declared __weak, only used in byref copy helpers
86 | BLOCK_BYREF_CALLER = 128, // called from __block (byref) copy/dispose support routines.
87 | } block_field_flags_t;
88 |
89 | /*
90 | * Block description.
91 | *
92 | * Block descriptions are shared across all instances of a block, and
93 | * provide basic information on the block size, as well as pointers
94 | * to any helper functions necessary to copy or dispose of the block.
95 | */
96 | struct Block_descriptor {
97 | /** Reserved value */
98 | unsigned long int reserved;
99 |
100 | /** Total size of the described block, including imported variables. */
101 | unsigned long int size;
102 |
103 | /** Optional block copy helper. May be NULL. */
104 | void (*copy)(void *dst, void *src);
105 |
106 | /** Optional block dispose helper. May be NULL. */
107 | void (*dispose)(void *);
108 | };
109 |
110 |
111 | /*
112 | * Block instance.
113 | *
114 | * The block layout defines the per-block instance state, which includes
115 | * a reference to the shared block descriptor.
116 | *
117 | * The block's imported variables are allocated following the block
118 | * descriptor member.
119 | */
120 | struct Block_layout {
121 | /** Pointer to the block's Objective-C class. */
122 | void *isa;
123 |
124 | /** Block flags. */
125 | int flags;
126 |
127 | /** Reserved value. */
128 | int reserved;
129 |
130 | /** Block invocation function. */
131 | void (*invoke)(void *, ...);
132 |
133 | /** Shared block descriptor. */
134 | struct Block_descriptor *descriptor;
135 |
136 | // imported variables
137 | };
--------------------------------------------------------------------------------
/Source/blockimp_tests.m:
--------------------------------------------------------------------------------
1 | /*
2 | * Author: Landon Fuller
3 | *
4 | * Copyright 2010-2011 Plausible Labs Cooperative, Inc.
5 | * All rights reserved.
6 | *
7 | * Permission is hereby granted, free of charge,
8 | * to any person obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without restriction,
10 | * including without limitation the rights to use, copy, modify, merge, publish,
11 | * distribute, sublicense, and/or sell copies of the Software, and to permit
12 | * persons to whom the Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | #import "GTMSenTestCase.h"
28 | #import "blockimp.h"
29 |
30 | @interface BlockIMPTests : SenTestCase @end
31 |
32 | /**
33 | * BlockIMP Tests
34 | */
35 | @implementation BlockIMPTests
36 |
37 | /**
38 | * Test basic IMP allocation and execution.
39 | */
40 | - (void) testAllocateIMP {
41 | /* A test block */
42 | __block BOOL didRun = NO;
43 | void (^Block)(id self) = ^(id blockself) {
44 | didRun = YES;
45 |
46 | STAssertEqualObjects(blockself, self, @"Incorrect 'self' pointer");
47 | };
48 |
49 | /* Create the IMP */
50 | IMP imp = pl_imp_implementationWithBlock(Block);
51 | STAssertTrue(imp != NULL, @"Returned NULL IMP");
52 |
53 | /* Verify the IMP is valid. */
54 | void (*ptr)(id self, SEL _cmd) = (void *) imp;
55 | ptr(self, @selector(testAllocateIMP));
56 | STAssertTrue(didRun, @"Block was not run");
57 |
58 | /* Clean up */
59 | pl_imp_removeBlock(imp);
60 | }
61 |
62 | /**
63 | * Test basic stret IMP allocation and execution.
64 | */
65 | - (void) testAllocateStretIMP {
66 | /* A test block */
67 | __block BOOL didRun = NO;
68 | NSRange (^Block)(id self) = ^NSRange (id blockself) {
69 | didRun = YES;
70 |
71 | STAssertEqualObjects(blockself, self, @"Incorrect 'self' pointer");
72 | return NSMakeRange(42, 1);
73 | };
74 |
75 | /* Create the IMP */
76 | IMP imp = pl_imp_implementationWithBlock(Block);
77 | STAssertTrue(imp != NULL, @"Returned NULL IMP");
78 |
79 | /* Verify the IMP is valid. */
80 | NSRange (*ptr)(id self, SEL _cmd) = (void *) imp;
81 | NSRange result = ptr(self, @selector(testAllocateStretIMP));
82 |
83 | STAssertTrue(didRun, @"Block was not run");
84 | STAssertEquals(result.location, (NSUInteger)42, @"Incorrect location");
85 | STAssertEquals(result.length, (NSUInteger)1, @"Incorrect length");
86 |
87 | /* Clean up */
88 | pl_imp_removeBlock(imp);
89 | }
90 |
91 | /**
92 | * Test fetching of the Block ptr from the IMP pointer.
93 | */
94 | - (void) testGetBlock {
95 | /* A test block */
96 | void (^Block)(id self) = [[^(id blockself) {
97 | STAssertEqualObjects(blockself, self, @"Incorrect 'self' pointer");
98 | } copy] autorelease];
99 |
100 | /* Create the IMP */
101 | IMP imp = pl_imp_implementationWithBlock(Block);
102 | STAssertTrue(imp != NULL, @"Returned NULL IMP");
103 |
104 | /* Try to fetch the underlying block */
105 | void *b = pl_imp_getBlock(imp);
106 | STAssertEquals(b, (void *) Block, @"Did not fetch block");
107 |
108 | /* Clean up */
109 | pl_imp_removeBlock(imp);
110 | }
111 |
112 | /**
113 | * Exercise block allocation
114 | */
115 | - (void) testAllocationExcercise {
116 | /* A test block */
117 | __block int callCount = 0;
118 | void (^Block)(id self) = [[^(id blockself) {
119 | callCount++;
120 | STAssertEqualObjects(blockself, self, @"Incorrect 'self' pointer");
121 | } copy] autorelease];
122 |
123 | /* Use a count larger than what a single page (on any architecture) can likely hold */
124 | int count=PAGE_SIZE*2;
125 |
126 | /* Generate the IMPs */
127 | IMP *imps = malloc(sizeof(IMP) * count);
128 | for (int i = 0; i < count; i++) {
129 | imps[i] = pl_imp_implementationWithBlock(Block);
130 | }
131 |
132 | /* Call the IMPs */
133 | for (int i = 0; i < count; i++) {
134 | void (*ptr)(id self, SEL _cmd) = (void *) imps[i];
135 | ptr(self, @selector(testAllocationExcercise));
136 | }
137 |
138 | /* Clean up the IMPs. We do this in reverse to exercise table reordering. */
139 | for (int i = count-1; i+1 >= 1; i--) {
140 | pl_imp_removeBlock(imps[i]);
141 | }
142 | free(imps);
143 |
144 | /* Verify the result */
145 | STAssertEquals(callCount, count, @"Call count does not match expected count; not all IMPs were called");
146 | }
147 |
148 | @end
149 |
--------------------------------------------------------------------------------
/Tools/google-toolbox-for-mac-1-5-1/ReleaseNotes.txt:
--------------------------------------------------------------------------------
1 | Google Toolbox for Mac Release Notes
2 |
3 | Project site: http://code.google.com/p/google-toolbox-for-mac/
4 | Discussion group: http://groups.google.com/group/google-toolbox-for-mac
5 |
6 | Release 1.5.1
7 | Changes since 1.5.0
8 | 16-June-2008
9 |
10 | - Fixed building tiger gcov w/ a directory path that contains a space.
11 |
12 |
13 | Release 1.5.0
14 | Changes since 1.0.0
15 | 13-June-2008
16 |
17 | - Updated the project to Xcode 3. This is the only supported Xcode version
18 | for the project. The code can build against the Tiger or Leopard SDKs, and
19 | developers can pull individual files into a Xcode 2.x project and things
20 | should work just fine.
21 |
22 | - Fixed up the prefix header of the project and prefix handing in the Unittest
23 | Xcode Config. (thanks schafdog)
24 |
25 | - Fixed error in handling default compression for NSData+zlib
26 |
27 | - Changed name on API in NSString+XML and added another api to make this a
28 | litte more clear. (thanks Kent)
29 |
30 | - GTMRegex
31 | - Found and fixed a bug in the enumerators that was causing them to
32 | incorrectly walk a string when using '^' in an expression.
33 | - Added helpers for substring tests and unittests for the new apis.
34 | - Added initializer that takes an outError to allow the collection of any
35 | pattern parsing error message (in case the pattern came from a user and
36 | complete error information is needed to message the user).
37 |
38 | - Added GTMScriptRunner for spawning scripts.
39 |
40 | - Added GTMNSFileManager+Path for two small helpers.
41 |
42 | - Added GTMNSWorkspace+ScreenSaver
43 |
44 | - Added GTMNSString+Data
45 |
46 | - added a common header (GTMDefines) for any common defines so the conditionals
47 | are all in one place
48 |
49 | - Support for things compiling against the iPhone SDK
50 | - Everything in the GTMiPhone project works in the iPhone
51 | - Added iPhone xcconfig files
52 | - Added iPhone unittests (See below)
53 |
54 | - More work on the UI unittests
55 | - support pretty much any part of a UI
56 | - support for CALayers
57 | - full support for the iPhone
58 | - the iPhone uses the same macro set at OCUnit, but has its own runtime
59 | for running tests.
60 | - extended capabilities of UIUnitTesting to be more flexible and give better
61 | error reporting for states.
62 |
63 | - Renamed the actual framework to "GoogleToolboxForMac.framework" (it should
64 | have matched the project on code.google.com from the start)
65 |
66 | - added a Debug-gcov target that will product debug bits w/ code coverage
67 | support to check unittests, etc.
68 |
69 | - GTMDebugSelectorValidation to provide something to include in class impls
70 | to get validation of object/selector pair(s) being implemented so you don't
71 | have to wait for a runtime invocation failures. (especially useful for
72 | things that take a success and failure selector so one doesn't always get
73 | called)
74 |
75 | - added _GTMDevLog (really in GTMDefines) that are a set of macros that can be
76 | used for logging. This allows any project to redefine them to direct logging
77 | into its runtime needs.
78 |
79 | - Moved GTMGeometryUtils into Foundation from AppKit
80 |
81 | - Removed several HI* calls from GTMGeometryUtils as Carbon UI in general is
82 | deprecated.
83 |
84 | - Xcode configs
85 | - changed the layout to make it a little easier to tell how to use them.
86 | - added Leopard or later configs
87 |
88 | - Unittest coverage greatly increased
89 |
90 | - Added RunMacOSUnitTests shell script. We run this script for starting up our
91 | unittests because it turns on a variety of "enhancements" (such as zombies,
92 | scribbling etc) to encourage our unittests to fail for us. It also will run
93 | the unittests using the _debug frameworks if you have them.
94 |
95 | https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=19915
96 |
97 | - Remove NSColor+Theme and NSWorkspace+Theme as they are no longer needed for
98 | testing things for unittests, instead GTMUnitTestingUtilities.m(Lines 64-79)
99 | force the user settable things to ensure tests are consistent.
100 |
101 | - Added GTMBase64.
102 |
103 | - Added GTMHTTPFetcher and GTMProgressMonitorInputStream.
104 |
105 | - Moved the data files for unittests into subdirectories call TestData to
106 | help make it a little easier to find files w/in the main directories.
107 |
108 | - GTMDelegatingTableColumn get an overhaul to match the 10.5 sdk so it's closer
109 | to a dropin for previous sdks.
110 |
111 | - Added a lot of functionality to NSAppleEventDescriptor and NSAppleScript
112 | allowing you to easily call labeled and positional handlers in an AppleScript,
113 | get/set properties and get NSAppleEventDescriptors for most basic datatypes.
114 |
115 | - Added GTMFourCharCode for wrapping FourCharCodes in an ObjC object. Mainly for
116 | use by the NSAppleEventDescriptor code, and also useful for storing them
117 | in ObjC collection classes.
118 |
119 | - Added GTMStackTrace.
120 |
121 | - Added NSString+URLArguments and NSDictionary+URLArguments
122 |
123 | - Added GTMHTTPServer as a simple server but mainly for use in unittesting.
124 |
125 | - Added _GTMCompileAssert for doing compile time assertions to GTMDefines.h
126 |
127 | - Added GTMUnitTestDevLog and GTMTestCase for logging and tracking logs while
128 | running unittests to verify what is being logged is what you expect. All
129 | unittests should now inherit from GTMTestCase instead of SenTestCase to take
130 | advantage of the new log tracking. See GTMUnitTestDevLog.h for details.
131 |
132 | - Extracted GTMIPhoneUnitTestDelegate from GTMIPhoneUnitTestMain.m to its own
133 | file. Tests can now be run from another application.
134 |
135 |
136 | Release 1.0.0
137 | 14-January-2008
138 |
139 | - Initial public release. Includes some simple utils, xcode configs, and
140 | some support for doing unit tests of graphical things.
141 |
--------------------------------------------------------------------------------
/Tools/google-toolbox-for-mac-1-5-1/UnitTesting/GTMIPhoneUnitTestDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // GTMIPhoneUnitTestDelegate.m
3 | //
4 | // Copyright 2008 Google Inc.
5 | //
6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | // use this file except in compliance with the License. You may obtain a copy
8 | // of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 | // License for the specific language governing permissions and limitations under
16 | // the License.
17 | //
18 |
19 | #import "GTMIPhoneUnitTestDelegate.h"
20 |
21 | #import "GTMDefines.h"
22 | #if !GTM_IPHONE_SDK
23 | #error GTMIPhoneUnitTestDelegate for iPhone only
24 | #endif
25 | #import
26 | #import
27 | #import
28 | #import "GTMSenTestCase.h"
29 |
30 | // Used for sorting methods below
31 | static int MethodSort(const void *a, const void *b) {
32 | const char *nameA = sel_getName(method_getName(*(Method*)a));
33 | const char *nameB = sel_getName(method_getName(*(Method*)b));
34 | return strcmp(nameA, nameB);
35 | }
36 |
37 | @implementation GTMIPhoneUnitTestDelegate
38 |
39 | // Return YES if class is subclass (1 or more generations) of SenTestCase
40 | - (BOOL)isTestFixture:(Class)aClass {
41 | BOOL iscase = NO;
42 | Class testCaseClass = [SenTestCase class];
43 | Class superclass;
44 | for (superclass = aClass;
45 | !iscase && superclass;
46 | superclass = class_getSuperclass(superclass)) {
47 | iscase = superclass == testCaseClass ? YES : NO;
48 | }
49 | return iscase;
50 | }
51 |
52 | // Run through all the registered classes and run test methods on any
53 | // that are subclasses of SenTestCase. Terminate the application upon
54 | // test completion.
55 | - (void)applicationDidFinishLaunching:(UIApplication *)application {
56 | if (![self runTests])
57 | exit(EXIT_FAILURE);
58 | exit(EXIT_SUCCESS);
59 | }
60 |
61 | // Run through all the registered classes and run test methods on any
62 | // that are subclasses of SenTestCase. Print results and run time to
63 | // the default output.
64 | - (BOOL)runTests {
65 | int count = objc_getClassList(NULL, 0);
66 | Class *classes = (Class*)malloc(sizeof(Class) * count);
67 | _GTMDevAssert(classes, @"Couldn't allocate class list");
68 | objc_getClassList(classes, count);
69 | int suiteSuccesses = 0;
70 | int suiteFailures = 0;
71 | int suiteTotal = 0;
72 | NSString *suiteName = [[NSBundle mainBundle] bundlePath];
73 | NSDate *suiteStartDate = [NSDate date];
74 | NSString *suiteStartString = [NSString stringWithFormat:@"Test Suite '%@' started at %@\n",
75 | suiteName, suiteStartDate];
76 | fputs([suiteStartString UTF8String], stderr);
77 | fflush(stderr);
78 | for (int i = 0; i < count; ++i) {
79 | Class currClass = classes[i];
80 | if ([self isTestFixture:currClass]) {
81 | NSDate *fixtureStartDate = [NSDate date];
82 | NSString *fixtureName = NSStringFromClass(currClass);
83 | NSString *fixtureStartString = [NSString stringWithFormat:@"Test Suite '%@' started at %@\n",
84 | fixtureName, fixtureStartDate];
85 | int fixtureSuccesses = 0;
86 | int fixtureFailures = 0;
87 | int fixtureTotal = 0;
88 | fputs([fixtureStartString UTF8String], stderr);
89 | fflush(stderr);
90 | id testcase = [[currClass alloc] init];
91 | _GTMDevAssert(testcase, @"Unable to instantiate Test Suite: '%@'\n",
92 | fixtureName);
93 | unsigned int methodCount;
94 | Method *methods = class_copyMethodList(currClass, &methodCount);
95 | // Sort our methods so they are called in Alphabetical order just
96 | // because we can.
97 | qsort(methods, methodCount, sizeof(Method), MethodSort);
98 | for (size_t j = 0; j < methodCount; ++j) {
99 | Method currMethod = methods[j];
100 | SEL sel = method_getName(currMethod);
101 | const char *name = sel_getName(sel);
102 | // If it starts with test, run it.
103 | if (strstr(name, "test") == name) {
104 | fixtureTotal += 1;
105 | BOOL failed = NO;
106 | NSDate *caseStartDate = [NSDate date];
107 | @try {
108 | [testcase performTest:sel];
109 | } @catch (NSException *exception) {
110 | failed = YES;
111 | }
112 | if (failed) {
113 | fixtureFailures += 1;
114 | } else {
115 | fixtureSuccesses += 1;
116 | }
117 | NSTimeInterval caseEndTime = [[NSDate date] timeIntervalSinceDate:caseStartDate];
118 | NSString *caseEndString = [NSString stringWithFormat:@"Test Case '-[%@ %s]' %s (%0.3f seconds).\n",
119 | fixtureName, name,
120 | failed ? "failed" : "passed", caseEndTime];
121 | fputs([caseEndString UTF8String], stderr);
122 | fflush(stderr);
123 | }
124 | }
125 | if (methods) {
126 | free(methods);
127 | }
128 | [testcase release];
129 | NSDate *fixtureEndDate = [NSDate date];
130 | NSTimeInterval fixtureEndTime = [fixtureEndDate timeIntervalSinceDate:fixtureStartDate];
131 | NSString *fixtureEndString = [NSString stringWithFormat:@"Test Suite '%@' finished at %@.\n"
132 | "Executed %d tests, with %d failures (%d unexpected) in %0.3f (%0.3f) seconds\n",
133 | fixtureName, fixtureEndDate, fixtureTotal,
134 | fixtureFailures, fixtureFailures,
135 | fixtureEndTime, fixtureEndTime];
136 |
137 | fputs([fixtureEndString UTF8String], stderr);
138 | fflush(stderr);
139 | suiteTotal += fixtureTotal;
140 | suiteSuccesses += fixtureSuccesses;
141 | suiteFailures += fixtureFailures;
142 | }
143 | }
144 | NSDate *suiteEndDate = [NSDate date];
145 | NSTimeInterval suiteEndTime = [suiteEndDate timeIntervalSinceDate:suiteStartDate];
146 | NSString *suiteEndString = [NSString stringWithFormat:@"Test Suite '%@' finished at %@.\n"
147 | "Executed %d tests, with %d failures (%d unexpected) in %0.3f (%0.3f) seconds\n",
148 | suiteName, suiteEndDate, suiteTotal,
149 | suiteFailures, suiteFailures,
150 | suiteEndTime, suiteEndTime];
151 | fputs([suiteEndString UTF8String], stderr);
152 | fflush(stderr);
153 |
154 | if (suiteFailures > 0)
155 | return NO;
156 |
157 | return YES;
158 | }
159 |
160 | @end
161 |
--------------------------------------------------------------------------------
/Tools/google-toolbox-for-mac-1-5-1/GTMDefines.h:
--------------------------------------------------------------------------------
1 | //
2 | // GTMDefines.h
3 | //
4 | // Copyright 2008 Google Inc.
5 | //
6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | // use this file except in compliance with the License. You may obtain a copy
8 | // of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 | // License for the specific language governing permissions and limitations under
16 | // the License.
17 | //
18 |
19 | // ============================================================================
20 |
21 | // ----------------------------------------------------------------------------
22 | // CPP symbols that can be overridden in a prefix to control how the toolbox
23 | // is compiled.
24 | // ----------------------------------------------------------------------------
25 |
26 |
27 | // GTMHTTPFetcher will support logging by default but only hook its input
28 | // stream support for logging when requested. You can control the inclusion of
29 | // the code by providing your own definitions for these w/in a prefix header.
30 | //
31 | #ifndef GTM_HTTPFETCHER_ENABLE_LOGGING
32 | # define GTM_HTTPFETCHER_ENABLE_LOGGING 1
33 | #endif // GTM_HTTPFETCHER_ENABLE_LOGGING
34 | #ifndef GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING
35 | # define GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING 0
36 | #endif // GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING
37 |
38 |
39 | // _GTMDevLog & _GTMDevAssert
40 | //
41 | // _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for
42 | // developer level errors. This implementation simply macros to NSLog/NSAssert.
43 | // It is not intended to be a general logging/reporting system.
44 | //
45 | // Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert
46 | // for a little more background on the usage of these macros.
47 | //
48 | // _GTMDevLog log some error/problem in debug builds
49 | // _GTMDevAssert assert if conditon isn't met w/in a method/function
50 | // in all builds.
51 | //
52 | // To replace this system, just provide different macro definitions in your
53 | // prefix header. Remember, any implementation you provide *must* be thread
54 | // safe since this could be called by anything in what ever situtation it has
55 | // been placed in.
56 | //
57 |
58 | // We only define the simple macros if nothing else has defined this.
59 | #ifndef _GTMDevLog
60 |
61 | #ifdef DEBUG
62 | #define _GTMDevLog(...) NSLog(__VA_ARGS__)
63 | #else
64 | #define _GTMDevLog(...) do { } while (0)
65 | #endif
66 |
67 | #endif // _GTMDevLog
68 |
69 | // Declared here so that it can easily be used for logging tracking if
70 | // necessary. See GTMUnitTestDevLog.h for details.
71 | @class NSString;
72 | extern void _GTMUnittestDevLog(NSString *format, ...);
73 |
74 | #ifndef _GTMDevAssert
75 | // we directly invoke the NSAssert handler so we can pass on the varargs
76 | // (NSAssert doesn't have a macro we can use that takes varargs)
77 | #if !defined(NS_BLOCK_ASSERTIONS)
78 | #define _GTMDevAssert(condition, ...) \
79 | do { \
80 | if (!(condition)) { \
81 | [[NSAssertionHandler currentHandler] \
82 | handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
83 | file:[NSString stringWithUTF8String:__FILE__] \
84 | lineNumber:__LINE__ \
85 | description:__VA_ARGS__]; \
86 | } \
87 | } while(0)
88 | #else // !defined(NS_BLOCK_ASSERTIONS)
89 | #define _GTMDevAssert(condition, ...) do { } while (0)
90 | #endif // !defined(NS_BLOCK_ASSERTIONS)
91 |
92 | #endif // _GTMDevAssert
93 |
94 | // _GTMCompileAssert
95 | // _GTMCompileAssert is an assert that is meant to fire at compile time if you
96 | // want to check things at compile instead of runtime. For example if you
97 | // want to check that a wchar is 4 bytes instead of 2 you would use
98 | // _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X)
99 | // Note that the second "arg" is not in quotes, and must be a valid processor
100 | // symbol in it's own right (no spaces, punctuation etc).
101 |
102 | // Wrapping this in an #ifndef allows external groups to define their own
103 | // compile time assert scheme.
104 | #ifndef _GTMCompileAssert
105 | // We got this technique from here:
106 | // http://unixjunkie.blogspot.com/2007/10/better-compile-time-asserts_29.html
107 |
108 | #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg
109 | #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg)
110 | #define _GTMCompileAssert(test, msg) \
111 | typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
112 | #endif // _GTMCompileAssert
113 |
114 | // ============================================================================
115 |
116 | // ----------------------------------------------------------------------------
117 | // CPP symbols defined based on the project settings so the GTM code has
118 | // simple things to test against w/o scattering the knowledge of project
119 | // setting through all the code.
120 | // ----------------------------------------------------------------------------
121 |
122 | // Provide a single constant CPP symbol that all of GTM uses for ifdefing
123 | // iPhone code.
124 | #include
125 | #if TARGET_OS_IPHONE // iPhone SDK
126 | // For iPhone specific stuff
127 | #define GTM_IPHONE_SDK 1
128 | #else
129 | // For MacOS specific stuff
130 | #define GTM_MACOS_SDK 1
131 | #endif
132 |
133 | // To simplify support for 64bit (and Leopard in general), we provide the type
134 | // defines for non Leopard SDKs
135 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
136 | // NSInteger/NSUInteger and Max/Mins
137 | #ifndef NSINTEGER_DEFINED
138 | #if __LP64__ || NS_BUILD_32_LIKE_64
139 | typedef long NSInteger;
140 | typedef unsigned long NSUInteger;
141 | #else
142 | typedef int NSInteger;
143 | typedef unsigned int NSUInteger;
144 | #endif
145 | #define NSIntegerMax LONG_MAX
146 | #define NSIntegerMin LONG_MIN
147 | #define NSUIntegerMax ULONG_MAX
148 | #define NSINTEGER_DEFINED 1
149 | #endif // NSINTEGER_DEFINED
150 | // CGFloat
151 | #ifndef CGFLOAT_DEFINED
152 | #if defined(__LP64__) && __LP64__
153 | // This really is an untested path (64bit on Tiger?)
154 | typedef double CGFloat;
155 | #define CGFLOAT_MIN DBL_MIN
156 | #define CGFLOAT_MAX DBL_MAX
157 | #define CGFLOAT_IS_DOUBLE 1
158 | #else /* !defined(__LP64__) || !__LP64__ */
159 | typedef float CGFloat;
160 | #define CGFLOAT_MIN FLT_MIN
161 | #define CGFLOAT_MAX FLT_MAX
162 | #define CGFLOAT_IS_DOUBLE 0
163 | #endif /* !defined(__LP64__) || !__LP64__ */
164 | #define CGFLOAT_DEFINED 1
165 | #endif // CGFLOAT_DEFINED
166 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
167 |
--------------------------------------------------------------------------------
/Other Sources/gentramp.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # -----------------------------------------------------------------------
4 | # gentramp.sh - Copyright (c) 2010-2011, Plausible Labs Cooperative, Inc.
5 | #
6 | # Trampoline Page Generator
7 | # Author: Landon Fuller
8 | #
9 | # Permission is hereby granted, free of charge, to any person obtaining
10 | # a copy of this software and associated documentation files (the
11 | # ``Software''), to deal in the Software without restriction, including
12 | # without limitation the rights to use, copy, modify, merge, publish,
13 | # distribute, sublicense, and/or sell copies of the Software, and to
14 | # permit persons to whom the Software is furnished to do so, subject to
15 | # the following conditions:
16 | #
17 | # The above copyright notice and this permission notice shall be included
18 | # in all copies or substantial portions of the Software.
19 | #
20 | # THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 | # DEALINGS IN THE SOFTWARE.
28 | # -----------------------------------------------------------------------
29 |
30 | PROGNAME="$0"
31 |
32 | INPUT_FILE_PATH="$1"
33 | CURRENT_ARCH="$2"
34 | PLATFORM_NAME="$3"
35 | OUTPUT_FILE_PREFIX="$4"
36 | OUTPUT_DIR="$5"
37 |
38 | if [ -z "${INPUT_FILE_PATH}" ] || [ -z "${CURRENT_ARCH}" ] || [ -z "${PLATFORM_NAME}" ] || [ -z "${OUTPUT_FILE_PREFIX}" ] || [ -z "${OUTPUT_DIR}" ]; then
39 | echo "USAGE: $PROGNAME