Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 Protect FFI::Function with Write Barrier by casperisfine · Pull Request #991 · ffi/ffi · GitHub
Nothing Special   »   [go: up one dir, main page]

Skip to content
Closed
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
45 changes: 12 additions & 33 deletions ext/ffi_c/AbstractMemory.c
10BC0 7440
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,15 @@ static VALUE memory_put_##name(VALUE self, VALUE offset, VALUE value); \
static VALUE \
memory_put_##name(VALUE self, VALUE offset, VALUE value) \
{ \
AbstractMemory* memory; \
Data_Get_Struct(self, AbstractMemory, memory); \
AbstractMemory* memory = MEMORY(self); \
memory_op_put_##name(memory, NUM2LONG(offset), value); \
return self; \
} \
static VALUE memory_write_##name(VALUE self, VALUE value); \
static VALUE \
memory_write_##name(VALUE self, VALUE value) \
{ \
AbstractMemory* memory; \
Data_Get_Struct(self, AbstractMemory, memory); \
AbstractMemory* memory = MEMORY(self); \
memory_op_put_##name(memory, 0, value); \
return self; \
} \
Expand All @@ -114,16 +112,14 @@ static VALUE memory_get_##name(VALUE self, VALUE offset); \
static VALUE \
memory_get_##name(VALUE self, VALUE offset) \
{ \
AbstractMemory* memory; \
Data_Get_Struct(self, AbstractMemory, memory); \
AbstractMemory* memory = MEMORY(self); \
return memory_op_get_##name(memory, NUM2LONG(offset)); \
} \
static VALUE memory_read_##name(VALUE self); \
static VALUE \
memory_read_##name(VALUE self) \
{ \
AbstractMemory* memory; \
Data_Get_Struct(self, AbstractMemory, memory); \
AbstractMemory* memory = MEMORY(self); \
return memory_op_get_##name(memory, 0); \
} \
static MemoryOp memory_op_##name = { memory_op_get_##name, memory_op_put_##name }; \
Expand Down Expand Up @@ -319,11 +315,7 @@ memory_clear(VALUE self)
static VALUE
memory_size(VALUE self)
{
AbstractMemory* ptr;

Data_Get_Struct(self, AbstractMemory, ptr);

return LONG2NUM(ptr->size);
return LONG2NUM(MEMORY_LEN(self));
}

/*
Expand All @@ -337,14 +329,13 @@ memory_size(VALUE self)
static VALUE
memory_get(VALUE self, VALUE type_name, VALUE offset)
{
AbstractMemory* ptr;
VALUE nType;
Type *type;

nType = rbffi_Type_Lookup(type_name);
if(NIL_P(nType)) goto undefined_type;

Data_Get_Struct(self, AbstractMemory, ptr);
AbstractMemory* ptr = MEMORY(self);
Data_Get_Struct(nType, Type, type);

MemoryOp *op = get_memory_op(type);
Expand All @@ -369,14 +360,13 @@ undefined_type: {
static VALUE
memory_put(VALUE self, VALUE type_name, VALUE offset, VALUE value)
{
AbstractMemory* ptr;
VALUE nType;
Type *type;

nType = rbffi_Type_Lookup(type_name);
if(NIL_P(nType)) goto undefined_type;

Data_Get_Struct(self, AbstractMemory, ptr);
AbstractMemory* ptr = MEMORY(self);
Data_Get_Struct(nType, Type, type);

MemoryOp *op = get_memory_op(type);
Expand Down Expand Up @@ -433,7 +423,6 @@ static VALUE
memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
{
VALUE offset = Qnil, countnum = Qnil, retVal = Qnil;
AbstractMemory* ptr;
long off;
int count;

Expand All @@ -442,7 +431,7 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
count = (countnum == Qnil ? 0 : NUM2INT(countnum));
retVal = rb_ary_new2(count);

Data_Get_Struct(self, AbstractMemory, ptr);
AbstractMemory* ptr = MEMORY(self);
checkRead(ptr);

if (countnum != Qnil) {
Expand Down Expand Up @@ -631,10 +620,7 @@ memory_write_bytes(int argc, VALUE* argv, VALUE self)
static VALUE
memory_type_size(VALUE self)
{
AbstractMemory* ptr;

Data_Get_Struct(self, AbstractMemory, ptr);

AbstractMemory* ptr = MEMORY(self);
return INT2NUM(ptr->typeSize);
}

Expand All @@ -648,11 +634,9 @@ memory_type_size(VALUE self)
static VALUE
memory_aref(VALUE self, VALUE idx)
{
AbstractMemory* ptr;
AbstractMemory* ptr = MEMORY(self);
VALUE rbOffset = Qnil;

Data_Get_Struct(self, AbstractMemory, ptr);

rbOffset = ULONG2NUM(NUM2ULONG(idx) * ptr->typeSize);

return rb_funcall2(self, id_plus, 1, &rbOffset);
Expand All @@ -667,11 +651,7 @@ memory_address(VALUE obj)
static VALUE
memory_copy_from(VALUE self, VALUE rbsrc, VALUE rblen)
{
AbstractMemory* dst;

Data_Get_Struct(self, AbstractMemory, dst);

memcpy(dst->address, rbffi_AbstractMemory_Cast(rbsrc, rbffi_AbstractMemoryClass)->address, NUM2INT(rblen));
memcpy(MEMORY_PTR(self), MEMORY_PTR(rbsrc), NUM2INT(rblen));

return self;
}
Expand All @@ -680,8 +660,7 @@ AbstractMemory*
rbffi_AbstractMemory_Cast(VALUE obj, VALUE klass)
{
if (rb_obj_is_kind_of(obj, klass)) {
AbstractMemory* memory;
Data_Get_Struct(obj, AbstractMemory, memory);
AbstractMemory* memory = RTYPEDDATA_DATA(obj);
return memory;
}

Expand Down
44 changes: 29 additions & 15 deletions ext/ffi_c/Buffer.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ typedef struct Buffer {

static VALUE buffer_allocate(VALUE klass);
static VALUE buffer_initialize(int argc, VALUE* argv, VALUE self);
static void buffer_release(Buffer* ptr);
static void buffer_mark(Buffer* ptr);
static void buffer_release(void* data);
static void buffer_mark(void* data);
static VALUE buffer_free(VALUE self);

static const rb_data_type_t buffer_data_type = {
.wrap_struct_name = "FFI::Buffer",
.function = {
.dmark = buffer_mark,
.dfree = buffer_release,
.dsize = NULL,
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY
};

static VALUE BufferClass = Qnil;

static VALUE
Expand All @@ -61,16 +71,17 @@ buffer_allocate(VALUE klass)
Buffer* buffer;
VALUE obj;

obj = Data_Make_Struct(klass, Buffer, NULL, buffer_release, buffer);
obj = TypedData_Make_Struct(klass, Buffer, &buffer_data_type, buffer);
buffer->data.rbParent = Qnil;
buffer->memory.flags = MEM_RD | MEM_WR;

return obj;
}

static void
buffer_release(Buffer* ptr)
buffer_release(void *data)
{
Buffer* ptr = (Buffer *)data;
if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) {
xfree(ptr->data.storage);
ptr->data.storage = NULL;
Expand All @@ -95,7 +106,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
Buffer* p;
int nargs;

Data_Get_Struct(self, Buffer, p);
TypedData_Get_Struct(self, Buffer, &buffer_data_type, p);

nargs = rb_scan_args(argc, argv, "12", &rbSize, &rbCount, &rbClear);
p->memory.typeSize = rbffi_type_size(rbSize);
Expand Down Expand Up @@ -138,7 +149,7 @@ buffer_initialize_copy(VALUE self, VALUE other)
AbstractMemory* src;
Buffer* dst;

Data_Get_Struct(self, Buffer, dst);
TypedData_Get_Struct(self, Buffer, &buffer_data_type, dst);
src = rbffi_AbstractMemory_Cast(other, BufferClass);
if ((dst->memory.flags & MEM_EMBED) == 0 && dst->data.storage != NULL) {
xfree(dst->data.storage);
Expand Down Expand Up @@ -172,10 +183,10 @@ slice(VALUE self, long offset, long len)
Buffer* result;
VALUE obj = Qnil;

Data_Get_Struct(self, Buffer, ptr);
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
checkBounds(&ptr->memory, offset, len);

obj = Data_Make_Struct(BufferClass, Buffer, buffer_mark, -1, result);
obj = TypedData_Make_Struct(BufferClass, Buffer, &buffer_data_type, result);
result->memory.address = ptr->memory.address + offset;
result->memory.size = len;
result->memory.flags = ptr->memory.flags;
Expand All @@ -197,7 +208,7 @@ buffer_plus(VALUE self, VALUE rbOffset)
Buffer* ptr;
long offset = NUM2LONG(rbOffset);

Data_Get_Struct(self, Buffer, ptr);
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);

return slice(self, offset, ptr->memory.size - offset);
}
Expand Down Expand Up @@ -226,7 +237,7 @@ buffer_inspect(VALUE self)
char tmp[100];
Buffer* ptr;

Data_Get_Struct(self, Buffer, ptr);
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);

snprintf(tmp, sizeof(tmp), "#<FFI:Buffer:%p address=%p size=%ld>", ptr, ptr->memory.address, ptr->memory.size);

Expand Down Expand Up @@ -255,7 +266,7 @@ buffer_order(int argc, VALUE* argv, VALUE self)
{
Buffer* ptr;

Data_Get_Struct(self, Buffer, ptr);
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
if (argc == 0) {
int order = (ptr->memory.flags & MEM_SWAP) == 0 ? BYTE_ORDER : SWAPPED_ORDER;
return order == BIG_ENDIAN ? ID2SYM(rb_intern("big")) : ID2SYM(rb_intern("little"));
Expand All @@ -279,7 +290,7 @@ buffer_order(int argc, VALUE* argv, VALUE self)
Buffer* p2;
VALUE retval = slice(self, 0, ptr->memory.size);

Data_Get_Struct(retval, Buffer, p2);
TypedData_Get_Struct(retval, Buffer, &buffer_data_type, p2);
p2->memory.flags |= MEM_SWAP;
return retval;
}
Expand All @@ -294,7 +305,7 @@ buffer_free(VALUE self)
{
Buffer* ptr;

Data_Get_Struct(self, Buffer, ptr);
TypedData_Get_Struct(self, Buffer, &buffer_data_type, ptr);
if ((ptr->memory.flags & MEM_EMBED) == 0 && ptr->data.storage != NULL) {
xfree(ptr->data.storage);
ptr->data.storage = NULL;
Expand All @@ -304,9 +315,12 @@ buffer_free(VALUE self)
}

static void
buffer_mark(Buffer* ptr)
buffer_mark(void *data)
{
rb_gc_mark(ptr->data.rbParent);
Buffer* ptr = (Buffer *)data;
if ((ptr->memory.flags & MEM_EMBED) != 0) {
rb_gc_mark(ptr->data.rbParent);
}
}

void
Expand Down
8 changes: 3 additions & 5 deletions ext/ffi_c/Call.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ getPointer(VALUE value, int type)

VALUE ptr = rb_funcall2(value, id_to_ptr, 0, NULL);
if (rb_obj_is_kind_of(ptr, rbffi_AbstractMemoryClass) && TYPE(ptr) == T_DATA) {
return ((AbstractMemory *) DATA_PTR(ptr))->address;
return MEMORY_PTR(ptr);
}
rb_raise(rb_eArgError, "to_ptr returned an invalid pointer");
}
Expand All @@ -465,15 +465,13 @@ callback_param(VALUE proc, VALUE cbInfo)

/* Handle Function pointers here */
if (rb_obj_is_kind_of(proc, rbffi_FunctionClass)) {
AbstractMemory* ptr;
Data_Get_Struct(proc, AbstractMemory, ptr);
return ptr->address;
return MEMORY_PTR(proc);
}

callback = rbffi_Function_ForProc(cbInfo, proc);
RB_GC_GUARD(callback);

return ((AbstractMemory *) DATA_PTR(callback))->address;
return MEMORY_PTR(callback);
}


Expand Down
23 changes: 17 additions & 6 deletions ext/ffi_c/DynamicLibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ typedef struct LibrarySymbol_ {
static VALUE library_initialize(VALUE self, VALUE libname, VALUE libflags);
static void library_free(Library* lib);


static VALUE symbol_allocate(VALUE klass);
static VALUE symbol_new(VALUE library, void* address, VALUE name);
static void symbol_mark(LibrarySymbol* sym);
static void symbol_mark(void *);

static const rb_data_type_t symbol_data_type = {
.wrap_struct_name = "FFI::DynamicLibrary::Symbol",
.function = {
.dmark = symbol_mark,
.dfree = RUBY_DEFAULT_FREE,
.dsize = NULL,
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY
};

static VALUE LibraryClass = Qnil, SymbolClass = Qnil;

Expand Down Expand Up @@ -198,7 +207,7 @@ static VALUE
symbol_allocate(VALUE klass)
{
LibrarySymbol* sym;
VALUE obj = Data_Make_Struct(klass, LibrarySymbol, NULL, -1, sym);
VALUE obj = TypedData_Make_Struct(SymbolClass, LibrarySymbol, &symbol_data_type, sym);
sym->name = Qnil;
sym->library = Qnil;
sym->base.rbParent = Qnil;
Expand All @@ -224,7 +233,7 @@ static VALUE
symbol_new(VALUE library, void* address, VALUE name)
{
LibrarySymbol* sym;
VALUE obj = Data_Make_Struct(SymbolClass, LibrarySymbol, symbol_mark, -1, sym);
VALUE obj = TypedData_Make_Struct(SymbolClass, LibrarySymbol, &symbol_data_type, sym);

sym->base.memory.address = address;
sym->base.memory.size = LONG_MAX;
Expand All @@ -237,10 +246,12 @@ symbol_new(VALUE library, void* address, VALUE name)
}

static void
symbol_mark(LibrarySymbol* sym)
symbol_mark(void *data)
{
LibrarySymbol *sym = (LibrarySymbol *)data;
rb_gc_mark(sym->library);
rb_gc_mark(sym->name);
rb_gc_mark(sym->base.rbParent);
}

/*
Expand All @@ -254,7 +265,7 @@ symbol_inspect(VALUE self)
LibrarySymbol* sym;
char buf[256];

Data_Get_Struct(self, LibrarySymbol, sym);
TypedData_Get_Struct(self, LibrarySymbol, &symbol_data_type, sym);
snprintf(buf, sizeof(buf), "#<FFI::Library::Symbol name=%s address=%p>",
StringValueCStr(sym->name), sym->base.memory.address);
return rb_str_new2(buf);
Expand Down
Loading
0