summaryrefslogtreecommitdiff
path: root/ext/ffi_c/Call.c
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2013-01-02 20:10:25 +1000
committerWayne Meissner <wmeissner@gmail.com>2013-01-02 20:10:25 +1000
commitf8ce0e2044c487ffa4afde2dace5ad762a2a6cb4 (patch)
treee0a2ef199f561ff85f581d39c7c40c3d10539389 /ext/ffi_c/Call.c
parentce106d75836e044badd4f0d5dfced667a8e86cd1 (diff)
downloadffi-f8ce0e2044c487ffa4afde2dace5ad762a2a6cb4.tar.gz
Fix #242 by coercing :string parameters using #to_str
Diffstat (limited to 'ext/ffi_c/Call.c')
-rw-r--r--ext/ffi_c/Call.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/ext/ffi_c/Call.c b/ext/ffi_c/Call.c
index 76cbb69..e9f1152 100644
--- a/ext/ffi_c/Call.c
+++ b/ext/ffi_c/Call.c
@@ -79,7 +79,6 @@ typedef int bool;
static void* callback_param(VALUE proc, VALUE cbinfo);
static inline void* getPointer(VALUE value, int type);
-static inline char* getString(VALUE value, int type);
static ID id_to_ptr, id_map_symbol, id_to_native;
@@ -221,7 +220,18 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
case NATIVE_STRING:
- param->ptr = getString(argv[argidx++], type);
+ if (type == T_NIL) {
+ param->ptr = NULL;
+
+ } else {
+ if (rb_safe_level() >= 1 && OBJ_TAINTED(argv[argidx])) {
+ rb_raise(rb_eSecurityError, "Unsafe string parameter");
+ }
+
+ param->ptr = StringValueCStr(argv[argidx]);
+ ++argidx;
+ }
+
ADJ(param, ADDRESS);
break;
@@ -397,25 +407,6 @@ getPointer(VALUE value, int type)
return NULL;
}
-static inline char*
-getString(VALUE value, int type)
-{
- if (type == T_STRING) {
-
- if (rb_safe_level() >= 1 && OBJ_TAINTED(value)) {
- rb_raise(rb_eSecurityError, "Unsafe string parameter");
- }
-
- return StringValueCStr(value);
-
- } else if (type == T_NIL) {
- return NULL;
- }
-
- rb_raise(rb_eArgError, "Invalid String value");
-}
-
-
Invoker
rbffi_GetInvoker(FunctionType *fnInfo)
{