]> git.saurik.com Git - cycript.git/blobdiff - Execute.cpp
Tighten (and sort of "fix") some native alignment.
[cycript.git] / Execute.cpp
index 1624b29e4c3ffdf64d0395a5b8204d4dd1b8bf6a..86009fc03a0cdba7f80bb0d42adf5e2404fcdb5e 100644 (file)
@@ -111,10 +111,10 @@ JSStringRef CYCopyJSString(JSStringRef value) {
 JSStringRef CYCopyJSString(CYUTF8String value) {
     if (memchr(value.data, '\0', value.size) != NULL) {
         CYPool pool;
-        return CYCopyJSString(pool.memdup(value.data, value.size));
+        return CYCopyJSString(CYPoolUTF16String(pool, value));
     } else if (value.data[value.size] != '\0') {
         CYPool pool;
-        return CYCopyJSString(CYPoolUTF16String(pool, value));
+        return CYCopyJSString(pool.strmemdup(value.data, value.size));
     } else {
         return CYCopyJSString(value.data);
     }
@@ -269,9 +269,9 @@ JSObjectRef CYMakeStruct(JSContextRef context, void *data, const sig::Type &type
     if (owner != NULL)
         internal->value_ = data;
     else {
-        size_t size(typical->GetFFI()->size);
-        void *copy(internal->pool_->malloc<void>(size));
-        memcpy(copy, data, size);
+        ffi_type *ffi(typical->GetFFI());
+        void *copy(internal->pool_->malloc<void>(ffi->size, ffi->alignment));
+        memcpy(copy, data, ffi->size);
         internal->value_ = copy;
     }
 
@@ -744,7 +744,6 @@ void Array::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *dat
         }
 
         type.PoolFFI(pool, context, field, base, rhs);
-        // XXX: alignment?
         base += field->size;
     }
 }
@@ -774,7 +773,6 @@ void Aggregate::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void
         }
 
         element->type->PoolFFI(pool, context, field, base, rhs);
-        // XXX: alignment?
         base += field->size;
     }
 }
@@ -1135,8 +1133,7 @@ JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, voi
     for (size_t index(setups); index != size; ++index) {
         sig::Element *element(&signature->elements[index + 1]);
         ffi_type *ffi(cif->arg_types[index]);
-        // XXX: alignment?
-        values[index] = new(pool) uint8_t[ffi->size];
+        values[index] = pool.malloc<uint8_t>(ffi->size, ffi->alignment);
         element->type->PoolFFI(&pool, context, ffi, values[index], arguments[index - setups]);
     }
 
@@ -1481,11 +1478,10 @@ static JSValueRef Type_callAsFunction(JSContextRef context, JSObjectRef object,
     if (sig::Function *function = dynamic_cast<sig::Function *>(internal->type_))
         return CYMakeFunctor(context, arguments[0], function->signature);
 
+    CYPool pool;
     sig::Type *type(internal->type_);
     ffi_type *ffi(internal->GetFFI());
-    // XXX: alignment?
-    uint8_t value[ffi->size];
-    CYPool pool;
+    void *value(pool.malloc<void>(ffi->size, ffi->alignment));
     type->PoolFFI(&pool, context, ffi, value, arguments[0]);
     return type->FromFFI(context, ffi, value);
 } CYCatch(NULL) }
@@ -1500,8 +1496,9 @@ static JSObjectRef Type_callAsConstructor(JSContextRef context, JSObjectRef obje
 
     JSObjectRef pointer(CYMakePointer(context, NULL, length, *type, NULL, NULL));
     Pointer *value(reinterpret_cast<Pointer *>(JSObjectGetPrivate(pointer)));
-    value->value_ = value->pool_->malloc<void>(internal->GetFFI()->size);
-    memset(value->value_, 0, internal->GetFFI()->size);
+    ffi_type *ffi(internal->GetFFI());
+    value->value_ = value->pool_->malloc<void>(ffi->size, ffi->alignment);
+    memset(value->value_, 0, ffi->size);
     return pointer;
 } CYCatch(NULL) }