+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ext/ffi_c/AbstractMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ get_memory_op(Type* type)
#define MEMORY_PTR(obj) MEMORY((obj))->address
#define MEMORY_LEN(obj) MEMORY((obj))->size

/* ensure the memory is aligned on at least a 8 byte boundary */
#if __x86_64__ || _WIN64 || __ppc64__
#define MEMORY_ALIGN_MASK 0x7ULL
#else
#define MEMORY_ALIGN_MASK 0x7UL
#endif
#define MEMORY_ALIGN(p) (((uintptr_t) p + MEMORY_ALIGN_MASK) & (uintptr_t) ~MEMORY_ALIGN_MASK)


#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions ext/ffi_c/Buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
}

/* ensure the memory is aligned on at least a 8 byte boundary */
p->memory.address = (void *) (((uintptr_t) p->data.storage + 0x7) & (uintptr_t) ~0x7UL);
p->memory.address = (void *) MEMORY_ALIGN(p->data.storage);

if (p->memory.size > 0 && (nargs < 3 || RTEST(rbClear))) {
memset(p->memory.address, 0, p->memory.size);
Expand Down Expand Up @@ -154,7 +154,7 @@ buffer_initialize_copy(VALUE self, VALUE other)
return Qnil;
}

dst->memory.address = (void *) (((uintptr_t) dst->data.storage + 0x7) & (uintptr_t) ~0x7UL);
dst->memory.address = (void *) MEMORY_ALIGN(dst->data.storage);
dst->memory.size = src->size;
dst->memory.typeSize = src->typeSize;

Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/MemoryPointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
p->memory.typeSize = (int) size;
p->memory.size = msize;
/* ensure the memory is aligned on at least a 8 byte boundary */
p->memory.address = (char *) (((uintptr_t) p->storage + 0x7) & (uintptr_t) ~0x7UL);;
p->memory.address = (char *) MEMORY_ALIGN(p->storage);
p->allocated = true;

if (clear && p->memory.size > 0) {
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/Pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ ptr_initialize_copy(VALUE self, VALUE other)

dst->allocated = true;
dst->autorelease = true;
dst->memory.address = (void *) (((uintptr_t) dst->storage + 0x7) & (uintptr_t) ~0x7UL);
dst->memory.address = (void *) MEMORY_ALIGN(dst->storage);
dst->memory.size = src->size;
dst->memory.typeSize = src->typeSize;

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载