Why does this block not copy and indicate pointers in its descriptor?

According to the file Block_private.h, whenever a block is declared in the Objective-c file, the following structures are created in the object file to represent it:

struct Block_descriptor {
    unsigned long int reserved;
    unsigned long int size;
    void (*copy)(void *dst, void *src);
    void (*dispose)(void *);
};

struct Block_layout {
    void *isa;
    int flags;
    int reserved; 
    void (*invoke)(void *, ...);
    struct Block_descriptor *descriptor;
    /* Imported variables. */
};

However, when I create the assembly file,, clang -S ...from

int(^squared)(int) = ^(int i) {
    return i*i;
};

I get the following snippet that represents a block:

    .type   .L.str210,@object       # @.str210
.L.str210:
    .asciz   "i12@?0i8"
    .size   .L.str210, 9

    .type   __block_descriptor_tmp,@object # @__block_descriptor_tmp
    .section    .rodata,"a",@progbits
    .align  16
__block_descriptor_tmp:
    .quad   0                       # 0x0
    .quad   32                      # 0x20
    .quad   .L.str210
    .quad   0
    .size   __block_descriptor_tmp, 32

    .type   __block_literal_global,@object # @__block_literal_global
    .align  8
__block_literal_global:
    .quad   _NSConcreteGlobalBlock
    .long   1342177280              # 0x50000000
    .long   0                       # 0x0
    .quad   __main_block_invoke
    .quad   __block_descriptor_tmp
    .size   __block_literal_global, 32

So, __block_literal_globaland __block_descriptor_tmpare Block_layoutand a Block_descriptor, respectively. But, as you can see, the third field __block_descriptor_tmp, which should be void (*copy)(void *dst, void *src)consistent with Block_private.h, is const char *that indicates the encoding of the block type.

: ? Block_private.h , Block_descriptor , ? , __block_descriptor_tmp a const char *, void (*copy)(void *dst, void *src)?

+5
1

, , ( : __block vars)

, block->flags & BLOCK_HAS_COPY_DISPOSE

, , : http://clang.llvm.org/docs/Block-ABI-Apple.html

+6

All Articles