]> git.saurik.com Git - cycript.git/blobdiff - Library.cpp
Removed a null-termination usage in Replace for concatenation of strings.
[cycript.git] / Library.cpp
index 7bc867bd43f9c7c5009094ceb3b1a2ad2a9852b8..2289e37ca0ed898746dc4f8539ad56d88a3d5437 100644 (file)
@@ -340,8 +340,19 @@ struct CStringMapLess :
     }
 };
 
     }
 };
 
-void Structor_(apr_pool_t *pool, const char *name, const char *types, sig::Type *&type) {
-    if (name == NULL)
+void Structor_(apr_pool_t *pool, sig::Type *&type) {
+    if (
+        type->primitive == sig::pointer_P &&
+        type->data.data.type != NULL &&
+        type->data.data.type->primitive == sig::struct_P &&
+        strcmp(type->data.data.type->name, "_objc_class") == 0
+    ) {
+        type->primitive = sig::typename_P;
+        type->data.data.type = NULL;
+        return;
+    }
+
+    if (type->primitive != sig::struct_P || type->name == NULL)
         return;
 
     sqlite3_stmt *statement;
         return;
 
     sqlite3_stmt *statement;
@@ -357,7 +368,7 @@ void Structor_(apr_pool_t *pool, const char *name, const char *types, sig::Type
         " limit 1"
     , -1, &statement, NULL));
 
         " limit 1"
     , -1, &statement, NULL));
 
-    _sqlcall(sqlite3_bind_text(statement, 1, name, -1, SQLITE_STATIC));
+    _sqlcall(sqlite3_bind_text(statement, 1, type->name, -1, SQLITE_STATIC));
 
     int mode;
     const char *value;
 
     int mode;
     const char *value;
@@ -528,7 +539,7 @@ static size_t Nonce_(0);
 
 static JSValueRef $cyq(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
     CYPool pool;
 
 static JSValueRef $cyq(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
     CYPool pool;
-    const char *name(apr_psprintf(pool, "%s%zu", CYPoolCString(pool, context, arguments[0]), Nonce_++));
+    const char *name(apr_psprintf(pool, "%s%"APR_SIZE_T_FMT"", CYPoolCString(pool, context, arguments[0]), Nonce_++));
     return CYCastJSValue(context, name);
 }
 
     return CYCastJSValue(context, name);
 }
 
@@ -805,8 +816,7 @@ JSValueRef CYFromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void
                 if (JSValueRef value = (*hooks_->FromFFI)(context, type, ffi, data, initialize, owner))
                     return value;
 
                 if (JSValueRef value = (*hooks_->FromFFI)(context, type, ffi, data, initialize, owner))
                     return value;
 
-            fprintf(stderr, "CYFromFFI(%c)\n", type->primitive);
-            _assert(false);
+            CYThrow("failed conversion from FFI format: '%c'\n", type->primitive);
     }
 }
 
     }
 }
 
@@ -1437,8 +1447,18 @@ CYPoolError::CYPoolError(const char *format, va_list args) {
     message_ = apr_pvsprintf(pool_, format, args);
 }
 
     message_ = apr_pvsprintf(pool_, format, args);
 }
 
+JSValueRef CYCastJSError(JSContextRef context, const char *message) {
+    JSValueRef arguments[1] = {CYCastJSValue(context, message)};
+
+    JSValueRef exception(NULL);
+    JSValueRef value(JSObjectCallAsConstructor(context, Error_, 1, arguments, &exception));
+    CYThrow(context, exception);
+
+    return value;
+}
+
 JSValueRef CYPoolError::CastJSValue(JSContextRef context) const {
 JSValueRef CYPoolError::CastJSValue(JSContextRef context) const {
-    return CYCastJSValue(context, message_);
+    return CYCastJSError(context, message_);
 }
 
 CYJSError::CYJSError(JSContextRef context, const char *format, ...) {
 }
 
 CYJSError::CYJSError(JSContextRef context, const char *format, ...) {
@@ -1452,11 +1472,7 @@ CYJSError::CYJSError(JSContextRef context, const char *format, ...) {
     const char *message(apr_pvsprintf(pool, format, args));
     va_end (args);
 
     const char *message(apr_pvsprintf(pool, format, args));
     va_end (args);
 
-    JSValueRef arguments[1] = {CYCastJSValue(context, CYJSString(message))};
-
-    JSValueRef exception(NULL);
-    value_ = JSObjectCallAsConstructor(context, Error_, 1, arguments, &exception);
-    CYThrow(context, exception);
+    value_ = CYCastJSError(context, message);
 }
 
 JSGlobalContextRef CYGetJSContext() {
 }
 
 JSGlobalContextRef CYGetJSContext() {