From a2f3ecabdf36b8b6e35dff67380ab7482993c60b Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 21 Jan 2014 07:24:59 -0800 Subject: [PATCH] Fix pointer crashes and round-trip const void *. --- Execute.cpp | 1 - Internal.hpp | 5 +++-- Replace.cpp | 2 +- sig/parse.cpp | 15 ++++++--------- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Execute.cpp b/Execute.cpp index 5baca2a..c4a1fbb 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -152,7 +152,6 @@ void CYFinalize(JSObjectRef object) { void Structor_(CYPool &pool, sig::Type *&type) { if ( type->primitive == sig::pointer_P && - type->data.data.type != NULL && type->data.data.type->primitive == sig::struct_P && type->data.data.type->name != NULL && strcmp(type->data.data.type->name, "_objc_class") == 0 diff --git a/Internal.hpp b/Internal.hpp index abb48ed..7c278b4 100644 --- a/Internal.hpp +++ b/Internal.hpp @@ -73,8 +73,9 @@ struct Type_privateData : Type_privateData(sig::Type *type) : ffi_(NULL) { - if (type != NULL) - Set(type); + // XXX: just in case I messed up migrating + _assert(type != NULL); + Set(type); } Type_privateData(sig::Type *type, ffi_type *ffi) { diff --git a/Replace.cpp b/Replace.cpp index ce01303..ba73201 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -951,7 +951,7 @@ CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL) } CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix) - return next_->TypeSignature(context, $ CYAdd(prefix, typed_->specifier_->Replace(context))); + return next_->TypeSignature(context, $ CYAdd(prefix, typed_->Replace(context))); } CYStatement *CYVar::Replace(CYContext &context) { diff --git a/sig/parse.cpp b/sig/parse.cpp index da590a8..d95af2f 100644 --- a/sig/parse.cpp +++ b/sig/parse.cpp @@ -149,14 +149,11 @@ Type *Parse_(CYPool &pool, const char **name, char eos, bool named, Callback cal case '^': type->primitive = pointer_P; - if (**name == '"') { + if (**name == '"') + // XXX: why is this here? type->data.data.type = NULL; - } else { + else type->data.data.type = Parse_(pool, name, eos, named, callback); - sig::Type *&target(type->data.data.type); - if (target != NULL && target->primitive == void_P) - target = NULL; - } break; case 'b': @@ -280,9 +277,9 @@ const char *Unparse_(CYPool &pool, struct Type *type) { } break; case pointer_P: { - if (type->data.data.type == NULL) - return "^v"; - else if (type->data.data.type->primitive == function_P) + // XXX: protect against the weird '"' check in Parse_ + _assert(type->data.data.type != NULL); + if (type->data.data.type->primitive == function_P) return "^?"; else return pool.strcat("^", Unparse(pool, type->data.data.type), NULL); -- 2.45.2