Skip to content

Commit d8f1868

Browse files
CarterLihnes
authored andcommitted
add type cast operation after the return of malloc function
PR #21 by Carter Li <[email protected]> @CarterLi Reviewed by Sen Han <[email protected]>
1 parent 3eda876 commit d8f1868

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

aco.c

+25-25
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
void aco_runtime_test(void){
2525
#ifdef __i386__
2626
_Static_assert(sizeof(void*) == 4, "require 'sizeof(void*) == 4'");
27-
#elif __x86_64__
27+
#elif __x86_64__
2828
_Static_assert(sizeof(void*) == 8, "require 'sizeof(void*) == 8'");
2929
_Static_assert(sizeof(__uint128_t) == 16, "require 'sizeof(__uint128_t) == 16'");
3030
#else
@@ -171,7 +171,7 @@ static __thread aco_cofuncp_t aco_gtls_last_word_fp = aco_default_protector_last
171171

172172
#ifdef __i386__
173173
static __thread void* aco_gtls_fpucw_mxcsr[2];
174-
#elif __x86_64__
174+
#elif __x86_64__
175175
static __thread void* aco_gtls_fpucw_mxcsr[1];
176176
#else
177177
#error "platform no support yet"
@@ -184,8 +184,8 @@ void aco_thread_init(aco_cofuncp_t last_word_co_fp){
184184
aco_gtls_last_word_fp = last_word_co_fp;
185185
}
186186

187-
// This function `aco_funcp_protector` should never be
188-
// called. If it's been called, that means the offending
187+
// This function `aco_funcp_protector` should never be
188+
// called. If it's been called, that means the offending
189189
// `co` didn't call aco_exit(co) instead of `return` to
190190
// finish its execution.
191191
void aco_funcp_protector(void){
@@ -216,7 +216,7 @@ aco_share_stack_t* aco_share_stack_new2(size_t sz, char guard_page_enabled){
216216

217217
size_t u_pgsz = 0;
218218
if(guard_page_enabled != 0){
219-
// although gcc's Built-in Functions to Perform Arithmetic with
219+
// although gcc's Built-in Functions to Perform Arithmetic with
220220
// Overflow Checking is better, but it would require gcc >= 5.0
221221
long pgsz = sysconf(_SC_PAGESIZE);
222222
// pgsz must be > 0 && a power of two
@@ -244,7 +244,7 @@ aco_share_stack_t* aco_share_stack_new2(size_t sz, char guard_page_enabled){
244244
}
245245
}
246246

247-
aco_share_stack_t* p = malloc(sizeof(aco_share_stack_t));
247+
aco_share_stack_t* p = (aco_share_stack_t*)malloc(sizeof(aco_share_stack_t));
248248
assertalloc_ptr(p);
249249
memset(p, 0, sizeof(aco_share_stack_t));
250250

@@ -266,7 +266,7 @@ aco_share_stack_t* aco_share_stack_new2(size_t sz, char guard_page_enabled){
266266
p->ptr = malloc(sz);
267267
assertalloc_ptr(p->ptr);
268268
}
269-
269+
270270
p->owner = NULL;
271271
#ifdef ACO_USE_VALGRIND
272272
p->valgrind_stk_id = VALGRIND_STACK_REGISTER(
@@ -277,7 +277,7 @@ aco_share_stack_t* aco_share_stack_new2(size_t sz, char guard_page_enabled){
277277
uintptr_t u_p = (uintptr_t)(p->sz - (sizeof(void*) << 1) + (uintptr_t)p->ptr);
278278
u_p = (u_p >> 4) << 4;
279279
p->align_highptr = (void*)u_p;
280-
p->align_retptr = (void*)(u_p - sizeof(void*));
280+
p->align_retptr = (void*)(u_p - sizeof(void*));
281281
*((void**)(p->align_retptr)) = (void*)(aco_funcp_protector_asm);
282282
assert(p->sz > (16 + (sizeof(void*) << 1) + sizeof(void*)));
283283
p->align_limit = p->sz - 16 - (sizeof(void*) << 1);
@@ -304,11 +304,11 @@ void aco_share_stack_destroy(aco_share_stack_t* sstk){
304304
}
305305

306306
aco_t* aco_create(
307-
aco_t* main_co, aco_share_stack_t* share_stack,
307+
aco_t* main_co, aco_share_stack_t* share_stack,
308308
size_t save_stack_sz, aco_cofuncp_t fp, void* arg
309309
){
310310

311-
aco_t* p = malloc(sizeof(aco_t));
311+
aco_t* p = (aco_t*)malloc(sizeof(aco_t));
312312
assertalloc_ptr(p);
313313
memset(p, 0, sizeof(aco_t));
314314

@@ -362,7 +362,7 @@ aco_t* aco_create(
362362

363363
aco_attr_no_asan
364364
void aco_resume(aco_t* resume_co){
365-
assert(resume_co != NULL && resume_co->main_co != NULL
365+
assert(resume_co != NULL && resume_co->main_co != NULL
366366
&& resume_co->is_end == 0
367367
);
368368
if(resume_co->share_stack->owner != resume_co){
@@ -385,9 +385,9 @@ void aco_resume(aco_t* resume_co){
385385
(uintptr_t)(owner_co->reg[ACO_REG_IDX_SP])
386386
)
387387
);
388-
owner_co->save_stack.valid_sz =
388+
owner_co->save_stack.valid_sz =
389389
(uintptr_t)(owner_co->share_stack->align_retptr)
390-
-
390+
-
391391
(uintptr_t)(owner_co->reg[ACO_REG_IDX_SP]);
392392
if(owner_co->save_stack.sz < owner_co->save_stack.valid_sz){
393393
free(owner_co->save_stack.ptr);
@@ -408,13 +408,13 @@ void aco_resume(aco_t* resume_co){
408408
#ifdef __x86_64__
409409
aco_amd64_optimized_memcpy_drop_in(
410410
owner_co->save_stack.ptr,
411-
owner_co->reg[ACO_REG_IDX_SP],
411+
owner_co->reg[ACO_REG_IDX_SP],
412412
owner_co->save_stack.valid_sz
413413
);
414414
#else
415415
memcpy(
416416
owner_co->save_stack.ptr,
417-
owner_co->reg[ACO_REG_IDX_SP],
417+
owner_co->reg[ACO_REG_IDX_SP],
418418
owner_co->save_stack.valid_sz
419419
);
420420
#endif
@@ -427,35 +427,35 @@ void aco_resume(aco_t* resume_co){
427427
owner_co->share_stack->align_validsz = 0;
428428
#else
429429
#error "platform no support yet"
430-
#endif
430+
#endif
431431
}
432432
assert(resume_co->share_stack->owner == NULL);
433433
#if defined(__i386__) || defined(__x86_64__)
434434
assert(
435-
resume_co->save_stack.valid_sz
436-
<=
435+
resume_co->save_stack.valid_sz
436+
<=
437437
resume_co->share_stack->align_limit - sizeof(void*)
438438
);
439439
// TODO: optimize the performance penalty of memcpy function call
440440
// for very short memory span
441441
if(resume_co->save_stack.valid_sz > 0) {
442442
#ifdef __x86_64__
443-
aco_amd64_optimized_memcpy_drop_in(
443+
aco_amd64_optimized_memcpy_drop_in(
444444
(void*)(
445-
(uintptr_t)(resume_co->share_stack->align_retptr)
445+
(uintptr_t)(resume_co->share_stack->align_retptr)
446446
-
447447
resume_co->save_stack.valid_sz
448-
),
448+
),
449449
resume_co->save_stack.ptr,
450450
resume_co->save_stack.valid_sz
451451
);
452452
#else
453453
memcpy(
454454
(void*)(
455-
(uintptr_t)(resume_co->share_stack->align_retptr)
455+
(uintptr_t)(resume_co->share_stack->align_retptr)
456456
-
457457
resume_co->save_stack.valid_sz
458-
),
458+
),
459459
resume_co->save_stack.ptr,
460460
resume_co->save_stack.valid_sz
461461
);
@@ -469,7 +469,7 @@ void aco_resume(aco_t* resume_co){
469469
resume_co->share_stack->owner = resume_co;
470470
#else
471471
#error "platform no support yet"
472-
#endif
472+
#endif
473473
}
474474
aco_gtls_co = resume_co;
475475
acosw(resume_co->main_co, resume_co);
@@ -479,7 +479,7 @@ void aco_resume(aco_t* resume_co){
479479
void aco_destroy(aco_t* co){
480480
assertptr(co);
481481
if(aco_is_main_co(co)){
482-
free(co);
482+
free(co);
483483
} else {
484484
if(co->share_stack->owner == co){
485485
co->share_stack->owner = NULL;

0 commit comments

Comments
 (0)