Skip to content

Commit

Permalink
Fix all static analysis problems fix alibaba#8
Browse files Browse the repository at this point in the history
  • Loading branch information
NianJi committed Mar 1, 2019
1 parent 18d21a4 commit 321d674
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>

static dispatch_queue_t get_test_queue(){
static dispatch_queue_t q = nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>
#import <coobjc/co_autorelease.h>

static int state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>
#import <coobjc/co_autorelease.h>

# define RR_PUSH() objc_autoreleasePoolPush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>
#import "coobjcCommon.h"

SpecBegin(coPerformance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>

SpecBegin(coCancel)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>


SpecBegin(coChannel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#import <Foundation/Foundation.h>

#import <coobjc.h>
#import <coobjc/coobjc.h>

@interface NSData (asyncio)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>

/*
SpecBegin(coCreate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>
#import "coobjcCommon.h"

SpecBegin(coDelay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>

static id testPromise1() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>
#import "coobjcCommon.h"

SpecBegin(coSequence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import <coobjc.h>
#import <coobjc/coobjc.h>
#import <coobjc/co_tuple.h>

#ifdef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion coobjc/api/COActorChan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@return The actor message object.
*/
- (COActorMessage *)next;
- (COActorMessage *_Nullable)next;

@end

Expand Down
4 changes: 2 additions & 2 deletions coobjc/api/COCoroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ id _Nullable co_await(id awaitable);
@param awaitableArray a list of awaitable
@return the value result list. `nil` is replaced by `NSNull`.
*/
NSArray *co_batch_await(NSArray * awaitableArray);
NSArray *_Nullable co_batch_await(NSArray *awaitableArray);

@class COCoroutine;

Expand Down Expand Up @@ -153,7 +153,7 @@ extern NSString *const COInvalidException;
@param stackSize : stackSize of the coroutine.
@return The coroutine object.
*/
+ (instancetype)coroutineWithBlock:(void(^)(void))block onQueue:(dispatch_queue_t _Nullable)queue stackSize:(NSUInteger)stackSize;
+ (_Nullable instancetype)coroutineWithBlock:(void(^)(void))block onQueue:(dispatch_queue_t _Nullable)queue stackSize:(NSUInteger)stackSize;


/**
Expand Down
4 changes: 2 additions & 2 deletions coobjc/api/COCoroutine.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ + (instancetype)coroutineWithBlock:(void (^)(void))block onQueue:(dispatch_queue
return [self coroutineWithBlock:block onQueue:queue stackSize:0];
}

+ (instancetype)coroutineWithBlock:(void(^)(void))block onQueue:(dispatch_queue_t _Nullable)queue stackSize:(NSUInteger)stackSize {
+ (instancetype)coroutineWithBlock:(void(^)(void))block onQueue:(dispatch_queue_t)queue stackSize:(NSUInteger)stackSize {
if (queue == NULL) {
queue = co_get_current_queue();
}
Expand Down Expand Up @@ -361,7 +361,7 @@ id co_await(id awaitable) {
}
}

NSArray *_Nonnull co_batch_await(NSArray * _Nonnull awaitableList) {
NSArray *co_batch_await(NSArray * awaitableList) {

coroutine_t *t = coroutine_self();
if (t == nil) {
Expand Down
61 changes: 31 additions & 30 deletions coobjc/core/coroutine.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"


void scheduler_add_coroutine (coroutine_list_t *l, coroutine_t *t);
void scheduler_delete_coroutine(coroutine_list_t *l, coroutine_t *t);
void scheduler_queue_push(coroutine_scheduler_t *scheduler, coroutine_t *co);
coroutine_t *scheduler_queue_pop(coroutine_scheduler_t *scheduler);
coroutine_scheduler_t *coroutine_scheduler_new(void);
void coroutine_scheduler_free(coroutine_scheduler_t *schedule);
void coroutine_resume_im(coroutine_t *co);
Expand Down Expand Up @@ -95,18 +95,16 @@ void coroutine_memory_free(void *ptr, size_t size) {

void coroutine_scheduler_main(coroutine_t *scheduler_co) {

coroutine_t *co;
coroutine_scheduler_t *scheduler = scheduler_co->scheduler;
for (;;) {

co = scheduler->coroutine_queue.head;
// pop a coroutine from queue.head.
coroutine_t *co = scheduler_queue_pop(scheduler);
if (co == NULL) {
// jump out. scheduler will enter idle.
coroutine_yield(scheduler_co);
continue;
}
// delete from the scheduler's queue
scheduler_delete_coroutine(&scheduler->coroutine_queue, co);
// set scheduler's current running coroutine.
scheduler->running_coroutine = co;
// resume the coroutine
Expand Down Expand Up @@ -203,6 +201,7 @@ void coroutine_resume_im(coroutine_t *co) {
// when proccess reenter(resume a coroutine), skip the remain codes, just return to pre func.
return;
}
#pragma unused(skip)
skip = true;

free(co->context);
Expand All @@ -221,6 +220,7 @@ void coroutine_resume_im(coroutine_t *co) {
// when proccess reenter(resume a coroutine), skip the remain codes, just return to pre func.
return;
}
#pragma unused(skip)
skip = true;
// setcontext
coroutine_setcontext(co->context);
Expand All @@ -238,11 +238,11 @@ void coroutine_resume(coroutine_t *co) {
coroutine_scheduler_t *scheduler = coroutine_scheduler_self_create_if_not_exists();
co->scheduler = scheduler;

scheduler_add_coroutine(&scheduler->coroutine_queue, co);
scheduler_queue_push(scheduler, co);

if (scheduler->running_coroutine) {
// resume a sub coroutine.
scheduler_add_coroutine (&scheduler->coroutine_queue, scheduler->running_coroutine);
scheduler_queue_push(scheduler, scheduler->running_coroutine);
coroutine_yield(scheduler->running_coroutine);
} else {
// scheduler is idle
Expand All @@ -262,7 +262,7 @@ void coroutine_add(coroutine_t *co) {
main_co->scheduler = scheduler;
scheduler->main_coroutine = main_co;
}
scheduler_add_coroutine(&scheduler->coroutine_queue, co);
scheduler_queue_push(scheduler, co);

if (!scheduler->running_coroutine) {
coroutine_resume_im(co->scheduler->main_coroutine);
Expand All @@ -283,6 +283,7 @@ void coroutine_yield(coroutine_t *co)
if (skip) {
return;
}
#pragma unused(skip)
skip = true;
co->status = COROUTINE_SUSPEND;
coroutine_setcontext(co->pre_context);
Expand All @@ -299,32 +300,32 @@ void coroutine_yield(coroutine_t *co)

#pragma mark - linked lists

// add routine to the queue
void scheduler_add_coroutine(coroutine_list_t *l, coroutine_t *t) {
if(l->tail) {
l->tail->next = t;
t->prev = l->tail;
void scheduler_queue_push(coroutine_scheduler_t *scheduler, coroutine_t *co) {
coroutine_list_t *queue = &scheduler->coroutine_queue;
if(queue->tail) {
queue->tail->next = co;
co->prev = queue->tail;
} else {
l->head = t;
t->prev = nil;
queue->head = co;
co->prev = nil;
}
l->tail = t;
t->next = nil;
queue->tail = co;
co->next = nil;
}

// delete routine from the queue
void scheduler_delete_coroutine(coroutine_list_t *l, coroutine_t *t) {
if(t->prev) {
t->prev->next = t->next;
} else {
l->head = t->next;
}

if(t->next) {
t->next->prev = t->prev;
} else {
l->tail = t->prev;
coroutine_t *scheduler_queue_pop(coroutine_scheduler_t *scheduler) {
coroutine_list_t *queue = &scheduler->coroutine_queue;
coroutine_t *co = queue->head;
if (co) {
queue->head = co->next;
// Actually, co->prev is nil now.
if (co->next) {
co->next->prev = co->prev;
} else {
queue->tail = co->prev;
}
}
return co;
}

#pragma clang diagnostic pop
Expand Down
4 changes: 2 additions & 2 deletions coobjc/objc/co_autorelease.mm
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void kill()
page->protect();
}
delete deathptr;
} while (deathptr != this);
} while (deathptr != this && page != nil);
}

static void routine_dealloc(void *p)
Expand Down Expand Up @@ -658,7 +658,7 @@ static BOOL co_is_autoreleasepage(void *ctx){
uintptr_t address = (uintptr_t)ctx;
uintptr_t baseAddress = (address / PAGE_MAX_SIZE) * PAGE_MAX_SIZE;
COAutoreleasePoolPage *page = (COAutoreleasePoolPage*)baseAddress;
if (page->bitMask == (uintptr_t)CO_AUTORELEASE_PAGE_MASK) {
if (page && page->bitMask == (uintptr_t)CO_AUTORELEASE_PAGE_MASK) {
return YES;
}
return NO;
Expand Down
2 changes: 1 addition & 1 deletion coobjc/objc/co_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#import <Foundation/Foundation.h>

@interface COTuple : NSObject<NSCopying, NSFastEnumeration>
@interface COTuple : NSObject<NSFastEnumeration>

// Creation
- (id)init; // Empty tuple
Expand Down
10 changes: 5 additions & 5 deletions coobjc/objc/co_tuple.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ - (id)initWithObjects:(id)objects, ... {
}

// Protocolic Obligations
- (id)copyWithZone:(NSZone *)zone {
id newtup = [[[self class] alloc] init];
[newtup _setStorage:[[self _storage] copy]];
return newtup;
}
//- (id)copyWithZone:(NSZone *)zone {
// id newtup = [[[self class] alloc] init];
// [newtup _setStorage:[[self _storage] copy]];
// return newtup;
//}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id arc_unsafe_unretained [])stackbuf count:(NSUInteger)len {
return [storage countByEnumeratingWithState:state objects:stackbuf count:len];
}
Expand Down

0 comments on commit 321d674

Please sign in to comment.