[macruby-changes] [1501] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Tue Apr 28 15:53:45 PDT 2009
Revision: 1501
http://trac.macosforge.org/projects/ruby/changeset/1501
Author: lsansonetti at apple.com
Date: 2009-04-28 15:53:43 -0700 (Tue, 28 Apr 2009)
Log Message:
-----------
when passing a Pointer object as '^', compare the encoding types and raise TypeError if necessary
Modified Paths:
--------------
MacRuby/branches/experimental/roxor.cpp
MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb
Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp 2009-04-28 05:53:14 UTC (rev 1500)
+++ MacRuby/branches/experimental/roxor.cpp 2009-04-28 22:53:43 UTC (rev 1501)
@@ -273,6 +273,7 @@
Function *newOpaqueFunc;
Function *getStructFieldsFunc;
Function *getOpaqueDataFunc;
+ Function *getPointerPtrFunc;
Function *checkArityFunc;
Function *setStructFunc;
Function *newRangeFunc;
@@ -363,6 +364,7 @@
rb_vm_bs_boxed_t *bs_boxed);
Value *compile_get_opaque_data(Value *val, rb_vm_bs_boxed_t *bs_boxed,
Value *slot);
+ Value *compile_get_cptr(Value *val, const char *type, Value *slot);
void compile_check_arity(Value *given, Value *requested);
void compile_set_struct(Value *rcv, int field, Value *val);
@@ -698,6 +700,7 @@
newOpaqueFunc = NULL;
getStructFieldsFunc = NULL;
getOpaqueDataFunc = NULL;
+ getPointerPtrFunc = NULL;
checkArityFunc = NULL;
setStructFunc = NULL;
newRangeFunc = NULL;
@@ -5070,24 +5073,19 @@
*ocval = (float)rval_to_double(rval);
}
-static void *rb_pointer_get_data(VALUE rcv);
+static void *rb_pointer_get_data(VALUE rcv, const char *type);
extern "C"
-void
-rb_vm_rval_to_cptr(VALUE rval, void **cptr)
+void *
+rb_vm_rval_to_cptr(VALUE rval, const char *type, void **cptr)
{
if (NIL_P(rval)) {
*cptr = NULL;
}
else {
- if (!rb_obj_is_kind_of(rval, rb_cPointer)) {
- rb_raise(rb_eTypeError,
- "expected instance of Pointer, got `%s' (%s)",
- RSTRING_PTR(rb_inspect(rval)),
- rb_obj_classname(rval));
- }
- *cptr = rb_pointer_get_data(rval);
+ *cptr = rb_pointer_get_data(rval, type);
}
+ return *cptr;
}
static inline long
@@ -5229,11 +5227,27 @@
params.push_back(compile_const_pointer(bs_boxed));
params.push_back(slot);
- return CallInst::Create(getOpaqueDataFunc, params.begin(), params.end(),
- "", bb);
+ return compile_protected_call(getOpaqueDataFunc, params);
}
Value *
+RoxorCompiler::compile_get_cptr(Value *val, const char *type, Value *slot)
+{
+ if (getPointerPtrFunc == NULL) {
+ getPointerPtrFunc = cast<Function>(module->getOrInsertFunction(
+ "rb_vm_rval_to_cptr",
+ PtrTy, RubyObjTy, PtrTy, PtrPtrTy, NULL));
+ }
+
+ std::vector<Value *> params;
+ params.push_back(val);
+ params.push_back(compile_const_pointer(sel_registerName(type)));
+ params.push_back(new BitCastInst(slot, PtrPtrTy, "", bb));
+
+ return compile_protected_call(getPointerPtrFunc, params);
+}
+
+Value *
RoxorCompiler::compile_conversion_to_c(const char *type, Value *val,
Value *slot)
{
@@ -5357,7 +5371,7 @@
return compile_get_opaque_data(val, bs_boxed, slot);
}
- func_name = "rb_vm_rval_to_cptr";
+ return compile_get_cptr(val, type, slot);
}
break;
}
@@ -9137,11 +9151,26 @@
}
static void *
-rb_pointer_get_data(VALUE rcv)
+rb_pointer_get_data(VALUE rcv, const char *type)
{
+ if (!rb_obj_is_kind_of(rcv, rb_cPointer)) {
+ rb_raise(rb_eTypeError,
+ "expected instance of Pointer, got `%s' (%s)",
+ RSTRING_PTR(rb_inspect(rcv)),
+ rb_obj_classname(rcv));
+ }
+
rb_vm_pointer_t *ptr;
Data_Get_Struct(rcv, rb_vm_pointer_t, ptr);
+ assert(*type == _C_PTR);
+ if (strcmp(RSTRING_PTR(ptr->type), type + 1) != 0) {
+ rb_raise(rb_eTypeError,
+ "expected instance of Pointer of type `%s', got `%s'",
+ RSTRING_PTR(ptr->type),
+ type + 1);
+ }
+
return ptr->val;
}
Modified: MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb 2009-04-28 05:53:14 UTC (rev 1500)
+++ MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb 2009-04-28 22:53:43 UTC (rev 1501)
@@ -372,9 +372,12 @@
@o.methodAcceptingIntPtr(p).should == 1
p[0].should == 43
+ lambda { @o.methodAcceptingIntPtr(Pointer.new(:uint)) }.should raise_error(TypeError)
lambda { @o.methodAcceptingIntPtr(123) }.should raise_error(TypeError)
@o.methodAcceptingIntPtr2(nil).should == 1
+
+ lambda { @o.methodAcceptingIntPtr2(Pointer.new(:uint)) }.should raise_error(TypeError)
end
it "accepting an 'id *' should be given a Pointer object and receive the pointer as expected" do
@@ -383,9 +386,12 @@
@o.methodAcceptingObjectPtr(p).should == 1
p[0].should == NSObject
+ lambda { @o.methodAcceptingObjectPtr(Pointer.new(:int)) }.should raise_error(TypeError)
lambda { @o.methodAcceptingObjectPtr(123) }.should raise_error(TypeError)
@o.methodAcceptingObjectPtr2(nil).should == 1
+
+ lambda { @o.methodAcceptingObjectPtr2(Pointer.new(:int)) }.should raise_error(TypeError)
end
it "accepting an 'NSRect *' should be given a Pointer object and receive the pointer as expected" do
@@ -397,8 +403,11 @@
p[0].size.width.should == 44
p[0].size.height.should == 45
+ lambda { @o.methodAcceptingNSRectPtr(Pointer.new(NSPoint.type)) }.should raise_error(TypeError)
lambda { @o.methodAcceptingNSRectPtr(123) }.should raise_error(TypeError)
@o.methodAcceptingNSRectPtr2(nil).should == 1
+
+ lambda { @o.methodAcceptingNSRectPtr2(Pointer.new(NSPoint.type)) }.should raise_error(TypeError)
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090428/9d1d024b/attachment.html>
More information about the macruby-changes
mailing list