Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改wax的pod spec,增加xml2和sqlite3的支持; #11

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a5e2ad3
修改wax的pod spec,增加xml2和sqlite3的支持;
Nov 11, 2015
521e497
(1)解决forwardInvocation 被多次替换的bug;
Nov 26, 2015
087a69c
Merge branch 'master' of https://github.com/philonpang/wax
Nov 26, 2015
beb87a4
(1) 修复通过class_replaceMethod获得prevIMP始终为0x0的错误,改为通过method_getImplement…
Nov 26, 2015
3ed50c9
去掉log;
Nov 26, 2015
d191046
默认打开capi的函数调用;
Nov 26, 2015
69c81d0
(1) wax_clear 加递归锁,waxClass倒序销毁,不销毁controller(防止hook dealloc crash,另外…
Nov 27, 2015
e2e1e89
Releasev1.0.0: ali-wax 增加patch现场恢复,修复部分bug;
Nov 27, 2015
86456f1
修改,去掉viewdidload的判断; 在ios9系统上没有问题,需要测试ios8和ios7的系统;
Jun 22, 2016
887512a
Revert "修改,去掉viewdidload的判断; 在ios9系统上没有问题,需要测试ios8和ios7的系统;"
Jun 22, 2016
fa06cf7
fixLog: 去掉hook显示的log;
Jul 12, 2016
2b7925c
Release1.0.1 去掉wax中hook的Log;
Jul 12, 2016
ad83bcd
Release1.0.2: 解决yawl引用导致pod1.0以上版本无法update的问题;
Nov 2, 2016
5c18fa3
删除yalj的引用文件;
Nov 2, 2016
28f8d24
提交api中的yalj中的引用文件到引用位置;
Nov 2, 2016
a1d4a7a
只取掉reference;位置目录保持不变;
Nov 2, 2016
5d413fe
修改wax_json.c直接以来api中的头文件;
Nov 2, 2016
f415d4c
修改因为use_frameworks导致的文件路径和arc问题
Dec 6, 2016
fbbb100
Release 1.0.3 : 修改因为use_frameworks导致的文件路径和arc问题
Jan 12, 2017
c8c2a38
Release1.0.4: 修复patch现场恢复的时候对于类方法复原崩溃的问题;
Feb 10, 2017
d6ab2b7
v1.0.5: 去掉system;
Apr 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/extensions/json/wax_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ int luaopen_wax_json(lua_State *L) {
return 0;
}

#include "yajl/yajl_parse.h"
#include "yajl/api/yajl_parse.h"
#include "yajl/yajl_lex.h"
#include "yajl/yajl_parser.h"
#include "yajl/yajl_bytestack.h"
#include "yajl/yajl_gen.h"
#include "yajl/api/yajl_gen.h"
#include <string.h>

static yajl_gen gen;
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/json/yajl/yajl_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#ifndef __YAJL_ALLOC_H__
#define __YAJL_ALLOC_H__

#include "api/yajl_common.h"
#include "yajl_common.h"

#define YA_MALLOC(afs, sz) (afs)->malloc((afs)->ctx, (sz))
#define YA_FREE(afs, ptr) (afs)->free((afs)->ctx, (ptr))
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/json/yajl/yajl_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#ifndef __YAJL_BUF_H__
#define __YAJL_BUF_H__

#include "api/yajl_common.h"
#include "yajl_common.h"
#include "yajl_alloc.h"

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/json/yajl/yajl_bytestack.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#ifndef __YAJL_BYTESTACK_H__
#define __YAJL_BYTESTACK_H__

#include "api/yajl_common.h"
#include "yajl_common.h"

#define YAJL_BS_INC 128

Expand Down
1 change: 0 additions & 1 deletion lib/extensions/json/yajl/yajl_common.h

This file was deleted.

2 changes: 1 addition & 1 deletion lib/extensions/json/yajl/yajl_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define __YAJL_ENCODE_H__

#include "yajl_buf.h"
#include "api/yajl_gen.h"
#include "yajl_gen.h"

void yajl_string_encode2(const yajl_print_t printer,
void * ctx,
Expand Down
1 change: 0 additions & 1 deletion lib/extensions/json/yajl/yajl_gen.h

This file was deleted.

2 changes: 1 addition & 1 deletion lib/extensions/json/yajl/yajl_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#ifndef __YAJL_LEX_H__
#define __YAJL_LEX_H__

#include "api/yajl_common.h"
#include "yajl_common.h"

typedef enum {
yajl_tok_bool,
Expand Down
1 change: 0 additions & 1 deletion lib/extensions/json/yajl/yajl_parse.h

This file was deleted.

2 changes: 1 addition & 1 deletion lib/extensions/json/yajl/yajl_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#ifndef __YAJL_PARSER_H__
#define __YAJL_PARSER_H__

#include "api/yajl_parse.h"
#include "yajl_parse.h"
#include "yajl_bytestack.h"
#include "yajl_buf.h"

Expand Down
2 changes: 1 addition & 1 deletion lib/lua/loslib.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int os_pushresult (lua_State *L, int i, const char *filename) {
static int os_execute (lua_State *L) {
#ifndef WAX_TARGET_OS_WATCH
#warning "compile not for TARGET_OS_WATCH"
lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
// lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
#endif
return 1;
}
Expand Down
10 changes: 9 additions & 1 deletion lib/wax.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ typedef void (*WaxLuaRuntimeErrorHandler)(NSString *reason, BOOL willExit);

void wax_setLuaRuntimeErrorHandler(WaxLuaRuntimeErrorHandler handler);

WaxLuaRuntimeErrorHandler wax_getLuaRuntimeErrorHandler();
WaxLuaRuntimeErrorHandler wax_getLuaRuntimeErrorHandler();


//记录wax-lua定义的selector
void addWaxDefinedSelectorDict(NSDictionary *dict);
//记录wax-lua中定义的类
void addWaxNewAddClassDict(NSDictionary *dict);
//判断forward转发的class_selector是否在wax中定义
BOOL isClassSelectorDefinedInWax(NSString *klassStr, NSString *selStr);
141 changes: 141 additions & 0 deletions lib/wax.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "wax_gc.h"
#import "wax_server.h"
#import "wax_stdlib.h"
#import "wax_capi.h"

#import "lauxlib.h"
#import "lobject.h"
Expand All @@ -40,6 +41,11 @@

extern int luaSetWaxConfig(lua_State *L);

//original runtime record
static NSMutableDictionary *waxDefinedSelectorClassDictionary;
static NSMutableArray *waxNewAddClassArray;
static void wax_clear();

//runtime error
static void (*wax_luaRuntimeErrorHandler)(NSString *reason, BOOL willExit);

Expand Down Expand Up @@ -93,6 +99,7 @@ void wax_setup() {
luaopen_wax_struct(L);

addGlobals(L);
wax_openBindOCFunction(L);

[wax_gc start];
}
Expand Down Expand Up @@ -188,6 +195,7 @@ void wax_startWithServer() {
}

void wax_end() {
wax_clear();
[wax_gc stop];
lua_close(wax_currentLuaState());
currentL = 0;
Expand Down Expand Up @@ -352,4 +360,137 @@ void wax_setLuaRuntimeErrorHandler(void (*handler)(NSString *reason, BOOL willEx
}
WaxLuaRuntimeErrorHandler wax_getLuaRuntimeErrorHandler(){
return wax_luaRuntimeErrorHandler;
}

#pragma mark original runtime-environment record

void addWaxDefinedSelectorDict(NSDictionary *dict) {
#if DEBUG
NSLog(@"methodDict===%@\n", dict);
#endif
if (waxDefinedSelectorClassDictionary == nil) {
waxDefinedSelectorClassDictionary = [[NSMutableDictionary alloc] initWithCapacity:5];
}

if(dict[@"class"]){
NSMutableArray *replaceMethodList = nil;
if([waxDefinedSelectorClassDictionary objectForKey:dict[@"class"]] != nil){
replaceMethodList = [NSMutableArray arrayWithArray:[waxDefinedSelectorClassDictionary objectForKey:dict[@"class"]]];
} else {
replaceMethodList = [[NSMutableArray alloc] initWithCapacity:5];
}

[replaceMethodList addObject:dict];
[waxDefinedSelectorClassDictionary setObject:replaceMethodList forKey:dict[@"class"]];
}
}

void addWaxNewAddClassDict(NSDictionary *dict) {
#if DEBUG
NSLog(@"classDict===%@\n", dict);
#endif
if (waxNewAddClassArray == nil) {
waxNewAddClassArray = [[NSMutableArray alloc] initWithCapacity:5];
}
[waxNewAddClassArray addObject:dict];
}

BOOL isClassSelectorDefinedInWax(NSString *klassStr, NSString *selStr){
if(klassStr == nil || selStr == nil) return NO;

BOOL isDefined = NO;
if(waxDefinedSelectorClassDictionary){
//derived calss forwarding selector will use base class's forwarding
while (!isDefined && waxDefinedSelectorClassDictionary[klassStr]) {
NSArray *replaceMethodList = waxDefinedSelectorClassDictionary[klassStr];
for(NSDictionary *dict in replaceMethodList){
NSString *tmpClassStr = dict[@"class"];
NSString *tmpSelStr = dict[@"sel"];
if(tmpClassStr && [tmpClassStr isEqualToString:klassStr] &&
tmpSelStr && [tmpSelStr isEqualToString:selStr]){
isDefined = YES;
break;
}
}//for

if(!isDefined){
Class klassSuper = [NSClassFromString(klassStr) superclass];
klassStr = NSStringFromClass(klassSuper);
}
}
}

return isDefined;
}

// clear the wax defined class and selectors
static void wax_clear() {
[wax_globalLock() lock];
for (NSString *classStr in waxDefinedSelectorClassDictionary.allKeys) {
//wax defined class directly dispose
BOOL isWaxClass = class_getInstanceVariable(NSClassFromString(classStr), WAX_CLASS_INSTANCE_USERDATA_IVAR_NAME) != nil;
if(isWaxClass) continue;

NSArray *replaceMethodList = [waxDefinedSelectorClassDictionary objectForKey:classStr];
for(NSDictionary *dict in replaceMethodList){
Class class = NSClassFromString(dict[@"class"]);
NSString *sel_str = dict[@"sel"];
NSString *sel_orig_str = dict[@"sel_orig"];
NSString *typeDesc = dict[@"typeDesc"];

if (class && sel_str && ![sel_str isKindOfClass:[NSNull class]]
&& sel_orig_str && ![sel_orig_str isKindOfClass:[NSNull class]]
&& typeDesc && ![typeDesc isKindOfClass:[NSNull class]]) {
SEL sel = NSSelectorFromString(sel_str);
SEL sel_orig = NSSelectorFromString(sel_orig_str);
if(sel && sel_orig && (sel != sel_orig)){
IMP imp = class_getMethodImplementation(class, sel_orig);
BOOL isNull = NO;
#if defined(__arm64__)
if(imp == _objc_msgForward) {
isNull = YES;
}
#else
if(imp == _objc_msgForward || imp == (IMP)_objc_msgForward_stret){
isNull = YES;
}
#endif
if (isNull) {
id metaclass = objc_getMetaClass(object_getClassName(class));
IMP metaImp = class_respondsToSelector(metaclass, sel_orig) ? class_getMethodImplementation(metaclass, sel_orig) : NULL;
class = metaclass;
imp = metaImp;
}

if(imp && imp != NULL){
class_replaceMethod(class, sel, imp, typeDesc.UTF8String);
class_replaceMethod(class, sel_orig, _objc_msgForward, typeDesc);
}
}//if(sel && sel_orig && (sel != sel_orig))
}//if
}//for replaceMethodlist
}//for class list

[waxDefinedSelectorClassDictionary removeAllObjects];
[waxDefinedSelectorClassDictionary release];
waxDefinedSelectorClassDictionary = nil;

// wax new add class rollback, inverse to dispose
// because almost subclasses added after baseclasses
// depends on require sequence
if(waxNewAddClassArray && waxNewAddClassArray.count > 0){
for (int i = waxNewAddClassArray.count-1; i >= 0; i--) {
NSDictionary *dict = [waxNewAddClassArray objectAtIndex:i];
NSString *newAddClassStr = dict[@"class"];
Class newAddClass = NSClassFromString(newAddClassStr);
if(newAddClass && !class_respondsToSelector(newAddClass, @selector(viewDidLoad))){
objc_disposeClassPair(newAddClass);
}
}
}

[waxNewAddClassArray removeAllObjects];
[waxNewAddClassArray release];
waxNewAddClassArray = nil;
[wax_globalLock() unlock];
}
7 changes: 7 additions & 0 deletions lib/wax_class.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ static int __call(lua_State *L) {
class_addMethod(metaclass, @selector(wax_originalAllocWithZone:), method_getImplementation(m), method_getTypeEncoding(m));
class_addMethod(metaclass, @selector(allocWithZone:), (IMP)allocWithZone, "@@:^{_NSZone=}");
}

addWaxNewAddClassDict(@{@"class":NSStringFromClass(klass)});
}else{
//if wax_clear not disposed the class because of class's subclass or instance used, still record the klass
if(class_getInstanceVariable(klass, WAX_CLASS_INSTANCE_USERDATA_IVAR_NAME) != nil){
addWaxNewAddClassDict(@{@"class":NSStringFromClass(klass)});
}
}

wax_instance_create(L, klass, YES);
Expand Down
2 changes: 1 addition & 1 deletion lib/wax_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


typedef struct _wax_instance_userdata {
id instance;
__unsafe_unretained id instance;
BOOL isClass;
Class isSuper; // isSuper not only stores whether the class is a super, but it also contains the value of the next superClass.
BOOL actAsSuper; // It only acts like a super once, when it is called for the first time.
Expand Down
Loading