mirror of https://github.com/bsnes-emu/bsnes.git
Merge pull request #10 from namandixit/optional-libc
Made the dependency on stdlib.h and assert.h optional
This commit is contained in:
commit
1931c7d20d
|
@ -2,8 +2,6 @@
|
|||
#include "libco.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#ifdef LIBCO_MPROTECT
|
||||
#include <unistd.h>
|
||||
|
@ -85,13 +83,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void))
|
|||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
|
||||
void* memory = malloc(size);
|
||||
void* memory = LIBCO_MALLOC(size);
|
||||
if(!memory) return (cothread_t)0;
|
||||
return co_derive(memory, size, entrypoint);
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle) {
|
||||
free(handle);
|
||||
LIBCO_FREE(handle);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t handle) {
|
||||
|
|
9
amd64.c
9
amd64.c
|
@ -2,9 +2,6 @@
|
|||
#include "libco.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -114,7 +111,7 @@ static void (*co_swap)(cothread_t, cothread_t) = 0;
|
|||
#endif
|
||||
|
||||
static void crash() {
|
||||
assert(0); /* called only if cothread_t entrypoint returns */
|
||||
LIBCO_ASSERT(0); /* called only if cothread_t entrypoint returns */
|
||||
}
|
||||
|
||||
cothread_t co_active() {
|
||||
|
@ -142,13 +139,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void))
|
|||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
|
||||
void* memory = malloc(size);
|
||||
void* memory = LIBCO_MALLOC(size);
|
||||
if(!memory) return (cothread_t)0;
|
||||
return co_derive(memory, size, entrypoint);
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle) {
|
||||
free(handle);
|
||||
LIBCO_FREE(handle);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t handle) {
|
||||
|
|
6
arm.c
6
arm.c
|
@ -2,8 +2,6 @@
|
|||
#include "libco.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef LIBCO_MPROTECT
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -61,13 +59,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void))
|
|||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
|
||||
void* memory = malloc(size);
|
||||
void* memory = LIBCO_MALLOC(size);
|
||||
if(!memory) return (cothread_t)0;
|
||||
return co_derive(memory, size, entrypoint);
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle) {
|
||||
free(handle);
|
||||
LIBCO_FREE(handle);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t handle) {
|
||||
|
|
5
ppc.c
5
ppc.c
|
@ -4,7 +4,6 @@
|
|||
#include "libco.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -327,7 +326,7 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entry_)(void)) {
|
|||
static uint32_t* co_create_(unsigned size, uintptr_t entry) {
|
||||
(void)entry;
|
||||
|
||||
uint32_t* t = (uint32_t*)malloc(size);
|
||||
uint32_t* t = (uint32_t*)LIBCO_MALLOC(size);
|
||||
|
||||
#if LIBCO_PPCDESC
|
||||
if(t) {
|
||||
|
@ -390,7 +389,7 @@ cothread_t co_create(unsigned int size, void (*entry_)(void)) {
|
|||
}
|
||||
|
||||
void co_delete(cothread_t t) {
|
||||
free(t);
|
||||
LIBCO_FREE(t);
|
||||
}
|
||||
|
||||
static void co_init_(void) {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "settings.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -223,7 +222,7 @@ __asm__(
|
|||
|
||||
cothread_t co_active() {
|
||||
if(!co_active_handle) {
|
||||
co_active_handle = (struct ppc64_context*)malloc(MIN_STACK + sizeof(struct ppc64_context));
|
||||
co_active_handle = (struct ppc64_context*)LIBCO_MALLOC(MIN_STACK + sizeof(struct ppc64_context));
|
||||
}
|
||||
return (cothread_t)co_active_handle;
|
||||
}
|
||||
|
@ -255,13 +254,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*coentry)(void)) {
|
|||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*coentry)(void)) {
|
||||
void* memory = malloc(size);
|
||||
void* memory = LIBCO_MALLOC(size);
|
||||
if(!memory) return (cothread_t)0;
|
||||
return co_derive(memory, size, coentry);
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle) {
|
||||
free(handle);
|
||||
LIBCO_FREE(handle);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t to) {
|
||||
|
|
12
settings.h
12
settings.h
|
@ -26,6 +26,17 @@
|
|||
#define alignas(bytes)
|
||||
#endif
|
||||
|
||||
#if !defined(LIBCO_ASSERT)
|
||||
#include <assert.h>
|
||||
#define LIBCO_ASSERT assert
|
||||
#endif
|
||||
|
||||
#if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE)
|
||||
#include <stdlib.h>
|
||||
#define LIBCO_MALLOC malloc
|
||||
#define LIBCO_FREE free
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define section(name) __declspec(allocate("." #name))
|
||||
#elif defined(__APPLE__)
|
||||
|
@ -34,5 +45,6 @@
|
|||
#define section(name) __attribute__((section("." #name "#")))
|
||||
#endif
|
||||
|
||||
|
||||
/* if defined(LIBCO_C) */
|
||||
#endif
|
||||
|
|
9
x86.c
9
x86.c
|
@ -2,9 +2,6 @@
|
|||
#include "libco.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -68,7 +65,7 @@ static const unsigned char co_swap_function[4096] = {
|
|||
#endif
|
||||
|
||||
static void crash() {
|
||||
assert(0); /* called only if cothread_t entrypoint returns */
|
||||
LIBCO_ASSERT(0); /* called only if cothread_t entrypoint returns */
|
||||
}
|
||||
|
||||
cothread_t co_active() {
|
||||
|
@ -96,13 +93,13 @@ cothread_t co_derive(void* memory, unsigned int size, void (*entrypoint)(void))
|
|||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
|
||||
void* memory = malloc(size);
|
||||
void* memory = LIBCO_MALLOC(size);
|
||||
if(!memory) return (cothread_t)0;
|
||||
return co_derive(memory, size, entrypoint);
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle) {
|
||||
free(handle);
|
||||
LIBCO_FREE(handle);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t handle) {
|
||||
|
|
Loading…
Reference in New Issue