From 83e1cbb80dd1735daaf58ae5db95cd099992632c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 23 Dec 2015 09:58:47 -0800 Subject: [PATCH] Add (future) flags field to the bindings database. --- Analyze.cpp | 22 +++++-- Bridge.def.in | 162 +++++++++++++++++++++++++------------------------- Execute.cpp | 34 +++++++---- libcycript.py | 10 ++-- libcycript.sh | 4 +- 5 files changed, 127 insertions(+), 105 deletions(-) diff --git a/Analyze.cpp b/Analyze.cpp index 42728bf..1eac8a0 100644 --- a/Analyze.cpp +++ b/Analyze.cpp @@ -126,7 +126,12 @@ std::ostream &operator <<(std::ostream &out, const CYCXPosition CYKeyMap; +struct CYKey { + std::string code_; + unsigned flags_; +}; + +typedef std::map CYKeyMap; struct CYChildBaton { CXTranslationUnit unit; @@ -288,6 +293,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien CYCXString spelling(cursor); std::string name(spelling); std::ostringstream value; + unsigned flags(0); /*CXSourceLocation location(clang_getCursorLocation(cursor)); CYCXPosition<> position(location); @@ -445,7 +451,11 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien } break; } - baton.keys[name] = value.str(); + { + CYKey &key(baton.keys[name]); + key.code_ = value.str(); + key.flags_ = flags; + } skip: return CXChildVisit_Continue; @@ -474,11 +484,11 @@ int main(int argc, const char *argv[]) { clang_visitChildren(clang_getTranslationUnitCursor(unit), &CYChildVisit, &baton); for (CYKeyMap::const_iterator key(keys.begin()); key != keys.end(); ++key) { - std::string value(key->second); - for (size_t i(0), e(value.size()); i != e; ++i) - if (value[i] <= 0 || value[i] >= 0x7f || value[i] == '\n') + std::string code(key->second.code_); + for (size_t i(0), e(code.size()); i != e; ++i) + if (code[i] <= 0 || code[i] >= 0x7f || code[i] == '\n') goto skip; - std::cout << key->first << "|\"" << value << "\"" << std::endl; + std::cout << key->first << "|" << key->second.flags_ << "\"" << code << "\"" << std::endl; skip:; } clang_disposeTranslationUnit(unit); diff --git a/Bridge.def.in b/Bridge.def.in index 7bec54a..b0c2446 100644 --- a/Bridge.def.in +++ b/Bridge.def.in @@ -1,89 +1,89 @@ -IMP|"(typedef void (*)())" +IMP|0"(typedef void (*)())" -malloc|"*(typedef void*(*)(unsigned long int))(dlsym(RTLD_DEFAULT,'malloc'))" -free|"*(typedef void(*)(void*))(dlsym(RTLD_DEFAULT,'free'))" +malloc|0"*(typedef void*(*)(unsigned long int))(dlsym(RTLD_DEFAULT,'malloc'))" +free|0"*(typedef void(*)(void*))(dlsym(RTLD_DEFAULT,'free'))" -class_addIvar|"*(typedef bool(*)(Class,const char*,unsigned long int,unsigned char,const char*))(dlsym(RTLD_DEFAULT,'class_addIvar'))" -class_addMethod|"*(typedef bool(*)(Class,SEL,IMP,const char*))(dlsym(RTLD_DEFAULT,'class_addMethod'))" -class_addProtocol|"*(typedef bool(*)(Class,id))(dlsym(RTLD_DEFAULT,'class_addProtocol'))" -class_conformsToProtocol|"*(typedef bool(*)(Class,id))(dlsym(RTLD_DEFAULT,'class_conformsToProtocol'))" -class_copyIvarList|"*(typedef struct objc_ivar**(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyIvarList'))" -class_copyMethodList|"*(typedef struct objc_method**(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyMethodList'))" -class_copyPropertyList|"*(typedef struct objc_property**(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyPropertyList'))" -class_copyProtocolList|"*(typedef id*(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyProtocolList'))" -class_createInstance|"*(typedef id(*)(Class,unsigned long int))(dlsym(RTLD_DEFAULT,'class_createInstance'))" -class_getClassMethod|"*(typedef struct objc_method*(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getClassMethod'))" -class_getClassVariable|"*(typedef struct objc_ivar*(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_getClassVariable'))" -class_getInstanceMethod|"*(typedef struct objc_method*(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getInstanceMethod'))" -class_getInstanceSize|"*(typedef unsigned long int(*)(Class))(dlsym(RTLD_DEFAULT,'class_getInstanceSize'))" -class_getInstanceVariable|"*(typedef struct objc_ivar*(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_getInstanceVariable'))" -class_getIvarLayout|"*(typedef const char*(*)(Class))(dlsym(RTLD_DEFAULT,'class_getIvarLayout'))" -class_getMethodImplementation|"*(typedef IMP(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getMethodImplementation'))" -class_getMethodImplementation_stret|"*(typedef IMP(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getMethodImplementation_stret'))" -class_getName|"*(typedef const char*(*)(Class))(dlsym(RTLD_DEFAULT,'class_getName'))" -class_getProperty|"*(typedef struct objc_property*(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_getProperty'))" -class_getSuperclass|"*(typedef Class(*)(Class))(dlsym(RTLD_DEFAULT,'class_getSuperclass'))" -class_getVersion|"*(typedef int(*)(Class))(dlsym(RTLD_DEFAULT,'class_getVersion'))" -class_getWeakIvarLayout|"*(typedef const char*(*)(Class))(dlsym(RTLD_DEFAULT,'class_getWeakIvarLayout'))" -class_isMetaClass|"*(typedef bool(*)(Class))(dlsym(RTLD_DEFAULT,'class_isMetaClass'))" -class_replaceMethod|"*(typedef IMP(*)(Class,SEL,IMP,const char*))(dlsym(RTLD_DEFAULT,'class_replaceMethod'))" -class_respondsToSelector|"*(typedef bool(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_respondsToSelector'))" -class_setIvarLayout|"*(typedef void(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_setIvarLayout'))" -class_setSuperclass|"*(typedef Class(*)(Class,Class))(dlsym(RTLD_DEFAULT,'class_setSuperclass'))" -class_setVersion|"*(typedef void(*)(Class,int))(dlsym(RTLD_DEFAULT,'class_setVersion'))" -class_setWeakIvarLayout|"*(typedef void(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_setWeakIvarLayout'))" +class_addIvar|0"*(typedef bool(*)(Class,const char*,unsigned long int,unsigned char,const char*))(dlsym(RTLD_DEFAULT,'class_addIvar'))" +class_addMethod|0"*(typedef bool(*)(Class,SEL,IMP,const char*))(dlsym(RTLD_DEFAULT,'class_addMethod'))" +class_addProtocol|0"*(typedef bool(*)(Class,id))(dlsym(RTLD_DEFAULT,'class_addProtocol'))" +class_conformsToProtocol|0"*(typedef bool(*)(Class,id))(dlsym(RTLD_DEFAULT,'class_conformsToProtocol'))" +class_copyIvarList|0"*(typedef struct objc_ivar**(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyIvarList'))" +class_copyMethodList|0"*(typedef struct objc_method**(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyMethodList'))" +class_copyPropertyList|0"*(typedef struct objc_property**(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyPropertyList'))" +class_copyProtocolList|0"*(typedef id*(*)(Class,unsigned int*))(dlsym(RTLD_DEFAULT,'class_copyProtocolList'))" +class_createInstance|0"*(typedef id(*)(Class,unsigned long int))(dlsym(RTLD_DEFAULT,'class_createInstance'))" +class_getClassMethod|0"*(typedef struct objc_method*(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getClassMethod'))" +class_getClassVariable|0"*(typedef struct objc_ivar*(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_getClassVariable'))" +class_getInstanceMethod|0"*(typedef struct objc_method*(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getInstanceMethod'))" +class_getInstanceSize|0"*(typedef unsigned long int(*)(Class))(dlsym(RTLD_DEFAULT,'class_getInstanceSize'))" +class_getInstanceVariable|0"*(typedef struct objc_ivar*(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_getInstanceVariable'))" +class_getIvarLayout|0"*(typedef const char*(*)(Class))(dlsym(RTLD_DEFAULT,'class_getIvarLayout'))" +class_getMethodImplementation|0"*(typedef IMP(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getMethodImplementation'))" +class_getMethodImplementation_stret|0"*(typedef IMP(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_getMethodImplementation_stret'))" +class_getName|0"*(typedef const char*(*)(Class))(dlsym(RTLD_DEFAULT,'class_getName'))" +class_getProperty|0"*(typedef struct objc_property*(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_getProperty'))" +class_getSuperclass|0"*(typedef Class(*)(Class))(dlsym(RTLD_DEFAULT,'class_getSuperclass'))" +class_getVersion|0"*(typedef int(*)(Class))(dlsym(RTLD_DEFAULT,'class_getVersion'))" +class_getWeakIvarLayout|0"*(typedef const char*(*)(Class))(dlsym(RTLD_DEFAULT,'class_getWeakIvarLayout'))" +class_isMetaClass|0"*(typedef bool(*)(Class))(dlsym(RTLD_DEFAULT,'class_isMetaClass'))" +class_replaceMethod|0"*(typedef IMP(*)(Class,SEL,IMP,const char*))(dlsym(RTLD_DEFAULT,'class_replaceMethod'))" +class_respondsToSelector|0"*(typedef bool(*)(Class,SEL))(dlsym(RTLD_DEFAULT,'class_respondsToSelector'))" +class_setIvarLayout|0"*(typedef void(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_setIvarLayout'))" +class_setSuperclass|0"*(typedef Class(*)(Class,Class))(dlsym(RTLD_DEFAULT,'class_setSuperclass'))" +class_setVersion|0"*(typedef void(*)(Class,int))(dlsym(RTLD_DEFAULT,'class_setVersion'))" +class_setWeakIvarLayout|0"*(typedef void(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'class_setWeakIvarLayout'))" -ivar_getName|"*(typedef const char*(*)(struct objc_ivar*))(dlsym(RTLD_DEFAULT,'ivar_getName'))" -ivar_getOffset|"*(typedef int(*)(struct objc_ivar*))(dlsym(RTLD_DEFAULT,'ivar_getOffset'))" -ivar_getTypeEncoding|"*(typedef const char*(*)(struct objc_ivar*))(dlsym(RTLD_DEFAULT,'ivar_getTypeEncoding'))" +ivar_getName|0"*(typedef const char*(*)(struct objc_ivar*))(dlsym(RTLD_DEFAULT,'ivar_getName'))" +ivar_getOffset|0"*(typedef int(*)(struct objc_ivar*))(dlsym(RTLD_DEFAULT,'ivar_getOffset'))" +ivar_getTypeEncoding|0"*(typedef const char*(*)(struct objc_ivar*))(dlsym(RTLD_DEFAULT,'ivar_getTypeEncoding'))" -method_copyArgumentType|"*(typedef char*(*)(struct objc_method*,unsigned int))(dlsym(RTLD_DEFAULT,'method_copyArgumentType'))" -method_copyReturnType|"*(typedef char*(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_copyReturnType'))" -method_exchangeImplementations|"*(typedef void(*)(struct objc_method*,struct objc_method*))(dlsym(RTLD_DEFAULT,'method_exchangeImplementations'))" -method_getArgumentType|"*(typedef void(*)(struct objc_method*,unsigned int,char*,unsigned long int))(dlsym(RTLD_DEFAULT,'method_getArgumentType'))" -method_getImplementation|"*(typedef IMP(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getImplementation'))" -method_getName|"*(typedef SEL(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getName'))" -method_getNumberOfArguments|"*(typedef unsigned int(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getNumberOfArguments'))" -method_getReturnType|"*(typedef void(*)(struct objc_method*,char*,unsigned long int))(dlsym(RTLD_DEFAULT,'method_getReturnType'))" -method_getTypeEncoding|"*(typedef const char*(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getTypeEncoding'))" -method_setImplementation|"*(typedef IMP(*)(struct objc_method*,IMP))(dlsym(RTLD_DEFAULT,'method_setImplementation'))" +method_copyArgumentType|0"*(typedef char*(*)(struct objc_method*,unsigned int))(dlsym(RTLD_DEFAULT,'method_copyArgumentType'))" +method_copyReturnType|0"*(typedef char*(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_copyReturnType'))" +method_exchangeImplementations|0"*(typedef void(*)(struct objc_method*,struct objc_method*))(dlsym(RTLD_DEFAULT,'method_exchangeImplementations'))" +method_getArgumentType|0"*(typedef void(*)(struct objc_method*,unsigned int,char*,unsigned long int))(dlsym(RTLD_DEFAULT,'method_getArgumentType'))" +method_getImplementation|0"*(typedef IMP(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getImplementation'))" +method_getName|0"*(typedef SEL(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getName'))" +method_getNumberOfArguments|0"*(typedef unsigned int(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getNumberOfArguments'))" +method_getReturnType|0"*(typedef void(*)(struct objc_method*,char*,unsigned long int))(dlsym(RTLD_DEFAULT,'method_getReturnType'))" +method_getTypeEncoding|0"*(typedef const char*(*)(struct objc_method*))(dlsym(RTLD_DEFAULT,'method_getTypeEncoding'))" +method_setImplementation|0"*(typedef IMP(*)(struct objc_method*,IMP))(dlsym(RTLD_DEFAULT,'method_setImplementation'))" -objc_allocateClassPair|"*(typedef Class(*)(Class,const char*,unsigned long int))(dlsym(RTLD_DEFAULT,'objc_allocateClassPair'))" -objc_copyProtocolList|"*(typedef id*(*)(unsigned int*))(dlsym(RTLD_DEFAULT,'objc_copyProtocolList'))" -objc_duplicateClass|"*(typedef Class(*)(Class,const char*,unsigned long int))(dlsym(RTLD_DEFAULT,'objc_duplicateClass'))" -objc_getClass|"*(typedef Class(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getClass'))" -objc_getClassList|"*(typedef int(*)(Class*,int))(dlsym(RTLD_DEFAULT,'objc_getClassList'))" -objc_getFutureClass|"*(typedef Class(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getFutureClass'))" -objc_getMetaClass|"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getMetaClass'))" -objc_getProtocol|"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getProtocol'))" -objc_getRequiredClass|"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getRequiredClass'))" -objc_lookUpClass|"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_lookUpClass'))" -objc_registerClassPair|"*(typedef void(*)(Class))(dlsym(RTLD_DEFAULT,'objc_registerClassPair'))" -objc_setFutureClass|"*(typedef void(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'objc_setFutureClass'))" +objc_allocateClassPair|0"*(typedef Class(*)(Class,const char*,unsigned long int))(dlsym(RTLD_DEFAULT,'objc_allocateClassPair'))" +objc_copyProtocolList|0"*(typedef id*(*)(unsigned int*))(dlsym(RTLD_DEFAULT,'objc_copyProtocolList'))" +objc_duplicateClass|0"*(typedef Class(*)(Class,const char*,unsigned long int))(dlsym(RTLD_DEFAULT,'objc_duplicateClass'))" +objc_getClass|0"*(typedef Class(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getClass'))" +objc_getClassList|0"*(typedef int(*)(Class*,int))(dlsym(RTLD_DEFAULT,'objc_getClassList'))" +objc_getFutureClass|0"*(typedef Class(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getFutureClass'))" +objc_getMetaClass|0"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getMetaClass'))" +objc_getProtocol|0"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getProtocol'))" +objc_getRequiredClass|0"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_getRequiredClass'))" +objc_lookUpClass|0"*(typedef id(*)(const char*))(dlsym(RTLD_DEFAULT,'objc_lookUpClass'))" +objc_registerClassPair|0"*(typedef void(*)(Class))(dlsym(RTLD_DEFAULT,'objc_registerClassPair'))" +objc_setFutureClass|0"*(typedef void(*)(Class,const char*))(dlsym(RTLD_DEFAULT,'objc_setFutureClass'))" -object_copy|"*(typedef id(*)(id,unsigned long int))(dlsym(RTLD_DEFAULT,'object_copy'))" -object_dispose|"*(typedef id(*)(id))(dlsym(RTLD_DEFAULT,'object_dispose'))" -object_getClass|"*(typedef Class(*)(id))(dlsym(RTLD_DEFAULT,'object_getClass'))" -object_getClassName|"*(typedef const char*(*)(id))(dlsym(RTLD_DEFAULT,'object_getClassName'))" -object_getIndexedIvars|"*(typedef void*(*)(id))(dlsym(RTLD_DEFAULT,'object_getIndexedIvars'))" -object_getInstanceVariable|"*(typedef struct objc_ivar*(*)(id,const char*,void**))(dlsym(RTLD_DEFAULT,'object_getInstanceVariable'))" -object_getIvar|"*(typedef id(*)(id,struct objc_ivar*))(dlsym(RTLD_DEFAULT,'object_getIvar'))" -object_setClass|"*(typedef Class(*)(id,Class))(dlsym(RTLD_DEFAULT,'object_setClass'))" -object_setInstanceVariable|"*(typedef struct objc_ivar*(*)(id,const char*,void*))(dlsym(RTLD_DEFAULT,'object_setInstanceVariable'))" -object_setIvar|"*(typedef void(*)(id,struct objc_ivar*,id))(dlsym(RTLD_DEFAULT,'object_setIvar'))" +object_copy|0"*(typedef id(*)(id,unsigned long int))(dlsym(RTLD_DEFAULT,'object_copy'))" +object_dispose|0"*(typedef id(*)(id))(dlsym(RTLD_DEFAULT,'object_dispose'))" +object_getClass|0"*(typedef Class(*)(id))(dlsym(RTLD_DEFAULT,'object_getClass'))" +object_getClassName|0"*(typedef const char*(*)(id))(dlsym(RTLD_DEFAULT,'object_getClassName'))" +object_getIndexedIvars|0"*(typedef void*(*)(id))(dlsym(RTLD_DEFAULT,'object_getIndexedIvars'))" +object_getInstanceVariable|0"*(typedef struct objc_ivar*(*)(id,const char*,void**))(dlsym(RTLD_DEFAULT,'object_getInstanceVariable'))" +object_getIvar|0"*(typedef id(*)(id,struct objc_ivar*))(dlsym(RTLD_DEFAULT,'object_getIvar'))" +object_setClass|0"*(typedef Class(*)(id,Class))(dlsym(RTLD_DEFAULT,'object_setClass'))" +object_setInstanceVariable|0"*(typedef struct objc_ivar*(*)(id,const char*,void*))(dlsym(RTLD_DEFAULT,'object_setInstanceVariable'))" +object_setIvar|0"*(typedef void(*)(id,struct objc_ivar*,id))(dlsym(RTLD_DEFAULT,'object_setIvar'))" -property_getAttributes|"*(typedef const char*(*)(struct objc_property*))(dlsym(RTLD_DEFAULT,'property_getAttributes'))" -property_getName|"*(typedef const char*(*)(struct objc_property*))(dlsym(RTLD_DEFAULT,'property_getName'))" -protocol_conformsToProtocol|"*(typedef bool(*)(id,id))(dlsym(RTLD_DEFAULT,'protocol_conformsToProtocol'))" -protocol_copyMethodDescriptionList|"*(typedef struct objc_method_description*(*)(id,bool,bool,unsigned int*))(dlsym(RTLD_DEFAULT,'protocol_copyMethodDescriptionList'))" -protocol_copyPropertyList|"*(typedef struct objc_property**(*)(id,unsigned int*))(dlsym(RTLD_DEFAULT,'protocol_copyPropertyList'))" -protocol_copyProtocolList|"*(typedef id*(*)(id,unsigned int*))(dlsym(RTLD_DEFAULT,'protocol_copyProtocolList'))" -protocol_getMethodDescription|"*(typedef struct objc_method_description(*)(id,SEL,bool,bool))(dlsym(RTLD_DEFAULT,'protocol_getMethodDescription'))" -protocol_getName|"*(typedef const char*(*)(id))(dlsym(RTLD_DEFAULT,'protocol_getName'))" -protocol_getProperty|"*(typedef struct objc_property*(*)(id,const char*,bool,bool))(dlsym(RTLD_DEFAULT,'protocol_getProperty'))" -protocol_isEqual|"*(typedef bool(*)(id,id))(dlsym(RTLD_DEFAULT,'protocol_isEqual'))" +property_getAttributes|0"*(typedef const char*(*)(struct objc_property*))(dlsym(RTLD_DEFAULT,'property_getAttributes'))" +property_getName|0"*(typedef const char*(*)(struct objc_property*))(dlsym(RTLD_DEFAULT,'property_getName'))" +protocol_conformsToProtocol|0"*(typedef bool(*)(id,id))(dlsym(RTLD_DEFAULT,'protocol_conformsToProtocol'))" +protocol_copyMethodDescriptionList|0"*(typedef struct objc_method_description*(*)(id,bool,bool,unsigned int*))(dlsym(RTLD_DEFAULT,'protocol_copyMethodDescriptionList'))" +protocol_copyPropertyList|0"*(typedef struct objc_property**(*)(id,unsigned int*))(dlsym(RTLD_DEFAULT,'protocol_copyPropertyList'))" +protocol_copyProtocolList|0"*(typedef id*(*)(id,unsigned int*))(dlsym(RTLD_DEFAULT,'protocol_copyProtocolList'))" +protocol_getMethodDescription|0"*(typedef struct objc_method_description(*)(id,SEL,bool,bool))(dlsym(RTLD_DEFAULT,'protocol_getMethodDescription'))" +protocol_getName|0"*(typedef const char*(*)(id))(dlsym(RTLD_DEFAULT,'protocol_getName'))" +protocol_getProperty|0"*(typedef struct objc_property*(*)(id,const char*,bool,bool))(dlsym(RTLD_DEFAULT,'protocol_getProperty'))" +protocol_isEqual|0"*(typedef bool(*)(id,id))(dlsym(RTLD_DEFAULT,'protocol_isEqual'))" -sel_getName|"*(typedef const char*(*)(SEL))(dlsym(RTLD_DEFAULT,'sel_getName'))" -sel_getUid|"*(typedef SEL(*)(const char*))(dlsym(RTLD_DEFAULT,'sel_getUid'))" -sel_isEqual|"*(typedef bool(*)(SEL,SEL))(dlsym(RTLD_DEFAULT,'sel_isEqual'))" -sel_registerName|"*(typedef SEL(*)(const char*))(dlsym(RTLD_DEFAULT,'sel_registerName'))" +sel_getName|0"*(typedef const char*(*)(SEL))(dlsym(RTLD_DEFAULT,'sel_getName'))" +sel_getUid|0"*(typedef SEL(*)(const char*))(dlsym(RTLD_DEFAULT,'sel_getUid'))" +sel_isEqual|0"*(typedef bool(*)(SEL,SEL))(dlsym(RTLD_DEFAULT,'sel_isEqual'))" +sel_registerName|0"*(typedef SEL(*)(const char*))(dlsym(RTLD_DEFAULT,'sel_registerName'))" diff --git a/Execute.cpp b/Execute.cpp index 2cd5765..413e291 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1137,12 +1137,13 @@ JSObjectRef CYMakeType(JSContextRef context, sig::Signature *signature) { return CYMakeType(context, &type); } -extern "C" const char *CYBridgeHash(CYPool &pool, CYUTF8String name) { +extern "C" bool CYBridgeHash(CYPool &pool, CYUTF8String name, const char *&code, unsigned &flags) { sqlite3_stmt *statement; _sqlcall(sqlite3_prepare(database_, "select " - "\"cache\".\"value\" " + "\"cache\".\"code\", " + "\"cache\".\"flags\" " "from \"cache\" " "where" " \"cache\".\"system\" & " CY_SYSTEM " == " CY_SYSTEM " and" @@ -1152,14 +1153,17 @@ extern "C" const char *CYBridgeHash(CYPool &pool, CYUTF8String name) { _sqlcall(sqlite3_bind_text(statement, 1, name.data, name.size, SQLITE_STATIC)); - const char *value; + bool success; if (_sqlcall(sqlite3_step(statement)) == SQLITE_DONE) - value = NULL; - else - value = sqlite3_column_pooled(pool, statement, 0); + success = false; + else { + success = true; + code = sqlite3_column_pooled(pool, statement, 0); + flags = sqlite3_column_int(statement, 1); + } _sqlcall(sqlite3_finalize(statement)); - return value; + return success; } static bool All_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef property) { @@ -1176,7 +1180,9 @@ static bool All_hasProperty(JSContextRef context, JSObjectRef object, JSStringRe return true; CYPool pool; - if (CYBridgeHash(pool, CYPoolUTF8String(pool, context, property)) != NULL) + const char *code; + unsigned flags; + if (CYBridgeHash(pool, CYPoolUTF8String(pool, context, property), code, flags)) return true; return false; @@ -1197,10 +1203,16 @@ static JSValueRef All_getProperty(JSContextRef context, JSObjectRef object, JSSt return value; CYPool pool; - if (const char *code = CYBridgeHash(pool, CYPoolUTF8String(pool, context, property))) { + const char *code; + unsigned flags; + if (CYBridgeHash(pool, CYPoolUTF8String(pool, context, property), code, flags)) { JSValueRef result(_jsccall(JSEvaluateScript, context, CYJSString(CYPoolCode(pool, code)), NULL, NULL, 0)); - JSObjectRef cache(CYGetCachedObject(context, CYJSString("cache"))); - CYSetProperty(context, cache, property, result); + + if (flags == 0) { + JSObjectRef cache(CYGetCachedObject(context, CYJSString("cache"))); + CYSetProperty(context, cache, property, result); + } + return result; } diff --git a/libcycript.py b/libcycript.py index 682e2d1..cd69d28 100755 --- a/libcycript.py +++ b/libcycript.py @@ -9,15 +9,15 @@ keys = {} for db in sys.argv[2:]: with sqlite3.connect(db) as sql: c = sql.cursor() - for name, system, value in c.execute('select name, system, value from cache'): - key = (name, value) + for name, system, flags, code in c.execute('select name, system, flags, code from cache'): + key = (name, flags, code) keys[key] = keys.get(key, 0) | system db = sys.argv[1] with sqlite3.connect(db) as sql: many = [] for key, system in keys.items(): - name, value = key - many.append((name, system, value)) + name, flags, code = key + many.append((name, system, flags, code)) c = sql.cursor() - c.executemany("insert into cache (name, system, value) values (?, ?, ?)", many) + c.executemany("insert into cache (name, system, flags, code) values (?, ?, ?, ?)", many) diff --git a/libcycript.sh b/libcycript.sh index d5aa9c8..2475a2b 100755 --- a/libcycript.sh +++ b/libcycript.sh @@ -25,9 +25,9 @@ sys=$1 sql=$2 rm -f "${sql}" -echo "create table cache (name text not null, system int not null, value text not null, primary key (name, system));" | sqlite3 "${sql}" +echo "create table cache (name text not null, system int not null, flags int not null, code text not null, primary key (name, system));" | sqlite3 "${sql}" def=$3 if [[ -n "${def}" ]]; then - { echo "begin;"; cat "$def"; echo "commit;"; } | sed -e 's/^\([^|]*\)|\"\(.*\)\"$/insert into cache (name, system, value) values (<@<\1>@>, '"$sys"', <@<\2>@>);/;s/'"'"'/'"'"''"'"'/g;s/\(<@<\|>@>\)/'"'"'/g' | sqlite3 "${sql}" + { echo "begin;"; cat "$def"; echo "commit;"; } | sed -e 's/^\([^|]*\)|\([0-9]*\)\"\(.*\)\"$/insert into cache (name, system, flags, code) values (<@<\1>@>, '"$sys"', \2, <@<\3>@>);/;s/'"'"'/'"'"''"'"'/g;s/\(<@<\|>@>\)/'"'"'/g' | sqlite3 "${sql}" fi -- 2.45.2