├── library ├── watchdog.c ├── tree.h └── darray.h ├── src ├── skynet_timer.c ├── lualib │ ├── lua-skynet.c │ ├── lua-clientsocket.c │ ├── lua-seri.h │ ├── sproto │ │ ├── msvcint.h │ │ └── sproto.h │ ├── lpeg │ │ ├── lpprint.h │ │ ├── lpcode.h │ │ ├── lpvm.h │ │ ├── lpcap.h │ │ └── lptree.h │ └── lua-memory.c ├── skynet_daemon.h ├── server │ ├── service_harbor.h │ ├── service_logger.h │ ├── service_snjs.h │ ├── service_snlua.h │ └── service_logger.c ├── skynet_env.h ├── skynet_timer.h ├── skynet_monitor.h ├── skynet_log.h ├── luashrtbl.h ├── skynet_imp.h ├── malloc_hook.h ├── skynet_handle.h ├── skynet_harbor.h ├── CMakeLists.txt ├── skynet_env.c ├── skynet_module.h ├── skynet_monitor.c ├── skynet_server.h ├── skynet_mq.h ├── skynet_harbor.c ├── atomic.h ├── skynet_error.c └── skynet_socket.h ├── CMakeLists.txt ├── jemalloc ├── src │ ├── spin.c │ ├── hash.c │ ├── prng.c │ ├── ticker.c │ ├── hooks.c │ └── extent_mmap.c └── include │ ├── jemalloc │ ├── internal │ │ ├── private_namespace.sh │ │ ├── public_unnamespace.sh │ │ ├── public_namespace.sh │ │ ├── extent_dss_structs.h │ │ ├── base_types.h │ │ ├── base_inlines.h │ │ ├── extent_types.h │ │ ├── tsd_types.h │ │ ├── arena_structs_a.h │ │ ├── extent_mmap_externs.h │ │ ├── extent_dss_types.h │ │ ├── public_unnamespace.h │ │ ├── extent_dss_externs.h │ │ ├── public_symbols.txt │ │ ├── rtree_ctx.h │ │ ├── rtree_witness.h │ │ ├── spin.h │ │ ├── mutex_externs.h │ │ ├── witness_structs.h │ │ ├── hooks.h │ │ ├── base_externs.h │ │ ├── public_namespace.h │ │ ├── witness_externs.h │ │ ├── jemalloc_internal_macros.h │ │ ├── nstime.h │ │ ├── large_externs.h │ │ ├── tsd_tls.h │ │ ├── private_symbols.sh │ │ ├── ticker.h │ │ ├── arena_types.h │ │ ├── tsd_malloc_thread_cleanup.h │ │ ├── rtree_structs.h │ │ ├── mutex_structs.h │ │ ├── assert.h │ │ ├── private_symbols.awk │ │ ├── private_symbols_jet.awk │ │ ├── base_structs.h │ │ ├── arena_inlines_a.h │ │ ├── util.h │ │ ├── prof_types.h │ │ ├── malloc_io.h │ │ ├── jemalloc_internal_decls.h │ │ └── rtree_externs.h │ ├── jemalloc_rename.sh │ ├── jemalloc.sh │ ├── jemalloc_rename.h │ ├── jemalloc_defs.h.in │ ├── jemalloc_mangle.sh │ ├── jemalloc_defs.h │ ├── jemalloc_mangle.h │ └── jemalloc_mangle_jet.h │ └── msvc_compat │ ├── windows_extra.h │ ├── C99 │ └── stdbool.h │ └── strings.h ├── duktape ├── CMakeLists.txt ├── duk_bi_thrower.c ├── duk_exception.h ├── duk_selftest.h ├── duk_jmpbuf.h ├── duk_hbufobj_misc.c ├── duk_replacements.h ├── duk_hnatfunc.h ├── duk_util_bitencoder.c ├── duk_alloc_default.c ├── duk_hobject_misc.c ├── duk_henv.h ├── duk_util_hashbytes.c ├── duk_harray.h ├── duk_replacements.c ├── duk_debug_fixedbuffer.c ├── duk_bi_pointer.c ├── duk_bi_boolean.c └── duk_api_buffer.c ├── vs ├── lua │ └── lua.vcxproj.user ├── duktape │ └── duktape.vcxproj.user ├── jemalloc │ └── jemalloc.vcxproj.user ├── agent │ ├── agent.vcxproj.filters │ └── agent.vcxproj.user ├── gate │ ├── gate.vcxproj.filters │ └── gate.vcxproj.user ├── watchdog │ ├── watchdog.vcxproj.filters │ └── watchdog.vcxproj.user └── znet │ └── znet.vcxproj.user ├── lua ├── CMakeLists.txt └── src │ ├── lua.hpp │ ├── lapi.h │ ├── lundump.h │ ├── lprefix.h │ ├── ldebug.h │ ├── lualib.h │ ├── lzio.c │ ├── lzio.h │ ├── lfunc.h │ ├── lstring.h │ ├── linit.c │ ├── ltm.h │ ├── lctype.h │ ├── ldo.h │ └── ltable.h ├── README.md ├── tool ├── zero │ ├── lualib │ │ ├── datacenter.lua │ │ ├── http │ │ │ └── url.lua │ │ ├── skynet │ │ │ ├── harbor.lua │ │ │ ├── queue.lua │ │ │ ├── inject.lua │ │ │ └── manager.lua │ │ ├── sprotoloader.lua │ │ ├── loader.lua │ │ ├── md5.lua │ │ ├── cluster.lua │ │ ├── sharedata.lua │ │ ├── sharemap.lua │ │ └── mqueue.lua │ ├── zero.lua │ └── service │ │ ├── bootstrap.lua │ │ └── cdummy.lua └── config.lua ├── .gitignore ├── LICENSE └── libuv ├── src ├── win │ ├── detect-wakeup.c │ ├── req.c │ ├── snprintf.c │ └── stream-inl.h ├── unix │ ├── posix-hrtime.c │ ├── spinlock.h │ └── pthread-fixes.c └── version.c ├── CMakeLists.txt └── include ├── uv-os390.h ├── uv-threadpool.h ├── uv-aix.h ├── uv-bsd.h ├── uv-linux.h ├── uv-version.h ├── android-ifaddrs.h ├── uv-sunos.h └── pthread-barrier.h /library/watchdog.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zero-rp/ZNet/HEAD/library/watchdog.c -------------------------------------------------------------------------------- /src/skynet_timer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zero-rp/ZNet/HEAD/src/skynet_timer.c -------------------------------------------------------------------------------- /src/lualib/lua-skynet.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zero-rp/ZNet/HEAD/src/lualib/lua-skynet.c -------------------------------------------------------------------------------- /src/lualib/lua-clientsocket.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zero-rp/ZNet/HEAD/src/lualib/lua-clientsocket.c -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(lua) 2 | add_subdirectory(duktape) 3 | add_subdirectory(libuv) 4 | add_subdirectory(src) 5 | 6 | -------------------------------------------------------------------------------- /jemalloc/src/spin.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_SPIN_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | 4 | #include "jemalloc/internal/spin.h" 5 | -------------------------------------------------------------------------------- /jemalloc/src/hash.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_HASH_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | -------------------------------------------------------------------------------- /jemalloc/src/prng.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_PRNG_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | -------------------------------------------------------------------------------- /jemalloc/src/ticker.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_TICKER_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/private_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat "$@"` ; do 4 | echo "#define ${symbol} JEMALLOC_N(${symbol})" 5 | done 6 | -------------------------------------------------------------------------------- /duktape/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(duktape) 2 | aux_source_directory(. src) 3 | add_library(duktape STATIC ${src}) 4 | set_target_properties(duktape PROPERTIES output_name "duktape") 5 | -------------------------------------------------------------------------------- /src/skynet_daemon.h: -------------------------------------------------------------------------------- 1 | #ifndef skynet_daemon_h 2 | #define skynet_daemon_h 3 | 4 | int daemon_init(const char *pidfile); 5 | int daemon_exit(const char *pidfile); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/public_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#undef je_${n}" 6 | done 7 | -------------------------------------------------------------------------------- /vs/lua/lua.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /jemalloc/include/msvc_compat/windows_extra.h: -------------------------------------------------------------------------------- 1 | #ifndef MSVC_COMPAT_WINDOWS_EXTRA_H 2 | #define MSVC_COMPAT_WINDOWS_EXTRA_H 3 | 4 | #include 5 | 6 | #endif /* MSVC_COMPAT_WINDOWS_EXTRA_H */ 7 | -------------------------------------------------------------------------------- /vs/duktape/duktape.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/public_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#define je_${n} JEMALLOC_N(${n})" 6 | done 7 | -------------------------------------------------------------------------------- /src/lualib/lua-seri.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_SERIALIZE_H 2 | #define LUA_SERIALIZE_H 3 | 4 | #include 5 | 6 | int luaseri_pack(lua_State *L); 7 | int luaseri_unpack(lua_State *L); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /vs/jemalloc/jemalloc.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(lua) 2 | include_directories(${CMAKE_SOURCE_DIR}/libuv/include) 3 | aux_source_directory(./src src) 4 | add_library(lua STATIC ${src}) 5 | set_target_properties(lua PROPERTIES output_name "lua") 6 | -------------------------------------------------------------------------------- /src/server/service_harbor.h: -------------------------------------------------------------------------------- 1 | struct harbor; 2 | 3 | struct harbor *harbor_create(void); 4 | void 5 | harbor_release(struct harbor *h); 6 | int 7 | harbor_init(struct harbor *h, struct skynet_context *ctx, const char * args); 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZNet 2 | 此框架为云大的skynet的libuv跨平台移植版 3 | 云大的skynet地址:https://github.com/cloudwu/skynet 4 | 云大的blog:http://blog.codingnow.com/ 5 | 有问题请留言或联系QQ:22249030 6 | # 上游Skynet版本:master-2017-5-17 7 |  此移植保持原skynet接口兼容 8 | -------------------------------------------------------------------------------- /src/skynet_env.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_ENV_H 2 | #define SKYNET_ENV_H 3 | 4 | const char * skynet_getenv(const char *key); 5 | void skynet_setenv(const char *key, const char *value); 6 | 7 | void skynet_env_init(); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lua/src/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/extent_dss_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_EXTENT_DSS_STRUCTS_H 2 | #define JEMALLOC_INTERNAL_EXTENT_DSS_STRUCTS_H 3 | 4 | extern const char *dss_prec_names[]; 5 | 6 | #endif /* JEMALLOC_INTERNAL_EXTENT_DSS_STRUCTS_H */ 7 | -------------------------------------------------------------------------------- /vs/agent/agent.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /duktape/duk_bi_thrower.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Type error thrower, E5 Section 13.2.3. 3 | */ 4 | 5 | #include "duk_internal.h" 6 | 7 | DUK_INTERNAL duk_ret_t duk_bi_type_error_thrower(duk_context *ctx) { 8 | DUK_DCERROR_TYPE_INVALID_ARGS((duk_hthread *) ctx); 9 | } 10 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/base_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BASE_TYPES_H 2 | #define JEMALLOC_INTERNAL_BASE_TYPES_H 3 | 4 | typedef struct base_block_s base_block_t; 5 | typedef struct base_s base_t; 6 | 7 | #endif /* JEMALLOC_INTERNAL_BASE_TYPES_H */ 8 | -------------------------------------------------------------------------------- /vs/gate/gate.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/base_inlines.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BASE_INLINES_H 2 | #define JEMALLOC_INTERNAL_BASE_INLINES_H 3 | 4 | static inline unsigned 5 | base_ind_get(const base_t *base) { 6 | return base->ind; 7 | } 8 | 9 | #endif /* JEMALLOC_INTERNAL_BASE_INLINES_H */ 10 | -------------------------------------------------------------------------------- /src/skynet_timer.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_TIMER_H 2 | #define SKYNET_TIMER_H 3 | 4 | #include 5 | 6 | 7 | void skynet_updatetime(void); 8 | uint32_t skynet_starttime(void); 9 | uint64_t skynet_thread_time(void); // for profile, in micro second 10 | 11 | void skynet_timer_init(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/extent_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_EXTENT_TYPES_H 2 | #define JEMALLOC_INTERNAL_EXTENT_TYPES_H 3 | 4 | typedef struct extent_s extent_t; 5 | typedef struct extents_s extents_t; 6 | 7 | #define EXTENT_HOOKS_INITIALIZER NULL 8 | 9 | #endif /* JEMALLOC_INTERNAL_EXTENT_TYPES_H */ 10 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/tsd_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_TSD_TYPES_H 2 | #define JEMALLOC_INTERNAL_TSD_TYPES_H 3 | 4 | #define MALLOC_TSD_CLEANUPS_MAX 2 5 | 6 | typedef struct tsd_s tsd_t; 7 | typedef struct tsdn_s tsdn_t; 8 | typedef bool (*malloc_tsd_cleanup_t)(void); 9 | 10 | #endif /* JEMALLOC_INTERNAL_TSD_TYPES_H */ 11 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/arena_structs_a.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H 2 | #define JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H 3 | 4 | #include "jemalloc/internal/bitmap.h" 5 | 6 | struct arena_slab_data_s { 7 | /* Per region allocated/deallocated bitmap. */ 8 | bitmap_t bitmap[BITMAP_GROUPS_MAX]; 9 | }; 10 | 11 | #endif /* JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H */ 12 | -------------------------------------------------------------------------------- /vs/watchdog/watchdog.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/extent_mmap_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_EXTENT_MMAP_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_EXTENT_MMAP_EXTERNS_H 3 | 4 | extern bool opt_retain; 5 | 6 | void *extent_alloc_mmap(void *new_addr, size_t size, size_t alignment, 7 | bool *zero, bool *commit); 8 | bool extent_dalloc_mmap(void *addr, size_t size); 9 | 10 | #endif /* JEMALLOC_INTERNAL_EXTENT_MMAP_EXTERNS_H */ 11 | -------------------------------------------------------------------------------- /src/skynet_monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MONITOR_H 2 | #define SKYNET_MONITOR_H 3 | 4 | #include 5 | 6 | struct skynet_monitor; 7 | 8 | struct skynet_monitor * skynet_monitor_new(); 9 | void skynet_monitor_delete(struct skynet_monitor *); 10 | void skynet_monitor_trigger(struct skynet_monitor *, uint32_t source, uint32_t destination); 11 | void skynet_monitor_check(struct skynet_monitor *); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/skynet_log.h: -------------------------------------------------------------------------------- 1 | #ifndef skynet_log_h 2 | #define skynet_log_h 3 | 4 | #include "skynet_env.h" 5 | #include "skynet.h" 6 | 7 | #include 8 | #include 9 | 10 | FILE * skynet_log_open(struct skynet_context * ctx, uint32_t handle); 11 | void skynet_log_close(struct skynet_context * ctx, FILE *f, uint32_t handle); 12 | void skynet_log_output(FILE *f, uint32_t source, int type, int session, void * buffer, size_t sz); 13 | 14 | #endif -------------------------------------------------------------------------------- /tool/zero/lualib/datacenter.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local datacenter = {} 4 | 5 | function datacenter.get(...) 6 | return skynet.call("DATACENTER", "lua", "QUERY", ...) 7 | end 8 | 9 | function datacenter.set(...) 10 | return skynet.call("DATACENTER", "lua", "UPDATE", ...) 11 | end 12 | 13 | function datacenter.wait(...) 14 | return skynet.call("DATACENTER", "lua", "WAIT", ...) 15 | end 16 | 17 | return datacenter 18 | 19 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/extent_dss_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_EXTENT_DSS_TYPES_H 2 | #define JEMALLOC_INTERNAL_EXTENT_DSS_TYPES_H 3 | 4 | typedef enum { 5 | dss_prec_disabled = 0, 6 | dss_prec_primary = 1, 7 | dss_prec_secondary = 2, 8 | 9 | dss_prec_limit = 3 10 | } dss_prec_t; 11 | #define DSS_PREC_DEFAULT dss_prec_secondary 12 | #define DSS_DEFAULT "secondary" 13 | 14 | #endif /* JEMALLOC_INTERNAL_EXTENT_DSS_TYPES_H */ 15 | -------------------------------------------------------------------------------- /jemalloc/src/hooks.c: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_preamble.h" 2 | 3 | /* 4 | * The hooks are a little bit screwy -- they're not genuinely exported in the 5 | * sense that we want them available to end-users, but we do want them visible 6 | * from outside the generated library, so that we can use them in test code. 7 | */ 8 | JEMALLOC_EXPORT 9 | void (*hooks_arena_new_hook)() = NULL; 10 | 11 | JEMALLOC_EXPORT 12 | void (*hooks_libc_hook)() = NULL; 13 | -------------------------------------------------------------------------------- /src/luashrtbl.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_SHORT_STRING_TABLE_H 2 | #define LUA_SHORT_STRING_TABLE_H 3 | 4 | #include "lstring.h" 5 | 6 | // If you use modified lua, this macro would be defined in lstring.h 7 | #ifndef ENABLE_SHORT_STRING_TABLE 8 | 9 | static inline int luaS_shrinfo(lua_State *L) { return 0; } 10 | static inline void luaS_initshr() {} 11 | static inline void luaS_exitshr() {} 12 | static inline void luaS_expandshr(int n) {} 13 | 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/server/service_logger.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct logger { 5 | FILE * handle; 6 | char * filename; 7 | int close; 8 | }; 9 | 10 | struct logger *logger_create(void); 11 | void logger_release(struct logger *inst); 12 | static int logger_cb(struct znet_context * context, void *ud, int type, int session, uint32_t source, const void * msg, size_t sz); 13 | int logger_init(struct logger * inst, struct znet_context *ctx, const char * parm); 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | bin/ 35 | build/ 36 | vs/.vs/* 37 | *.db 38 | *.exp 39 | tool/admin.bak 40 | *.iobj 41 | *.ipdb 42 | -------------------------------------------------------------------------------- /src/skynet_imp.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_IMP_H 2 | #define SKYNET_IMP_H 3 | 4 | struct skynet_config { 5 | int thread; 6 | int harbor; 7 | int profile; 8 | const char * daemon; 9 | const char * module_path; 10 | const char * bootstrap; 11 | const char * logger; 12 | const char * logservice; 13 | }; 14 | 15 | #define THREAD_WORKER 0 16 | #define THREAD_MAIN 1 17 | #define THREAD_SOCKET 2 18 | #define THREAD_TIMER 3 19 | #define THREAD_MONITOR 4 20 | 21 | void skynet_start(struct skynet_config * config); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/server/service_snjs.h: -------------------------------------------------------------------------------- 1 | #include"skynet.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define MEMORY_WARNING_REPORT 1024*1024*32 13 | 14 | struct snjs; 15 | 16 | 17 | 18 | int snjs_init(struct snjs *l, struct skynet_context *ctx, const char * args); 19 | struct snjs *snjs_create(void); 20 | void snjs_release(struct snjs *l); 21 | void snjs_signal(struct snjs *l, int signal); 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/public_unnamespace.h: -------------------------------------------------------------------------------- 1 | #undef je_aligned_alloc 2 | #undef je_calloc 3 | #undef je_dallocx 4 | #undef je_free 5 | #undef je_mallctl 6 | #undef je_mallctlbymib 7 | #undef je_mallctlnametomib 8 | #undef je_malloc 9 | #undef je_malloc_conf 10 | #undef je_malloc_message 11 | #undef je_malloc_stats_print 12 | #undef je_malloc_usable_size 13 | #undef je_mallocx 14 | #undef je_nallocx 15 | #undef je_posix_memalign 16 | #undef je_rallocx 17 | #undef je_realloc 18 | #undef je_sallocx 19 | #undef je_sdallocx 20 | #undef je_xallocx 21 | -------------------------------------------------------------------------------- /duktape/duk_exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Exception for Duktape internal throws when C++ exceptions are used 3 | * for long control transfers. 4 | * 5 | * Doesn't inherit from any exception base class to minimize the chance 6 | * that user code would accidentally catch this exception. 7 | */ 8 | 9 | #if !defined(DUK_EXCEPTION_H_INCLUDED) 10 | #define DUK_EXCEPTION_H_INCLUDED 11 | 12 | #if defined(DUK_USE_CPP_EXCEPTIONS) 13 | class duk_internal_exception { 14 | /* intentionally empty */ 15 | }; 16 | #endif 17 | 18 | #endif /* DUK_EXCEPTION_H_INCLUDED */ 19 | -------------------------------------------------------------------------------- /duktape/duk_selftest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Selftest code 3 | */ 4 | 5 | #if !defined(DUK_SELFTEST_H_INCLUDED) 6 | #define DUK_SELFTEST_H_INCLUDED 7 | 8 | #if defined(DUK_USE_SELF_TESTS) 9 | DUK_INTERNAL_DECL duk_uint_t duk_selftest_run_tests(duk_alloc_function alloc_func, 10 | duk_realloc_function realloc_func, 11 | duk_free_function free_func, 12 | void *udata); 13 | #endif 14 | 15 | #endif /* DUK_SELFTEST_H_INCLUDED */ 16 | -------------------------------------------------------------------------------- /jemalloc/include/msvc_compat/C99/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef stdbool_h 2 | #define stdbool_h 3 | 4 | #include 5 | 6 | /* MSVC doesn't define _Bool or bool in C, but does have BOOL */ 7 | /* Note this doesn't pass autoconf's test because (bool) 0.5 != true */ 8 | /* Clang-cl uses MSVC headers, so needs msvc_compat, but has _Bool as 9 | * a built-in type. */ 10 | #ifndef __clang__ 11 | typedef BOOL _Bool; 12 | #endif 13 | 14 | #define bool _Bool 15 | #define true 1 16 | #define false 0 17 | 18 | #define __bool_true_false_are_defined 1 19 | 20 | #endif /* stdbool_h */ 21 | -------------------------------------------------------------------------------- /src/malloc_hook.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MALLOC_HOOK_H 2 | #define SKYNET_MALLOC_HOOK_H 3 | 4 | #include 5 | #include 6 | 7 | extern size_t malloc_used_memory(void); 8 | extern size_t malloc_memory_block(void); 9 | extern void memory_info_dump(void); 10 | extern size_t mallctl_int64(const char* name, size_t* newval); 11 | extern int mallctl_opt(const char* name, int* newval); 12 | extern void dump_c_mem(void); 13 | extern int dump_mem_lua(lua_State *L); 14 | extern size_t malloc_current_memory(void); 15 | 16 | #endif /* SKYNET_MALLOC_HOOK_H */ 17 | 18 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc_rename.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | public_symbols_txt=$1 4 | 5 | cat < 2 | 3 | 4 | $(SolutionDir)..\bin\$(Platform)\$(Configuration)\znet.exe 5 | WindowsLocalDebugger 6 | config.lua 7 | $(SolutionDir)..\tool 8 | 9 | -------------------------------------------------------------------------------- /vs/agent/agent.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(SolutionDir)..\bin\$(Platform)\$(Configuration)\znet.exe 5 | WindowsLocalDebugger 6 | config.lua 7 | $(SolutionDir)..\tool 8 | 9 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | objroot=$1 4 | 5 | cat <top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /tool/zero/lualib/skynet/harbor.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local harbor = {} 4 | 5 | function harbor.globalname(name, handle) 6 | handle = handle or skynet.self() 7 | skynet.send(".cslave", "lua", "REGISTER", name, handle) 8 | end 9 | 10 | function harbor.queryname(name) 11 | return skynet.call(".cslave", "lua", "QUERYNAME", name) 12 | end 13 | 14 | function harbor.link(id) 15 | skynet.call(".cslave", "lua", "LINK", id) 16 | end 17 | 18 | function harbor.connect(id) 19 | skynet.call(".cslave", "lua", "CONNECT", id) 20 | end 21 | 22 | function harbor.linkmaster() 23 | skynet.call(".cslave", "lua", "LINKMASTER") 24 | end 25 | 26 | return harbor 27 | -------------------------------------------------------------------------------- /tool/zero/zero.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | require "skynet.manager" -- import skynet.register 3 | 4 | local max_client = 99999 5 | 6 | skynet.start(function() 7 | skynet.error("[LOG]",os.date("%m-%d-%Y %X", skynet.starttime()),"Server start") 8 | --启动调试器 9 | skynet.newservice("debug_console",8000) 10 | --启动watchdog 11 | skynet.launch("watchdog", "0.0.0.0", 8888, max_client) 12 | --启动js脚本 13 | skynet.launch("snjs", "test") 14 | --local watchdog = skynet.newservice("watchdog") 15 | --skynet.call(watchdog, "lua", "start", { 16 | -- ip = "0.0.0.0", 17 | -- port = 8888, 18 | -- maxclient = max_client, 19 | --}) 20 | --退出服务 21 | skynet.exit() 22 | end) -------------------------------------------------------------------------------- /duktape/duk_hbufobj_misc.c: -------------------------------------------------------------------------------- 1 | #include "duk_internal.h" 2 | 3 | #if defined(DUK_USE_BUFFEROBJECT_SUPPORT) 4 | DUK_INTERNAL duk_uint_t duk_hbufobj_clamp_bytelength(duk_hbufobj *h_bufobj, duk_uint_t len) { 5 | duk_uint_t buf_size; 6 | duk_uint_t buf_avail; 7 | 8 | DUK_ASSERT(h_bufobj != NULL); 9 | DUK_ASSERT(h_bufobj->buf != NULL); 10 | 11 | buf_size = (duk_uint_t) DUK_HBUFFER_GET_SIZE(h_bufobj->buf); 12 | if (h_bufobj->offset > buf_size) { 13 | /* Slice starting point is beyond current length. */ 14 | return 0; 15 | } 16 | buf_avail = buf_size - h_bufobj->offset; 17 | 18 | return buf_avail >= len ? len : buf_avail; 19 | } 20 | #endif /* DUK_USE_BUFFEROBJECT_SUPPORT */ 21 | -------------------------------------------------------------------------------- /src/server/service_snlua.h: -------------------------------------------------------------------------------- 1 | #include"skynet.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define MEMORY_WARNING_REPORT 1024*1024*32 13 | 14 | struct snlua{ 15 | lua_State*L; 16 | struct skynet_context*ctx; 17 | size_t mem; 18 | size_t mem_report; 19 | size_t mem_limit; 20 | }; 21 | 22 | 23 | 24 | int snlua_init(struct snlua *l, struct skynet_context *ctx, const char * args); 25 | struct snlua *snlua_create(void); 26 | void snlua_release(struct snlua *l); 27 | void snlua_signal(struct snlua *l, int signal); 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/skynet_handle.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_CONTEXT_HANDLE_H 2 | #define SKYNET_CONTEXT_HANDLE_H 3 | 4 | #include 5 | 6 | // reserve high 8 bits for remote id 7 | #define HANDLE_MASK 0xffffff 8 | #define HANDLE_REMOTE_SHIFT 24 9 | 10 | struct skynet_context; 11 | 12 | uint32_t skynet_handle_register(struct skynet_context *); 13 | int skynet_handle_retire(uint32_t handle); 14 | struct skynet_context * skynet_handle_grab(uint32_t handle); 15 | void skynet_handle_retireall(); 16 | 17 | uint32_t skynet_handle_findname(const char * name); 18 | const char * skynet_handle_namehandle(uint32_t handle, const char *name); 19 | 20 | void skynet_handle_init(int harbor); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/skynet_harbor.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_HARBOR_H 2 | #define SKYNET_HARBOR_H 3 | 4 | #include 5 | #include 6 | 7 | #define GLOBALNAME_LENGTH 16 8 | #define REMOTE_MAX 256 9 | 10 | struct remote_name { 11 | char name[GLOBALNAME_LENGTH]; 12 | uint32_t handle; 13 | }; 14 | 15 | struct remote_message { 16 | struct remote_name destination; 17 | const void * message; 18 | size_t sz; 19 | }; 20 | 21 | void skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session); 22 | int skynet_harbor_message_isremote(uint32_t handle); 23 | void skynet_harbor_init(int harbor); 24 | void skynet_harbor_start(void * ctx); 25 | void skynet_harbor_exit(); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/rtree_ctx.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_RTREE_CTX_H 2 | #define JEMALLOC_INTERNAL_RTREE_CTX_H 3 | 4 | #include "jemalloc/internal/rtree_types.h" 5 | 6 | typedef struct rtree_ctx_cache_elm_s rtree_ctx_cache_elm_t; 7 | struct rtree_ctx_cache_elm_s { 8 | uintptr_t leafkey; 9 | rtree_leaf_elm_t *leaf; 10 | }; 11 | 12 | typedef struct rtree_ctx_s rtree_ctx_t; 13 | struct rtree_ctx_s { 14 | /* Direct mapped cache. */ 15 | rtree_ctx_cache_elm_t cache[RTREE_CTX_NCACHE]; 16 | /* L2 LRU cache. */ 17 | rtree_ctx_cache_elm_t l2_cache[RTREE_CTX_NCACHE_L2]; 18 | }; 19 | 20 | void rtree_ctx_data_init(rtree_ctx_t *ctx); 21 | 22 | #endif /* JEMALLOC_INTERNAL_RTREE_CTX_H */ 23 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/rtree_witness.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_RTREE_WITNESS_H 2 | #define JEMALLOC_INTERNAL_RTREE_WITNESS_H 3 | 4 | #include "jemalloc/internal/rtree_types.h" 5 | #include "jemalloc/internal/witness_types.h" 6 | #include "jemalloc/internal/witness_structs.h" 7 | 8 | typedef struct rtree_leaf_elm_witness_s rtree_leaf_elm_witness_t; 9 | struct rtree_leaf_elm_witness_s { 10 | const rtree_leaf_elm_t *elm; 11 | witness_t witness; 12 | }; 13 | 14 | typedef struct rtree_leaf_elm_witness_tsd_s rtree_leaf_elm_witness_tsd_t; 15 | struct rtree_leaf_elm_witness_tsd_s { 16 | rtree_leaf_elm_witness_t witnesses[RTREE_ELM_ACQUIRE_MAX]; 17 | }; 18 | 19 | #endif /* JEMALLOC_INTERNAL_RTREE_WITNESS_H */ 20 | -------------------------------------------------------------------------------- /tool/zero/lualib/sprotoloader.lua: -------------------------------------------------------------------------------- 1 | local parser = require "sprotoparser" 2 | local core = require "sproto.core" 3 | local sproto = require "sproto" 4 | 5 | local loader = {} 6 | 7 | function loader.register(filename, index) 8 | local f = assert(io.open(filename), "Can't open sproto file") 9 | local data = f:read "a" 10 | f:close() 11 | local sp = core.newproto(parser.parse(data)) 12 | core.saveproto(sp, index) 13 | end 14 | 15 | function loader.save(bin, index) 16 | local sp = core.newproto(bin) 17 | core.saveproto(sp, index) 18 | end 19 | 20 | function loader.load(index) 21 | local sp = core.loadproto(index) 22 | -- no __gc in metatable 23 | return sproto.sharenew(sp) 24 | end 25 | 26 | return loader 27 | 28 | -------------------------------------------------------------------------------- /tool/config.lua: -------------------------------------------------------------------------------- 1 | -- root = "./" 2 | -- thread = 8 3 | -- logger = nil 4 | -- harbor = 0 5 | -- start = "main" -- main script 6 | -- bootstrap = "snlua bootstrap" -- The service for bootstrap 7 | -- luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua" 8 | -- lualoader = "lualib/loader.lua" 9 | -- snax = root.."examples/?.lua;"..root.."test/?.lua" 10 | -- cpath = root.."cservice/?.so" 11 | 12 | root = "./zero/" 13 | thread = 1 14 | logger = nil 15 | harbor = 0 16 | start = "zero" -- main script 17 | bootstrap = "snlua bootstrap" -- The service for bootstrap 18 | luaservice = root.."?.lua;"..root.."service/?.lua" 19 | lua_path = root.."lualib/?.lua" 20 | lualoader = root.."lualib/loader.lua" 21 | cpath = root.."?.dll" 22 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(znet) 2 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g") 3 | add_definitions("-D_GNU_SOURCE") 4 | add_definitions("-DNOUSE_JEMALLOC") 5 | include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/libuv/include ${CMAKE_SOURCE_DIR}/libuv/src ${CMAKE_SOURCE_DIR}/lua/src ${CMAKE_SOURCE_DIR}/duktape) 6 | aux_source_directory(./ src) 7 | aux_source_directory(./lualib lualib) 8 | aux_source_directory(./lualib/sproto lualib_sproto) 9 | aux_source_directory(./lualib/lpeg lualib_lpeg) 10 | aux_source_directory(./server server) 11 | add_executable(znet ${src} ${lualib} ${server} ${lualib_sproto} ${lualib_lpeg}) 12 | target_link_libraries(znet uv lua duktape pthread m dl) 13 | set_target_properties(znet PROPERTIES output_name "znet") 14 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/spin.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_SPIN_H 2 | #define JEMALLOC_INTERNAL_SPIN_H 3 | 4 | #ifdef JEMALLOC_SPIN_C_ 5 | # define SPIN_INLINE extern inline 6 | #else 7 | # define SPIN_INLINE inline 8 | #endif 9 | 10 | #define SPIN_INITIALIZER {0U} 11 | 12 | typedef struct { 13 | unsigned iteration; 14 | } spin_t; 15 | 16 | SPIN_INLINE void 17 | spin_adaptive(spin_t *spin) { 18 | volatile uint32_t i; 19 | 20 | if (spin->iteration < 5) { 21 | for (i = 0; i < (1U << spin->iteration); i++) { 22 | CPU_SPINWAIT; 23 | } 24 | spin->iteration++; 25 | } else { 26 | #ifdef _WIN32 27 | SwitchToThread(); 28 | #else 29 | sched_yield(); 30 | #endif 31 | } 32 | } 33 | 34 | #undef SPIN_INLINE 35 | 36 | #endif /* JEMALLOC_INTERNAL_SPIN_H */ 37 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/mutex_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_MUTEX_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_MUTEX_EXTERNS_H 3 | 4 | #include "jemalloc/internal/tsd_types.h" 5 | 6 | #ifdef JEMALLOC_LAZY_LOCK 7 | extern bool isthreaded; 8 | #else 9 | # undef isthreaded /* Undo private_namespace.h definition. */ 10 | # define isthreaded true 11 | #endif 12 | 13 | bool malloc_mutex_init(malloc_mutex_t *mutex, const char *name, 14 | witness_rank_t rank); 15 | void malloc_mutex_prefork(tsdn_t *tsdn, malloc_mutex_t *mutex); 16 | void malloc_mutex_postfork_parent(tsdn_t *tsdn, malloc_mutex_t *mutex); 17 | void malloc_mutex_postfork_child(tsdn_t *tsdn, malloc_mutex_t *mutex); 18 | bool malloc_mutex_boot(void); 19 | void malloc_mutex_prof_data_reset(tsdn_t *tsdn, malloc_mutex_t *mutex); 20 | 21 | #endif /* JEMALLOC_INTERNAL_MUTEX_EXTERNS_H */ 22 | -------------------------------------------------------------------------------- /src/lualib/sproto/msvcint.h: -------------------------------------------------------------------------------- 1 | #ifndef msvc_int_h 2 | #define msvc_int_h 3 | 4 | #ifdef _MSC_VER 5 | # define inline __inline 6 | # ifndef _MSC_STDINT_H_ 7 | # if (_MSC_VER < 1300) 8 | typedef signed char int8_t; 9 | typedef signed short int16_t; 10 | typedef signed int int32_t; 11 | typedef unsigned char uint8_t; 12 | typedef unsigned short uint16_t; 13 | typedef unsigned int uint32_t; 14 | # else 15 | typedef signed __int8 int8_t; 16 | typedef signed __int16 int16_t; 17 | typedef signed __int32 int32_t; 18 | typedef unsigned __int8 uint8_t; 19 | typedef unsigned __int16 uint16_t; 20 | typedef unsigned __int32 uint32_t; 21 | # endif 22 | typedef signed __int64 int64_t; 23 | typedef unsigned __int64 uint64_t; 24 | # endif 25 | 26 | #else 27 | 28 | #include 29 | 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/witness_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_WITNESS_STRUCTS_H 2 | #define JEMALLOC_INTERNAL_WITNESS_STRUCTS_H 3 | 4 | struct witness_s { 5 | /* Name, used for printing lock order reversal messages. */ 6 | const char *name; 7 | 8 | /* 9 | * Witness rank, where 0 is lowest and UINT_MAX is highest. Witnesses 10 | * must be acquired in order of increasing rank. 11 | */ 12 | witness_rank_t rank; 13 | 14 | /* 15 | * If two witnesses are of equal rank and they have the samp comp 16 | * function pointer, it is called as a last attempt to differentiate 17 | * between witnesses of equal rank. 18 | */ 19 | witness_comp_t *comp; 20 | 21 | /* Opaque data, passed to comp(). */ 22 | void *opaque; 23 | 24 | /* Linkage for thread's currently owned locks. */ 25 | ql_elm(witness_t) link; 26 | }; 27 | 28 | #endif /* JEMALLOC_INTERNAL_WITNESS_STRUCTS_H */ 29 | -------------------------------------------------------------------------------- /src/lualib/lpeg/lpprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpprint.h,v 1.2 2015/06/12 18:18:08 roberto Exp $ 3 | */ 4 | 5 | 6 | #if !defined(lpprint_h) 7 | #define lpprint_h 8 | 9 | 10 | #include "lptree.h" 11 | #include "lpvm.h" 12 | 13 | 14 | #if defined(LPEG_DEBUG) 15 | 16 | void printpatt (Instruction *p, int n); 17 | void printtree (TTree *tree, int ident); 18 | void printktable (lua_State *L, int idx); 19 | void printcharset (const byte *st); 20 | void printcaplist (Capture *cap, Capture *limit); 21 | void printinst (const Instruction *op, const Instruction *p); 22 | 23 | #else 24 | 25 | #define printktable(L,idx) \ 26 | luaL_error(L, "function only implemented in debug mode") 27 | #define printtree(tree,i) \ 28 | luaL_error(L, "function only implemented in debug mode") 29 | #define printpatt(p,n) \ 30 | luaL_error(L, "function only implemented in debug mode") 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/hooks.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_HOOKS_H 2 | #define JEMALLOC_INTERNAL_HOOKS_H 3 | 4 | extern JEMALLOC_EXPORT void (*hooks_arena_new_hook)(); 5 | extern JEMALLOC_EXPORT void (*hooks_libc_hook)(); 6 | 7 | #define JEMALLOC_HOOK(fn, hook) ((void)(hook != NULL && (hook(), 0)), fn) 8 | 9 | #define open JEMALLOC_HOOK(open, hooks_libc_hook) 10 | #define read JEMALLOC_HOOK(read, hooks_libc_hook) 11 | #define write JEMALLOC_HOOK(write, hooks_libc_hook) 12 | #define readlink JEMALLOC_HOOK(readlink, hooks_libc_hook) 13 | #define close JEMALLOC_HOOK(close, hooks_libc_hook) 14 | #define creat JEMALLOC_HOOK(creat, hooks_libc_hook) 15 | #define secure_getenv JEMALLOC_HOOK(secure_getenv, hooks_libc_hook) 16 | /* Note that this is undef'd and re-define'd in src/prof.c. */ 17 | #define _Unwind_Backtrace JEMALLOC_HOOK(_Unwind_Backtrace, hooks_libc_hook) 18 | 19 | #endif /* JEMALLOC_INTERNAL_HOOKS_H */ 20 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/base_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BASE_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_BASE_EXTERNS_H 3 | 4 | base_t *b0get(void); 5 | base_t *base_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks); 6 | void base_delete(base_t *base); 7 | extent_hooks_t *base_extent_hooks_get(base_t *base); 8 | extent_hooks_t *base_extent_hooks_set(base_t *base, 9 | extent_hooks_t *extent_hooks); 10 | void *base_alloc(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment); 11 | extent_t *base_alloc_extent(tsdn_t *tsdn, base_t *base); 12 | void base_stats_get(tsdn_t *tsdn, base_t *base, size_t *allocated, 13 | size_t *resident, size_t *mapped); 14 | void base_prefork(tsdn_t *tsdn, base_t *base); 15 | void base_postfork_parent(tsdn_t *tsdn, base_t *base); 16 | void base_postfork_child(tsdn_t *tsdn, base_t *base); 17 | bool base_boot(tsdn_t *tsdn); 18 | 19 | #endif /* JEMALLOC_INTERNAL_BASE_EXTERNS_H */ 20 | -------------------------------------------------------------------------------- /lua/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /duktape/duk_replacements.h: -------------------------------------------------------------------------------- 1 | #if !defined(DUK_REPLACEMENTS_H_INCLUDED) 2 | #define DUK_REPLACEMENTS_H_INCLUDED 3 | 4 | #if !defined(DUK_SINGLE_FILE) 5 | #if defined(DUK_USE_COMPUTED_INFINITY) 6 | DUK_INTERNAL_DECL double duk_computed_infinity; 7 | #endif 8 | #if defined(DUK_USE_COMPUTED_NAN) 9 | DUK_INTERNAL_DECL double duk_computed_nan; 10 | #endif 11 | #endif /* !DUK_SINGLE_FILE */ 12 | 13 | #if defined(DUK_USE_REPL_FPCLASSIFY) 14 | DUK_INTERNAL_DECL int duk_repl_fpclassify(double x); 15 | #endif 16 | #if defined(DUK_USE_REPL_SIGNBIT) 17 | DUK_INTERNAL_DECL int duk_repl_signbit(double x); 18 | #endif 19 | #if defined(DUK_USE_REPL_ISFINITE) 20 | DUK_INTERNAL_DECL int duk_repl_isfinite(double x); 21 | #endif 22 | #if defined(DUK_USE_REPL_ISNAN) 23 | DUK_INTERNAL_DECL int duk_repl_isnan(double x); 24 | #endif 25 | #if defined(DUK_USE_REPL_ISINF) 26 | DUK_INTERNAL_DECL int duk_repl_isinf(double x); 27 | #endif 28 | 29 | #endif /* DUK_REPLACEMENTS_H_INCLUDED */ 30 | -------------------------------------------------------------------------------- /src/lualib/lpeg/lpcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcode.h,v 1.8 2016/09/15 17:46:13 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcode_h) 6 | #define lpcode_h 7 | 8 | #include "lua.h" 9 | 10 | #include "lptypes.h" 11 | #include "lptree.h" 12 | #include "lpvm.h" 13 | 14 | int tocharset (TTree *tree, Charset *cs); 15 | int checkaux (TTree *tree, int pred); 16 | int fixedlen (TTree *tree); 17 | int hascaptures (TTree *tree); 18 | int lp_gc (lua_State *L); 19 | Instruction *compile (lua_State *L, Pattern *p); 20 | void realloccode (lua_State *L, Pattern *p, int nsize); 21 | int sizei (const Instruction *i); 22 | 23 | 24 | #define PEnullable 0 25 | #define PEnofail 1 26 | 27 | /* 28 | ** nofail(t) implies that 't' cannot fail with any input 29 | */ 30 | #define nofail(t) checkaux(t, PEnofail) 31 | 32 | /* 33 | ** (not nullable(t)) implies 't' cannot match without consuming 34 | ** something 35 | */ 36 | #define nullable(t) checkaux(t, PEnullable) 37 | 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /tool/zero/lualib/skynet/queue.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local coroutine = coroutine 3 | local xpcall = xpcall 4 | local traceback = debug.traceback 5 | local table = table 6 | 7 | function skynet.queue() 8 | local current_thread 9 | local ref = 0 10 | local thread_queue = {} 11 | 12 | local function xpcall_ret(ok, ...) 13 | ref = ref - 1 14 | if ref == 0 then 15 | current_thread = table.remove(thread_queue,1) 16 | if current_thread then 17 | skynet.wakeup(current_thread) 18 | end 19 | end 20 | assert(ok, (...)) 21 | return ... 22 | end 23 | 24 | return function(f, ...) 25 | local thread = coroutine.running() 26 | if current_thread and current_thread ~= thread then 27 | table.insert(thread_queue, thread) 28 | skynet.wait() 29 | assert(ref == 0) -- current_thread == thread 30 | end 31 | current_thread = thread 32 | 33 | ref = ref + 1 34 | return xpcall_ret(xpcall(f, traceback, ...)) 35 | end 36 | end 37 | 38 | return skynet.queue 39 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/public_namespace.h: -------------------------------------------------------------------------------- 1 | #define je_aligned_alloc JEMALLOC_N(aligned_alloc) 2 | #define je_calloc JEMALLOC_N(calloc) 3 | #define je_dallocx JEMALLOC_N(dallocx) 4 | #define je_free JEMALLOC_N(free) 5 | #define je_mallctl JEMALLOC_N(mallctl) 6 | #define je_mallctlbymib JEMALLOC_N(mallctlbymib) 7 | #define je_mallctlnametomib JEMALLOC_N(mallctlnametomib) 8 | #define je_malloc JEMALLOC_N(malloc) 9 | #define je_malloc_conf JEMALLOC_N(malloc_conf) 10 | #define je_malloc_message JEMALLOC_N(malloc_message) 11 | #define je_malloc_stats_print JEMALLOC_N(malloc_stats_print) 12 | #define je_malloc_usable_size JEMALLOC_N(malloc_usable_size) 13 | #define je_mallocx JEMALLOC_N(mallocx) 14 | #define je_nallocx JEMALLOC_N(nallocx) 15 | #define je_posix_memalign JEMALLOC_N(posix_memalign) 16 | #define je_rallocx JEMALLOC_N(rallocx) 17 | #define je_realloc JEMALLOC_N(realloc) 18 | #define je_sallocx JEMALLOC_N(sallocx) 19 | #define je_sdallocx JEMALLOC_N(sdallocx) 20 | #define je_xallocx JEMALLOC_N(xallocx) 21 | -------------------------------------------------------------------------------- /src/skynet_env.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | #include "skynet_env.h" 3 | #include "spinlock.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | struct skynet_env { 12 | spinlock lock; 13 | lua_State *L; 14 | }; 15 | 16 | static struct skynet_env *E = NULL; 17 | 18 | const char * 19 | skynet_getenv(const char *key) { 20 | SPIN_LOCK(E) 21 | 22 | lua_State *L = E->L; 23 | 24 | lua_getglobal(L, key); 25 | const char * result = lua_tostring(L, -1); 26 | lua_pop(L, 1); 27 | 28 | SPIN_UNLOCK(E) 29 | 30 | return result; 31 | } 32 | 33 | void 34 | skynet_setenv(const char *key, const char *value) { 35 | SPIN_LOCK(E) 36 | 37 | lua_State *L = E->L; 38 | lua_getglobal(L, key); 39 | assert(lua_isnil(L, -1)); 40 | lua_pop(L,1); 41 | lua_pushstring(L,value); 42 | lua_setglobal(L,key); 43 | 44 | SPIN_UNLOCK(E) 45 | } 46 | 47 | void 48 | skynet_env_init() { 49 | E = skynet_malloc(sizeof(*E)); 50 | SPIN_INIT(E) 51 | E->L = luaL_newstate(); 52 | } 53 | -------------------------------------------------------------------------------- /library/tree.h: -------------------------------------------------------------------------------- 1 | #ifndef __TREE_H__ 2 | #define __TREE_H__ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef int key_t; 11 | typedef void *data_t; 12 | 13 | typedef struct rb_node_ 14 | { 15 | struct rb_node_ *rb_right; 16 | struct rb_node_ *rb_left; 17 | size_t rb_parent_color; 18 | key_t key; 19 | data_t data; 20 | }rb_node; 21 | 22 | typedef struct rb_root_ 23 | { 24 | rb_node *rb_node; 25 | }rb_root; 26 | 27 | 28 | typedef void(*TreeVisitFunc)(void *data); 29 | 30 | /*操作函数*/ 31 | 32 | /*初始化*/ 33 | rb_root *rb_new(); 34 | /*插入*/ 35 | int rb_insert(key_t key, data_t data, rb_root *root); 36 | /*搜索*/ 37 | rb_node *rb_search(key_t key, rb_root*root); 38 | /*删除*/ 39 | void rb_delete(key_t key, rb_root*root); 40 | /*释放树*/ 41 | void rb_free(rb_root*root); 42 | /*遍历树*/ 43 | void rb_foreach(rb_root *root, TreeVisitFunc visitfunc); 44 | rb_node *rb_minkey(rb_root *root); 45 | 46 | 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif //__TREE_H__ -------------------------------------------------------------------------------- /jemalloc/src/extent_mmap.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_EXTENT_MMAP_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | 5 | #include "jemalloc/internal/assert.h" 6 | 7 | /******************************************************************************/ 8 | /* Data. */ 9 | 10 | bool opt_retain = 11 | #ifdef JEMALLOC_RETAIN 12 | true 13 | #else 14 | false 15 | #endif 16 | ; 17 | 18 | /******************************************************************************/ 19 | 20 | void * 21 | extent_alloc_mmap(void *new_addr, size_t size, size_t alignment, bool *zero, 22 | bool *commit) { 23 | void *ret = pages_map(new_addr, size, ALIGNMENT_CEILING(alignment, 24 | PAGE), commit); 25 | if (ret == NULL) { 26 | return NULL; 27 | } 28 | assert(ret != NULL); 29 | if (*commit) { 30 | *zero = true; 31 | } 32 | return ret; 33 | } 34 | 35 | bool 36 | extent_dalloc_mmap(void *addr, size_t size) { 37 | if (!opt_retain) { 38 | pages_unmap(addr, size); 39 | } 40 | return opt_retain; 41 | } 42 | -------------------------------------------------------------------------------- /vs/watchdog/watchdog.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(SolutionDir)..\bin\$(Platform)\$(Configuration)\znet.exe 5 | WindowsLocalDebugger 6 | config.lua 7 | $(SolutionDir)..\tool 8 | 9 | 10 | $(SolutionDir)..\bin\$(Platform)\$(Configuration)\znet.exe 11 | WindowsLocalDebugger 12 | config.lua 13 | $(SolutionDir)..\tool 14 | 15 | -------------------------------------------------------------------------------- /lua/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /src/skynet_module.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MODULE_H 2 | #define SKYNET_MODULE_H 3 | 4 | struct skynet_context; 5 | 6 | typedef void * (*skynet_dl_create)(void); 7 | typedef int (*skynet_dl_init)(void * inst, struct skynet_context *, const char * parm); 8 | typedef void (*skynet_dl_release)(void * inst); 9 | typedef void (*skynet_dl_signal)(void * inst, int signal); 10 | 11 | struct skynet_module { 12 | const char * name; 13 | void * module; 14 | skynet_dl_create create; 15 | skynet_dl_init init; 16 | skynet_dl_release release; 17 | skynet_dl_signal signal; 18 | }; 19 | 20 | void skynet_module_insert(struct skynet_module *mod); 21 | struct skynet_module * skynet_module_query(const char * name); 22 | void * skynet_module_instance_create(struct skynet_module *); 23 | int skynet_module_instance_init(struct skynet_module *, void * inst, struct skynet_context *ctx, const char * parm); 24 | void skynet_module_instance_release(struct skynet_module *, void *inst); 25 | void skynet_module_instance_signal(struct skynet_module *, void *inst, int signal); 26 | 27 | void skynet_module_init(const char *path); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc_rename.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Name mangling for public symbols is controlled by --with-mangling and 3 | * --with-jemalloc-prefix. With default settings the je_ prefix is stripped by 4 | * these macro definitions. 5 | */ 6 | #ifndef JEMALLOC_NO_RENAME 7 | # define je_aligned_alloc je_aligned_alloc 8 | # define je_calloc je_calloc 9 | # define je_dallocx je_dallocx 10 | # define je_free je_free 11 | # define je_mallctl je_mallctl 12 | # define je_mallctlbymib je_mallctlbymib 13 | # define je_mallctlnametomib je_mallctlnametomib 14 | # define je_malloc je_malloc 15 | # define je_malloc_conf je_malloc_conf 16 | # define je_malloc_message je_malloc_message 17 | # define je_malloc_stats_print je_malloc_stats_print 18 | # define je_malloc_usable_size je_malloc_usable_size 19 | # define je_mallocx je_mallocx 20 | # define je_nallocx je_nallocx 21 | # define je_posix_memalign je_posix_memalign 22 | # define je_rallocx je_rallocx 23 | # define je_realloc je_realloc 24 | # define je_sallocx je_sallocx 25 | # define je_sdallocx je_sdallocx 26 | # define je_xallocx je_xallocx 27 | #endif 28 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/witness_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_WITNESS_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_WITNESS_EXTERNS_H 3 | 4 | void witness_init(witness_t *witness, const char *name, witness_rank_t rank, 5 | witness_comp_t *comp, void *opaque); 6 | 7 | typedef void (witness_lock_error_t)(const witness_list_t *, const witness_t *); 8 | extern witness_lock_error_t *JET_MUTABLE witness_lock_error; 9 | 10 | typedef void (witness_owner_error_t)(const witness_t *); 11 | extern witness_owner_error_t *JET_MUTABLE witness_owner_error; 12 | 13 | typedef void (witness_not_owner_error_t)(const witness_t *); 14 | extern witness_not_owner_error_t *JET_MUTABLE witness_not_owner_error; 15 | 16 | typedef void (witness_depth_error_t)(const witness_list_t *, 17 | witness_rank_t rank_inclusive, unsigned depth); 18 | extern witness_depth_error_t *JET_MUTABLE witness_depth_error; 19 | 20 | void witnesses_cleanup(tsd_t *tsd); 21 | void witness_prefork(tsd_t *tsd); 22 | void witness_postfork_parent(tsd_t *tsd); 23 | void witness_postfork_child(tsd_t *tsd); 24 | 25 | #endif /* JEMALLOC_INTERNAL_WITNESS_EXTERNS_H */ 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 冉朋 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/jemalloc_internal_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_MACROS_H 2 | #define JEMALLOC_INTERNAL_MACROS_H 3 | 4 | #ifdef JEMALLOC_DEBUG 5 | # define JEMALLOC_ALWAYS_INLINE static inline 6 | #else 7 | # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline 8 | #endif 9 | #ifdef _MSC_VER 10 | # define inline _inline 11 | #endif 12 | 13 | #define UNUSED JEMALLOC_ATTR(unused) 14 | 15 | #define ZU(z) ((size_t)z) 16 | #define ZD(z) ((ssize_t)z) 17 | #define QU(q) ((uint64_t)q) 18 | #define QD(q) ((int64_t)q) 19 | 20 | #define KZU(z) ZU(z##ULL) 21 | #define KZD(z) ZD(z##LL) 22 | #define KQU(q) QU(q##ULL) 23 | #define KQD(q) QI(q##LL) 24 | 25 | #ifndef __DECONST 26 | # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 27 | #endif 28 | 29 | #if !defined(JEMALLOC_HAS_RESTRICT) || defined(__cplusplus) 30 | # define restrict 31 | #endif 32 | 33 | /* Various function pointers are statick and immutable except during testing. */ 34 | #ifdef JEMALLOC_JET 35 | # define JET_MUTABLE 36 | #else 37 | # define JET_MUTABLE const 38 | #endif 39 | 40 | #endif /* JEMALLOC_INTERNAL_MACROS_H */ 41 | -------------------------------------------------------------------------------- /duktape/duk_hnatfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Heap native function representation. 3 | */ 4 | 5 | #if !defined(DUK_HNATFUNC_H_INCLUDED) 6 | #define DUK_HNATFUNC_H_INCLUDED 7 | 8 | #define DUK_HNATFUNC_NARGS_VARARGS ((duk_int16_t) -1) 9 | #define DUK_HNATFUNC_NARGS_MAX ((duk_int16_t) 0x7fff) 10 | 11 | struct duk_hnatfunc { 12 | /* shared object part */ 13 | duk_hobject obj; 14 | 15 | duk_c_function func; 16 | duk_int16_t nargs; 17 | duk_int16_t magic; 18 | 19 | /* The 'magic' field allows an opaque 16-bit field to be accessed by the 20 | * Duktape/C function. This allows, for instance, the same native function 21 | * to be used for a set of very similar functions, with the 'magic' field 22 | * providing the necessary non-argument flags / values to guide the behavior 23 | * of the native function. The value is signed on purpose: it is easier to 24 | * convert a signed value to unsigned (simply AND with 0xffff) than vice 25 | * versa. 26 | * 27 | * Note: cannot place nargs/magic into the heaphdr flags, because 28 | * duk_hobject takes almost all flags already (and needs the spare). 29 | */ 30 | }; 31 | 32 | #endif /* DUK_HNATFUNC_H_INCLUDED */ 33 | -------------------------------------------------------------------------------- /duktape/duk_util_bitencoder.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Bitstream encoder. 3 | */ 4 | 5 | #include "duk_internal.h" 6 | 7 | DUK_INTERNAL void duk_be_encode(duk_bitencoder_ctx *ctx, duk_uint32_t data, duk_small_int_t bits) { 8 | duk_uint8_t tmp; 9 | 10 | DUK_ASSERT(ctx != NULL); 11 | DUK_ASSERT(ctx->currbits < 8); 12 | 13 | /* This limitation would be fixable but adds unnecessary complexity. */ 14 | DUK_ASSERT(bits >= 1 && bits <= 24); 15 | 16 | ctx->currval = (ctx->currval << bits) | data; 17 | ctx->currbits += bits; 18 | 19 | while (ctx->currbits >= 8) { 20 | if (ctx->offset < ctx->length) { 21 | tmp = (duk_uint8_t) ((ctx->currval >> (ctx->currbits - 8)) & 0xff); 22 | ctx->data[ctx->offset++] = tmp; 23 | } else { 24 | /* If buffer has been exhausted, truncate bitstream */ 25 | ctx->truncated = 1; 26 | } 27 | 28 | ctx->currbits -= 8; 29 | } 30 | } 31 | 32 | DUK_INTERNAL void duk_be_finish(duk_bitencoder_ctx *ctx) { 33 | duk_small_int_t npad; 34 | 35 | DUK_ASSERT(ctx != NULL); 36 | DUK_ASSERT(ctx->currbits < 8); 37 | 38 | npad = (duk_small_int_t) (8 - ctx->currbits); 39 | if (npad > 0) { 40 | duk_be_encode(ctx, 0, npad); 41 | } 42 | DUK_ASSERT(ctx->currbits == 0); 43 | } 44 | -------------------------------------------------------------------------------- /tool/zero/lualib/loader.lua: -------------------------------------------------------------------------------- 1 | local args = {} 2 | for word in string.gmatch(..., "%S+") do 3 | table.insert(args, word) 4 | end 5 | 6 | SERVICE_NAME = args[1] 7 | 8 | local main, pattern 9 | 10 | local err = {} 11 | for pat in string.gmatch(LUA_SERVICE, "([^;]+);*") do 12 | local filename = string.gsub(pat, "?", SERVICE_NAME) 13 | local f, msg = loadfile(filename) 14 | if not f then 15 | table.insert(err, msg) 16 | else 17 | pattern = pat 18 | main = f 19 | break 20 | end 21 | end 22 | 23 | if not main then 24 | error(table.concat(err, "\n")) 25 | end 26 | 27 | LUA_SERVICE = nil 28 | package.path , LUA_PATH = LUA_PATH 29 | package.cpath , LUA_CPATH = LUA_CPATH 30 | 31 | local service_path = string.match(pattern, "(.*/)[^/?]+$") 32 | 33 | if service_path then 34 | service_path = string.gsub(service_path, "?", args[1]) 35 | package.path = service_path .. "?.lua;" .. package.path 36 | SERVICE_PATH = service_path 37 | else 38 | local p = string.match(pattern, "(.*/).+$") 39 | SERVICE_PATH = p 40 | end 41 | 42 | if LUA_PRELOAD then 43 | local f = assert(loadfile(LUA_PRELOAD)) 44 | f(table.unpack(args)) 45 | LUA_PRELOAD = nil 46 | end 47 | 48 | main(select(2, table.unpack(args))) 49 | -------------------------------------------------------------------------------- /tool/zero/lualib/md5.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | -- Modify version from https://github.com/keplerproject/md5 3 | ---------------------------------------------------------------------------- 4 | 5 | local core = require "md5.core" 6 | 7 | ---------------------------------------------------------------------------- 8 | -- @param k String with original message. 9 | -- @return String with the md5 hash value converted to hexadecimal digits 10 | 11 | function core.sumhexa (k) 12 | k = core.sum(k) 13 | return (string.gsub(k, ".", function (c) 14 | return string.format("%02x", string.byte(c)) 15 | end)) 16 | end 17 | 18 | local function get_ipad(c) 19 | return string.char(c:byte() ~ 0x36) 20 | end 21 | 22 | local function get_opad(c) 23 | return string.char(c:byte() ~ 0x5c) 24 | end 25 | 26 | function core.hmacmd5(data,key) 27 | if #key>64 then 28 | key=core.sum(key) 29 | key=key:sub(1,16) 30 | end 31 | local ipad_s=key:gsub(".", get_ipad)..string.rep("6",64-#key) 32 | local opad_s=key:gsub(".", get_opad)..string.rep("\\",64-#key) 33 | local istr=core.sum(ipad_s..data) 34 | local ostr=core.sumhexa(opad_s..istr) 35 | return ostr 36 | end 37 | 38 | return core 39 | -------------------------------------------------------------------------------- /duktape/duk_alloc_default.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Default allocation functions. 3 | * 4 | * Assumes behavior such as malloc allowing zero size, yielding 5 | * a NULL or a unique pointer which is a no-op for free. 6 | */ 7 | 8 | #include "duk_internal.h" 9 | 10 | #if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS) 11 | DUK_INTERNAL void *duk_default_alloc_function(void *udata, duk_size_t size) { 12 | void *res; 13 | DUK_UNREF(udata); 14 | res = DUK_ANSI_MALLOC(size); 15 | DUK_DDD(DUK_DDDPRINT("default alloc function: %lu -> %p", 16 | (unsigned long) size, (void *) res)); 17 | return res; 18 | } 19 | 20 | DUK_INTERNAL void *duk_default_realloc_function(void *udata, void *ptr, duk_size_t newsize) { 21 | void *res; 22 | DUK_UNREF(udata); 23 | res = DUK_ANSI_REALLOC(ptr, newsize); 24 | DUK_DDD(DUK_DDDPRINT("default realloc function: %p %lu -> %p", 25 | (void *) ptr, (unsigned long) newsize, (void *) res)); 26 | return res; 27 | } 28 | 29 | DUK_INTERNAL void duk_default_free_function(void *udata, void *ptr) { 30 | DUK_DDD(DUK_DDDPRINT("default free function: %p", (void *) ptr)); 31 | DUK_UNREF(udata); 32 | DUK_ANSI_FREE(ptr); 33 | } 34 | #endif /* DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS */ 35 | -------------------------------------------------------------------------------- /src/skynet_monitor.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | 3 | #include "skynet_monitor.h" 4 | #include "skynet_server.h" 5 | #include "skynet.h" 6 | #include "atomic.h" 7 | 8 | #include 9 | #include 10 | 11 | struct skynet_monitor { 12 | int version; 13 | int check_version; 14 | uint32_t source; 15 | uint32_t destination; 16 | }; 17 | 18 | struct skynet_monitor * 19 | skynet_monitor_new() { 20 | struct skynet_monitor * ret = skynet_malloc(sizeof(*ret)); 21 | memset(ret, 0, sizeof(*ret)); 22 | return ret; 23 | } 24 | 25 | void 26 | skynet_monitor_delete(struct skynet_monitor *sm) { 27 | skynet_free(sm); 28 | } 29 | 30 | void 31 | skynet_monitor_trigger(struct skynet_monitor *sm, uint32_t source, uint32_t destination) { 32 | sm->source = source; 33 | sm->destination = destination; 34 | ATOM_INC(&sm->version); 35 | } 36 | 37 | void 38 | skynet_monitor_check(struct skynet_monitor *sm) { 39 | if (sm->version == sm->check_version) { 40 | if (sm->destination) { 41 | skynet_context_endless(sm->destination); 42 | skynet_error(NULL, "A message from [ :%08x ] to [ :%08x ] maybe in an endless loop (version = %d)", sm->source , sm->destination, sm->version); 43 | } 44 | } else { 45 | sm->check_version = sm->version; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/skynet_server.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_SERVER_H 2 | #define SKYNET_SERVER_H 3 | 4 | #include 5 | #include 6 | 7 | struct skynet_context; 8 | struct skynet_message; 9 | struct skynet_monitor; 10 | 11 | struct skynet_context * skynet_context_new(const char * name, const char * parm); 12 | void skynet_context_grab(struct skynet_context *); 13 | void skynet_context_reserve(struct skynet_context *ctx); 14 | struct skynet_context * skynet_context_release(struct skynet_context *); 15 | uint32_t skynet_context_handle(struct skynet_context *); 16 | int skynet_context_push(uint32_t handle, struct skynet_message *message); 17 | void skynet_context_send(struct skynet_context * context, void * msg, size_t sz, uint32_t source, int type, int session); 18 | struct message_queue * skynet_context_message_dispatch(struct skynet_monitor *, struct message_queue *, int weight); // return next queue 19 | int skynet_context_total(); 20 | void skynet_context_dispatchall(struct skynet_context * context); // for skynet_error output before exit 21 | 22 | void skynet_context_endless(uint32_t handle); // for monitor 23 | 24 | void skynet_globalinit(void); 25 | void skynet_globalexit(void); 26 | void skynet_initthread(int m); 27 | 28 | void skynet_profile_enable(int enable); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /libuv/src/win/detect-wakeup.c: -------------------------------------------------------------------------------- 1 | #include "uv.h" 2 | #include "internal.h" 3 | #include "winapi.h" 4 | 5 | static void uv__register_system_resume_callback(void); 6 | 7 | void uv__init_detect_system_wakeup(void) { 8 | /* Try registering system power event callback. This is the cleanest 9 | * method, but it will only work on Win8 and above. 10 | */ 11 | uv__register_system_resume_callback(); 12 | } 13 | 14 | static ULONG CALLBACK uv__system_resume_callback(PVOID Context, 15 | ULONG Type, 16 | PVOID Setting) { 17 | if (Type == PBT_APMRESUMESUSPEND || Type == PBT_APMRESUMEAUTOMATIC) 18 | uv__wake_all_loops(); 19 | 20 | return 0; 21 | } 22 | 23 | static void uv__register_system_resume_callback(void) { 24 | _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS recipient; 25 | _HPOWERNOTIFY registration_handle; 26 | 27 | if (pPowerRegisterSuspendResumeNotification == NULL) 28 | return; 29 | 30 | recipient.Callback = uv__system_resume_callback; 31 | recipient.Context = NULL; 32 | (*pPowerRegisterSuspendResumeNotification)(DEVICE_NOTIFY_CALLBACK, 33 | &recipient, 34 | ®istration_handle); 35 | } 36 | -------------------------------------------------------------------------------- /src/skynet_mq.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MESSAGE_QUEUE_H 2 | #define SKYNET_MESSAGE_QUEUE_H 3 | 4 | #include 5 | #include 6 | 7 | struct skynet_message { 8 | uint32_t source; 9 | int session; 10 | void * data; 11 | size_t sz; 12 | }; 13 | 14 | // type is encoding in skynet_message.sz high 8bit 15 | #define MESSAGE_TYPE_MASK (SIZE_MAX >> 8) 16 | #define MESSAGE_TYPE_SHIFT ((sizeof(size_t)-1) * 8) 17 | 18 | struct message_queue; 19 | 20 | void skynet_globalmq_push(struct message_queue * queue); 21 | struct message_queue * skynet_globalmq_pop(void); 22 | 23 | struct message_queue * skynet_mq_create(uint32_t handle); 24 | void skynet_mq_mark_release(struct message_queue *q); 25 | 26 | typedef void (*message_drop)(struct skynet_message *, void *); 27 | 28 | void skynet_mq_release(struct message_queue *q, message_drop drop_func, void *ud); 29 | uint32_t skynet_mq_handle(struct message_queue *); 30 | 31 | // 0 for success 32 | int skynet_mq_pop(struct message_queue *q, struct skynet_message *message); 33 | void skynet_mq_push(struct message_queue *q, struct skynet_message *message); 34 | 35 | // return the length of message queue, for debug 36 | int skynet_mq_length(struct message_queue *q); 37 | int skynet_mq_overload(struct message_queue *q); 38 | 39 | void skynet_mq_init(); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libuv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(uv) 2 | include_directories(./include ./src) 3 | aux_source_directory(./src src) 4 | add_library(uv STATIC ${src} 5 | ./src/unix/async.c 6 | ./src/unix/atomic-ops.h 7 | ./src/unix/core.c 8 | ./src/unix/dl.c 9 | ./src/unix/fs.c 10 | ./src/unix/getaddrinfo.c 11 | ./src/unix/getnameinfo.c 12 | ./src/unix/internal.h 13 | ./src/unix/loop-watcher.c 14 | ./src/unix/loop.c 15 | ./src/unix/pipe.c 16 | ./src/unix/poll.c 17 | ./src/unix/process.c 18 | ./src/unix/signal.c 19 | ./src/unix/spinlock.h 20 | ./src/unix/stream.c 21 | ./src/unix/tcp.c 22 | ./src/unix/thread.c 23 | ./src/unix/timer.c 24 | ./src/unix/tty.c 25 | ./src/unix/udp.c 26 | ./src/unix/linux-core.c 27 | ./src/unix/linux-inotify.c 28 | ./src/unix/linux-syscalls.c 29 | ./src/unix/proctitle.c 30 | ) 31 | set_target_properties(uv PROPERTIES output_name "uv") 32 | -------------------------------------------------------------------------------- /libuv/src/win/req.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | 24 | #include "uv.h" 25 | #include "internal.h" 26 | -------------------------------------------------------------------------------- /jemalloc/include/msvc_compat/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef strings_h 2 | #define strings_h 3 | 4 | /* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided 5 | * for both */ 6 | #ifdef _MSC_VER 7 | # include 8 | # pragma intrinsic(_BitScanForward) 9 | static __forceinline int ffsl(long x) { 10 | unsigned long i; 11 | 12 | if (_BitScanForward(&i, x)) { 13 | return i + 1; 14 | } 15 | return 0; 16 | } 17 | 18 | static __forceinline int ffs(int x) { 19 | return ffsl(x); 20 | } 21 | 22 | # ifdef _M_X64 23 | # pragma intrinsic(_BitScanForward64) 24 | # endif 25 | 26 | static __forceinline int ffsll(unsigned __int64 x) { 27 | unsigned long i; 28 | #ifdef _M_X64 29 | if (_BitScanForward64(&i, x)) { 30 | return i + 1; 31 | } 32 | return 0; 33 | #else 34 | // Fallback for 32-bit build where 64-bit version not available 35 | // assuming little endian 36 | union { 37 | unsigned __int64 ll; 38 | unsigned long l[2]; 39 | } s; 40 | 41 | s.ll = x; 42 | 43 | if (_BitScanForward(&i, s.l[0])) { 44 | return i + 1; 45 | } else if(_BitScanForward(&i, s.l[1])) { 46 | return i + 33; 47 | } 48 | return 0; 49 | #endif 50 | } 51 | 52 | #else 53 | # define ffsll(x) __builtin_ffsll(x) 54 | # define ffsl(x) __builtin_ffsl(x) 55 | # define ffs(x) __builtin_ffs(x) 56 | #endif 57 | 58 | #endif /* strings_h */ 59 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/nstime.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_NSTIME_H 2 | #define JEMALLOC_INTERNAL_NSTIME_H 3 | 4 | /* Maximum supported number of seconds (~584 years). */ 5 | #define NSTIME_SEC_MAX KQU(18446744072) 6 | #define NSTIME_ZERO_INITIALIZER {0} 7 | 8 | typedef struct { 9 | uint64_t ns; 10 | } nstime_t; 11 | 12 | void nstime_init(nstime_t *time, uint64_t ns); 13 | void nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec); 14 | uint64_t nstime_ns(const nstime_t *time); 15 | uint64_t nstime_sec(const nstime_t *time); 16 | uint64_t nstime_msec(const nstime_t *time); 17 | uint64_t nstime_nsec(const nstime_t *time); 18 | void nstime_copy(nstime_t *time, const nstime_t *source); 19 | int nstime_compare(const nstime_t *a, const nstime_t *b); 20 | void nstime_add(nstime_t *time, const nstime_t *addend); 21 | void nstime_subtract(nstime_t *time, const nstime_t *subtrahend); 22 | void nstime_imultiply(nstime_t *time, uint64_t multiplier); 23 | void nstime_idivide(nstime_t *time, uint64_t divisor); 24 | uint64_t nstime_divide(const nstime_t *time, const nstime_t *divisor); 25 | 26 | typedef bool (nstime_monotonic_t)(void); 27 | extern nstime_monotonic_t *JET_MUTABLE nstime_monotonic; 28 | 29 | typedef bool (nstime_update_t)(nstime_t *); 30 | extern nstime_update_t *JET_MUTABLE nstime_update; 31 | 32 | #endif /* JEMALLOC_INTERNAL_NSTIME_H */ 33 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc_defs.h.in: -------------------------------------------------------------------------------- 1 | /* Defined if __attribute__((...)) syntax is supported. */ 2 | #undef JEMALLOC_HAVE_ATTR 3 | 4 | /* Defined if alloc_size attribute is supported. */ 5 | #undef JEMALLOC_HAVE_ATTR_ALLOC_SIZE 6 | 7 | /* Defined if format(gnu_printf, ...) attribute is supported. */ 8 | #undef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF 9 | 10 | /* Defined if format(printf, ...) attribute is supported. */ 11 | #undef JEMALLOC_HAVE_ATTR_FORMAT_PRINTF 12 | 13 | /* 14 | * Define overrides for non-standard allocator-related functions if they are 15 | * present on the system. 16 | */ 17 | #undef JEMALLOC_OVERRIDE_MEMALIGN 18 | #undef JEMALLOC_OVERRIDE_VALLOC 19 | 20 | /* 21 | * At least Linux omits the "const" in: 22 | * 23 | * size_t malloc_usable_size(const void *ptr); 24 | * 25 | * Match the operating system's prototype. 26 | */ 27 | #undef JEMALLOC_USABLE_SIZE_CONST 28 | 29 | /* 30 | * If defined, specify throw() for the public function prototypes when compiling 31 | * with C++. The only justification for this is to match the prototypes that 32 | * glibc defines. 33 | */ 34 | #undef JEMALLOC_USE_CXX_THROW 35 | 36 | #ifdef _MSC_VER 37 | # ifdef _WIN64 38 | # define LG_SIZEOF_PTR_WIN 3 39 | # else 40 | # define LG_SIZEOF_PTR_WIN 2 41 | # endif 42 | #endif 43 | 44 | /* sizeof(void *) == 2^LG_SIZEOF_PTR. */ 45 | #undef LG_SIZEOF_PTR 46 | -------------------------------------------------------------------------------- /library/darray.h: -------------------------------------------------------------------------------- 1 | #ifndef __DARRAY_H__ 2 | #define __DARRAY_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define DEFAULT_A_SIZE 10 11 | 12 | /**动态数组结构*/ 13 | typedef struct _DArray 14 | { 15 | int size; 16 | int count; 17 | void **data; 18 | 19 | }DArray; 20 | 21 | 22 | typedef void(*VisitFunc)(void *ctx, void *data); 23 | 24 | DArray *darray_create(); //创建动态数组 25 | static int darray_expand(DArray *darray, int needone); //增加指定数组的容量 26 | int darray_shrink(DArray *darray); //缩减指定数组的容量 27 | int darray_preappend(DArray *darray, void * data);//添加(头)元素 28 | int darray_append(DArray *darray, void * data); //添加(尾)元素 29 | int darray_insert(DArray *darray, int index, void * data); //插入元素 30 | int darray_delete(DArray *darray, int index); //删除元素 31 | int darray_len(DArray * darray); //数组长度 32 | int darray_find(DArray * darray, void * data); //查找成员第一次出现的索引 33 | int darray_isempty(DArray * darray); //数组是否为空 34 | void darray_empty(DArray * darray); //清空数组 35 | void *darray_getat(DArray * darray, int index); //取指定下标数据 36 | int darray_set_by_index(DArray *darray, int index, void *data);//替换数组指定位置的值 37 | int darray_foreach(DArray *darray, VisitFunc visitfunc, void *ctx);//遍历数组 38 | int darray_destroy(DArray *darray);//释放指定数组内存 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif //__CARRAY_H__ 45 | -------------------------------------------------------------------------------- /src/skynet_harbor.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | #include "skynet_harbor.h" 3 | #include "skynet_server.h" 4 | #include "skynet_mq.h" 5 | #include "skynet_handle.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | static struct skynet_context * REMOTE = 0; 12 | static unsigned int HARBOR = ~0; 13 | 14 | void 15 | skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session) { 16 | int type = rmsg->sz >> MESSAGE_TYPE_SHIFT; 17 | rmsg->sz &= MESSAGE_TYPE_MASK; 18 | assert(type != PTYPE_SYSTEM && type != PTYPE_HARBOR && REMOTE); 19 | skynet_context_send(REMOTE, rmsg, sizeof(*rmsg) , source, type , session); 20 | } 21 | 22 | int 23 | skynet_harbor_message_isremote(uint32_t handle) { 24 | assert(HARBOR != ~0); 25 | int h = (handle & ~HANDLE_MASK); 26 | return h != HARBOR && h !=0; 27 | } 28 | 29 | void 30 | skynet_harbor_init(int harbor) { 31 | HARBOR = (unsigned int)harbor << HANDLE_REMOTE_SHIFT; 32 | } 33 | 34 | void 35 | skynet_harbor_start(void *ctx) { 36 | // the HARBOR must be reserved to ensure the pointer is valid. 37 | // It will be released at last by calling skynet_harbor_exit 38 | skynet_context_reserve(ctx); 39 | REMOTE = ctx; 40 | } 41 | 42 | void 43 | skynet_harbor_exit() { 44 | struct skynet_context * ctx = REMOTE; 45 | REMOTE= NULL; 46 | if (ctx) { 47 | skynet_context_release(ctx); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/large_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_LARGE_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_LARGE_EXTERNS_H 3 | 4 | void *large_malloc(tsdn_t *tsdn, arena_t *arena, size_t usize, bool zero); 5 | void *large_palloc(tsdn_t *tsdn, arena_t *arena, size_t usize, size_t alignment, 6 | bool zero); 7 | bool large_ralloc_no_move(tsdn_t *tsdn, extent_t *extent, size_t usize_min, 8 | size_t usize_max, bool zero); 9 | void *large_ralloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent, size_t usize, 10 | size_t alignment, bool zero, tcache_t *tcache); 11 | 12 | typedef void (large_dalloc_junk_t)(void *, size_t); 13 | extern large_dalloc_junk_t *JET_MUTABLE large_dalloc_junk; 14 | 15 | typedef void (large_dalloc_maybe_junk_t)(void *, size_t); 16 | extern large_dalloc_maybe_junk_t *JET_MUTABLE large_dalloc_maybe_junk; 17 | 18 | void large_dalloc_prep_junked_locked(tsdn_t *tsdn, extent_t *extent); 19 | void large_dalloc_finish(tsdn_t *tsdn, extent_t *extent); 20 | void large_dalloc(tsdn_t *tsdn, extent_t *extent); 21 | size_t large_salloc(tsdn_t *tsdn, const extent_t *extent); 22 | prof_tctx_t *large_prof_tctx_get(tsdn_t *tsdn, const extent_t *extent); 23 | void large_prof_tctx_set(tsdn_t *tsdn, extent_t *extent, prof_tctx_t *tctx); 24 | void large_prof_tctx_reset(tsdn_t *tsdn, extent_t *extent); 25 | 26 | #endif /* JEMALLOC_INTERNAL_LARGE_EXTERNS_H */ 27 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/tsd_tls.h: -------------------------------------------------------------------------------- 1 | #ifdef JEMALLOC_INTERNAL_TSD_TLS_H 2 | #error This file should be included only once, by tsd.h. 3 | #endif 4 | #define JEMALLOC_INTERNAL_TSD_TLS_H 5 | 6 | extern __thread tsd_t tsd_tls; 7 | extern pthread_key_t tsd_tsd; 8 | extern bool tsd_booted; 9 | 10 | /* Initialization/cleanup. */ 11 | JEMALLOC_ALWAYS_INLINE bool 12 | tsd_boot0(void) { 13 | if (pthread_key_create(&tsd_tsd, &tsd_cleanup) != 0) { 14 | return true; 15 | } 16 | tsd_booted = true; 17 | return false; 18 | } 19 | 20 | JEMALLOC_ALWAYS_INLINE void 21 | tsd_boot1(void) { 22 | /* Do nothing. */ 23 | } 24 | 25 | JEMALLOC_ALWAYS_INLINE bool 26 | tsd_boot(void) { 27 | return tsd_boot0(); 28 | } 29 | 30 | JEMALLOC_ALWAYS_INLINE bool 31 | tsd_booted_get(void) { 32 | return tsd_booted; 33 | } 34 | 35 | JEMALLOC_ALWAYS_INLINE bool 36 | tsd_get_allocates(void) { 37 | return false; 38 | } 39 | 40 | /* Get/set. */ 41 | JEMALLOC_ALWAYS_INLINE tsd_t * 42 | tsd_get(bool init) { 43 | assert(tsd_booted); 44 | return &tsd_tls; 45 | } 46 | 47 | JEMALLOC_ALWAYS_INLINE void 48 | tsd_set(tsd_t *val) { 49 | assert(tsd_booted); 50 | if (likely(&tsd_tls != val)) { 51 | tsd_tls = (*val); 52 | } 53 | if (pthread_setspecific(tsd_tsd, (void *)(&tsd_tls)) != 0) { 54 | malloc_write(": Error setting tsd.\n"); 55 | if (opt_abort) { 56 | abort(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/private_symbols.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Generate private_symbols[_jet].awk. 4 | # 5 | # Usage: private_symbols.sh * 6 | # 7 | # is typically "" or "_". 8 | 9 | sym_prefix=$1 10 | shift 11 | 12 | cat <' output. 35 | # 36 | # Handle lines like: 37 | # 0000000000000008 D opt_junk 38 | # 0000000000007574 T malloc_initialized 39 | (NF == 3 && $2 ~ /^[ABCDGRSTVW]$/ && !($3 in exported_symbols) && $3 ~ /^[A-Za-z0-9_]+$/) { 40 | print substr($3, 1+length(sym_prefix), length($3)-length(sym_prefix)) 41 | } 42 | 43 | # Process 'dumpbin /SYMBOLS ' output. 44 | # 45 | # Handle lines like: 46 | # 353 00008098 SECT4 notype External | opt_junk 47 | # 3F1 00000000 SECT7 notype () External | malloc_initialized 48 | ($3 ~ /^SECT[0-9]+/ && $(NF-2) == "External" && !($NF in exported_symbols)) { 49 | print $NF 50 | } 51 | EOF 52 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/ticker.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_TICKER_H 2 | #define JEMALLOC_INTERNAL_TICKER_H 3 | 4 | #include "jemalloc/internal/util.h" 5 | 6 | /** 7 | * A ticker makes it easy to count-down events until some limit. You 8 | * ticker_init the ticker to trigger every nticks events. You then notify it 9 | * that an event has occurred with calls to ticker_tick (or that nticks events 10 | * have occurred with a call to ticker_ticks), which will return true (and reset 11 | * the counter) if the countdown hit zero. 12 | */ 13 | 14 | typedef struct { 15 | int32_t tick; 16 | int32_t nticks; 17 | } ticker_t; 18 | 19 | static inline void 20 | ticker_init(ticker_t *ticker, int32_t nticks) { 21 | ticker->tick = nticks; 22 | ticker->nticks = nticks; 23 | } 24 | 25 | static inline void 26 | ticker_copy(ticker_t *ticker, const ticker_t *other) { 27 | *ticker = *other; 28 | } 29 | 30 | static inline int32_t 31 | ticker_read(const ticker_t *ticker) { 32 | return ticker->tick; 33 | } 34 | 35 | static inline bool 36 | ticker_ticks(ticker_t *ticker, int32_t nticks) { 37 | if (unlikely(ticker->tick < nticks)) { 38 | ticker->tick = ticker->nticks; 39 | return true; 40 | } 41 | ticker->tick -= nticks; 42 | return(false); 43 | } 44 | 45 | static inline bool 46 | ticker_tick(ticker_t *ticker) { 47 | return ticker_ticks(ticker, 1); 48 | } 49 | 50 | #endif /* JEMALLOC_INTERNAL_TICKER_H */ 51 | -------------------------------------------------------------------------------- /tool/zero/service/bootstrap.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local harbor = require "skynet.harbor" 3 | require "skynet.manager" -- import skynet.launch, ... 4 | local memory = require "memory" 5 | 6 | skynet.start(function() 7 | local sharestring = tonumber(skynet.getenv "sharestring" or 4096) 8 | memory.ssexpand(sharestring) 9 | 10 | local standalone = skynet.getenv "standalone" 11 | 12 | local launcher = assert(skynet.launch("snlua","launcher")) 13 | skynet.name(".launcher", launcher) 14 | 15 | local harbor_id = tonumber(skynet.getenv "harbor" or 0) 16 | if harbor_id == 0 then 17 | assert(standalone == nil) 18 | standalone = true 19 | skynet.setenv("standalone", "true") 20 | 21 | local ok, slave = pcall(skynet.newservice, "cdummy") 22 | if not ok then 23 | skynet.abort() 24 | end 25 | skynet.name(".cslave", slave) 26 | 27 | else 28 | if standalone then 29 | if not pcall(skynet.newservice,"cmaster") then 30 | skynet.abort() 31 | end 32 | end 33 | 34 | local ok, slave = pcall(skynet.newservice, "cslave") 35 | if not ok then 36 | skynet.abort() 37 | end 38 | skynet.name(".cslave", slave) 39 | end 40 | 41 | if standalone then 42 | local datacenter = skynet.newservice "datacenterd" 43 | skynet.name("DATACENTER", datacenter) 44 | end 45 | skynet.newservice "service_mgr" 46 | pcall(skynet.newservice,skynet.getenv "start" or "main") 47 | skynet.exit() 48 | end) 49 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/arena_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_ARENA_TYPES_H 2 | #define JEMALLOC_INTERNAL_ARENA_TYPES_H 3 | 4 | #define LARGE_MINCLASS (ZU(1) << LG_LARGE_MINCLASS) 5 | 6 | /* Maximum number of regions in one slab. */ 7 | #define LG_SLAB_MAXREGS (LG_PAGE - LG_TINY_MIN) 8 | #define SLAB_MAXREGS (1U << LG_SLAB_MAXREGS) 9 | 10 | /* Default decay times in seconds. */ 11 | #define DIRTY_DECAY_TIME_DEFAULT 10 12 | #define MUZZY_DECAY_TIME_DEFAULT 10 13 | /* Number of event ticks between time checks. */ 14 | #define DECAY_NTICKS_PER_UPDATE 1000 15 | 16 | typedef struct arena_slab_data_s arena_slab_data_t; 17 | typedef struct arena_bin_info_s arena_bin_info_t; 18 | typedef struct arena_decay_s arena_decay_t; 19 | typedef struct arena_bin_s arena_bin_t; 20 | typedef struct arena_s arena_t; 21 | typedef struct arena_tdata_s arena_tdata_t; 22 | typedef struct alloc_ctx_s alloc_ctx_t; 23 | 24 | typedef enum { 25 | percpu_arena_disabled = 0, 26 | percpu_arena = 1, 27 | per_phycpu_arena = 2, /* i.e. hyper threads share arena. */ 28 | 29 | percpu_arena_mode_limit = 3 30 | } percpu_arena_mode_t; 31 | 32 | #ifdef JEMALLOC_PERCPU_ARENA 33 | #define PERCPU_ARENA_MODE_DEFAULT percpu_arena 34 | #define OPT_PERCPU_ARENA_DEFAULT "percpu" 35 | #else 36 | #define PERCPU_ARENA_MODE_DEFAULT percpu_arena_disabled 37 | #define OPT_PERCPU_ARENA_DEFAULT "disabled" 38 | #endif 39 | 40 | #endif /* JEMALLOC_INTERNAL_ARENA_TYPES_H */ 41 | -------------------------------------------------------------------------------- /duktape/duk_hobject_misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Misc support functions 3 | */ 4 | 5 | #include "duk_internal.h" 6 | 7 | DUK_INTERNAL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *thr, duk_hobject *h, duk_hobject *p, duk_bool_t ignore_loop) { 8 | duk_uint_t sanity; 9 | 10 | DUK_ASSERT(thr != NULL); 11 | 12 | /* False if the object is NULL or the prototype 'p' is NULL. 13 | * In particular, false if both are NULL (don't compare equal). 14 | */ 15 | if (h == NULL || p == NULL) { 16 | return 0; 17 | } 18 | 19 | sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY; 20 | do { 21 | if (h == p) { 22 | return 1; 23 | } 24 | 25 | if (sanity-- == 0) { 26 | if (ignore_loop) { 27 | break; 28 | } else { 29 | DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); 30 | } 31 | } 32 | h = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h); 33 | } while (h); 34 | 35 | return 0; 36 | } 37 | 38 | DUK_INTERNAL void duk_hobject_set_prototype_updref(duk_hthread *thr, duk_hobject *h, duk_hobject *p) { 39 | #if defined(DUK_USE_REFERENCE_COUNTING) 40 | duk_hobject *tmp; 41 | 42 | DUK_ASSERT(h); 43 | tmp = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h); 44 | DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p); 45 | DUK_HOBJECT_INCREF_ALLOWNULL(thr, p); /* avoid problems if p == h->prototype */ 46 | DUK_HOBJECT_DECREF_ALLOWNULL(thr, tmp); 47 | #else 48 | DUK_ASSERT(h); 49 | DUK_UNREF(thr); 50 | DUK_HOBJECT_SET_PROTOTYPE(thr->heap, h, p); 51 | #endif 52 | } 53 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/tsd_malloc_thread_cleanup.h: -------------------------------------------------------------------------------- 1 | #ifdef JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H 2 | #error This file should be included only once, by tsd.h. 3 | #endif 4 | #define JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H 5 | 6 | extern __thread tsd_t tsd_tls; 7 | extern __thread bool tsd_initialized; 8 | extern bool tsd_booted; 9 | 10 | /* Initialization/cleanup. */ 11 | JEMALLOC_ALWAYS_INLINE bool 12 | tsd_cleanup_wrapper(void) { 13 | if (tsd_initialized) { 14 | tsd_initialized = false; 15 | tsd_cleanup(&tsd_tls); 16 | } 17 | return tsd_initialized; 18 | } 19 | 20 | JEMALLOC_ALWAYS_INLINE bool 21 | tsd_boot0(void) { 22 | malloc_tsd_cleanup_register(&tsd_cleanup_wrapper); 23 | tsd_booted = true; 24 | return false; 25 | } 26 | 27 | JEMALLOC_ALWAYS_INLINE void 28 | tsd_boot1(void) { 29 | /* Do nothing. */ 30 | } 31 | 32 | JEMALLOC_ALWAYS_INLINE bool 33 | tsd_boot(void) { 34 | return tsd_boot0(); 35 | } 36 | 37 | JEMALLOC_ALWAYS_INLINE bool 38 | tsd_booted_get(void) { 39 | return tsd_booted; 40 | } 41 | 42 | JEMALLOC_ALWAYS_INLINE bool 43 | tsd_get_allocates(void) { 44 | return false; 45 | } 46 | 47 | /* Get/set. */ 48 | JEMALLOC_ALWAYS_INLINE tsd_t * 49 | tsd_get(bool init) { 50 | assert(tsd_booted); 51 | return &tsd_tls; 52 | } 53 | JEMALLOC_ALWAYS_INLINE void 54 | tsd_set(tsd_t *val) { 55 | assert(tsd_booted); 56 | if (likely(&tsd_tls != val)) { 57 | tsd_tls = (*val); 58 | } 59 | tsd_initialized = true; 60 | } 61 | -------------------------------------------------------------------------------- /src/atomic.h: -------------------------------------------------------------------------------- 1 | #ifndef _ZNET_ATOMIC_H 2 | #define _ZNET_ATOMIC_H 3 | #if !(defined(_WIN32) || defined(_WIN64)) 4 | 5 | #define ATOM_CAS(ptr, oval, nval) __sync_bool_compare_and_swap(ptr, oval, nval) 6 | #define ATOM_CAS16(ptr, oval, nval) __sync_bool_compare_and_swap(ptr, oval, nval) 7 | #define ATOM_CAS_POINTER(ptr, oval, nval) __sync_bool_compare_and_swap(ptr, oval, nval) 8 | #define ATOM_INC(ptr) __sync_add_and_fetch(ptr, 1) 9 | #define ATOM_FINC(ptr) __sync_fetch_and_add(ptr, 1) 10 | #define ATOM_DEC(ptr) __sync_sub_and_fetch(ptr, 1) 11 | #define ATOM_FDEC(ptr) __sync_fetch_and_sub(ptr, 1) 12 | #define ATOM_ADD(ptr,n) __sync_add_and_fetch(ptr, n) 13 | #define ATOM_SUB(ptr,n) __sync_sub_and_fetch(ptr, n) 14 | #define ATOM_AND(ptr,n) __sync_and_and_fetch(ptr, n) 15 | 16 | #else 17 | 18 | #include 19 | 20 | #define ATOM_INC(ptr) InterlockedIncrement((ptr)) 21 | #define ATOM_DEC(ptr) InterlockedDecrement((ptr)) 22 | #define ATOM_ADD(ptr,n) InterlockedAdd(ptr, n) 23 | #define ATOM_AND(ptr,n) InterlockedAnd(ptr,n) 24 | 25 | 26 | #define ATOM_CAS_POINTER(ptr, oval, nval) InterlockedCompareExchangePointer(ptr, nval, oval)//log 27 | #define ATOM_CAS(ptr, oval, nval) (InterlockedCompareExchange(ptr, nval, oval)!=nval) 28 | #define ATOM_CAS16(ptr, oval, nval) (InterlockedCompareExchange16(ptr, nval, oval)!=nval) 29 | #define ATOM_FINC(ptr) InterlockedIncrement((ptr)) 30 | #define ATOM_SUB(ptr,n) InterlockedExchangeAdd64 (ptr,-(ssize_t)(n)) 31 | 32 | #endif 33 | #endif 34 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc_mangle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | public_symbols_txt=$1 4 | symbol_prefix=$2 5 | 6 | cat < 2 | 3 | 4 | $(SolutionDir)..\tool 5 | WindowsLocalDebugger 6 | config.lua 7 | 8 | 9 | config.lua 10 | WindowsLocalDebugger 11 | $(SolutionDir)..\tool 12 | 13 | 14 | config.lua 15 | WindowsLocalDebugger 16 | $(SolutionDir)..\tool 17 | 18 | 19 | config.lua 20 | WindowsLocalDebugger 21 | $(SolutionDir)..\tool 22 | 23 | -------------------------------------------------------------------------------- /libuv/include/uv-os390.h: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_MVS_H 23 | #define UV_MVS_H 24 | 25 | #define UV_PLATFORM_SEM_T int 26 | 27 | #define UV_PLATFORM_LOOP_FIELDS \ 28 | void* ep; \ 29 | 30 | #endif /* UV_MVS_H */ 31 | -------------------------------------------------------------------------------- /duktape/duk_henv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Environment object representation. 3 | */ 4 | 5 | #if !defined(DUK_HENV_H_INCLUDED) 6 | #define DUK_HENV_H_INCLUDED 7 | 8 | #define DUK_ASSERT_HDECENV_VALID(h) do { \ 9 | DUK_ASSERT((h) != NULL); \ 10 | DUK_ASSERT(DUK_HOBJECT_IS_DECENV((duk_hobject *) (h))); \ 11 | DUK_ASSERT((h)->thread == NULL || (h)->varmap != NULL); \ 12 | } while (0) 13 | 14 | #define DUK_ASSERT_HOBJENV_VALID(h) do { \ 15 | DUK_ASSERT((h) != NULL); \ 16 | DUK_ASSERT(DUK_HOBJECT_IS_OBJENV((duk_hobject *) (h))); \ 17 | DUK_ASSERT((h)->target != NULL); \ 18 | DUK_ASSERT((h)->has_this == 0 || (h)->has_this == 1); \ 19 | } while (0) 20 | 21 | struct duk_hdecenv { 22 | /* Shared object part. */ 23 | duk_hobject obj; 24 | 25 | /* These control variables provide enough information to access live 26 | * variables for a closure that is still open. If thread == NULL, 27 | * the record is closed and the identifiers are in the property table. 28 | */ 29 | duk_hthread *thread; 30 | duk_hobject *varmap; 31 | duk_size_t regbase; 32 | }; 33 | 34 | struct duk_hobjenv { 35 | /* Shared object part. */ 36 | duk_hobject obj; 37 | 38 | /* Target object and 'this' binding for object binding. */ 39 | duk_hobject *target; 40 | 41 | /* The 'target' object is used as a this binding in only some object 42 | * environments. For example, the global environment does not provide 43 | * a this binding, but a with statement does. 44 | */ 45 | duk_bool_t has_this; 46 | }; 47 | 48 | #endif /* DUK_HENV_H_INCLUDED */ 49 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc_defs.h: -------------------------------------------------------------------------------- 1 | /* include/jemalloc/jemalloc_defs.h. Generated from jemalloc_defs.h.in by configure. */ 2 | /* Defined if __attribute__((...)) syntax is supported. */ 3 | /* #undef JEMALLOC_HAVE_ATTR */ 4 | 5 | /* Defined if alloc_size attribute is supported. */ 6 | /* #undef JEMALLOC_HAVE_ATTR_ALLOC_SIZE */ 7 | 8 | /* Defined if format(gnu_printf, ...) attribute is supported. */ 9 | /* #undef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF */ 10 | 11 | /* Defined if format(printf, ...) attribute is supported. */ 12 | /* #undef JEMALLOC_HAVE_ATTR_FORMAT_PRINTF */ 13 | 14 | /* 15 | * Define overrides for non-standard allocator-related functions if they are 16 | * present on the system. 17 | */ 18 | /* #undef JEMALLOC_OVERRIDE_MEMALIGN */ 19 | /* #undef JEMALLOC_OVERRIDE_VALLOC */ 20 | 21 | /* 22 | * At least Linux omits the "const" in: 23 | * 24 | * size_t malloc_usable_size(const void *ptr); 25 | * 26 | * Match the operating system's prototype. 27 | */ 28 | #define JEMALLOC_USABLE_SIZE_CONST const 29 | 30 | /* 31 | * If defined, specify throw() for the public function prototypes when compiling 32 | * with C++. The only justification for this is to match the prototypes that 33 | * glibc defines. 34 | */ 35 | /* #undef JEMALLOC_USE_CXX_THROW */ 36 | 37 | #ifdef _MSC_VER 38 | # ifdef _WIN64 39 | # define LG_SIZEOF_PTR_WIN 3 40 | # else 41 | # define LG_SIZEOF_PTR_WIN 2 42 | # endif 43 | #endif 44 | 45 | /* sizeof(void *) == 2^LG_SIZEOF_PTR. */ 46 | #define LG_SIZEOF_PTR LG_SIZEOF_PTR_WIN 47 | -------------------------------------------------------------------------------- /src/skynet_error.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | #include "skynet_handle.h" 3 | #include "skynet_mq.h" 4 | #include "skynet_server.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define LOG_MESSAGE_SIZE 256 12 | 13 | void 14 | skynet_error(struct skynet_context * context, const char *msg, ...) { 15 | static uint32_t logger = 0; 16 | if (logger == 0) { 17 | logger = skynet_handle_findname("logger"); 18 | } 19 | if (logger == 0) { 20 | return; 21 | } 22 | 23 | char tmp[LOG_MESSAGE_SIZE]; 24 | char *data = NULL; 25 | 26 | va_list ap; 27 | 28 | va_start(ap,msg); 29 | size_t len = vsnprintf(tmp, LOG_MESSAGE_SIZE, msg, ap); 30 | va_end(ap); 31 | if (len >=0 && len < LOG_MESSAGE_SIZE) { 32 | data = skynet_strdup(tmp); 33 | } else { 34 | int max_size = LOG_MESSAGE_SIZE; 35 | for (;;) { 36 | max_size *= 2; 37 | data = skynet_malloc(max_size); 38 | va_start(ap,msg); 39 | len = vsnprintf(data, max_size, msg, ap); 40 | va_end(ap); 41 | if (len < max_size) { 42 | break; 43 | } 44 | skynet_free(data); 45 | } 46 | } 47 | if (len < 0) { 48 | skynet_free(data); 49 | perror("vsnprintf error :"); 50 | return; 51 | } 52 | 53 | 54 | struct skynet_message smsg; 55 | if (context == NULL) { 56 | smsg.source = 0; 57 | } else { 58 | smsg.source = skynet_context_handle(context); 59 | } 60 | smsg.session = 0; 61 | smsg.data = data; 62 | smsg.sz = len | ((size_t)PTYPE_TEXT << MESSAGE_TYPE_SHIFT); 63 | skynet_context_push(logger, &smsg); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/lualib/lua-memory.c: -------------------------------------------------------------------------------- 1 | #define LUA_LIB 2 | 3 | #include 4 | #include 5 | 6 | #include "malloc_hook.h" 7 | #include "luashrtbl.h" 8 | 9 | static int 10 | ltotal(lua_State *L) { 11 | size_t t = malloc_used_memory(); 12 | lua_pushinteger(L, (lua_Integer)t); 13 | 14 | return 1; 15 | } 16 | 17 | static int 18 | lblock(lua_State *L) { 19 | size_t t = malloc_memory_block(); 20 | lua_pushinteger(L, (lua_Integer)t); 21 | 22 | return 1; 23 | } 24 | 25 | static int 26 | ldumpinfo(lua_State *L) { 27 | memory_info_dump(); 28 | 29 | return 0; 30 | } 31 | 32 | static int 33 | ldump(lua_State *L) { 34 | dump_c_mem(); 35 | 36 | return 0; 37 | } 38 | 39 | static int 40 | lexpandshrtbl(lua_State *L) { 41 | int n = luaL_checkinteger(L, 1); 42 | luaS_expandshr(n); 43 | return 0; 44 | } 45 | 46 | static int 47 | lcurrent(lua_State *L) { 48 | lua_pushinteger(L, malloc_current_memory()); 49 | return 1; 50 | } 51 | 52 | LUAMOD_API int 53 | luaopen_memory_(lua_State *L) { 54 | luaL_checkversion(L); 55 | 56 | luaL_Reg l[] = { 57 | { "total", ltotal }, 58 | { "block", lblock }, 59 | { "dumpinfo", ldumpinfo }, 60 | { "dump", ldump }, 61 | { "info", dump_mem_lua }, 62 | { "ssinfo", luaS_shrinfo }, 63 | { "ssexpand", lexpandshrtbl }, 64 | { "current", lcurrent }, 65 | { NULL, NULL }, 66 | }; 67 | 68 | luaL_newlib(L,l); 69 | 70 | return 1; 71 | } 72 | 73 | LUAMOD_API int luaopen_memory(lua_State *L) { 74 | luaL_requiref(L, "memory", luaopen_memory_, 1); 75 | lua_pop(L, 1); /* remove lib */ 76 | return 1; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/rtree_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_RTREE_STRUCTS_H 2 | #define JEMALLOC_INTERNAL_RTREE_STRUCTS_H 3 | 4 | #include "jemalloc/internal/atomic.h" 5 | 6 | struct rtree_node_elm_s { 7 | atomic_p_t child; /* (rtree_{node,leaf}_elm_t *) */ 8 | }; 9 | 10 | struct rtree_leaf_elm_s { 11 | #ifdef RTREE_LEAF_COMPACT 12 | /* 13 | * Single pointer-width field containing all three leaf element fields. 14 | * For example, on a 64-bit x64 system with 48 significant virtual 15 | * memory address bits, the index, extent, and slab fields are packed as 16 | * such: 17 | * 18 | * x: index 19 | * e: extent 20 | * b: slab 21 | * k: lock 22 | * 23 | * 00000000 xxxxxxxx eeeeeeee [...] eeeeeeee eeee00bk 24 | */ 25 | atomic_p_t le_bits; 26 | #else 27 | atomic_p_t le_extent; /* (extent_t *), lock in low bit */ 28 | atomic_u_t le_szind; /* (szind_t) */ 29 | atomic_b_t le_slab; /* (bool) */ 30 | #endif 31 | }; 32 | 33 | struct rtree_level_s { 34 | /* Number of key bits distinguished by this level. */ 35 | unsigned bits; 36 | /* 37 | * Cumulative number of key bits distinguished by traversing to 38 | * corresponding tree level. 39 | */ 40 | unsigned cumbits; 41 | }; 42 | 43 | struct rtree_s { 44 | malloc_mutex_t init_lock; 45 | /* Number of elements based on rtree_levels[0].bits. */ 46 | #if RTREE_HEIGHT > 1 47 | rtree_node_elm_t root[1U << (RTREE_NSB/RTREE_HEIGHT)]; 48 | #else 49 | rtree_leaf_elm_t root[1U << (RTREE_NSB/RTREE_HEIGHT)]; 50 | #endif 51 | }; 52 | 53 | #endif /* JEMALLOC_INTERNAL_RTREE_STRUCTS_H */ 54 | -------------------------------------------------------------------------------- /libuv/src/unix/posix-hrtime.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | #undef NANOSEC 29 | #define NANOSEC ((uint64_t) 1e9) 30 | 31 | uint64_t uv__hrtime(uv_clocktype_t type) { 32 | struct timespec ts; 33 | clock_gettime(CLOCK_MONOTONIC, &ts); 34 | return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); 35 | } 36 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/mutex_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_MUTEX_STRUCTS_H 2 | #define JEMALLOC_INTERNAL_MUTEX_STRUCTS_H 3 | 4 | #include "jemalloc/internal/atomic.h" 5 | #include "jemalloc/internal/mutex_prof.h" 6 | 7 | struct malloc_mutex_s { 8 | union { 9 | struct { 10 | /* 11 | * prof_data is defined first to reduce cacheline 12 | * bouncing: the data is not touched by the mutex holder 13 | * during unlocking, while might be modified by 14 | * contenders. Having it before the mutex itself could 15 | * avoid prefetching a modified cacheline (for the 16 | * unlocking thread). 17 | */ 18 | mutex_prof_data_t prof_data; 19 | #ifdef _WIN32 20 | # if _WIN32_WINNT >= 0x0600 21 | SRWLOCK lock; 22 | # else 23 | CRITICAL_SECTION lock; 24 | # endif 25 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 26 | os_unfair_lock lock; 27 | #elif (defined(JEMALLOC_OSSPIN)) 28 | OSSpinLock lock; 29 | #elif (defined(JEMALLOC_MUTEX_INIT_CB)) 30 | pthread_mutex_t lock; 31 | malloc_mutex_t *postponed_next; 32 | #else 33 | pthread_mutex_t lock; 34 | #endif 35 | }; 36 | /* 37 | * We only touch witness when configured w/ debug. However we 38 | * keep the field in a union when !debug so that we don't have 39 | * to pollute the code base with #ifdefs, while avoid paying the 40 | * memory cost. 41 | */ 42 | #if !defined(JEMALLOC_DEBUG) 43 | witness_t witness; 44 | #endif 45 | }; 46 | 47 | #if defined(JEMALLOC_DEBUG) 48 | witness_t witness; 49 | #endif 50 | }; 51 | 52 | #endif /* JEMALLOC_INTERNAL_MUTEX_STRUCTS_H */ 53 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/assert.h: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/malloc_io.h" 2 | #include "jemalloc/internal/util.h" 3 | 4 | /* 5 | * Define a custom assert() in order to reduce the chances of deadlock during 6 | * assertion failure. 7 | */ 8 | #ifndef assert 9 | #define assert(e) do { \ 10 | if (unlikely(config_debug && !(e))) { \ 11 | malloc_printf( \ 12 | ": %s:%d: Failed assertion: \"%s\"\n", \ 13 | __FILE__, __LINE__, #e); \ 14 | abort(); \ 15 | } \ 16 | } while (0) 17 | #endif 18 | 19 | #ifndef not_reached 20 | #define not_reached() do { \ 21 | if (config_debug) { \ 22 | malloc_printf( \ 23 | ": %s:%d: Unreachable code reached\n", \ 24 | __FILE__, __LINE__); \ 25 | abort(); \ 26 | } \ 27 | unreachable(); \ 28 | } while (0) 29 | #endif 30 | 31 | #ifndef not_implemented 32 | #define not_implemented() do { \ 33 | if (config_debug) { \ 34 | malloc_printf(": %s:%d: Not implemented\n", \ 35 | __FILE__, __LINE__); \ 36 | abort(); \ 37 | } \ 38 | } while (0) 39 | #endif 40 | 41 | #ifndef assert_not_implemented 42 | #define assert_not_implemented(e) do { \ 43 | if (unlikely(config_debug && !(e))) { \ 44 | not_implemented(); \ 45 | } \ 46 | } while (0) 47 | #endif 48 | 49 | /* Use to assert a particular configuration, e.g., cassert(config_debug). */ 50 | #ifndef cassert 51 | #define cassert(c) do { \ 52 | if (unlikely(!(c))) { \ 53 | not_reached(); \ 54 | } \ 55 | } while (0) 56 | #endif 57 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/private_symbols.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env awk -f 2 | 3 | BEGIN { 4 | sym_prefix = "" 5 | split("\ 6 | je_aligned_alloc \ 7 | je_calloc \ 8 | je_dallocx \ 9 | je_free \ 10 | je_mallctl \ 11 | je_mallctlbymib \ 12 | je_mallctlnametomib \ 13 | je_malloc \ 14 | je_malloc_conf \ 15 | je_malloc_message \ 16 | je_malloc_stats_print \ 17 | je_malloc_usable_size \ 18 | je_mallocx \ 19 | je_nallocx \ 20 | je_posix_memalign \ 21 | je_rallocx \ 22 | je_realloc \ 23 | je_sallocx \ 24 | je_sdallocx \ 25 | je_xallocx \ 26 | tls_callback \ 27 | ", exported_symbol_names) 28 | # Store exported symbol names as keys in exported_symbols. 29 | for (i in exported_symbol_names) { 30 | exported_symbols[exported_symbol_names[i]] = 1 31 | } 32 | } 33 | 34 | # Process 'nm -a ' output. 35 | # 36 | # Handle lines like: 37 | # 0000000000000008 D opt_junk 38 | # 0000000000007574 T malloc_initialized 39 | (NF == 3 && $2 ~ /^[ABCDGRSTVW]$/ && !($3 in exported_symbols) && $3 ~ /^[A-Za-z0-9_]+$/) { 40 | print substr($3, 1+length(sym_prefix), length($3)-length(sym_prefix)) 41 | } 42 | 43 | # Process 'dumpbin /SYMBOLS ' output. 44 | # 45 | # Handle lines like: 46 | # 353 00008098 SECT4 notype External | opt_junk 47 | # 3F1 00000000 SECT7 notype () External | malloc_initialized 48 | ($3 ~ /^SECT[0-9]+/ && $(NF-2) == "External" && !($NF in exported_symbols)) { 49 | print $NF 50 | } 51 | -------------------------------------------------------------------------------- /lua/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->sp->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->sp->lineinfo) ? (f)->sp->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/private_symbols_jet.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env awk -f 2 | 3 | BEGIN { 4 | sym_prefix = "" 5 | split("\ 6 | jet_aligned_alloc \ 7 | jet_calloc \ 8 | jet_dallocx \ 9 | jet_free \ 10 | jet_mallctl \ 11 | jet_mallctlbymib \ 12 | jet_mallctlnametomib \ 13 | jet_malloc \ 14 | jet_malloc_conf \ 15 | jet_malloc_message \ 16 | jet_malloc_stats_print \ 17 | jet_malloc_usable_size \ 18 | jet_mallocx \ 19 | jet_nallocx \ 20 | jet_posix_memalign \ 21 | jet_rallocx \ 22 | jet_realloc \ 23 | jet_sallocx \ 24 | jet_sdallocx \ 25 | jet_xallocx \ 26 | tls_callback \ 27 | ", exported_symbol_names) 28 | # Store exported symbol names as keys in exported_symbols. 29 | for (i in exported_symbol_names) { 30 | exported_symbols[exported_symbol_names[i]] = 1 31 | } 32 | } 33 | 34 | # Process 'nm -a ' output. 35 | # 36 | # Handle lines like: 37 | # 0000000000000008 D opt_junk 38 | # 0000000000007574 T malloc_initialized 39 | (NF == 3 && $2 ~ /^[ABCDGRSTVW]$/ && !($3 in exported_symbols) && $3 ~ /^[A-Za-z0-9_]+$/) { 40 | print substr($3, 1+length(sym_prefix), length($3)-length(sym_prefix)) 41 | } 42 | 43 | # Process 'dumpbin /SYMBOLS ' output. 44 | # 45 | # Handle lines like: 46 | # 353 00008098 SECT4 notype External | opt_junk 47 | # 3F1 00000000 SECT7 notype () External | malloc_initialized 48 | ($3 ~ /^SECT[0-9]+/ && $(NF-2) == "External" && !($NF in exported_symbols)) { 49 | print $NF 50 | } 51 | -------------------------------------------------------------------------------- /lua/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | #define LUA_CACHELIB 51 | LUAMOD_API int (luaopen_cache) (lua_State *L); 52 | 53 | /* open all previous libraries */ 54 | LUALIB_API void (luaL_openlibs) (lua_State *L); 55 | 56 | 57 | 58 | #if !defined(lua_assert) 59 | #define lua_assert(x) ((void)0) 60 | #endif 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/base_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BASE_STRUCTS_H 2 | #define JEMALLOC_INTERNAL_BASE_STRUCTS_H 3 | 4 | #include "jemalloc/internal/jemalloc_internal_types.h" 5 | #include "jemalloc/internal/size_classes.h" 6 | 7 | /* Embedded at the beginning of every block of base-managed virtual memory. */ 8 | struct base_block_s { 9 | /* Total size of block's virtual memory mapping. */ 10 | size_t size; 11 | 12 | /* Next block in list of base's blocks. */ 13 | base_block_t *next; 14 | 15 | /* Tracks unused trailing space. */ 16 | extent_t extent; 17 | }; 18 | 19 | struct base_s { 20 | /* Associated arena's index within the arenas array. */ 21 | unsigned ind; 22 | 23 | /* 24 | * User-configurable extent hook functions. Points to an 25 | * extent_hooks_t. 26 | */ 27 | atomic_p_t extent_hooks; 28 | 29 | /* Protects base_alloc() and base_stats_get() operations. */ 30 | malloc_mutex_t mtx; 31 | 32 | /* 33 | * Most recent size class in the series of increasingly large base 34 | * extents. Logarithmic spacing between subsequent allocations ensures 35 | * that the total number of distinct mappings remains small. 36 | */ 37 | pszind_t pind_last; 38 | 39 | /* Serial number generation state. */ 40 | size_t extent_sn_next; 41 | 42 | /* Chain of all blocks associated with base. */ 43 | base_block_t *blocks; 44 | 45 | /* Heap of extents that track unused trailing space within blocks. */ 46 | extent_heap_t avail[NSIZES]; 47 | 48 | /* Stats, only maintained if config_stats. */ 49 | size_t allocated; 50 | size_t resident; 51 | size_t mapped; 52 | }; 53 | 54 | #endif /* JEMALLOC_INTERNAL_BASE_STRUCTS_H */ 55 | -------------------------------------------------------------------------------- /libuv/include/uv-threadpool.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | /* 23 | * This file is private to libuv. It provides common functionality to both 24 | * Windows and Unix backends. 25 | */ 26 | 27 | #ifndef UV_THREADPOOL_H_ 28 | #define UV_THREADPOOL_H_ 29 | 30 | struct uv__work { 31 | void (*work)(struct uv__work *w); 32 | void (*done)(struct uv__work *w, int status); 33 | struct uv_loop_s* loop; 34 | void* wq[2]; 35 | }; 36 | 37 | #endif /* UV_THREADPOOL_H_ */ 38 | -------------------------------------------------------------------------------- /lua/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /tool/zero/lualib/cluster.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local clusterd 4 | local cluster = {} 5 | 6 | function cluster.call(node, address, ...) 7 | -- skynet.pack(...) will free by cluster.core.packrequest 8 | return skynet.call(clusterd, "lua", "req", node, address, skynet.pack(...)) 9 | end 10 | 11 | function cluster.send(node, address, ...) 12 | -- push is the same with req, but no response 13 | skynet.send(clusterd, "lua", "push", node, address, skynet.pack(...)) 14 | end 15 | 16 | function cluster.open(port) 17 | if type(port) == "string" then 18 | skynet.call(clusterd, "lua", "listen", port) 19 | else 20 | skynet.call(clusterd, "lua", "listen", "0.0.0.0", port) 21 | end 22 | end 23 | 24 | function cluster.reload(config) 25 | skynet.call(clusterd, "lua", "reload", config) 26 | end 27 | 28 | function cluster.proxy(node, name) 29 | return skynet.call(clusterd, "lua", "proxy", node, name) 30 | end 31 | 32 | function cluster.snax(node, name, address) 33 | local snax = require "snax" 34 | if not address then 35 | address = cluster.call(node, ".service", "QUERY", "snaxd" , name) 36 | end 37 | local handle = skynet.call(clusterd, "lua", "proxy", node, address) 38 | return snax.bind(handle, name) 39 | end 40 | 41 | function cluster.register(name, addr) 42 | assert(type(name) == "string") 43 | assert(addr == nil or type(addr) == "number") 44 | return skynet.call(clusterd, "lua", "register", name, addr) 45 | end 46 | 47 | function cluster.query(node, name) 48 | return skynet.call(clusterd, "lua", "req", node, 0, skynet.pack(name)) 49 | end 50 | 51 | skynet.init(function() 52 | clusterd = skynet.uniqueservice("clusterd") 53 | end) 54 | 55 | return cluster 56 | -------------------------------------------------------------------------------- /tool/zero/lualib/skynet/inject.lua: -------------------------------------------------------------------------------- 1 | local function getupvaluetable(u, func, unique) 2 | local i = 1 3 | while true do 4 | local name, value = debug.getupvalue(func, i) 5 | if name == nil then 6 | return 7 | end 8 | local t = type(value) 9 | if t == "table" then 10 | u[name] = value 11 | elseif t == "function" then 12 | if not unique[value] then 13 | unique[value] = true 14 | getupvaluetable(u, value, unique) 15 | end 16 | end 17 | i=i+1 18 | end 19 | end 20 | 21 | return function(skynet, source, filename , ...) 22 | if filename then 23 | filename = "@" .. filename 24 | else 25 | filename = "=(load)" 26 | end 27 | local output = {} 28 | 29 | local function print(...) 30 | local value = { ... } 31 | for k,v in ipairs(value) do 32 | value[k] = tostring(v) 33 | end 34 | table.insert(output, table.concat(value, "\t")) 35 | end 36 | local u = {} 37 | local unique = {} 38 | local funcs = { ... } 39 | for k, func in ipairs(funcs) do 40 | getupvaluetable(u, func, unique) 41 | end 42 | local p = {} 43 | local proto = u.proto 44 | if proto then 45 | for k,v in pairs(proto) do 46 | local name, dispatch = v.name, v.dispatch 47 | if name and dispatch and not p[name] then 48 | local pp = {} 49 | p[name] = pp 50 | getupvaluetable(pp, dispatch, unique) 51 | end 52 | end 53 | end 54 | local env = setmetatable( { print = print , _U = u, _P = p}, { __index = _ENV }) 55 | local func, err = load(source, filename, "bt", env) 56 | if not func then 57 | return false, { err } 58 | end 59 | local ok, err = skynet.pcall(func) 60 | if not ok then 61 | table.insert(output, err) 62 | return false, output 63 | end 64 | 65 | return true, output 66 | end 67 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/arena_inlines_a.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_ARENA_INLINES_A_H 2 | #define JEMALLOC_INTERNAL_ARENA_INLINES_A_H 3 | 4 | static inline unsigned 5 | arena_ind_get(const arena_t *arena) { 6 | return base_ind_get(arena->base); 7 | } 8 | 9 | static inline void 10 | arena_internal_add(arena_t *arena, size_t size) { 11 | atomic_fetch_add_zu(&arena->stats.internal, size, ATOMIC_RELAXED); 12 | } 13 | 14 | static inline void 15 | arena_internal_sub(arena_t *arena, size_t size) { 16 | atomic_fetch_sub_zu(&arena->stats.internal, size, ATOMIC_RELAXED); 17 | } 18 | 19 | static inline size_t 20 | arena_internal_get(arena_t *arena) { 21 | return atomic_load_zu(&arena->stats.internal, ATOMIC_RELAXED); 22 | } 23 | 24 | static inline bool 25 | arena_prof_accum(tsdn_t *tsdn, arena_t *arena, uint64_t accumbytes) { 26 | cassert(config_prof); 27 | 28 | if (likely(prof_interval == 0)) { 29 | return false; 30 | } 31 | 32 | return prof_accum_add(tsdn, &arena->prof_accum, accumbytes); 33 | } 34 | 35 | static inline void 36 | percpu_arena_update(tsd_t *tsd, unsigned cpu) { 37 | assert(have_percpu_arena); 38 | arena_t *oldarena = tsd_arena_get(tsd); 39 | assert(oldarena != NULL); 40 | unsigned oldind = arena_ind_get(oldarena); 41 | 42 | if (oldind != cpu) { 43 | unsigned newind = cpu; 44 | arena_t *newarena = arena_get(tsd_tsdn(tsd), newind, true); 45 | assert(newarena != NULL); 46 | 47 | /* Set new arena/tcache associations. */ 48 | arena_migrate(tsd, oldind, newind); 49 | tcache_t *tcache = tcache_get(tsd); 50 | if (tcache != NULL) { 51 | tcache_arena_reassociate(tsd_tsdn(tsd), tcache, 52 | newarena); 53 | } 54 | } 55 | } 56 | 57 | #endif /* JEMALLOC_INTERNAL_ARENA_INLINES_A_H */ 58 | -------------------------------------------------------------------------------- /libuv/src/win/snprintf.c: -------------------------------------------------------------------------------- 1 | /* Copyright the libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #if defined(_MSC_VER) && _MSC_VER < 1900 23 | 24 | #include 25 | #include 26 | 27 | /* Emulate snprintf() on MSVC<2015, _snprintf() doesn't zero-terminate the buffer 28 | * on overflow... 29 | */ 30 | int snprintf(char* buf, size_t len, const char* fmt, ...) { 31 | int n; 32 | va_list ap; 33 | va_start(ap, fmt); 34 | 35 | n = _vscprintf(fmt, ap); 36 | vsnprintf_s(buf, len, _TRUNCATE, fmt, ap); 37 | 38 | va_end(ap); 39 | return n; 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /libuv/include/uv-aix.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_AIX_H 23 | #define UV_AIX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | int fs_fd; \ 27 | 28 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 29 | uv__io_t event_watcher; \ 30 | char *dir_filename; \ 31 | 32 | #endif /* UV_AIX_H */ 33 | -------------------------------------------------------------------------------- /duktape/duk_util_hashbytes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Hash function duk_util_hashbytes(). 3 | * 4 | * Currently, 32-bit MurmurHash2. 5 | * 6 | * Don't rely on specific hash values; hash function may be endianness 7 | * dependent, for instance. 8 | */ 9 | 10 | #include "duk_internal.h" 11 | 12 | #if defined(DUK_USE_STRHASH_DENSE) 13 | /* 'magic' constants for Murmurhash2 */ 14 | #define DUK__MAGIC_M ((duk_uint32_t) 0x5bd1e995UL) 15 | #define DUK__MAGIC_R 24 16 | 17 | DUK_INTERNAL duk_uint32_t duk_util_hashbytes(const duk_uint8_t *data, duk_size_t len, duk_uint32_t seed) { 18 | duk_uint32_t h = seed ^ ((duk_uint32_t) len); 19 | 20 | while (len >= 4) { 21 | /* Portability workaround is required for platforms without 22 | * unaligned access. The replacement code emulates little 23 | * endian access even on big endian architectures, which is 24 | * OK as long as it is consistent for a build. 25 | */ 26 | #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS) 27 | duk_uint32_t k = *((const duk_uint32_t *) (const void *) data); 28 | #else 29 | duk_uint32_t k = ((duk_uint32_t) data[0]) | 30 | (((duk_uint32_t) data[1]) << 8) | 31 | (((duk_uint32_t) data[2]) << 16) | 32 | (((duk_uint32_t) data[3]) << 24); 33 | #endif 34 | 35 | k *= DUK__MAGIC_M; 36 | k ^= k >> DUK__MAGIC_R; 37 | k *= DUK__MAGIC_M; 38 | h *= DUK__MAGIC_M; 39 | h ^= k; 40 | data += 4; 41 | len -= 4; 42 | } 43 | 44 | switch (len) { 45 | case 3: h ^= data[2] << 16; 46 | case 2: h ^= data[1] << 8; 47 | case 1: h ^= data[0]; 48 | h *= DUK__MAGIC_M; 49 | } 50 | 51 | h ^= h >> 13; 52 | h *= DUK__MAGIC_M; 53 | h ^= h >> 15; 54 | 55 | return h; 56 | } 57 | #endif /* DUK_USE_STRHASH_DENSE */ 58 | -------------------------------------------------------------------------------- /src/server/service_logger.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct logger { 9 | FILE * handle; 10 | char * filename; 11 | int close; 12 | }; 13 | 14 | struct logger * 15 | logger_create(void) { 16 | struct logger * inst = skynet_malloc(sizeof(*inst)); 17 | inst->handle = NULL; 18 | inst->close = 0; 19 | inst->filename = NULL; 20 | 21 | return inst; 22 | } 23 | 24 | void 25 | logger_release(struct logger * inst) { 26 | if (inst->close) { 27 | fclose(inst->handle); 28 | } 29 | skynet_free(inst->filename); 30 | skynet_free(inst); 31 | } 32 | 33 | static int 34 | logger_cb(struct skynet_context * context, void *ud, int type, int session, uint32_t source, const void * msg, size_t sz) { 35 | struct logger * inst = ud; 36 | switch (type) { 37 | case PTYPE_SYSTEM: 38 | if (inst->filename) { 39 | inst->handle = freopen(inst->filename, "a", inst->handle); 40 | } 41 | break; 42 | case PTYPE_TEXT: 43 | fprintf(inst->handle, "[:%08x] ",source); 44 | fwrite(msg, sz , 1, inst->handle); 45 | fprintf(inst->handle, "\n"); 46 | fflush(inst->handle); 47 | break; 48 | } 49 | 50 | return 0; 51 | } 52 | 53 | int 54 | logger_init(struct logger * inst, struct skynet_context *ctx, const char * parm) { 55 | if (parm) { 56 | inst->handle = fopen(parm,"w"); 57 | if (inst->handle == NULL) { 58 | return 1; 59 | } 60 | inst->filename = skynet_malloc(strlen(parm)+1); 61 | strcpy(inst->filename, parm); 62 | inst->close = 1; 63 | } else { 64 | inst->handle = stdout; 65 | } 66 | if (inst->handle) { 67 | skynet_callback(ctx, inst, logger_cb); 68 | skynet_command(ctx, "REG", ".logger"); 69 | return 0; 70 | } 71 | return 1; 72 | } 73 | -------------------------------------------------------------------------------- /lua/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /tool/zero/lualib/sharedata.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local sd = require "sharedata.corelib" 3 | 4 | local service 5 | 6 | skynet.init(function() 7 | service = skynet.uniqueservice "sharedatad" 8 | end) 9 | 10 | local sharedata = {} 11 | local cache = setmetatable({}, { __mode = "kv" }) 12 | 13 | local function monitor(name, obj, cobj) 14 | local newobj = cobj 15 | while true do 16 | newobj = skynet.call(service, "lua", "monitor", name, newobj) 17 | if newobj == nil then 18 | break 19 | end 20 | sd.update(obj, newobj) 21 | end 22 | if cache[name] == obj then 23 | cache[name] = nil 24 | end 25 | end 26 | 27 | function sharedata.query(name) 28 | if cache[name] then 29 | return cache[name] 30 | end 31 | local obj = skynet.call(service, "lua", "query", name) 32 | local r = sd.box(obj) 33 | skynet.send(service, "lua", "confirm" , obj) 34 | skynet.fork(monitor,name, r, obj) 35 | cache[name] = r 36 | return r 37 | end 38 | 39 | function sharedata.new(name, v, ...) 40 | skynet.call(service, "lua", "new", name, v, ...) 41 | end 42 | 43 | function sharedata.update(name, v, ...) 44 | skynet.call(service, "lua", "update", name, v, ...) 45 | end 46 | 47 | function sharedata.delete(name) 48 | skynet.call(service, "lua", "delete", name) 49 | end 50 | 51 | function sharedata.flush() 52 | for name, obj in pairs(cache) do 53 | sd.flush(obj) 54 | end 55 | collectgarbage() 56 | end 57 | 58 | function sharedata.deepcopy(name, ...) 59 | if cache[name] then 60 | local cobj = cache[name].__obj 61 | return sd.copy(cobj, ...) 62 | end 63 | 64 | local cobj = skynet.call(service, "lua", "query", name) 65 | local ret = sd.copy(cobj, ...) 66 | skynet.send(service, "lua", "confirm" , cobj) 67 | return ret 68 | end 69 | 70 | return sharedata 71 | -------------------------------------------------------------------------------- /libuv/include/uv-bsd.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_BSD_H 23 | #define UV_BSD_H 24 | 25 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 26 | uv__io_t event_watcher; \ 27 | 28 | #define UV_IO_PRIVATE_PLATFORM_FIELDS \ 29 | int rcount; \ 30 | int wcount; \ 31 | 32 | #define UV_HAVE_KQUEUE 1 33 | 34 | #endif /* UV_BSD_H */ 35 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/util.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_UTIL_H 2 | #define JEMALLOC_INTERNAL_UTIL_H 3 | 4 | #define UTIL_INLINE static inline 5 | 6 | /* Junk fill patterns. */ 7 | #ifndef JEMALLOC_ALLOC_JUNK 8 | # define JEMALLOC_ALLOC_JUNK ((uint8_t)0xa5) 9 | #endif 10 | #ifndef JEMALLOC_FREE_JUNK 11 | # define JEMALLOC_FREE_JUNK ((uint8_t)0x5a) 12 | #endif 13 | 14 | /* 15 | * Wrap a cpp argument that contains commas such that it isn't broken up into 16 | * multiple arguments. 17 | */ 18 | #define JEMALLOC_ARG_CONCAT(...) __VA_ARGS__ 19 | 20 | /* cpp macro definition stringification. */ 21 | #define STRINGIFY_HELPER(x) #x 22 | #define STRINGIFY(x) STRINGIFY_HELPER(x) 23 | 24 | /* 25 | * Silence compiler warnings due to uninitialized values. This is used 26 | * wherever the compiler fails to recognize that the variable is never used 27 | * uninitialized. 28 | */ 29 | #define JEMALLOC_CC_SILENCE_INIT(v) = v 30 | 31 | #ifdef __GNUC__ 32 | # define likely(x) __builtin_expect(!!(x), 1) 33 | # define unlikely(x) __builtin_expect(!!(x), 0) 34 | #else 35 | # define likely(x) !!(x) 36 | # define unlikely(x) !!(x) 37 | #endif 38 | 39 | #if !defined(JEMALLOC_INTERNAL_UNREACHABLE) 40 | # error JEMALLOC_INTERNAL_UNREACHABLE should have been defined by configure 41 | #endif 42 | 43 | #define unreachable() JEMALLOC_INTERNAL_UNREACHABLE() 44 | 45 | /* Set error code. */ 46 | UTIL_INLINE void 47 | set_errno(int errnum) { 48 | #ifdef _WIN32 49 | SetLastError(errnum); 50 | #else 51 | errno = errnum; 52 | #endif 53 | } 54 | 55 | /* Get last error code. */ 56 | UTIL_INLINE int 57 | get_errno(void) { 58 | #ifdef _WIN32 59 | return GetLastError(); 60 | #else 61 | return errno; 62 | #endif 63 | } 64 | 65 | #undef UTIL_INLINE 66 | 67 | #endif /* JEMALLOC_INTERNAL_UTIL_H */ 68 | -------------------------------------------------------------------------------- /tool/zero/lualib/sharemap.lua: -------------------------------------------------------------------------------- 1 | local stm = require "stm" 2 | local sprotoloader = require "sprotoloader" 3 | local sproto = require "sproto" 4 | local setmetatable = setmetatable 5 | 6 | local sharemap = {} 7 | 8 | function sharemap.register(protofile) 9 | -- use global slot 0 for type define 10 | sprotoloader.register(protofile, 0) 11 | end 12 | 13 | local sprotoobj 14 | local function loadsp() 15 | if sprotoobj == nil then 16 | sprotoobj = sprotoloader.load(0) 17 | end 18 | return sprotoobj 19 | end 20 | 21 | function sharemap:commit() 22 | self.__obj(sprotoobj:encode(self.__typename, self.__data)) 23 | end 24 | 25 | function sharemap:copy() 26 | return stm.copy(self.__obj) 27 | end 28 | 29 | function sharemap.writer(typename, obj) 30 | local sp = loadsp() 31 | obj = obj or {} 32 | local stmobj = stm.new(sp:encode(typename,obj)) 33 | local ret = { 34 | __typename = typename, 35 | __obj = stmobj, 36 | __data = obj, 37 | commit = sharemap.commit, 38 | copy = sharemap.copy, 39 | } 40 | return setmetatable(ret, { __index = obj, __newindex = obj }) 41 | end 42 | 43 | local function decode(msg, sz, self) 44 | local data = self.__data 45 | for k in pairs(data) do 46 | data[k] = nil 47 | end 48 | return sprotoobj:decode(self.__typename, msg, sz, data) 49 | end 50 | 51 | function sharemap:update() 52 | return self.__obj(decode, self) 53 | end 54 | 55 | function sharemap.reader(typename, stmcpy) 56 | local sp = loadsp() 57 | local stmobj = stm.newcopy(stmcpy) 58 | local _, data = stmobj(function(msg, sz) 59 | return sp:decode(typename, msg, sz) 60 | end) 61 | 62 | local obj = { 63 | __typename = typename, 64 | __obj = stmobj, 65 | __data = data, 66 | update = sharemap.update, 67 | } 68 | return setmetatable(obj, { __index = data, __newindex = error }) 69 | end 70 | 71 | return sharemap 72 | -------------------------------------------------------------------------------- /duktape/duk_harray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Heap Array object representation. Used for actual Array instances. 3 | * 4 | * All objects with the exotic array behavior (which must coincide with having 5 | * internal class array) MUST be duk_harrays. No other object can be a 6 | * duk_harray. However, duk_harrays may not always have an array part. 7 | */ 8 | 9 | #if !defined(DUK_HARRAY_H_INCLUDED) 10 | #define DUK_HARRAY_H_INCLUDED 11 | 12 | #define DUK_ASSERT_HARRAY_VALID(h) do { \ 13 | DUK_ASSERT((h) != NULL); \ 14 | DUK_ASSERT(DUK_HOBJECT_IS_ARRAY((duk_hobject *) (h))); \ 15 | DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_ARRAY((duk_hobject *) (h))); \ 16 | } while (0) 17 | 18 | #define DUK_HARRAY_LENGTH_WRITABLE(h) (!(h)->length_nonwritable) 19 | #define DUK_HARRAY_LENGTH_NONWRITABLE(h) ((h)->length_nonwritable) 20 | #define DUK_HARRAY_SET_LENGTH_WRITABLE(h) do { (h)->length_nonwritable = 0; } while (0) 21 | #define DUK_HARRAY_SET_LENGTH_NONWRITABLE(h) do { (h)->length_nonwritable = 1; } while (0) 22 | 23 | struct duk_harray { 24 | /* Shared object part. */ 25 | duk_hobject obj; 26 | 27 | /* Array .length. 28 | * 29 | * At present Array .length may be smaller, equal, or even larger 30 | * than the allocated underlying array part. Fast path code must 31 | * always take this into account carefully. 32 | */ 33 | duk_uint32_t length; 34 | 35 | /* Array .length property attributes. The property is always 36 | * non-enumerable and non-configurable. It's initially writable 37 | * but per Object.defineProperty() rules it can be made non-writable 38 | * even if it is non-configurable. Thus we need to track the 39 | * writability explicitly. 40 | * 41 | * XXX: this field to be eliminated and moved into duk_hobject 42 | * flags field to save space. 43 | */ 44 | duk_bool_t length_nonwritable; 45 | }; 46 | 47 | #endif /* DUK_HARRAY_H_INCLUDED */ 48 | -------------------------------------------------------------------------------- /src/lualib/lpeg/lpvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpvm.h,v 1.3 2014/02/21 13:06:41 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpvm_h) 6 | #define lpvm_h 7 | 8 | #include "lpcap.h" 9 | 10 | 11 | /* Virtual Machine's instructions */ 12 | typedef enum Opcode { 13 | IAny, /* if no char, fail */ 14 | IChar, /* if char != aux, fail */ 15 | ISet, /* if char not in buff, fail */ 16 | ITestAny, /* in no char, jump to 'offset' */ 17 | ITestChar, /* if char != aux, jump to 'offset' */ 18 | ITestSet, /* if char not in buff, jump to 'offset' */ 19 | ISpan, /* read a span of chars in buff */ 20 | IBehind, /* walk back 'aux' characters (fail if not possible) */ 21 | IRet, /* return from a rule */ 22 | IEnd, /* end of pattern */ 23 | IChoice, /* stack a choice; next fail will jump to 'offset' */ 24 | IJmp, /* jump to 'offset' */ 25 | ICall, /* call rule at 'offset' */ 26 | IOpenCall, /* call rule number 'key' (must be closed to a ICall) */ 27 | ICommit, /* pop choice and jump to 'offset' */ 28 | IPartialCommit, /* update top choice to current position and jump */ 29 | IBackCommit, /* "fails" but jump to its own 'offset' */ 30 | IFailTwice, /* pop one choice and then fail */ 31 | IFail, /* go back to saved state on choice and jump to saved offset */ 32 | IGiveup, /* internal use */ 33 | IFullCapture, /* complete capture of last 'off' chars */ 34 | IOpenCapture, /* start a capture */ 35 | ICloseCapture, 36 | ICloseRunTime 37 | } Opcode; 38 | 39 | 40 | 41 | typedef union Instruction { 42 | struct Inst { 43 | byte code; 44 | byte aux; 45 | short key; 46 | } i; 47 | int offset; 48 | byte buff[1]; 49 | } Instruction; 50 | 51 | 52 | void printpatt (Instruction *p, int n); 53 | const char *match (lua_State *L, const char *o, const char *s, const char *e, 54 | Instruction *op, Capture *capture, int ptop); 55 | 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /lua/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L, SharedProto *sp); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /libuv/include/uv-linux.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_LINUX_H 23 | #define UV_LINUX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | uv__io_t inotify_read_watcher; \ 27 | void* inotify_watchers; \ 28 | int inotify_fd; \ 29 | 30 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 31 | void* watchers[2]; \ 32 | int wd; \ 33 | 34 | #endif /* UV_LINUX_H */ 35 | -------------------------------------------------------------------------------- /lua/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | #define ENABLE_SHORT_STRING_TABLE 49 | 50 | LUA_API void luaS_initshr(); 51 | LUA_API void luaS_exitshr(); 52 | LUA_API void luaS_expandshr(int n); 53 | LUAI_FUNC TString *luaS_clonestring(lua_State *L, TString *); 54 | LUA_API int luaS_shrinfo(lua_State *L); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/skynet_socket.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKYNET_SOCKET_H_ 2 | #define _SKYNET_SOCKET_H_ 3 | #include "skynet.h" 4 | struct skynet_context; 5 | 6 | #define SKYNET_SOCKET_TYPE_DATA 1 7 | #define SKYNET_SOCKET_TYPE_CONNECT 2 8 | #define SKYNET_SOCKET_TYPE_CLOSE 3 9 | #define SKYNET_SOCKET_TYPE_ACCEPT 4 10 | #define SKYNET_SOCKET_TYPE_ERROR 5 11 | #define SKYNET_SOCKET_TYPE_UDP 6 12 | #define SKYNET_SOCKET_TYPE_WARNING 7 13 | 14 | struct skynet_socket_message { 15 | int type; 16 | int id; 17 | int ud; 18 | char * buffer; 19 | }; 20 | 21 | void skynet_socket_init(); 22 | void skynet_socket_exit(); 23 | void skynet_socket_free(); 24 | int skynet_socket_poll(); 25 | 26 | SKYNET_EXTERN int skynet_socket_send(struct skynet_context *ctx, int id, void *buffer, int sz); 27 | SKYNET_EXTERN int skynet_socket_send_lowpriority(struct skynet_context *ctx, int id, void *buffer, int sz); 28 | SKYNET_EXTERN int skynet_socket_listen(struct skynet_context *ctx, const char *host, int port, int backlog); 29 | SKYNET_EXTERN int skynet_socket_connect(struct skynet_context *ctx, const char *host, int port); 30 | SKYNET_EXTERN int skynet_socket_bind(struct skynet_context *ctx, int fd); 31 | SKYNET_EXTERN void skynet_socket_close(struct skynet_context *ctx, int id); 32 | SKYNET_EXTERN void skynet_socket_shutdown(struct skynet_context *ctx, int id); 33 | SKYNET_EXTERN void skynet_socket_start(struct skynet_context *ctx, int id); 34 | SKYNET_EXTERN void skynet_socket_nodelay(struct skynet_context *ctx, int id); 35 | 36 | SKYNET_EXTERN int skynet_socket_udp(struct skynet_context *ctx, const char * addr, int port); 37 | SKYNET_EXTERN int skynet_socket_udp_connect(struct skynet_context *ctx, int id, const char * addr, int port); 38 | SKYNET_EXTERN int skynet_socket_udp_send(struct skynet_context *ctx, int id, const char * address, const void *buffer, int sz); 39 | SKYNET_EXTERN const char * skynet_socket_udp_address(struct skynet_socket_message *, int *addrsz); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libuv/src/version.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | 24 | #define UV_STRINGIFY(v) UV_STRINGIFY_HELPER(v) 25 | #define UV_STRINGIFY_HELPER(v) #v 26 | 27 | #define UV_VERSION_STRING_BASE UV_STRINGIFY(UV_VERSION_MAJOR) "." \ 28 | UV_STRINGIFY(UV_VERSION_MINOR) "." \ 29 | UV_STRINGIFY(UV_VERSION_PATCH) 30 | 31 | #if UV_VERSION_IS_RELEASE 32 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE 33 | #else 34 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE "-" UV_VERSION_SUFFIX 35 | #endif 36 | 37 | 38 | unsigned int uv_version(void) { 39 | return UV_VERSION_HEX; 40 | } 41 | 42 | 43 | const char* uv_version_string(void) { 44 | return UV_VERSION_STRING; 45 | } 46 | -------------------------------------------------------------------------------- /src/lualib/lpeg/lpcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcap.h,v 1.3 2016/09/13 17:45:58 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcap_h) 6 | #define lpcap_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* kinds of captures */ 13 | typedef enum CapKind { 14 | Cclose, /* not used in trees */ 15 | Cposition, 16 | Cconst, /* ktable[key] is Lua constant */ 17 | Cbackref, /* ktable[key] is "name" of group to get capture */ 18 | Carg, /* 'key' is arg's number */ 19 | Csimple, /* next node is pattern */ 20 | Ctable, /* next node is pattern */ 21 | Cfunction, /* ktable[key] is function; next node is pattern */ 22 | Cquery, /* ktable[key] is table; next node is pattern */ 23 | Cstring, /* ktable[key] is string; next node is pattern */ 24 | Cnum, /* numbered capture; 'key' is number of value to return */ 25 | Csubst, /* substitution capture; next node is pattern */ 26 | Cfold, /* ktable[key] is function; next node is pattern */ 27 | Cruntime, /* not used in trees (is uses another type for tree) */ 28 | Cgroup /* ktable[key] is group's "name" */ 29 | } CapKind; 30 | 31 | 32 | typedef struct Capture { 33 | const char *s; /* subject position */ 34 | unsigned short idx; /* extra info (group name, arg index, etc.) */ 35 | byte kind; /* kind of capture */ 36 | byte siz; /* size of full capture + 1 (0 = not a full capture) */ 37 | } Capture; 38 | 39 | 40 | typedef struct CapState { 41 | Capture *cap; /* current capture */ 42 | Capture *ocap; /* (original) capture list */ 43 | lua_State *L; 44 | int ptop; /* index of last argument to 'match' */ 45 | const char *s; /* original string */ 46 | int valuecached; /* value stored in cache slot */ 47 | } CapState; 48 | 49 | 50 | int runtimecap (CapState *cs, Capture *close, const char *s, int *rem); 51 | int getcaptures (lua_State *L, const char *s, const char *r, int ptop); 52 | int finddyncap (Capture *cap, Capture *last); 53 | 54 | #endif 55 | 56 | 57 | -------------------------------------------------------------------------------- /libuv/include/uv-version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_VERSION_H 23 | #define UV_VERSION_H 24 | 25 | /* 26 | * Versions with the same major number are ABI stable. API is allowed to 27 | * evolve between minor releases, but only in a backwards compatible way. 28 | * Make sure you update the -soname directives in configure.ac 29 | * and uv.gyp whenever you bump UV_VERSION_MAJOR or UV_VERSION_MINOR (but 30 | * not UV_VERSION_PATCH.) 31 | */ 32 | 33 | #define UV_VERSION_MAJOR 1 34 | #define UV_VERSION_MINOR 11 35 | #define UV_VERSION_PATCH 1 36 | #define UV_VERSION_IS_RELEASE 0 37 | #define UV_VERSION_SUFFIX "dev" 38 | 39 | #define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \ 40 | (UV_VERSION_MINOR << 8) | \ 41 | (UV_VERSION_PATCH)) 42 | 43 | #endif /* UV_VERSION_H */ 44 | -------------------------------------------------------------------------------- /lua/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/prof_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_PROF_TYPES_H 2 | #define JEMALLOC_INTERNAL_PROF_TYPES_H 3 | 4 | typedef struct prof_bt_s prof_bt_t; 5 | typedef struct prof_accum_s prof_accum_t; 6 | typedef struct prof_cnt_s prof_cnt_t; 7 | typedef struct prof_tctx_s prof_tctx_t; 8 | typedef struct prof_gctx_s prof_gctx_t; 9 | typedef struct prof_tdata_s prof_tdata_t; 10 | 11 | /* Option defaults. */ 12 | #ifdef JEMALLOC_PROF 13 | # define PROF_PREFIX_DEFAULT "jeprof" 14 | #else 15 | # define PROF_PREFIX_DEFAULT "" 16 | #endif 17 | #define LG_PROF_SAMPLE_DEFAULT 19 18 | #define LG_PROF_INTERVAL_DEFAULT -1 19 | 20 | /* 21 | * Hard limit on stack backtrace depth. The version of prof_backtrace() that 22 | * is based on __builtin_return_address() necessarily has a hard-coded number 23 | * of backtrace frame handlers, and should be kept in sync with this setting. 24 | */ 25 | #define PROF_BT_MAX 128 26 | 27 | /* Initial hash table size. */ 28 | #define PROF_CKH_MINITEMS 64 29 | 30 | /* Size of memory buffer to use when writing dump files. */ 31 | #define PROF_DUMP_BUFSIZE 65536 32 | 33 | /* Size of stack-allocated buffer used by prof_printf(). */ 34 | #define PROF_PRINTF_BUFSIZE 128 35 | 36 | /* 37 | * Number of mutexes shared among all gctx's. No space is allocated for these 38 | * unless profiling is enabled, so it's okay to over-provision. 39 | */ 40 | #define PROF_NCTX_LOCKS 1024 41 | 42 | /* 43 | * Number of mutexes shared among all tdata's. No space is allocated for these 44 | * unless profiling is enabled, so it's okay to over-provision. 45 | */ 46 | #define PROF_NTDATA_LOCKS 256 47 | 48 | /* 49 | * prof_tdata pointers close to NULL are used to encode state information that 50 | * is used for cleaning up during thread shutdown. 51 | */ 52 | #define PROF_TDATA_STATE_REINCARNATED ((prof_tdata_t *)(uintptr_t)1) 53 | #define PROF_TDATA_STATE_PURGATORY ((prof_tdata_t *)(uintptr_t)2) 54 | #define PROF_TDATA_STATE_MAX PROF_TDATA_STATE_PURGATORY 55 | 56 | #endif /* JEMALLOC_INTERNAL_PROF_TYPES_H */ 57 | -------------------------------------------------------------------------------- /src/lualib/sproto/sproto.h: -------------------------------------------------------------------------------- 1 | #ifndef sproto_h 2 | #define sproto_h 3 | 4 | #include 5 | 6 | struct sproto; 7 | struct sproto_type; 8 | 9 | #define SPROTO_REQUEST 0 10 | #define SPROTO_RESPONSE 1 11 | 12 | // type (sproto_arg.type) 13 | #define SPROTO_TINTEGER 0 14 | #define SPROTO_TBOOLEAN 1 15 | #define SPROTO_TSTRING 2 16 | #define SPROTO_TSTRUCT 3 17 | 18 | // sub type of string (sproto_arg.extra) 19 | #define SPROTO_TSTRING_STRING 0 20 | #define SPROTO_TSTRING_BINARY 1 21 | 22 | #define SPROTO_CB_ERROR -1 23 | #define SPROTO_CB_NIL -2 24 | #define SPROTO_CB_NOARRAY -3 25 | 26 | struct sproto * sproto_create(const void * proto, size_t sz); 27 | void sproto_release(struct sproto *); 28 | 29 | int sproto_prototag(const struct sproto *, const char * name); 30 | const char * sproto_protoname(const struct sproto *, int proto); 31 | // SPROTO_REQUEST(0) : request, SPROTO_RESPONSE(1): response 32 | struct sproto_type * sproto_protoquery(const struct sproto *, int proto, int what); 33 | int sproto_protoresponse(const struct sproto *, int proto); 34 | 35 | struct sproto_type * sproto_type(const struct sproto *, const char * type_name); 36 | 37 | int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz); 38 | int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz); 39 | 40 | struct sproto_arg { 41 | void *ud; 42 | const char *tagname; 43 | int tagid; 44 | int type; 45 | struct sproto_type *subtype; 46 | void *value; 47 | int length; 48 | int index; // array base 1 49 | int mainindex; // for map 50 | int extra; // SPROTO_TINTEGER: decimal ; SPROTO_TSTRING 0:utf8 string 1:binary 51 | }; 52 | 53 | typedef int (*sproto_callback)(const struct sproto_arg *args); 54 | 55 | int sproto_decode(const struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud); 56 | int sproto_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud); 57 | 58 | // for debug use 59 | void sproto_dump(struct sproto *); 60 | const char * sproto_name(struct sproto_type *); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libuv/include/android-ifaddrs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 1999 3 | * Berkeley Software Design, Inc. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND 12 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE 15 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 16 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 17 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 19 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 20 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 21 | * SUCH DAMAGE. 22 | * 23 | * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp 24 | */ 25 | 26 | #ifndef _IFADDRS_H_ 27 | #define _IFADDRS_H_ 28 | 29 | struct ifaddrs { 30 | struct ifaddrs *ifa_next; 31 | char *ifa_name; 32 | unsigned int ifa_flags; 33 | struct sockaddr *ifa_addr; 34 | struct sockaddr *ifa_netmask; 35 | struct sockaddr *ifa_dstaddr; 36 | void *ifa_data; 37 | }; 38 | 39 | /* 40 | * This may have been defined in . Note that if is 41 | * to be included it must be included before this header file. 42 | */ 43 | #ifndef ifa_broadaddr 44 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 45 | #endif 46 | 47 | #include 48 | 49 | __BEGIN_DECLS 50 | extern int getifaddrs(struct ifaddrs **ifap); 51 | extern void freeifaddrs(struct ifaddrs *ifa); 52 | __END_DECLS 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lua/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/malloc_io.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_MALLOC_IO_H 2 | #define JEMALLOC_INTERNAL_MALLOC_IO_H 3 | 4 | #ifdef _WIN32 5 | # ifdef _WIN64 6 | # define FMT64_PREFIX "ll" 7 | # define FMTPTR_PREFIX "ll" 8 | # else 9 | # define FMT64_PREFIX "ll" 10 | # define FMTPTR_PREFIX "" 11 | # endif 12 | # define FMTd32 "d" 13 | # define FMTu32 "u" 14 | # define FMTx32 "x" 15 | # define FMTd64 FMT64_PREFIX "d" 16 | # define FMTu64 FMT64_PREFIX "u" 17 | # define FMTx64 FMT64_PREFIX "x" 18 | # define FMTdPTR FMTPTR_PREFIX "d" 19 | # define FMTuPTR FMTPTR_PREFIX "u" 20 | # define FMTxPTR FMTPTR_PREFIX "x" 21 | #else 22 | # include 23 | # define FMTd32 PRId32 24 | # define FMTu32 PRIu32 25 | # define FMTx32 PRIx32 26 | # define FMTd64 PRId64 27 | # define FMTu64 PRIu64 28 | # define FMTx64 PRIx64 29 | # define FMTdPTR PRIdPTR 30 | # define FMTuPTR PRIuPTR 31 | # define FMTxPTR PRIxPTR 32 | #endif 33 | 34 | /* Size of stack-allocated buffer passed to buferror(). */ 35 | #define BUFERROR_BUF 64 36 | 37 | /* 38 | * Size of stack-allocated buffer used by malloc_{,v,vc}printf(). This must be 39 | * large enough for all possible uses within jemalloc. 40 | */ 41 | #define MALLOC_PRINTF_BUFSIZE 4096 42 | 43 | int buferror(int err, char *buf, size_t buflen); 44 | uintmax_t malloc_strtoumax(const char *restrict nptr, char **restrict endptr, 45 | int base); 46 | void malloc_write(const char *s); 47 | 48 | /* 49 | * malloc_vsnprintf() supports a subset of snprintf(3) that avoids floating 50 | * point math. 51 | */ 52 | size_t malloc_vsnprintf(char *str, size_t size, const char *format, 53 | va_list ap); 54 | size_t malloc_snprintf(char *str, size_t size, const char *format, ...) 55 | JEMALLOC_FORMAT_PRINTF(3, 4); 56 | void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque, 57 | const char *format, va_list ap); 58 | void malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque, 59 | const char *format, ...) JEMALLOC_FORMAT_PRINTF(3, 4); 60 | void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2); 61 | 62 | #endif /* JEMALLOC_INTERNAL_MALLOC_IO_H */ 63 | -------------------------------------------------------------------------------- /libuv/include/uv-sunos.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_SUNOS_H 23 | #define UV_SUNOS_H 24 | 25 | #include 26 | #include 27 | 28 | /* For the sake of convenience and reduced #ifdef-ery in src/unix/sunos.c, 29 | * add the fs_event fields even when this version of SunOS doesn't support 30 | * file watching. 31 | */ 32 | #define UV_PLATFORM_LOOP_FIELDS \ 33 | uv__io_t fs_event_watcher; \ 34 | int fs_fd; \ 35 | 36 | #if defined(PORT_SOURCE_FILE) 37 | 38 | # define UV_PLATFORM_FS_EVENT_FIELDS \ 39 | file_obj_t fo; \ 40 | int fd; \ 41 | 42 | #endif /* defined(PORT_SOURCE_FILE) */ 43 | 44 | #endif /* UV_SUNOS_H */ 45 | -------------------------------------------------------------------------------- /tool/zero/service/cdummy.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | require "skynet.manager" -- import skynet.launch, ... 3 | 4 | local globalname = {} 5 | local queryname = {} 6 | local harbor = {} 7 | local harbor_service 8 | 9 | skynet.register_protocol { 10 | name = "harbor", 11 | id = skynet.PTYPE_HARBOR, 12 | pack = function(...) return ... end, 13 | unpack = skynet.tostring, 14 | } 15 | 16 | skynet.register_protocol { 17 | name = "text", 18 | id = skynet.PTYPE_TEXT, 19 | pack = function(...) return ... end, 20 | unpack = skynet.tostring, 21 | } 22 | 23 | local function response_name(name) 24 | local address = globalname[name] 25 | if queryname[name] then 26 | local tmp = queryname[name] 27 | queryname[name] = nil 28 | for _,resp in ipairs(tmp) do 29 | resp(true, address) 30 | end 31 | end 32 | end 33 | 34 | function harbor.REGISTER(name, handle) 35 | assert(globalname[name] == nil) 36 | globalname[name] = handle 37 | response_name(name) 38 | skynet.redirect(harbor_service, handle, "harbor", 0, "N " .. name) 39 | end 40 | 41 | function harbor.QUERYNAME(name) 42 | if name:byte() == 46 then -- "." , local name 43 | skynet.ret(skynet.pack(skynet.localname(name))) 44 | return 45 | end 46 | local result = globalname[name] 47 | if result then 48 | skynet.ret(skynet.pack(result)) 49 | return 50 | end 51 | local queue = queryname[name] 52 | if queue == nil then 53 | queue = { skynet.response() } 54 | queryname[name] = queue 55 | else 56 | table.insert(queue, skynet.response()) 57 | end 58 | end 59 | 60 | function harbor.LINK(id) 61 | skynet.ret() 62 | end 63 | 64 | function harbor.CONNECT(id) 65 | skynet.error("Can't connect to other harbor in single node mode") 66 | end 67 | 68 | skynet.start(function() 69 | local harbor_id = tonumber(skynet.getenv "harbor") 70 | assert(harbor_id == 0) 71 | 72 | skynet.dispatch("lua", function (session,source,command,...) 73 | local f = assert(harbor[command]) 74 | f(...) 75 | end) 76 | skynet.dispatch("text", function(session,source,command) 77 | -- ignore all the command 78 | end) 79 | 80 | harbor_service = assert(skynet.launch("harbor", harbor_id, skynet.self())) 81 | end) 82 | -------------------------------------------------------------------------------- /duktape/duk_replacements.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Replacements for missing platform functions. 3 | * 4 | * Unlike the originals, fpclassify() and signbit() replacements don't 5 | * work on any floating point types, only doubles. The C typing here 6 | * mimics the standard prototypes. 7 | */ 8 | 9 | #include "duk_internal.h" 10 | 11 | #if defined(DUK_USE_COMPUTED_NAN) 12 | DUK_INTERNAL double duk_computed_nan; 13 | #endif 14 | 15 | #if defined(DUK_USE_COMPUTED_INFINITY) 16 | DUK_INTERNAL double duk_computed_infinity; 17 | #endif 18 | 19 | #if defined(DUK_USE_REPL_FPCLASSIFY) 20 | DUK_INTERNAL int duk_repl_fpclassify(double x) { 21 | duk_double_union u; 22 | duk_uint_fast16_t expt; 23 | duk_small_int_t mzero; 24 | 25 | u.d = x; 26 | expt = (duk_uint_fast16_t) (u.us[DUK_DBL_IDX_US0] & 0x7ff0UL); 27 | if (expt > 0x0000UL && expt < 0x7ff0UL) { 28 | /* expt values [0x001,0x7fe] = normal */ 29 | return DUK_FP_NORMAL; 30 | } 31 | 32 | mzero = (u.ui[DUK_DBL_IDX_UI1] == 0 && (u.ui[DUK_DBL_IDX_UI0] & 0x000fffffUL) == 0); 33 | if (expt == 0x0000UL) { 34 | /* expt 0x000 is zero/subnormal */ 35 | if (mzero) { 36 | return DUK_FP_ZERO; 37 | } else { 38 | return DUK_FP_SUBNORMAL; 39 | } 40 | } else { 41 | /* expt 0xfff is infinite/nan */ 42 | if (mzero) { 43 | return DUK_FP_INFINITE; 44 | } else { 45 | return DUK_FP_NAN; 46 | } 47 | } 48 | } 49 | #endif 50 | 51 | #if defined(DUK_USE_REPL_SIGNBIT) 52 | DUK_INTERNAL int duk_repl_signbit(double x) { 53 | duk_double_union u; 54 | u.d = x; 55 | return (int) (u.uc[DUK_DBL_IDX_UC0] & 0x80UL); 56 | } 57 | #endif 58 | 59 | #if defined(DUK_USE_REPL_ISFINITE) 60 | DUK_INTERNAL int duk_repl_isfinite(double x) { 61 | int c = DUK_FPCLASSIFY(x); 62 | if (c == DUK_FP_NAN || c == DUK_FP_INFINITE) { 63 | return 0; 64 | } else { 65 | return 1; 66 | } 67 | } 68 | #endif 69 | 70 | #if defined(DUK_USE_REPL_ISNAN) 71 | DUK_INTERNAL int duk_repl_isnan(double x) { 72 | int c = DUK_FPCLASSIFY(x); 73 | return (c == DUK_FP_NAN); 74 | } 75 | #endif 76 | 77 | #if defined(DUK_USE_REPL_ISINF) 78 | DUK_INTERNAL int duk_repl_isinf(double x) { 79 | int c = DUK_FPCLASSIFY(x); 80 | return (c == DUK_FP_INFINITE); 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /tool/zero/lualib/mqueue.lua: -------------------------------------------------------------------------------- 1 | -- This is a deprecated module, use skynet.queue instead. 2 | 3 | local skynet = require "skynet" 4 | local c = require "skynet.core" 5 | 6 | local mqueue = {} 7 | local init_once 8 | local thread_id 9 | local message_queue = {} 10 | 11 | skynet.register_protocol { 12 | name = "queue", 13 | -- please read skynet.h for magic number 8 14 | id = 8, 15 | pack = skynet.pack, 16 | unpack = skynet.unpack, 17 | dispatch = function(session, from, ...) 18 | table.insert(message_queue, {session = session, addr = from, ... }) 19 | if thread_id then 20 | skynet.wakeup(thread_id) 21 | thread_id = nil 22 | end 23 | end 24 | } 25 | 26 | local function do_func(f, msg) 27 | return pcall(f, table.unpack(msg)) 28 | end 29 | 30 | local function message_dispatch(f) 31 | while true do 32 | if #message_queue==0 then 33 | thread_id = coroutine.running() 34 | skynet.wait() 35 | else 36 | local msg = table.remove(message_queue,1) 37 | local session = msg.session 38 | if session == 0 then 39 | local ok, msg = do_func(f, msg) 40 | if ok then 41 | if msg then 42 | skynet.fork(message_dispatch,f) 43 | error(string.format("[:%x] send a message to [:%x] return something", msg.addr, skynet.self())) 44 | end 45 | else 46 | skynet.fork(message_dispatch,f) 47 | error(string.format("[:%x] send a message to [:%x] throw an error : %s", msg.addr, skynet.self(),msg)) 48 | end 49 | else 50 | local data, size = skynet.pack(do_func(f,msg)) 51 | -- 1 means response 52 | c.send(msg.addr, 1, session, data, size) 53 | end 54 | end 55 | end 56 | end 57 | 58 | function mqueue.register(f) 59 | assert(init_once == nil) 60 | init_once = true 61 | skynet.fork(message_dispatch,f) 62 | end 63 | 64 | local function catch(succ, ...) 65 | if succ then 66 | return ... 67 | else 68 | error(...) 69 | end 70 | end 71 | 72 | function mqueue.call(addr, ...) 73 | return catch(skynet.call(addr, "queue", ...)) 74 | end 75 | 76 | function mqueue.send(addr, ...) 77 | return skynet.send(addr, "queue", ...) 78 | end 79 | 80 | function mqueue.size() 81 | return #message_queue 82 | end 83 | 84 | return mqueue 85 | -------------------------------------------------------------------------------- /libuv/src/unix/spinlock.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Ben Noordhuis 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | */ 15 | 16 | #ifndef UV_SPINLOCK_H_ 17 | #define UV_SPINLOCK_H_ 18 | 19 | #include "internal.h" /* ACCESS_ONCE, UV_UNUSED */ 20 | #include "atomic-ops.h" 21 | 22 | #define UV_SPINLOCK_INITIALIZER { 0 } 23 | 24 | typedef struct { 25 | int lock; 26 | } uv_spinlock_t; 27 | 28 | UV_UNUSED(static void uv_spinlock_init(uv_spinlock_t* spinlock)); 29 | UV_UNUSED(static void uv_spinlock_lock(uv_spinlock_t* spinlock)); 30 | UV_UNUSED(static void uv_spinlock_unlock(uv_spinlock_t* spinlock)); 31 | UV_UNUSED(static int uv_spinlock_trylock(uv_spinlock_t* spinlock)); 32 | 33 | UV_UNUSED(static void uv_spinlock_init(uv_spinlock_t* spinlock)) { 34 | ACCESS_ONCE(int, spinlock->lock) = 0; 35 | } 36 | 37 | UV_UNUSED(static void uv_spinlock_lock(uv_spinlock_t* spinlock)) { 38 | while (!uv_spinlock_trylock(spinlock)) cpu_relax(); 39 | } 40 | 41 | UV_UNUSED(static void uv_spinlock_unlock(uv_spinlock_t* spinlock)) { 42 | ACCESS_ONCE(int, spinlock->lock) = 0; 43 | } 44 | 45 | UV_UNUSED(static int uv_spinlock_trylock(uv_spinlock_t* spinlock)) { 46 | /* TODO(bnoordhuis) Maybe change to a ticket lock to guarantee fair queueing. 47 | * Not really critical until we have locks that are (frequently) contended 48 | * for by several threads. 49 | */ 50 | return 0 == cmpxchgi(&spinlock->lock, 0, 1); 51 | } 52 | 53 | #endif /* UV_SPINLOCK_H_ */ 54 | -------------------------------------------------------------------------------- /duktape/duk_debug_fixedbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Fixed buffer helper useful for debugging, requires no allocation 3 | * which is critical for debugging. 4 | */ 5 | 6 | #include "duk_internal.h" 7 | 8 | #if defined(DUK_USE_DEBUG) 9 | 10 | DUK_INTERNAL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length) { 11 | duk_size_t avail; 12 | duk_size_t copylen; 13 | 14 | avail = (fb->offset >= fb->length ? (duk_size_t) 0 : (duk_size_t) (fb->length - fb->offset)); 15 | if (length > avail) { 16 | copylen = avail; 17 | fb->truncated = 1; 18 | } else { 19 | copylen = length; 20 | } 21 | DUK_MEMCPY(fb->buffer + fb->offset, buffer, copylen); 22 | fb->offset += copylen; 23 | } 24 | 25 | DUK_INTERNAL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x) { 26 | duk_fb_put_bytes(fb, (const duk_uint8_t *) &x, 1); 27 | } 28 | 29 | DUK_INTERNAL void duk_fb_put_cstring(duk_fixedbuffer *fb, const char *x) { 30 | duk_fb_put_bytes(fb, (const duk_uint8_t *) x, (duk_size_t) DUK_STRLEN(x)); 31 | } 32 | 33 | DUK_INTERNAL void duk_fb_sprintf(duk_fixedbuffer *fb, const char *fmt, ...) { 34 | duk_size_t avail; 35 | va_list ap; 36 | 37 | va_start(ap, fmt); 38 | avail = (fb->offset >= fb->length ? (duk_size_t) 0 : (duk_size_t) (fb->length - fb->offset)); 39 | if (avail > 0) { 40 | duk_int_t res = (duk_int_t) DUK_VSNPRINTF((char *) (fb->buffer + fb->offset), avail, fmt, ap); 41 | if (res < 0) { 42 | /* error */ 43 | } else if ((duk_size_t) res >= avail) { 44 | /* (maybe) truncated */ 45 | fb->offset += avail; 46 | if ((duk_size_t) res > avail) { 47 | /* actual chars dropped (not just NUL term) */ 48 | fb->truncated = 1; 49 | } 50 | } else { 51 | /* normal */ 52 | fb->offset += res; 53 | } 54 | } 55 | va_end(ap); 56 | } 57 | 58 | DUK_INTERNAL void duk_fb_put_funcptr(duk_fixedbuffer *fb, duk_uint8_t *fptr, duk_size_t fptr_size) { 59 | char buf[64+1]; 60 | duk_debug_format_funcptr(buf, sizeof(buf), fptr, fptr_size); 61 | buf[sizeof(buf) - 1] = (char) 0; 62 | duk_fb_put_cstring(fb, buf); 63 | } 64 | 65 | DUK_INTERNAL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb) { 66 | return (fb->offset >= fb->length); 67 | } 68 | 69 | #endif /* DUK_USE_DEBUG */ 70 | -------------------------------------------------------------------------------- /duktape/duk_bi_pointer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Pointer built-ins 3 | */ 4 | 5 | #include "duk_internal.h" 6 | 7 | /* 8 | * Constructor 9 | */ 10 | 11 | DUK_INTERNAL duk_ret_t duk_bi_pointer_constructor(duk_context *ctx) { 12 | /* XXX: this behavior is quite useless now; it would be nice to be able 13 | * to create pointer values from e.g. numbers or strings. Numbers are 14 | * problematic on 64-bit platforms though. Hex encoded strings? 15 | */ 16 | if (duk_get_top(ctx) == 0) { 17 | duk_push_pointer(ctx, NULL); 18 | } else { 19 | duk_to_pointer(ctx, 0); 20 | } 21 | DUK_ASSERT(duk_is_pointer(ctx, 0)); 22 | duk_set_top(ctx, 1); 23 | 24 | if (duk_is_constructor_call(ctx)) { 25 | (void) duk_push_object_helper(ctx, 26 | DUK_HOBJECT_FLAG_EXTENSIBLE | 27 | DUK_HOBJECT_FLAG_FASTREFS | 28 | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_POINTER), 29 | DUK_BIDX_POINTER_PROTOTYPE); 30 | 31 | /* Pointer object internal value is immutable */ 32 | duk_dup_0(ctx); 33 | duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); 34 | } 35 | /* Note: unbalanced stack on purpose */ 36 | 37 | return 1; 38 | } 39 | 40 | /* 41 | * toString(), valueOf() 42 | */ 43 | 44 | DUK_INTERNAL duk_ret_t duk_bi_pointer_prototype_tostring_shared(duk_context *ctx) { 45 | duk_tval *tv; 46 | duk_small_int_t to_string = duk_get_current_magic(ctx); 47 | 48 | duk_push_this(ctx); 49 | tv = duk_require_tval(ctx, -1); 50 | DUK_ASSERT(tv != NULL); 51 | 52 | if (DUK_TVAL_IS_POINTER(tv)) { 53 | /* nop */ 54 | } else if (DUK_TVAL_IS_OBJECT(tv)) { 55 | duk_hobject *h = DUK_TVAL_GET_OBJECT(tv); 56 | DUK_ASSERT(h != NULL); 57 | 58 | /* Must be a "pointer object", i.e. class "Pointer" */ 59 | if (DUK_HOBJECT_GET_CLASS_NUMBER(h) != DUK_HOBJECT_CLASS_POINTER) { 60 | goto type_error; 61 | } 62 | 63 | duk_get_prop_stridx_short(ctx, -1, DUK_STRIDX_INT_VALUE); 64 | } else { 65 | goto type_error; 66 | } 67 | 68 | if (to_string) { 69 | duk_to_string(ctx, -1); 70 | } 71 | return 1; 72 | 73 | type_error: 74 | DUK_DCERROR_TYPE_INVALID_ARGS((duk_hthread *) ctx); 75 | } 76 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/jemalloc_internal_decls.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_DECLS_H 2 | #define JEMALLOC_INTERNAL_DECLS_H 3 | 4 | #include 5 | #ifdef _WIN32 6 | # include 7 | # include "msvc_compat/windows_extra.h" 8 | 9 | #else 10 | # include 11 | # include 12 | # if !defined(__pnacl__) && !defined(__native_client__) 13 | # include 14 | # if !defined(SYS_write) && defined(__NR_write) 15 | # define SYS_write __NR_write 16 | # endif 17 | # if defined(SYS_open) && defined(__aarch64__) 18 | /* Android headers may define SYS_open to __NR_open even though 19 | * __NR_open may not exist on AArch64 (superseded by __NR_openat). */ 20 | # undef SYS_open 21 | # endif 22 | # include 23 | # endif 24 | # include 25 | # ifdef JEMALLOC_OS_UNFAIR_LOCK 26 | # include 27 | # endif 28 | # ifdef JEMALLOC_GLIBC_MALLOC_HOOK 29 | # include 30 | # endif 31 | # include 32 | # include 33 | # include 34 | # ifdef JEMALLOC_HAVE_MACH_ABSOLUTE_TIME 35 | # include 36 | # endif 37 | #endif 38 | #include 39 | 40 | #include 41 | #ifndef SIZE_T_MAX 42 | # define SIZE_T_MAX SIZE_MAX 43 | #endif 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #ifndef offsetof 51 | # define offsetof(type, member) ((size_t)&(((type *)NULL)->member)) 52 | #endif 53 | #include 54 | #include 55 | #include 56 | #ifdef _MSC_VER 57 | # include 58 | typedef intptr_t ssize_t; 59 | # define PATH_MAX 1024 60 | # define STDERR_FILENO 2 61 | # define __func__ __FUNCTION__ 62 | # ifdef JEMALLOC_HAS_RESTRICT 63 | # define restrict __restrict 64 | # endif 65 | /* Disable warnings about deprecated system functions. */ 66 | # pragma warning(disable: 4996) 67 | #if _MSC_VER < 1800 68 | static int 69 | isblank(int c) { 70 | return (c == '\t' || c == ' '); 71 | } 72 | #endif 73 | #else 74 | # include 75 | #endif 76 | #include 77 | 78 | #endif /* JEMALLOC_INTERNAL_H */ 79 | -------------------------------------------------------------------------------- /libuv/src/win/stream-inl.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_WIN_STREAM_INL_H_ 23 | #define UV_WIN_STREAM_INL_H_ 24 | 25 | #include 26 | 27 | #include "uv.h" 28 | #include "internal.h" 29 | #include "handle-inl.h" 30 | #include "req-inl.h" 31 | 32 | 33 | INLINE static void uv_stream_init(uv_loop_t* loop, 34 | uv_stream_t* handle, 35 | uv_handle_type type) { 36 | uv__handle_init(loop, (uv_handle_t*) handle, type); 37 | handle->write_queue_size = 0; 38 | handle->activecnt = 0; 39 | } 40 | 41 | 42 | INLINE static void uv_connection_init(uv_stream_t* handle) { 43 | handle->flags |= UV_HANDLE_CONNECTION; 44 | handle->stream.conn.write_reqs_pending = 0; 45 | 46 | UV_REQ_INIT(&handle->read_req, UV_READ); 47 | handle->read_req.event_handle = NULL; 48 | handle->read_req.wait_handle = INVALID_HANDLE_VALUE; 49 | handle->read_req.data = handle; 50 | 51 | handle->stream.conn.shutdown_req = NULL; 52 | } 53 | 54 | 55 | #endif /* UV_WIN_STREAM_INL_H_ */ 56 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/internal/rtree_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_RTREE_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_RTREE_EXTERNS_H 3 | 4 | /* 5 | * Split the bits into one to three partitions depending on number of 6 | * significant bits. It the number of bits does not divide evenly into the 7 | * number of levels, place one remainder bit per level starting at the leaf 8 | * level. 9 | */ 10 | static const rtree_level_t rtree_levels[] = { 11 | #if RTREE_HEIGHT == 1 12 | {RTREE_NSB, RTREE_NHIB + RTREE_NSB} 13 | #elif RTREE_HEIGHT == 2 14 | {RTREE_NSB/2, RTREE_NHIB + RTREE_NSB/2}, 15 | {RTREE_NSB/2 + RTREE_NSB%2, RTREE_NHIB + RTREE_NSB} 16 | #elif RTREE_HEIGHT == 3 17 | {RTREE_NSB/3, RTREE_NHIB + RTREE_NSB/3}, 18 | {RTREE_NSB/3 + RTREE_NSB%3/2, 19 | RTREE_NHIB + RTREE_NSB/3*2 + RTREE_NSB%3/2}, 20 | {RTREE_NSB/3 + RTREE_NSB%3 - RTREE_NSB%3/2, RTREE_NHIB + RTREE_NSB} 21 | #else 22 | # error Unsupported rtree height 23 | #endif 24 | }; 25 | 26 | bool rtree_new(rtree_t *rtree, bool zeroed); 27 | 28 | typedef rtree_node_elm_t *(rtree_node_alloc_t)(tsdn_t *, rtree_t *, size_t); 29 | extern rtree_node_alloc_t *JET_MUTABLE rtree_node_alloc; 30 | 31 | typedef rtree_leaf_elm_t *(rtree_leaf_alloc_t)(tsdn_t *, rtree_t *, size_t); 32 | extern rtree_leaf_alloc_t *JET_MUTABLE rtree_leaf_alloc; 33 | 34 | typedef void (rtree_node_dalloc_t)(tsdn_t *, rtree_t *, rtree_node_elm_t *); 35 | extern rtree_node_dalloc_t *JET_MUTABLE rtree_node_dalloc; 36 | 37 | typedef void (rtree_leaf_dalloc_t)(tsdn_t *, rtree_t *, rtree_leaf_elm_t *); 38 | extern rtree_leaf_dalloc_t *JET_MUTABLE rtree_leaf_dalloc; 39 | #ifdef JEMALLOC_JET 40 | void rtree_delete(tsdn_t *tsdn, rtree_t *rtree); 41 | #endif 42 | rtree_leaf_elm_t *rtree_leaf_elm_lookup_hard(tsdn_t *tsdn, rtree_t *rtree, 43 | rtree_ctx_t *rtree_ctx, uintptr_t key, bool dependent, bool init_missing); 44 | void rtree_leaf_elm_witness_acquire(tsdn_t *tsdn, const rtree_t *rtree, 45 | uintptr_t key, const rtree_leaf_elm_t *elm); 46 | void rtree_leaf_elm_witness_access(tsdn_t *tsdn, const rtree_t *rtree, 47 | const rtree_leaf_elm_t *elm); 48 | void rtree_leaf_elm_witness_release(tsdn_t *tsdn, const rtree_t *rtree, 49 | const rtree_leaf_elm_t *elm); 50 | 51 | #endif /* JEMALLOC_INTERNAL_RTREE_EXTERNS_H */ 52 | -------------------------------------------------------------------------------- /duktape/duk_bi_boolean.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Boolean built-ins 3 | */ 4 | 5 | #include "duk_internal.h" 6 | 7 | #if defined(DUK_USE_BOOLEAN_BUILTIN) 8 | 9 | /* Shared helper to provide toString() and valueOf(). Checks 'this', gets 10 | * the primitive value to stack top, and optionally coerces with ToString(). 11 | */ 12 | DUK_INTERNAL duk_ret_t duk_bi_boolean_prototype_tostring_shared(duk_context *ctx) { 13 | duk_tval *tv; 14 | duk_hobject *h; 15 | duk_small_int_t coerce_tostring = duk_get_current_magic(ctx); 16 | 17 | /* XXX: there is room to use a shared helper here, many built-ins 18 | * check the 'this' type, and if it's an object, check its class, 19 | * then get its internal value, etc. 20 | */ 21 | 22 | duk_push_this(ctx); 23 | tv = duk_get_tval(ctx, -1); 24 | DUK_ASSERT(tv != NULL); 25 | 26 | if (DUK_TVAL_IS_BOOLEAN(tv)) { 27 | goto type_ok; 28 | } else if (DUK_TVAL_IS_OBJECT(tv)) { 29 | h = DUK_TVAL_GET_OBJECT(tv); 30 | DUK_ASSERT(h != NULL); 31 | 32 | if (DUK_HOBJECT_GET_CLASS_NUMBER(h) == DUK_HOBJECT_CLASS_BOOLEAN) { 33 | duk_get_prop_stridx_short(ctx, -1, DUK_STRIDX_INT_VALUE); 34 | DUK_ASSERT(duk_is_boolean(ctx, -1)); 35 | goto type_ok; 36 | } 37 | } 38 | 39 | DUK_DCERROR_TYPE_INVALID_ARGS((duk_hthread *) ctx); 40 | /* never here */ 41 | 42 | type_ok: 43 | if (coerce_tostring) { 44 | duk_to_string(ctx, -1); 45 | } 46 | return 1; 47 | } 48 | 49 | DUK_INTERNAL duk_ret_t duk_bi_boolean_constructor(duk_context *ctx) { 50 | duk_hthread *thr = (duk_hthread *) ctx; 51 | duk_hobject *h_this; 52 | 53 | DUK_UNREF(thr); 54 | 55 | duk_to_boolean(ctx, 0); 56 | 57 | if (duk_is_constructor_call(ctx)) { 58 | /* XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable */ 59 | duk_push_this(ctx); 60 | h_this = duk_known_hobject(ctx, -1); 61 | DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h_this) == thr->builtins[DUK_BIDX_BOOLEAN_PROTOTYPE]); 62 | 63 | DUK_HOBJECT_SET_CLASS_NUMBER(h_this, DUK_HOBJECT_CLASS_BOOLEAN); 64 | 65 | duk_dup_0(ctx); /* -> [ val obj val ] */ 66 | duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE); /* XXX: proper flags? */ 67 | } /* unbalanced stack */ 68 | 69 | return 1; 70 | } 71 | 72 | #endif /* DUK_USE_BOOLEAN_BUILTIN */ 73 | -------------------------------------------------------------------------------- /lua/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /lua/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc_mangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * By default application code must explicitly refer to mangled symbol names, 3 | * so that it is possible to use jemalloc in conjunction with another allocator 4 | * in the same application. Define JEMALLOC_MANGLE in order to cause automatic 5 | * name mangling that matches the API prefixing that happened as a result of 6 | * --with-mangling and/or --with-jemalloc-prefix configuration settings. 7 | */ 8 | #ifdef JEMALLOC_MANGLE 9 | # ifndef JEMALLOC_NO_DEMANGLE 10 | # define JEMALLOC_NO_DEMANGLE 11 | # endif 12 | # define aligned_alloc je_aligned_alloc 13 | # define calloc je_calloc 14 | # define dallocx je_dallocx 15 | # define free je_free 16 | # define mallctl je_mallctl 17 | # define mallctlbymib je_mallctlbymib 18 | # define mallctlnametomib je_mallctlnametomib 19 | # define malloc je_malloc 20 | # define malloc_conf je_malloc_conf 21 | # define malloc_message je_malloc_message 22 | # define malloc_stats_print je_malloc_stats_print 23 | # define malloc_usable_size je_malloc_usable_size 24 | # define mallocx je_mallocx 25 | # define nallocx je_nallocx 26 | # define posix_memalign je_posix_memalign 27 | # define rallocx je_rallocx 28 | # define realloc je_realloc 29 | # define sallocx je_sallocx 30 | # define sdallocx je_sdallocx 31 | # define xallocx je_xallocx 32 | #endif 33 | 34 | /* 35 | * The je_* macros can be used as stable alternative names for the 36 | * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily 37 | * meant for use in jemalloc itself, but it can be used by application code to 38 | * provide isolation from the name mangling specified via --with-mangling 39 | * and/or --with-jemalloc-prefix. 40 | */ 41 | #ifndef JEMALLOC_NO_DEMANGLE 42 | # undef je_aligned_alloc 43 | # undef je_calloc 44 | # undef je_dallocx 45 | # undef je_free 46 | # undef je_mallctl 47 | # undef je_mallctlbymib 48 | # undef je_mallctlnametomib 49 | # undef je_malloc 50 | # undef je_malloc_conf 51 | # undef je_malloc_message 52 | # undef je_malloc_stats_print 53 | # undef je_malloc_usable_size 54 | # undef je_mallocx 55 | # undef je_nallocx 56 | # undef je_posix_memalign 57 | # undef je_rallocx 58 | # undef je_realloc 59 | # undef je_sallocx 60 | # undef je_sdallocx 61 | # undef je_xallocx 62 | #endif 63 | -------------------------------------------------------------------------------- /libuv/include/pthread-barrier.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Kari Tristan Helgason 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _UV_PTHREAD_BARRIER_ 18 | #define _UV_PTHREAD_BARRIER_ 19 | #include 20 | #include 21 | #if !defined(__MVS__) 22 | #include /* sem_t */ 23 | #endif 24 | 25 | #define PTHREAD_BARRIER_SERIAL_THREAD 0x12345 26 | 27 | /* 28 | * To maintain ABI compatibility with 29 | * libuv v1.x struct is padded according 30 | * to target platform 31 | */ 32 | #if defined(__ANDROID__) 33 | # define UV_BARRIER_STRUCT_PADDING \ 34 | sizeof(pthread_mutex_t) + \ 35 | sizeof(pthread_cond_t) + \ 36 | sizeof(unsigned int) - \ 37 | sizeof(void *) 38 | #elif defined(__APPLE__) 39 | # define UV_BARRIER_STRUCT_PADDING \ 40 | sizeof(pthread_mutex_t) + \ 41 | 2 * sizeof(sem_t) + \ 42 | 2 * sizeof(unsigned int) - \ 43 | sizeof(void *) 44 | #else 45 | # define UV_BARRIER_STRUCT_PADDING 0 46 | #endif 47 | 48 | typedef struct { 49 | pthread_mutex_t mutex; 50 | pthread_cond_t cond; 51 | unsigned threshold; 52 | unsigned in; 53 | unsigned out; 54 | } _uv_barrier; 55 | 56 | typedef struct { 57 | _uv_barrier* b; 58 | char _pad[UV_BARRIER_STRUCT_PADDING]; 59 | } pthread_barrier_t; 60 | 61 | int pthread_barrier_init(pthread_barrier_t* barrier, 62 | const void* barrier_attr, 63 | unsigned count); 64 | 65 | int pthread_barrier_wait(pthread_barrier_t* barrier); 66 | int pthread_barrier_destroy(pthread_barrier_t *barrier); 67 | 68 | #endif /* _UV_PTHREAD_BARRIER_ */ 69 | -------------------------------------------------------------------------------- /duktape/duk_api_buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Buffer 3 | */ 4 | 5 | #include "duk_internal.h" 6 | 7 | DUK_EXTERNAL void *duk_resize_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t new_size) { 8 | duk_hthread *thr = (duk_hthread *) ctx; 9 | duk_hbuffer_dynamic *h; 10 | 11 | DUK_ASSERT_CTX_VALID(ctx); 12 | 13 | h = (duk_hbuffer_dynamic *) duk_require_hbuffer(ctx, idx); 14 | DUK_ASSERT(h != NULL); 15 | 16 | if (!(DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h))) { 17 | DUK_ERROR_TYPE(thr, DUK_STR_WRONG_BUFFER_TYPE); 18 | } 19 | 20 | /* maximum size check is handled by callee */ 21 | duk_hbuffer_resize(thr, h, new_size); 22 | 23 | return DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h); 24 | } 25 | 26 | DUK_EXTERNAL void *duk_steal_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size) { 27 | duk_hthread *thr = (duk_hthread *) ctx; 28 | duk_hbuffer_dynamic *h; 29 | void *ptr; 30 | duk_size_t sz; 31 | 32 | DUK_ASSERT(ctx != NULL); 33 | 34 | h = (duk_hbuffer_dynamic *) duk_require_hbuffer(ctx, idx); 35 | DUK_ASSERT(h != NULL); 36 | 37 | if (!(DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h))) { 38 | DUK_ERROR_TYPE(thr, DUK_STR_WRONG_BUFFER_TYPE); 39 | } 40 | 41 | /* Forget the previous allocation, setting size to 0 and alloc to 42 | * NULL. Caller is responsible for freeing the previous allocation. 43 | * Getting the allocation and clearing it is done in the same API 44 | * call to avoid any chance of a realloc. 45 | */ 46 | ptr = DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h); 47 | sz = DUK_HBUFFER_DYNAMIC_GET_SIZE(h); 48 | if (out_size) { 49 | *out_size = sz; 50 | } 51 | DUK_HBUFFER_DYNAMIC_SET_DATA_PTR_NULL(thr->heap, h); 52 | DUK_HBUFFER_DYNAMIC_SET_SIZE(h, 0); 53 | 54 | return ptr; 55 | } 56 | 57 | DUK_EXTERNAL void duk_config_buffer(duk_context *ctx, duk_idx_t idx, void *ptr, duk_size_t len) { 58 | duk_hthread *thr = (duk_hthread *) ctx; 59 | duk_hbuffer_external *h; 60 | 61 | DUK_ASSERT(ctx != NULL); 62 | 63 | h = (duk_hbuffer_external *) duk_require_hbuffer(ctx, idx); 64 | DUK_ASSERT(h != NULL); 65 | 66 | if (!DUK_HBUFFER_HAS_EXTERNAL(h)) { 67 | DUK_ERROR_TYPE(thr, DUK_STR_WRONG_BUFFER_TYPE); 68 | } 69 | DUK_ASSERT(DUK_HBUFFER_HAS_DYNAMIC(h)); 70 | 71 | DUK_HBUFFER_EXTERNAL_SET_DATA_PTR(thr->heap, h, ptr); 72 | DUK_HBUFFER_EXTERNAL_SET_SIZE(h, len); 73 | } 74 | -------------------------------------------------------------------------------- /src/lualib/lpeg/lptree.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lptree_h) 6 | #define lptree_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* 13 | ** types of trees 14 | */ 15 | typedef enum TTag { 16 | TChar = 0, /* 'n' = char */ 17 | TSet, /* the set is stored in next CHARSETSIZE bytes */ 18 | TAny, 19 | TTrue, 20 | TFalse, 21 | TRep, /* 'sib1'* */ 22 | TSeq, /* 'sib1' 'sib2' */ 23 | TChoice, /* 'sib1' / 'sib2' */ 24 | TNot, /* !'sib1' */ 25 | TAnd, /* &'sib1' */ 26 | TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */ 27 | TOpenCall, /* ktable[key] is rule's key */ 28 | TRule, /* ktable[key] is rule's key (but key == 0 for unused rules); 29 | 'sib1' is rule's pattern; 30 | 'sib2' is next rule; 'cap' is rule's sequential number */ 31 | TGrammar, /* 'sib1' is initial (and first) rule */ 32 | TBehind, /* 'sib1' is pattern, 'n' is how much to go back */ 33 | TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind'); 34 | ktable[key] is Lua value associated with capture; 35 | 'sib1' is capture body */ 36 | TRunTime /* run-time capture: 'key' is Lua function; 37 | 'sib1' is capture body */ 38 | } TTag; 39 | 40 | 41 | /* 42 | ** Tree trees 43 | ** The first child of a tree (if there is one) is immediately after 44 | ** the tree. A reference to a second child (ps) is its position 45 | ** relative to the position of the tree itself. 46 | */ 47 | typedef struct TTree { 48 | byte tag; 49 | byte cap; /* kind of capture (if it is a capture) */ 50 | unsigned short key; /* key in ktable for Lua data (0 if no key) */ 51 | union { 52 | int ps; /* occasional second child */ 53 | int n; /* occasional counter */ 54 | } u; 55 | } TTree; 56 | 57 | 58 | /* 59 | ** A complete pattern has its tree plus, if already compiled, 60 | ** its corresponding code 61 | */ 62 | typedef struct Pattern { 63 | union Instruction *code; 64 | int codesize; 65 | TTree tree[1]; 66 | } Pattern; 67 | 68 | 69 | /* number of children for each tree */ 70 | extern const byte numsiblings[]; 71 | 72 | /* access to children */ 73 | #define sib1(t) ((t) + 1) 74 | #define sib2(t) ((t) + (t)->u.ps) 75 | 76 | 77 | 78 | 79 | 80 | 81 | #endif 82 | 83 | -------------------------------------------------------------------------------- /tool/zero/lualib/skynet/manager.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local c = require "skynet.core" 3 | 4 | function skynet.launch(...) 5 | local addr = c.command("LAUNCH", table.concat({...}," ")) 6 | if addr then 7 | return tonumber("0x" .. string.sub(addr , 2)) 8 | end 9 | end 10 | 11 | function skynet.kill(name) 12 | if type(name) == "number" then 13 | skynet.send(".launcher","lua","REMOVE",name, true) 14 | name = skynet.address(name) 15 | end 16 | c.command("KILL",name) 17 | end 18 | 19 | function skynet.abort() 20 | c.command("ABORT") 21 | end 22 | 23 | local function globalname(name, handle) 24 | local c = string.sub(name,1,1) 25 | assert(c ~= ':') 26 | if c == '.' then 27 | return false 28 | end 29 | 30 | assert(#name <= 16) -- GLOBALNAME_LENGTH is 16, defined in skynet_harbor.h 31 | assert(tonumber(name) == nil) -- global name can't be number 32 | 33 | local harbor = require "skynet.harbor" 34 | 35 | harbor.globalname(name, handle) 36 | 37 | return true 38 | end 39 | 40 | function skynet.register(name) 41 | if not globalname(name) then 42 | c.command("REG", name) 43 | end 44 | end 45 | 46 | function skynet.name(name, handle) 47 | if not globalname(name, handle) then 48 | c.command("NAME", name .. " " .. skynet.address(handle)) 49 | end 50 | end 51 | 52 | local dispatch_message = skynet.dispatch_message 53 | 54 | function skynet.forward_type(map, start_func) 55 | c.callback(function(ptype, msg, sz, ...) 56 | local prototype = map[ptype] 57 | if prototype then 58 | dispatch_message(prototype, msg, sz, ...) 59 | else 60 | dispatch_message(ptype, msg, sz, ...) 61 | c.trash(msg, sz) 62 | end 63 | end, true) 64 | skynet.timeout(0, function() 65 | skynet.init_service(start_func) 66 | end) 67 | end 68 | 69 | function skynet.filter(f ,start_func) 70 | c.callback(function(...) 71 | dispatch_message(f(...)) 72 | end) 73 | skynet.timeout(0, function() 74 | skynet.init_service(start_func) 75 | end) 76 | end 77 | 78 | function skynet.monitor(service, query) 79 | local monitor 80 | if query then 81 | monitor = skynet.queryservice(true, service) 82 | else 83 | monitor = skynet.uniqueservice(true, service) 84 | end 85 | assert(monitor, "Monitor launch failed") 86 | c.command("MONITOR", string.format(":%08x", monitor)) 87 | return monitor 88 | end 89 | 90 | return skynet 91 | -------------------------------------------------------------------------------- /jemalloc/include/jemalloc/jemalloc_mangle_jet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * By default application code must explicitly refer to mangled symbol names, 3 | * so that it is possible to use jemalloc in conjunction with another allocator 4 | * in the same application. Define JEMALLOC_MANGLE in order to cause automatic 5 | * name mangling that matches the API prefixing that happened as a result of 6 | * --with-mangling and/or --with-jemalloc-prefix configuration settings. 7 | */ 8 | #ifdef JEMALLOC_MANGLE 9 | # ifndef JEMALLOC_NO_DEMANGLE 10 | # define JEMALLOC_NO_DEMANGLE 11 | # endif 12 | # define aligned_alloc jet_aligned_alloc 13 | # define calloc jet_calloc 14 | # define dallocx jet_dallocx 15 | # define free jet_free 16 | # define mallctl jet_mallctl 17 | # define mallctlbymib jet_mallctlbymib 18 | # define mallctlnametomib jet_mallctlnametomib 19 | # define malloc jet_malloc 20 | # define malloc_conf jet_malloc_conf 21 | # define malloc_message jet_malloc_message 22 | # define malloc_stats_print jet_malloc_stats_print 23 | # define malloc_usable_size jet_malloc_usable_size 24 | # define mallocx jet_mallocx 25 | # define nallocx jet_nallocx 26 | # define posix_memalign jet_posix_memalign 27 | # define rallocx jet_rallocx 28 | # define realloc jet_realloc 29 | # define sallocx jet_sallocx 30 | # define sdallocx jet_sdallocx 31 | # define xallocx jet_xallocx 32 | #endif 33 | 34 | /* 35 | * The jet_* macros can be used as stable alternative names for the 36 | * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily 37 | * meant for use in jemalloc itself, but it can be used by application code to 38 | * provide isolation from the name mangling specified via --with-mangling 39 | * and/or --with-jemalloc-prefix. 40 | */ 41 | #ifndef JEMALLOC_NO_DEMANGLE 42 | # undef jet_aligned_alloc 43 | # undef jet_calloc 44 | # undef jet_dallocx 45 | # undef jet_free 46 | # undef jet_mallctl 47 | # undef jet_mallctlbymib 48 | # undef jet_mallctlnametomib 49 | # undef jet_malloc 50 | # undef jet_malloc_conf 51 | # undef jet_malloc_message 52 | # undef jet_malloc_stats_print 53 | # undef jet_malloc_usable_size 54 | # undef jet_mallocx 55 | # undef jet_nallocx 56 | # undef jet_posix_memalign 57 | # undef jet_rallocx 58 | # undef jet_realloc 59 | # undef jet_sallocx 60 | # undef jet_sdallocx 61 | # undef jet_xallocx 62 | #endif 63 | -------------------------------------------------------------------------------- /lua/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* true when 't' is using 'dummynode' as its hash part */ 31 | #define isdummy(t) ((t)->lastfree == NULL) 32 | 33 | 34 | /* allocated size for hash nodes */ 35 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 36 | 37 | 38 | /* returns the key, given the value of a table entry */ 39 | #define keyfromval(v) \ 40 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 41 | 42 | 43 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 44 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 45 | TValue *value); 46 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 47 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 48 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 49 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 50 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 51 | LUAI_FUNC Table *luaH_new (lua_State *L); 52 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 53 | unsigned int nhsize); 54 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 55 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 56 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 57 | LUAI_FUNC int luaH_getn (Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | LUAI_FUNC int luaH_isdummy (const Table *t); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /libuv/src/unix/pthread-fixes.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Sony Mobile Communications AB 2 | * Copyright (c) 2012, Google Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | * Neither the name of Google Inc. nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /* Android versions < 4.1 have a broken pthread_sigmask. */ 33 | #include 34 | #include 35 | #include 36 | 37 | int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset) { 38 | static int workaround; 39 | int err; 40 | 41 | if (workaround) { 42 | return sigprocmask(how, set, oset); 43 | } else { 44 | err = pthread_sigmask(how, set, oset); 45 | if (err) { 46 | if (err == EINVAL && sigprocmask(how, set, oset) == 0) { 47 | workaround = 1; 48 | return 0; 49 | } else { 50 | return -1; 51 | } 52 | } 53 | } 54 | 55 | return 0; 56 | } 57 | --------------------------------------------------------------------------------