├── .gitignore ├── 00-RELEASENOTES ├── BUGS ├── CONTRIBUTING ├── COPYING ├── INSTALL ├── MANIFESTO ├── Makefile ├── README ├── README.rst ├── deps ├── Makefile ├── hiredis │ ├── .gitignore │ ├── CHANGELOG.md │ ├── COPYING │ ├── Makefile │ ├── README.md │ ├── adapters │ │ ├── ae.h │ │ ├── libev.h │ │ └── libevent.h │ ├── async.c │ ├── async.h │ ├── dict.c │ ├── dict.h │ ├── example-ae.c │ ├── example-libev.c │ ├── example-libevent.c │ ├── example.c │ ├── fmacros.h │ ├── hiredis.c │ ├── hiredis.h │ ├── net.c │ ├── net.h │ ├── sds.c │ ├── sds.h │ ├── test.c │ └── zmalloc.h ├── jemalloc │ ├── .gitignore │ ├── COPYING │ ├── ChangeLog │ ├── INSTALL │ ├── Makefile.in │ ├── README │ ├── VERSION │ ├── autogen.sh │ ├── bin │ │ ├── jemalloc.sh.in │ │ └── pprof │ ├── config.guess │ ├── config.stamp.in │ ├── config.sub │ ├── configure │ ├── configure.ac │ ├── doc │ │ ├── html.xsl.in │ │ ├── jemalloc.3 │ │ ├── jemalloc.html │ │ ├── jemalloc.xml.in │ │ ├── manpages.xsl.in │ │ └── stylesheet.xsl │ ├── include │ │ ├── jemalloc │ │ │ ├── internal │ │ │ │ ├── arena.h │ │ │ │ ├── atomic.h │ │ │ │ ├── base.h │ │ │ │ ├── bitmap.h │ │ │ │ ├── chunk.h │ │ │ │ ├── chunk_dss.h │ │ │ │ ├── chunk_mmap.h │ │ │ │ ├── ckh.h │ │ │ │ ├── ctl.h │ │ │ │ ├── extent.h │ │ │ │ ├── hash.h │ │ │ │ ├── huge.h │ │ │ │ ├── jemalloc_internal.h.in │ │ │ │ ├── mb.h │ │ │ │ ├── mutex.h │ │ │ │ ├── private_namespace.h │ │ │ │ ├── prng.h │ │ │ │ ├── prof.h │ │ │ │ ├── ql.h │ │ │ │ ├── qr.h │ │ │ │ ├── quarantine.h │ │ │ │ ├── rb.h │ │ │ │ ├── rtree.h │ │ │ │ ├── size_classes.sh │ │ │ │ ├── stats.h │ │ │ │ ├── tcache.h │ │ │ │ ├── tsd.h │ │ │ │ └── util.h │ │ │ ├── jemalloc.h.in │ │ │ └── jemalloc_defs.h.in │ │ └── msvc_compat │ │ │ ├── inttypes.h │ │ │ ├── stdbool.h │ │ │ ├── stdint.h │ │ │ └── strings.h │ ├── install-sh │ ├── src │ │ ├── arena.c │ │ ├── atomic.c │ │ ├── base.c │ │ ├── bitmap.c │ │ ├── chunk.c │ │ ├── chunk_dss.c │ │ ├── chunk_mmap.c │ │ ├── ckh.c │ │ ├── ctl.c │ │ ├── extent.c │ │ ├── hash.c │ │ ├── huge.c │ │ ├── jemalloc.c │ │ ├── mb.c │ │ ├── mutex.c │ │ ├── prof.c │ │ ├── quarantine.c │ │ ├── rtree.c │ │ ├── stats.c │ │ ├── tcache.c │ │ ├── tsd.c │ │ ├── util.c │ │ └── zone.c │ └── test │ │ ├── ALLOCM_ARENA.c │ │ ├── ALLOCM_ARENA.exp │ │ ├── aligned_alloc.c │ │ ├── aligned_alloc.exp │ │ ├── allocated.c │ │ ├── allocated.exp │ │ ├── allocm.c │ │ ├── allocm.exp │ │ ├── bitmap.c │ │ ├── bitmap.exp │ │ ├── jemalloc_test.h.in │ │ ├── mremap.c │ │ ├── mremap.exp │ │ ├── posix_memalign.c │ │ ├── posix_memalign.exp │ │ ├── rallocm.c │ │ ├── rallocm.exp │ │ ├── thread_arena.c │ │ ├── thread_arena.exp │ │ ├── thread_tcache_enabled.c │ │ └── thread_tcache_enabled.exp ├── linenoise │ ├── .gitignore │ ├── Makefile │ ├── README.markdown │ ├── example.c │ ├── linenoise.c │ └── linenoise.h └── lua │ ├── COPYRIGHT │ ├── HISTORY │ ├── INSTALL │ ├── Makefile │ ├── README │ ├── doc │ ├── contents.html │ ├── cover.png │ ├── logo.gif │ ├── lua.1 │ ├── lua.css │ ├── lua.html │ ├── luac.1 │ ├── luac.html │ ├── manual.css │ ├── manual.html │ └── readme.html │ ├── etc │ ├── Makefile │ ├── README │ ├── all.c │ ├── lua.hpp │ ├── lua.ico │ ├── lua.pc │ ├── luavs.bat │ ├── min.c │ ├── noparser.c │ └── strict.lua │ ├── src │ ├── Makefile │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lcode.c │ ├── lcode.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── liolib.c │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── lua_cjson.c │ ├── lua_cmsgpack.c │ ├── lua_struct.c │ ├── luac.c │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ ├── lzio.h │ ├── print.c │ ├── strbuf.c │ └── strbuf.h │ └── test │ ├── README │ ├── bisect.lua │ ├── cf.lua │ ├── echo.lua │ ├── env.lua │ ├── factorial.lua │ ├── fib.lua │ ├── fibfor.lua │ ├── globals.lua │ ├── hello.lua │ ├── life.lua │ ├── luac.lua │ ├── printf.lua │ ├── readonly.lua │ ├── sieve.lua │ ├── sort.lua │ ├── table.lua │ ├── trace-calls.lua │ ├── trace-globals.lua │ └── xd.lua ├── redis.conf ├── runtest ├── runtest-cluster ├── runtest-sentinel ├── sentinel.conf ├── src ├── .gitignore ├── Makefile ├── Makefile.dep ├── adlist.c ├── adlist.h ├── ae.c ├── ae.h ├── ae_epoll.c ├── ae_evport.c ├── ae_kqueue.c ├── ae_select.c ├── anet.c ├── anet.h ├── aof.c ├── asciilogo.h ├── bio.c ├── bio.h ├── bitops.c ├── blocked.c ├── cluster.c ├── cluster.h ├── config.c ├── config.h ├── crc16.c ├── crc64.c ├── crc64.h ├── db.c ├── debug.c ├── dict.c ├── dict.h ├── endianconv.c ├── endianconv.h ├── fmacros.h ├── help.h ├── hyperloglog.c ├── intset.c ├── intset.h ├── lzf.h ├── lzfP.h ├── lzf_c.c ├── lzf_d.c ├── memtest.c ├── mkreleasehdr.sh ├── multi.c ├── networking.c ├── notify.c ├── object.c ├── pqsort.c ├── pqsort.h ├── pubsub.c ├── rand.c ├── rand.h ├── rdb.c ├── rdb.h ├── redis-benchmark.c ├── redis-check-aof.c ├── redis-check-dump.c ├── redis-cli.c ├── redis-trib.rb ├── redis.c ├── redis.h ├── redisassert.h ├── release.c ├── replication.c ├── rio.c ├── rio.h ├── scripting.c ├── sds.c ├── sds.h ├── sentinel.c ├── setproctitle.c ├── sha1.c ├── sha1.h ├── slowlog.c ├── slowlog.h ├── solarisfixes.h ├── sort.c ├── syncio.c ├── t_hash.c ├── t_list.c ├── t_set.c ├── t_string.c ├── t_zset.c ├── testhelp.h ├── util.c ├── util.h ├── valgrind.sup ├── version.h ├── ziplist.c ├── ziplist.h ├── zipmap.c ├── zipmap.h ├── zmalloc.c └── zmalloc.h ├── tests ├── assets │ ├── default.conf │ ├── encodings.rdb │ └── hash-zipmap.rdb ├── cluster │ ├── cluster.tcl │ ├── run.tcl │ └── tests │ │ ├── 00-base.tcl │ │ └── includes │ │ └── init-tests.tcl ├── helpers │ ├── bg_complex_data.tcl │ └── gen_write_load.tcl ├── instances.tcl ├── integration │ ├── aof-race.tcl │ ├── aof.tcl │ ├── convert-zipmap-hash-on-load.tcl │ ├── rdb.tcl │ ├── redis-cli.tcl │ ├── replication-2.tcl │ ├── replication-3.tcl │ ├── replication-4.tcl │ ├── replication-psync.tcl │ └── replication.tcl ├── sentinel │ ├── run.tcl │ ├── tests │ │ ├── 00-base.tcl │ │ ├── 01-conf-update.tcl │ │ ├── 02-slaves-reconf.tcl │ │ ├── 03-runtime-reconf.tcl │ │ ├── 04-slave-selection.tcl │ │ └── includes │ │ │ └── init-tests.tcl │ └── tmp │ │ └── .gitignore ├── support │ ├── cluster.tcl │ ├── redis.tcl │ ├── server.tcl │ ├── test.tcl │ ├── tmpfile.tcl │ └── util.tcl ├── test_helper.tcl ├── tmp │ └── .gitignore └── unit │ ├── aofrw.tcl │ ├── auth.tcl │ ├── basic.tcl │ ├── bitops.tcl │ ├── dump.tcl │ ├── expire.tcl │ ├── hyperloglog.tcl │ ├── introspection.tcl │ ├── limits.tcl │ ├── maxmemory.tcl │ ├── memefficiency.tcl │ ├── multi.tcl │ ├── obuf-limits.tcl │ ├── other.tcl │ ├── printver.tcl │ ├── protocol.tcl │ ├── pubsub.tcl │ ├── quit.tcl │ ├── scan.tcl │ ├── scripting.tcl │ ├── slowlog.tcl │ ├── sort.tcl │ └── type │ ├── hash.tcl │ ├── list-2.tcl │ ├── list-3.tcl │ ├── list-common.tcl │ ├── list.tcl │ ├── set.tcl │ └── zset.tcl └── utils ├── build-static-symbols.tcl ├── generate-command-help.rb ├── hyperloglog ├── .gitignore ├── hll-err.rb └── hll-gnuplot-graph.rb ├── install_server.sh ├── lru ├── README └── test-lru.rb ├── mkrelease.sh ├── redis-copy.rb ├── redis-sha1.rb ├── redis_init_script ├── redis_init_script.tpl ├── speed-regression.tcl └── whatisdoing.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | *.o 3 | *.log 4 | dump.rdb 5 | redis-benchmark 6 | redis-check-aof 7 | redis-check-dump 8 | redis-cli 9 | redis-sentinel 10 | redis-server 11 | doc-tools 12 | release 13 | misc/* 14 | src/release.h 15 | appendonly.aof 16 | SHORT_TERM_TODO 17 | release.h 18 | src/transfer.sh 19 | src/configs 20 | redis.ds 21 | src/redis.conf 22 | deps/lua/src/lua 23 | deps/lua/src/luac 24 | deps/lua/src/liblua.a 25 | .make-* 26 | .prerequisites 27 | *.dSYM 28 | -------------------------------------------------------------------------------- /00-RELEASENOTES: -------------------------------------------------------------------------------- 1 | Hello! This file is just a placeholder, since this is the "unstable" branch 2 | of Redis, the place where all the development happens. 3 | 4 | There is no release notes for this branch, it gets forked into another branch 5 | every time there is a partial feature freeze in order to eventually create 6 | a new stable release. 7 | 8 | Usually "unstable" is stable enough for you to use it in development enviromnets 9 | however you should never use it in production environments. It is possible 10 | to download the latest stable release here: 11 | 12 | http://download.redis.io/releases/redis-stable.tar.gz 13 | 14 | More information is available at http://redis.io 15 | 16 | Happy hacking! 17 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | Plese check https://github.com/antirez/redis/issues 2 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Note: by contributing code to the Redis project in any form, including sending 2 | a pull request via Github, a code fragment or patch via private email or 3 | public discussion groups, you agree to release your code under the terms 4 | of the BSD license that you can find in the COPYING file included in the Redis 5 | source distribution. You will include BSD license in the COPYING file within 6 | each source file that you contribute. 7 | 8 | # IMPORTANT: HOW TO USE REDIS GITHUB ISSUES 9 | 10 | * Github issues SHOULD ONLY BE USED to report bugs, and for DETAILED feature 11 | requests. Everything else belongs to the Redis Google Group. 12 | 13 | PLEASE DO NOT POST GENERAL QUESTIONS that are not about bugs or suspected 14 | bugs in the Github issues system. We'll be very happy to help you and provide 15 | all the support in the Redis Google Group. 16 | 17 | Redis Google Group address: 18 | 19 | https://groups.google.com/forum/?fromgroups#!forum/redis-db 20 | 21 | # How to provide a patch for a new feature 22 | 23 | 1. Drop a message to the Redis Google Group with a proposal of semantics/API. 24 | 25 | 2. If in step 1 you get an acknowledge from the project leaders, use the 26 | following procedure to submit a patch: 27 | 28 | a. Fork Redis on github ( http://help.github.com/fork-a-repo/ ) 29 | b. Create a topic branch (git checkout -b my_branch) 30 | c. Push to your branch (git push origin my_branch) 31 | d. Initiate a pull request on github ( http://help.github.com/send-pull-requests/ ) 32 | e. Done :) 33 | 34 | Thanks! 35 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2014, Salvatore Sanfilippo 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | * Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | See README 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Top level makefile, the real shit is at src/Makefile 2 | 3 | default: all 4 | 5 | .DEFAULT: 6 | cd src && $(MAKE) $@ 7 | 8 | install: 9 | cd src && $(MAKE) $@ 10 | 11 | .PHONY: install 12 | -------------------------------------------------------------------------------- /deps/Makefile: -------------------------------------------------------------------------------- 1 | # Redis dependency Makefile 2 | 3 | uname_S:= $(shell sh -c 'uname -s 2>/dev/null || echo not') 4 | 5 | CCCOLOR="\033[34m" 6 | LINKCOLOR="\033[34;1m" 7 | SRCCOLOR="\033[33m" 8 | BINCOLOR="\033[37;1m" 9 | MAKECOLOR="\033[32;1m" 10 | ENDCOLOR="\033[0m" 11 | 12 | default: 13 | @echo "Explicit target required" 14 | 15 | .PHONY: default 16 | 17 | # Prerequisites target 18 | .make-prerequisites: 19 | @touch $@ 20 | 21 | # Clean everything when CFLAGS is different 22 | ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(CFLAGS)) 23 | .make-cflags: distclean 24 | -(echo "$(CFLAGS)" > .make-cflags) 25 | .make-prerequisites: .make-cflags 26 | endif 27 | 28 | # Clean everything when LDFLAGS is different 29 | ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(LDFLAGS)) 30 | .make-ldflags: distclean 31 | -(echo "$(LDFLAGS)" > .make-ldflags) 32 | .make-prerequisites: .make-ldflags 33 | endif 34 | 35 | distclean: 36 | -(cd hiredis && $(MAKE) clean) > /dev/null || true 37 | -(cd linenoise && $(MAKE) clean) > /dev/null || true 38 | -(cd lua && $(MAKE) clean) > /dev/null || true 39 | -(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true 40 | -(rm -f .make-*) 41 | 42 | .PHONY: distclean 43 | 44 | hiredis: .make-prerequisites 45 | @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 46 | cd hiredis && $(MAKE) static 47 | 48 | .PHONY: hiredis 49 | 50 | linenoise: .make-prerequisites 51 | @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 52 | cd linenoise && $(MAKE) 53 | 54 | .PHONY: linenoise 55 | 56 | ifeq ($(uname_S),SunOS) 57 | # Make isinf() available 58 | LUA_CFLAGS= -D__C99FEATURES__=1 59 | endif 60 | 61 | LUA_CFLAGS+= -O2 -Wall -DLUA_ANSI $(CFLAGS) 62 | LUA_LDFLAGS+= $(LDFLAGS) 63 | 64 | lua: .make-prerequisites 65 | @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 66 | cd lua/src && $(MAKE) all CFLAGS="$(LUA_CFLAGS)" MYLDFLAGS="$(LUA_LDFLAGS)" 67 | 68 | .PHONY: lua 69 | 70 | JEMALLOC_CFLAGS= -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops $(CFLAGS) 71 | JEMALLOC_LDFLAGS= $(LDFLAGS) 72 | 73 | jemalloc: .make-prerequisites 74 | @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 75 | cd jemalloc && ./configure --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" 76 | cd jemalloc && $(MAKE) CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" lib/libjemalloc.a 77 | 78 | .PHONY: jemalloc 79 | -------------------------------------------------------------------------------- /deps/hiredis/.gitignore: -------------------------------------------------------------------------------- 1 | /hiredis-test 2 | /hiredis-example* 3 | /*.o 4 | /*.so 5 | /*.dylib 6 | /*.a 7 | -------------------------------------------------------------------------------- /deps/hiredis/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 0.10.1 2 | 3 | * Makefile overhaul. Important to check out if you override one or more 4 | variables using environment variables or via arguments to the "make" tool. 5 | 6 | * Issue #45: Fix potential memory leak for a multi bulk reply with 0 elements 7 | being created by the default reply object functions. 8 | 9 | * Issue #43: Don't crash in an asynchronous context when Redis returns an error 10 | reply after the connection has been made (this happens when the maximum 11 | number of connections is reached). 12 | 13 | ### 0.10.0 14 | 15 | * See commit log. 16 | 17 | -------------------------------------------------------------------------------- /deps/hiredis/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2011, Salvatore Sanfilippo 2 | Copyright (c) 2010-2011, Pieter Noordhuis 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Redis nor the names of its contributors may be used 17 | to endorse or promote products derived from this software without specific 18 | prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /deps/hiredis/example-ae.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "hiredis.h" 6 | #include "async.h" 7 | #include "adapters/ae.h" 8 | 9 | /* Put event loop in the global scope, so it can be explicitly stopped */ 10 | static aeEventLoop *loop; 11 | 12 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 13 | redisReply *reply = r; 14 | if (reply == NULL) return; 15 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 16 | 17 | /* Disconnect after receiving the reply to GET */ 18 | redisAsyncDisconnect(c); 19 | } 20 | 21 | void connectCallback(const redisAsyncContext *c, int status) { 22 | if (status != REDIS_OK) { 23 | printf("Error: %s\n", c->errstr); 24 | return; 25 | } 26 | printf("Connected...\n"); 27 | } 28 | 29 | void disconnectCallback(const redisAsyncContext *c, int status) { 30 | if (status != REDIS_OK) { 31 | printf("Error: %s\n", c->errstr); 32 | return; 33 | } 34 | printf("Disconnected...\n"); 35 | } 36 | 37 | int main (int argc, char **argv) { 38 | signal(SIGPIPE, SIG_IGN); 39 | 40 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 41 | if (c->err) { 42 | /* Let *c leak for now... */ 43 | printf("Error: %s\n", c->errstr); 44 | return 1; 45 | } 46 | 47 | loop = aeCreateEventLoop(); 48 | redisAeAttach(loop, c); 49 | redisAsyncSetConnectCallback(c,connectCallback); 50 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 51 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 52 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 53 | aeMain(loop); 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /deps/hiredis/example-libev.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "hiredis.h" 6 | #include "async.h" 7 | #include "adapters/libev.h" 8 | 9 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 10 | redisReply *reply = r; 11 | if (reply == NULL) return; 12 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 13 | 14 | /* Disconnect after receiving the reply to GET */ 15 | redisAsyncDisconnect(c); 16 | } 17 | 18 | void connectCallback(const redisAsyncContext *c, int status) { 19 | if (status != REDIS_OK) { 20 | printf("Error: %s\n", c->errstr); 21 | return; 22 | } 23 | printf("Connected...\n"); 24 | } 25 | 26 | void disconnectCallback(const redisAsyncContext *c, int status) { 27 | if (status != REDIS_OK) { 28 | printf("Error: %s\n", c->errstr); 29 | return; 30 | } 31 | printf("Disconnected...\n"); 32 | } 33 | 34 | int main (int argc, char **argv) { 35 | signal(SIGPIPE, SIG_IGN); 36 | 37 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 38 | if (c->err) { 39 | /* Let *c leak for now... */ 40 | printf("Error: %s\n", c->errstr); 41 | return 1; 42 | } 43 | 44 | redisLibevAttach(EV_DEFAULT_ c); 45 | redisAsyncSetConnectCallback(c,connectCallback); 46 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 47 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 48 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 49 | ev_loop(EV_DEFAULT_ 0); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /deps/hiredis/example-libevent.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "hiredis.h" 6 | #include "async.h" 7 | #include "adapters/libevent.h" 8 | 9 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 10 | redisReply *reply = r; 11 | if (reply == NULL) return; 12 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 13 | 14 | /* Disconnect after receiving the reply to GET */ 15 | redisAsyncDisconnect(c); 16 | } 17 | 18 | void connectCallback(const redisAsyncContext *c, int status) { 19 | if (status != REDIS_OK) { 20 | printf("Error: %s\n", c->errstr); 21 | return; 22 | } 23 | printf("Connected...\n"); 24 | } 25 | 26 | void disconnectCallback(const redisAsyncContext *c, int status) { 27 | if (status != REDIS_OK) { 28 | printf("Error: %s\n", c->errstr); 29 | return; 30 | } 31 | printf("Disconnected...\n"); 32 | } 33 | 34 | int main (int argc, char **argv) { 35 | signal(SIGPIPE, SIG_IGN); 36 | struct event_base *base = event_base_new(); 37 | 38 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 39 | if (c->err) { 40 | /* Let *c leak for now... */ 41 | printf("Error: %s\n", c->errstr); 42 | return 1; 43 | } 44 | 45 | redisLibeventAttach(c,base); 46 | redisAsyncSetConnectCallback(c,connectCallback); 47 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 48 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 49 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 50 | event_base_dispatch(base); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /deps/hiredis/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "hiredis.h" 6 | 7 | int main(void) { 8 | unsigned int j; 9 | redisContext *c; 10 | redisReply *reply; 11 | 12 | struct timeval timeout = { 1, 500000 }; // 1.5 seconds 13 | c = redisConnectWithTimeout((char*)"127.0.0.2", 6379, timeout); 14 | if (c->err) { 15 | printf("Connection error: %s\n", c->errstr); 16 | exit(1); 17 | } 18 | 19 | /* PING server */ 20 | reply = redisCommand(c,"PING"); 21 | printf("PING: %s\n", reply->str); 22 | freeReplyObject(reply); 23 | 24 | /* Set a key */ 25 | reply = redisCommand(c,"SET %s %s", "foo", "hello world"); 26 | printf("SET: %s\n", reply->str); 27 | freeReplyObject(reply); 28 | 29 | /* Set a key using binary safe API */ 30 | reply = redisCommand(c,"SET %b %b", "bar", 3, "hello", 5); 31 | printf("SET (binary API): %s\n", reply->str); 32 | freeReplyObject(reply); 33 | 34 | /* Try a GET and two INCR */ 35 | reply = redisCommand(c,"GET foo"); 36 | printf("GET foo: %s\n", reply->str); 37 | freeReplyObject(reply); 38 | 39 | reply = redisCommand(c,"INCR counter"); 40 | printf("INCR counter: %lld\n", reply->integer); 41 | freeReplyObject(reply); 42 | /* again ... */ 43 | reply = redisCommand(c,"INCR counter"); 44 | printf("INCR counter: %lld\n", reply->integer); 45 | freeReplyObject(reply); 46 | 47 | /* Create a list of numbers, from 0 to 9 */ 48 | reply = redisCommand(c,"DEL mylist"); 49 | freeReplyObject(reply); 50 | for (j = 0; j < 10; j++) { 51 | char buf[64]; 52 | 53 | snprintf(buf,64,"%d",j); 54 | reply = redisCommand(c,"LPUSH mylist element-%s", buf); 55 | freeReplyObject(reply); 56 | } 57 | 58 | /* Let's check what we have inside the list */ 59 | reply = redisCommand(c,"LRANGE mylist 0 -1"); 60 | if (reply->type == REDIS_REPLY_ARRAY) { 61 | for (j = 0; j < reply->elements; j++) { 62 | printf("%u) %s\n", j, reply->element[j]->str); 63 | } 64 | } 65 | freeReplyObject(reply); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /deps/hiredis/fmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef __HIREDIS_FMACRO_H 2 | #define __HIREDIS_FMACRO_H 3 | 4 | #if !defined(_BSD_SOURCE) 5 | #define _BSD_SOURCE 6 | #endif 7 | 8 | #if defined(__sun__) 9 | #define _POSIX_C_SOURCE 200112L 10 | #elif defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) 11 | #define _XOPEN_SOURCE 600 12 | #else 13 | #define _XOPEN_SOURCE 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /deps/hiredis/net.h: -------------------------------------------------------------------------------- 1 | /* Extracted from anet.c to work properly with Hiredis error reporting. 2 | * 3 | * Copyright (c) 2006-2011, Salvatore Sanfilippo 4 | * Copyright (c) 2010-2011, Pieter Noordhuis 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Redis nor the names of its contributors may be used 17 | * to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __NET_H 34 | #define __NET_H 35 | 36 | #include "hiredis.h" 37 | 38 | #if defined(__sun) 39 | #define AF_LOCAL AF_UNIX 40 | #endif 41 | 42 | int redisCheckSocketError(redisContext *c, int fd); 43 | int redisContextSetTimeout(redisContext *c, struct timeval tv); 44 | int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout); 45 | int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /deps/hiredis/zmalloc.h: -------------------------------------------------------------------------------- 1 | /* Drop in replacement for zmalloc.h in order to just use libc malloc without 2 | * any wrappering. */ 3 | 4 | #ifndef ZMALLOC_H 5 | #define ZMALLOC_H 6 | 7 | #define zmalloc malloc 8 | #define zrealloc realloc 9 | #define zcalloc(x) calloc(x,1) 10 | #define zfree free 11 | #define zstrdup strdup 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /deps/jemalloc/.gitignore: -------------------------------------------------------------------------------- 1 | /autom4te.cache/ 2 | /config.stamp 3 | /config.log 4 | /config.status 5 | /doc/html.xsl 6 | /doc/manpages.xsl 7 | /doc/jemalloc.xml 8 | /lib/ 9 | /Makefile 10 | /include/jemalloc/internal/jemalloc_internal\.h 11 | /include/jemalloc/internal/size_classes\.h 12 | /include/jemalloc/jemalloc\.h 13 | /include/jemalloc/jemalloc_defs\.h 14 | /src/*.[od] 15 | /test/*.[od] 16 | /test/*.out 17 | /test/[a-zA-Z_]* 18 | !test/*.c 19 | !test/*.exp 20 | /bin/jemalloc.sh 21 | -------------------------------------------------------------------------------- /deps/jemalloc/COPYING: -------------------------------------------------------------------------------- 1 | Unless otherwise specified, files in the jemalloc source distribution are 2 | subject to the following license: 3 | -------------------------------------------------------------------------------- 4 | Copyright (C) 2002-2012 Jason Evans . 5 | All rights reserved. 6 | Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved. 7 | Copyright (C) 2009-2012 Facebook, Inc. All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 1. Redistributions of source code must retain the above copyright notice(s), 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice(s), 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS 18 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- 28 | -------------------------------------------------------------------------------- /deps/jemalloc/README: -------------------------------------------------------------------------------- 1 | jemalloc is a general-purpose scalable concurrent malloc(3) implementation. 2 | This distribution is a "portable" implementation that currently targets 3 | FreeBSD, Linux, Apple OS X, and MinGW. jemalloc is included as the default 4 | allocator in the FreeBSD and NetBSD operating systems, and it is used by the 5 | Mozilla Firefox web browser on Microsoft Windows-related platforms. Depending 6 | on your needs, one of the other divergent versions may suit your needs better 7 | than this distribution. 8 | 9 | The COPYING file contains copyright and licensing information. 10 | 11 | The INSTALL file contains information on how to configure, build, and install 12 | jemalloc. 13 | 14 | The ChangeLog file contains a brief summary of changes for each release. 15 | 16 | URL: http://www.canonware.com/jemalloc/ 17 | -------------------------------------------------------------------------------- /deps/jemalloc/VERSION: -------------------------------------------------------------------------------- 1 | 3.2.0-0-g87499f6748ebe4817571e817e9f680ccb5bf54a9 2 | -------------------------------------------------------------------------------- /deps/jemalloc/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i in autoconf; do 4 | echo "$i" 5 | $i 6 | if [ $? -ne 0 ]; then 7 | echo "Error $? in $i" 8 | exit 1 9 | fi 10 | done 11 | 12 | echo "./configure --enable-autogen $@" 13 | ./configure --enable-autogen $@ 14 | if [ $? -ne 0 ]; then 15 | echo "Error $? in ./configure" 16 | exit 1 17 | fi 18 | -------------------------------------------------------------------------------- /deps/jemalloc/bin/jemalloc.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | 7 | @LD_PRELOAD_VAR@=${libdir}/libjemalloc.@SOREV@ 8 | export @LD_PRELOAD_VAR@ 9 | exec "$@" 10 | -------------------------------------------------------------------------------- /deps/jemalloc/config.stamp.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/redis-3.0-annotated/8e60a75884e75503fb8be1a322406f21fb455f67/deps/jemalloc/config.stamp.in -------------------------------------------------------------------------------- /deps/jemalloc/doc/html.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /deps/jemalloc/doc/jemalloc.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/redis-3.0-annotated/8e60a75884e75503fb8be1a322406f21fb455f67/deps/jemalloc/doc/jemalloc.html -------------------------------------------------------------------------------- /deps/jemalloc/doc/manpages.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /deps/jemalloc/doc/stylesheet.xsl: -------------------------------------------------------------------------------- 1 | 2 | ansi 3 | 4 | 5 | "" 6 | 7 | 8 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/base.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *base_alloc(size_t size); 13 | void *base_calloc(size_t number, size_t size); 14 | extent_node_t *base_node_alloc(void); 15 | void base_node_dealloc(extent_node_t *node); 16 | bool base_boot(void); 17 | void base_prefork(void); 18 | void base_postfork_parent(void); 19 | void base_postfork_child(void); 20 | 21 | #endif /* JEMALLOC_H_EXTERNS */ 22 | /******************************************************************************/ 23 | #ifdef JEMALLOC_H_INLINES 24 | 25 | #endif /* JEMALLOC_H_INLINES */ 26 | /******************************************************************************/ 27 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/chunk.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | /* 5 | * Size and alignment of memory chunks that are allocated by the OS's virtual 6 | * memory system. 7 | */ 8 | #define LG_CHUNK_DEFAULT 22 9 | 10 | /* Return the chunk address for allocation address a. */ 11 | #define CHUNK_ADDR2BASE(a) \ 12 | ((void *)((uintptr_t)(a) & ~chunksize_mask)) 13 | 14 | /* Return the chunk offset of address a. */ 15 | #define CHUNK_ADDR2OFFSET(a) \ 16 | ((size_t)((uintptr_t)(a) & chunksize_mask)) 17 | 18 | /* Return the smallest chunk multiple that is >= s. */ 19 | #define CHUNK_CEILING(s) \ 20 | (((s) + chunksize_mask) & ~chunksize_mask) 21 | 22 | #endif /* JEMALLOC_H_TYPES */ 23 | /******************************************************************************/ 24 | #ifdef JEMALLOC_H_STRUCTS 25 | 26 | #endif /* JEMALLOC_H_STRUCTS */ 27 | /******************************************************************************/ 28 | #ifdef JEMALLOC_H_EXTERNS 29 | 30 | extern size_t opt_lg_chunk; 31 | extern const char *opt_dss; 32 | 33 | /* Protects stats_chunks; currently not used for any other purpose. */ 34 | extern malloc_mutex_t chunks_mtx; 35 | /* Chunk statistics. */ 36 | extern chunk_stats_t stats_chunks; 37 | 38 | extern rtree_t *chunks_rtree; 39 | 40 | extern size_t chunksize; 41 | extern size_t chunksize_mask; /* (chunksize - 1). */ 42 | extern size_t chunk_npages; 43 | extern size_t map_bias; /* Number of arena chunk header pages. */ 44 | extern size_t arena_maxclass; /* Max size class for arenas. */ 45 | 46 | void *chunk_alloc(size_t size, size_t alignment, bool base, bool *zero, 47 | dss_prec_t dss_prec); 48 | void chunk_unmap(void *chunk, size_t size); 49 | void chunk_dealloc(void *chunk, size_t size, bool unmap); 50 | bool chunk_boot(void); 51 | void chunk_prefork(void); 52 | void chunk_postfork_parent(void); 53 | void chunk_postfork_child(void); 54 | 55 | #endif /* JEMALLOC_H_EXTERNS */ 56 | /******************************************************************************/ 57 | #ifdef JEMALLOC_H_INLINES 58 | 59 | #endif /* JEMALLOC_H_INLINES */ 60 | /******************************************************************************/ 61 | 62 | #include "jemalloc/internal/chunk_dss.h" 63 | #include "jemalloc/internal/chunk_mmap.h" 64 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/chunk_dss.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 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_H_TYPES */ 15 | /******************************************************************************/ 16 | #ifdef JEMALLOC_H_STRUCTS 17 | 18 | extern const char *dss_prec_names[]; 19 | 20 | #endif /* JEMALLOC_H_STRUCTS */ 21 | /******************************************************************************/ 22 | #ifdef JEMALLOC_H_EXTERNS 23 | 24 | dss_prec_t chunk_dss_prec_get(void); 25 | bool chunk_dss_prec_set(dss_prec_t dss_prec); 26 | void *chunk_alloc_dss(size_t size, size_t alignment, bool *zero); 27 | bool chunk_in_dss(void *chunk); 28 | bool chunk_dss_boot(void); 29 | void chunk_dss_prefork(void); 30 | void chunk_dss_postfork_parent(void); 31 | void chunk_dss_postfork_child(void); 32 | 33 | #endif /* JEMALLOC_H_EXTERNS */ 34 | /******************************************************************************/ 35 | #ifdef JEMALLOC_H_INLINES 36 | 37 | #endif /* JEMALLOC_H_INLINES */ 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/chunk_mmap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | bool pages_purge(void *addr, size_t length); 13 | 14 | void *chunk_alloc_mmap(size_t size, size_t alignment, bool *zero); 15 | bool chunk_dealloc_mmap(void *chunk, size_t size); 16 | 17 | #endif /* JEMALLOC_H_EXTERNS */ 18 | /******************************************************************************/ 19 | #ifdef JEMALLOC_H_INLINES 20 | 21 | #endif /* JEMALLOC_H_INLINES */ 22 | /******************************************************************************/ 23 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/extent.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct extent_node_s extent_node_t; 5 | 6 | #endif /* JEMALLOC_H_TYPES */ 7 | /******************************************************************************/ 8 | #ifdef JEMALLOC_H_STRUCTS 9 | 10 | /* Tree of extents. */ 11 | struct extent_node_s { 12 | /* Linkage for the size/address-ordered tree. */ 13 | rb_node(extent_node_t) link_szad; 14 | 15 | /* Linkage for the address-ordered tree. */ 16 | rb_node(extent_node_t) link_ad; 17 | 18 | /* Profile counters, used for huge objects. */ 19 | prof_ctx_t *prof_ctx; 20 | 21 | /* Pointer to the extent that this tree node is responsible for. */ 22 | void *addr; 23 | 24 | /* Total region size. */ 25 | size_t size; 26 | 27 | /* True if zero-filled; used by chunk recycling code. */ 28 | bool zeroed; 29 | }; 30 | typedef rb_tree(extent_node_t) extent_tree_t; 31 | 32 | #endif /* JEMALLOC_H_STRUCTS */ 33 | /******************************************************************************/ 34 | #ifdef JEMALLOC_H_EXTERNS 35 | 36 | rb_proto(, extent_tree_szad_, extent_tree_t, extent_node_t) 37 | 38 | rb_proto(, extent_tree_ad_, extent_tree_t, extent_node_t) 39 | 40 | #endif /* JEMALLOC_H_EXTERNS */ 41 | /******************************************************************************/ 42 | #ifdef JEMALLOC_H_INLINES 43 | 44 | #endif /* JEMALLOC_H_INLINES */ 45 | /******************************************************************************/ 46 | 47 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/hash.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | #endif /* JEMALLOC_H_EXTERNS */ 13 | /******************************************************************************/ 14 | #ifdef JEMALLOC_H_INLINES 15 | 16 | #ifndef JEMALLOC_ENABLE_INLINE 17 | uint64_t hash(const void *key, size_t len, uint64_t seed); 18 | #endif 19 | 20 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_HASH_C_)) 21 | /* 22 | * The following hash function is based on MurmurHash64A(), placed into the 23 | * public domain by Austin Appleby. See http://murmurhash.googlepages.com/ for 24 | * details. 25 | */ 26 | JEMALLOC_INLINE uint64_t 27 | hash(const void *key, size_t len, uint64_t seed) 28 | { 29 | const uint64_t m = UINT64_C(0xc6a4a7935bd1e995); 30 | const int r = 47; 31 | uint64_t h = seed ^ (len * m); 32 | const uint64_t *data = (const uint64_t *)key; 33 | const uint64_t *end = data + (len/8); 34 | const unsigned char *data2; 35 | 36 | assert(((uintptr_t)key & 0x7) == 0); 37 | 38 | while(data != end) { 39 | uint64_t k = *data++; 40 | 41 | k *= m; 42 | k ^= k >> r; 43 | k *= m; 44 | 45 | h ^= k; 46 | h *= m; 47 | } 48 | 49 | data2 = (const unsigned char *)data; 50 | switch(len & 7) { 51 | case 7: h ^= ((uint64_t)(data2[6])) << 48; 52 | case 6: h ^= ((uint64_t)(data2[5])) << 40; 53 | case 5: h ^= ((uint64_t)(data2[4])) << 32; 54 | case 4: h ^= ((uint64_t)(data2[3])) << 24; 55 | case 3: h ^= ((uint64_t)(data2[2])) << 16; 56 | case 2: h ^= ((uint64_t)(data2[1])) << 8; 57 | case 1: h ^= ((uint64_t)(data2[0])); 58 | h *= m; 59 | } 60 | 61 | h ^= h >> r; 62 | h *= m; 63 | h ^= h >> r; 64 | 65 | return (h); 66 | } 67 | #endif 68 | 69 | #endif /* JEMALLOC_H_INLINES */ 70 | /******************************************************************************/ 71 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/huge.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | /* Huge allocation statistics. */ 13 | extern uint64_t huge_nmalloc; 14 | extern uint64_t huge_ndalloc; 15 | extern size_t huge_allocated; 16 | 17 | /* Protects chunk-related data structures. */ 18 | extern malloc_mutex_t huge_mtx; 19 | 20 | void *huge_malloc(size_t size, bool zero); 21 | void *huge_palloc(size_t size, size_t alignment, bool zero); 22 | void *huge_ralloc_no_move(void *ptr, size_t oldsize, size_t size, 23 | size_t extra); 24 | void *huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra, 25 | size_t alignment, bool zero, bool try_tcache_dalloc); 26 | void huge_dalloc(void *ptr, bool unmap); 27 | size_t huge_salloc(const void *ptr); 28 | prof_ctx_t *huge_prof_ctx_get(const void *ptr); 29 | void huge_prof_ctx_set(const void *ptr, prof_ctx_t *ctx); 30 | bool huge_boot(void); 31 | void huge_prefork(void); 32 | void huge_postfork_parent(void); 33 | void huge_postfork_child(void); 34 | 35 | #endif /* JEMALLOC_H_EXTERNS */ 36 | /******************************************************************************/ 37 | #ifdef JEMALLOC_H_INLINES 38 | 39 | #endif /* JEMALLOC_H_INLINES */ 40 | /******************************************************************************/ 41 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/prng.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | /* 5 | * Simple linear congruential pseudo-random number generator: 6 | * 7 | * prng(y) = (a*x + c) % m 8 | * 9 | * where the following constants ensure maximal period: 10 | * 11 | * a == Odd number (relatively prime to 2^n), and (a-1) is a multiple of 4. 12 | * c == Odd number (relatively prime to 2^n). 13 | * m == 2^32 14 | * 15 | * See Knuth's TAOCP 3rd Ed., Vol. 2, pg. 17 for details on these constraints. 16 | * 17 | * This choice of m has the disadvantage that the quality of the bits is 18 | * proportional to bit position. For example. the lowest bit has a cycle of 2, 19 | * the next has a cycle of 4, etc. For this reason, we prefer to use the upper 20 | * bits. 21 | * 22 | * Macro parameters: 23 | * uint32_t r : Result. 24 | * unsigned lg_range : (0..32], number of least significant bits to return. 25 | * uint32_t state : Seed value. 26 | * const uint32_t a, c : See above discussion. 27 | */ 28 | #define prng32(r, lg_range, state, a, c) do { \ 29 | assert(lg_range > 0); \ 30 | assert(lg_range <= 32); \ 31 | \ 32 | r = (state * (a)) + (c); \ 33 | state = r; \ 34 | r >>= (32 - lg_range); \ 35 | } while (false) 36 | 37 | /* Same as prng32(), but 64 bits of pseudo-randomness, using uint64_t. */ 38 | #define prng64(r, lg_range, state, a, c) do { \ 39 | assert(lg_range > 0); \ 40 | assert(lg_range <= 64); \ 41 | \ 42 | r = (state * (a)) + (c); \ 43 | state = r; \ 44 | r >>= (64 - lg_range); \ 45 | } while (false) 46 | 47 | #endif /* JEMALLOC_H_TYPES */ 48 | /******************************************************************************/ 49 | #ifdef JEMALLOC_H_STRUCTS 50 | 51 | #endif /* JEMALLOC_H_STRUCTS */ 52 | /******************************************************************************/ 53 | #ifdef JEMALLOC_H_EXTERNS 54 | 55 | #endif /* JEMALLOC_H_EXTERNS */ 56 | /******************************************************************************/ 57 | #ifdef JEMALLOC_H_INLINES 58 | 59 | #endif /* JEMALLOC_H_INLINES */ 60 | /******************************************************************************/ 61 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/ql.h: -------------------------------------------------------------------------------- 1 | /* 2 | * List definitions. 3 | */ 4 | #define ql_head(a_type) \ 5 | struct { \ 6 | a_type *qlh_first; \ 7 | } 8 | 9 | #define ql_head_initializer(a_head) {NULL} 10 | 11 | #define ql_elm(a_type) qr(a_type) 12 | 13 | /* List functions. */ 14 | #define ql_new(a_head) do { \ 15 | (a_head)->qlh_first = NULL; \ 16 | } while (0) 17 | 18 | #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field) 19 | 20 | #define ql_first(a_head) ((a_head)->qlh_first) 21 | 22 | #define ql_last(a_head, a_field) \ 23 | ((ql_first(a_head) != NULL) \ 24 | ? qr_prev(ql_first(a_head), a_field) : NULL) 25 | 26 | #define ql_next(a_head, a_elm, a_field) \ 27 | ((ql_last(a_head, a_field) != (a_elm)) \ 28 | ? qr_next((a_elm), a_field) : NULL) 29 | 30 | #define ql_prev(a_head, a_elm, a_field) \ 31 | ((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field) \ 32 | : NULL) 33 | 34 | #define ql_before_insert(a_head, a_qlelm, a_elm, a_field) do { \ 35 | qr_before_insert((a_qlelm), (a_elm), a_field); \ 36 | if (ql_first(a_head) == (a_qlelm)) { \ 37 | ql_first(a_head) = (a_elm); \ 38 | } \ 39 | } while (0) 40 | 41 | #define ql_after_insert(a_qlelm, a_elm, a_field) \ 42 | qr_after_insert((a_qlelm), (a_elm), a_field) 43 | 44 | #define ql_head_insert(a_head, a_elm, a_field) do { \ 45 | if (ql_first(a_head) != NULL) { \ 46 | qr_before_insert(ql_first(a_head), (a_elm), a_field); \ 47 | } \ 48 | ql_first(a_head) = (a_elm); \ 49 | } while (0) 50 | 51 | #define ql_tail_insert(a_head, a_elm, a_field) do { \ 52 | if (ql_first(a_head) != NULL) { \ 53 | qr_before_insert(ql_first(a_head), (a_elm), a_field); \ 54 | } \ 55 | ql_first(a_head) = qr_next((a_elm), a_field); \ 56 | } while (0) 57 | 58 | #define ql_remove(a_head, a_elm, a_field) do { \ 59 | if (ql_first(a_head) == (a_elm)) { \ 60 | ql_first(a_head) = qr_next(ql_first(a_head), a_field); \ 61 | } \ 62 | if (ql_first(a_head) != (a_elm)) { \ 63 | qr_remove((a_elm), a_field); \ 64 | } else { \ 65 | ql_first(a_head) = NULL; \ 66 | } \ 67 | } while (0) 68 | 69 | #define ql_head_remove(a_head, a_type, a_field) do { \ 70 | a_type *t = ql_first(a_head); \ 71 | ql_remove((a_head), t, a_field); \ 72 | } while (0) 73 | 74 | #define ql_tail_remove(a_head, a_type, a_field) do { \ 75 | a_type *t = ql_last(a_head, a_field); \ 76 | ql_remove((a_head), t, a_field); \ 77 | } while (0) 78 | 79 | #define ql_foreach(a_var, a_head, a_field) \ 80 | qr_foreach((a_var), ql_first(a_head), a_field) 81 | 82 | #define ql_reverse_foreach(a_var, a_head, a_field) \ 83 | qr_reverse_foreach((a_var), ql_first(a_head), a_field) 84 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/qr.h: -------------------------------------------------------------------------------- 1 | /* Ring definitions. */ 2 | #define qr(a_type) \ 3 | struct { \ 4 | a_type *qre_next; \ 5 | a_type *qre_prev; \ 6 | } 7 | 8 | /* Ring functions. */ 9 | #define qr_new(a_qr, a_field) do { \ 10 | (a_qr)->a_field.qre_next = (a_qr); \ 11 | (a_qr)->a_field.qre_prev = (a_qr); \ 12 | } while (0) 13 | 14 | #define qr_next(a_qr, a_field) ((a_qr)->a_field.qre_next) 15 | 16 | #define qr_prev(a_qr, a_field) ((a_qr)->a_field.qre_prev) 17 | 18 | #define qr_before_insert(a_qrelm, a_qr, a_field) do { \ 19 | (a_qr)->a_field.qre_prev = (a_qrelm)->a_field.qre_prev; \ 20 | (a_qr)->a_field.qre_next = (a_qrelm); \ 21 | (a_qr)->a_field.qre_prev->a_field.qre_next = (a_qr); \ 22 | (a_qrelm)->a_field.qre_prev = (a_qr); \ 23 | } while (0) 24 | 25 | #define qr_after_insert(a_qrelm, a_qr, a_field) \ 26 | do \ 27 | { \ 28 | (a_qr)->a_field.qre_next = (a_qrelm)->a_field.qre_next; \ 29 | (a_qr)->a_field.qre_prev = (a_qrelm); \ 30 | (a_qr)->a_field.qre_next->a_field.qre_prev = (a_qr); \ 31 | (a_qrelm)->a_field.qre_next = (a_qr); \ 32 | } while (0) 33 | 34 | #define qr_meld(a_qr_a, a_qr_b, a_field) do { \ 35 | void *t; \ 36 | (a_qr_a)->a_field.qre_prev->a_field.qre_next = (a_qr_b); \ 37 | (a_qr_b)->a_field.qre_prev->a_field.qre_next = (a_qr_a); \ 38 | t = (a_qr_a)->a_field.qre_prev; \ 39 | (a_qr_a)->a_field.qre_prev = (a_qr_b)->a_field.qre_prev; \ 40 | (a_qr_b)->a_field.qre_prev = t; \ 41 | } while (0) 42 | 43 | /* qr_meld() and qr_split() are functionally equivalent, so there's no need to 44 | * have two copies of the code. */ 45 | #define qr_split(a_qr_a, a_qr_b, a_field) \ 46 | qr_meld((a_qr_a), (a_qr_b), a_field) 47 | 48 | #define qr_remove(a_qr, a_field) do { \ 49 | (a_qr)->a_field.qre_prev->a_field.qre_next \ 50 | = (a_qr)->a_field.qre_next; \ 51 | (a_qr)->a_field.qre_next->a_field.qre_prev \ 52 | = (a_qr)->a_field.qre_prev; \ 53 | (a_qr)->a_field.qre_next = (a_qr); \ 54 | (a_qr)->a_field.qre_prev = (a_qr); \ 55 | } while (0) 56 | 57 | #define qr_foreach(var, a_qr, a_field) \ 58 | for ((var) = (a_qr); \ 59 | (var) != NULL; \ 60 | (var) = (((var)->a_field.qre_next != (a_qr)) \ 61 | ? (var)->a_field.qre_next : NULL)) 62 | 63 | #define qr_reverse_foreach(var, a_qr, a_field) \ 64 | for ((var) = ((a_qr) != NULL) ? qr_prev(a_qr, a_field) : NULL; \ 65 | (var) != NULL; \ 66 | (var) = (((var) != (a_qr)) \ 67 | ? (var)->a_field.qre_prev : NULL)) 68 | -------------------------------------------------------------------------------- /deps/jemalloc/include/jemalloc/internal/quarantine.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | /* Default per thread quarantine size if valgrind is enabled. */ 5 | #define JEMALLOC_VALGRIND_QUARANTINE_DEFAULT (ZU(1) << 24) 6 | 7 | #endif /* JEMALLOC_H_TYPES */ 8 | /******************************************************************************/ 9 | #ifdef JEMALLOC_H_STRUCTS 10 | 11 | #endif /* JEMALLOC_H_STRUCTS */ 12 | /******************************************************************************/ 13 | #ifdef JEMALLOC_H_EXTERNS 14 | 15 | void quarantine(void *ptr); 16 | bool quarantine_boot(void); 17 | 18 | #endif /* JEMALLOC_H_EXTERNS */ 19 | /******************************************************************************/ 20 | #ifdef JEMALLOC_H_INLINES 21 | 22 | #endif /* JEMALLOC_H_INLINES */ 23 | /******************************************************************************/ 24 | 25 | -------------------------------------------------------------------------------- /deps/jemalloc/include/msvc_compat/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 | typedef BOOL _Bool; 9 | 10 | #define bool _Bool 11 | #define true 1 12 | #define false 0 13 | 14 | #define __bool_true_false_are_defined 1 15 | 16 | #endif /* stdbool_h */ 17 | -------------------------------------------------------------------------------- /deps/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 | #include 7 | #pragma intrinsic(_BitScanForward) 8 | static __forceinline int ffsl(long x) 9 | { 10 | unsigned long i; 11 | 12 | if (_BitScanForward(&i, x)) 13 | return (i + 1); 14 | return (0); 15 | } 16 | 17 | static __forceinline int ffs(int x) 18 | { 19 | 20 | return (ffsl(x)); 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /deps/jemalloc/src/atomic.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_ATOMIC_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /deps/jemalloc/src/bitmap.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_BITMAP_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | /******************************************************************************/ 5 | /* Function prototypes for non-inline static functions. */ 6 | 7 | static size_t bits2groups(size_t nbits); 8 | 9 | /******************************************************************************/ 10 | 11 | static size_t 12 | bits2groups(size_t nbits) 13 | { 14 | 15 | return ((nbits >> LG_BITMAP_GROUP_NBITS) + 16 | !!(nbits & BITMAP_GROUP_NBITS_MASK)); 17 | } 18 | 19 | void 20 | bitmap_info_init(bitmap_info_t *binfo, size_t nbits) 21 | { 22 | unsigned i; 23 | size_t group_count; 24 | 25 | assert(nbits > 0); 26 | assert(nbits <= (ZU(1) << LG_BITMAP_MAXBITS)); 27 | 28 | /* 29 | * Compute the number of groups necessary to store nbits bits, and 30 | * progressively work upward through the levels until reaching a level 31 | * that requires only one group. 32 | */ 33 | binfo->levels[0].group_offset = 0; 34 | group_count = bits2groups(nbits); 35 | for (i = 1; group_count > 1; i++) { 36 | assert(i < BITMAP_MAX_LEVELS); 37 | binfo->levels[i].group_offset = binfo->levels[i-1].group_offset 38 | + group_count; 39 | group_count = bits2groups(group_count); 40 | } 41 | binfo->levels[i].group_offset = binfo->levels[i-1].group_offset 42 | + group_count; 43 | binfo->nlevels = i; 44 | binfo->nbits = nbits; 45 | } 46 | 47 | size_t 48 | bitmap_info_ngroups(const bitmap_info_t *binfo) 49 | { 50 | 51 | return (binfo->levels[binfo->nlevels].group_offset << LG_SIZEOF_BITMAP); 52 | } 53 | 54 | size_t 55 | bitmap_size(size_t nbits) 56 | { 57 | bitmap_info_t binfo; 58 | 59 | bitmap_info_init(&binfo, nbits); 60 | return (bitmap_info_ngroups(&binfo)); 61 | } 62 | 63 | void 64 | bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo) 65 | { 66 | size_t extra; 67 | unsigned i; 68 | 69 | /* 70 | * Bits are actually inverted with regard to the external bitmap 71 | * interface, so the bitmap starts out with all 1 bits, except for 72 | * trailing unused bits (if any). Note that each group uses bit 0 to 73 | * correspond to the first logical bit in the group, so extra bits 74 | * are the most significant bits of the last group. 75 | */ 76 | memset(bitmap, 0xffU, binfo->levels[binfo->nlevels].group_offset << 77 | LG_SIZEOF_BITMAP); 78 | extra = (BITMAP_GROUP_NBITS - (binfo->nbits & BITMAP_GROUP_NBITS_MASK)) 79 | & BITMAP_GROUP_NBITS_MASK; 80 | if (extra != 0) 81 | bitmap[binfo->levels[1].group_offset - 1] >>= extra; 82 | for (i = 1; i < binfo->nlevels; i++) { 83 | size_t group_count = binfo->levels[i].group_offset - 84 | binfo->levels[i-1].group_offset; 85 | extra = (BITMAP_GROUP_NBITS - (group_count & 86 | BITMAP_GROUP_NBITS_MASK)) & BITMAP_GROUP_NBITS_MASK; 87 | if (extra != 0) 88 | bitmap[binfo->levels[i+1].group_offset - 1] >>= extra; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /deps/jemalloc/src/extent.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_EXTENT_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | /******************************************************************************/ 5 | 6 | static inline int 7 | extent_szad_comp(extent_node_t *a, extent_node_t *b) 8 | { 9 | int ret; 10 | size_t a_size = a->size; 11 | size_t b_size = b->size; 12 | 13 | ret = (a_size > b_size) - (a_size < b_size); 14 | if (ret == 0) { 15 | uintptr_t a_addr = (uintptr_t)a->addr; 16 | uintptr_t b_addr = (uintptr_t)b->addr; 17 | 18 | ret = (a_addr > b_addr) - (a_addr < b_addr); 19 | } 20 | 21 | return (ret); 22 | } 23 | 24 | /* Generate red-black tree functions. */ 25 | rb_gen(, extent_tree_szad_, extent_tree_t, extent_node_t, link_szad, 26 | extent_szad_comp) 27 | 28 | static inline int 29 | extent_ad_comp(extent_node_t *a, extent_node_t *b) 30 | { 31 | uintptr_t a_addr = (uintptr_t)a->addr; 32 | uintptr_t b_addr = (uintptr_t)b->addr; 33 | 34 | return ((a_addr > b_addr) - (a_addr < b_addr)); 35 | } 36 | 37 | /* Generate red-black tree functions. */ 38 | rb_gen(, extent_tree_ad_, extent_tree_t, extent_node_t, link_ad, 39 | extent_ad_comp) 40 | -------------------------------------------------------------------------------- /deps/jemalloc/src/hash.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_HASH_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /deps/jemalloc/src/mb.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MB_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /deps/jemalloc/src/rtree.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_RTREE_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | rtree_t * 5 | rtree_new(unsigned bits) 6 | { 7 | rtree_t *ret; 8 | unsigned bits_per_level, height, i; 9 | 10 | bits_per_level = ffs(pow2_ceil((RTREE_NODESIZE / sizeof(void *)))) - 1; 11 | height = bits / bits_per_level; 12 | if (height * bits_per_level != bits) 13 | height++; 14 | assert(height * bits_per_level >= bits); 15 | 16 | ret = (rtree_t*)base_alloc(offsetof(rtree_t, level2bits) + 17 | (sizeof(unsigned) * height)); 18 | if (ret == NULL) 19 | return (NULL); 20 | memset(ret, 0, offsetof(rtree_t, level2bits) + (sizeof(unsigned) * 21 | height)); 22 | 23 | if (malloc_mutex_init(&ret->mutex)) { 24 | /* Leak the rtree. */ 25 | return (NULL); 26 | } 27 | ret->height = height; 28 | if (bits_per_level * height > bits) 29 | ret->level2bits[0] = bits % bits_per_level; 30 | else 31 | ret->level2bits[0] = bits_per_level; 32 | for (i = 1; i < height; i++) 33 | ret->level2bits[i] = bits_per_level; 34 | 35 | ret->root = (void**)base_alloc(sizeof(void *) << ret->level2bits[0]); 36 | if (ret->root == NULL) { 37 | /* 38 | * We leak the rtree here, since there's no generic base 39 | * deallocation. 40 | */ 41 | return (NULL); 42 | } 43 | memset(ret->root, 0, sizeof(void *) << ret->level2bits[0]); 44 | 45 | return (ret); 46 | } 47 | 48 | void 49 | rtree_prefork(rtree_t *rtree) 50 | { 51 | 52 | malloc_mutex_prefork(&rtree->mutex); 53 | } 54 | 55 | void 56 | rtree_postfork_parent(rtree_t *rtree) 57 | { 58 | 59 | malloc_mutex_postfork_parent(&rtree->mutex); 60 | } 61 | 62 | void 63 | rtree_postfork_child(rtree_t *rtree) 64 | { 65 | 66 | malloc_mutex_postfork_child(&rtree->mutex); 67 | } 68 | -------------------------------------------------------------------------------- /deps/jemalloc/src/tsd.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_TSD_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | /******************************************************************************/ 5 | /* Data. */ 6 | 7 | static unsigned ncleanups; 8 | static malloc_tsd_cleanup_t cleanups[MALLOC_TSD_CLEANUPS_MAX]; 9 | 10 | /******************************************************************************/ 11 | 12 | void * 13 | malloc_tsd_malloc(size_t size) 14 | { 15 | 16 | /* Avoid choose_arena() in order to dodge bootstrapping issues. */ 17 | return (arena_malloc(arenas[0], size, false, false)); 18 | } 19 | 20 | void 21 | malloc_tsd_dalloc(void *wrapper) 22 | { 23 | 24 | idalloc(wrapper); 25 | } 26 | 27 | void 28 | malloc_tsd_no_cleanup(void *arg) 29 | { 30 | 31 | not_reached(); 32 | } 33 | 34 | #if defined(JEMALLOC_MALLOC_THREAD_CLEANUP) || defined(_WIN32) 35 | #ifndef _WIN32 36 | JEMALLOC_EXPORT 37 | #endif 38 | void 39 | _malloc_thread_cleanup(void) 40 | { 41 | bool pending[MALLOC_TSD_CLEANUPS_MAX], again; 42 | unsigned i; 43 | 44 | for (i = 0; i < ncleanups; i++) 45 | pending[i] = true; 46 | 47 | do { 48 | again = false; 49 | for (i = 0; i < ncleanups; i++) { 50 | if (pending[i]) { 51 | pending[i] = cleanups[i](); 52 | if (pending[i]) 53 | again = true; 54 | } 55 | } 56 | } while (again); 57 | } 58 | #endif 59 | 60 | void 61 | malloc_tsd_cleanup_register(bool (*f)(void)) 62 | { 63 | 64 | assert(ncleanups < MALLOC_TSD_CLEANUPS_MAX); 65 | cleanups[ncleanups] = f; 66 | ncleanups++; 67 | } 68 | 69 | void 70 | malloc_tsd_boot(void) 71 | { 72 | 73 | ncleanups = 0; 74 | } 75 | 76 | #ifdef _WIN32 77 | static BOOL WINAPI 78 | _tls_callback(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 79 | { 80 | 81 | switch (fdwReason) { 82 | #ifdef JEMALLOC_LAZY_LOCK 83 | case DLL_THREAD_ATTACH: 84 | isthreaded = true; 85 | break; 86 | #endif 87 | case DLL_THREAD_DETACH: 88 | _malloc_thread_cleanup(); 89 | break; 90 | default: 91 | break; 92 | } 93 | return (true); 94 | } 95 | 96 | #ifdef _MSC_VER 97 | # ifdef _M_IX86 98 | # pragma comment(linker, "/INCLUDE:__tls_used") 99 | # else 100 | # pragma comment(linker, "/INCLUDE:_tls_used") 101 | # endif 102 | # pragma section(".CRT$XLY",long,read) 103 | #endif 104 | JEMALLOC_SECTION(".CRT$XLY") JEMALLOC_ATTR(used) 105 | static const BOOL (WINAPI *tls_callback)(HINSTANCE hinstDLL, 106 | DWORD fdwReason, LPVOID lpvReserved) = _tls_callback; 107 | #endif 108 | -------------------------------------------------------------------------------- /deps/jemalloc/test/ALLOCM_ARENA.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MANGLE 2 | #include "jemalloc_test.h" 3 | 4 | #define NTHREADS 10 5 | 6 | void * 7 | je_thread_start(void *arg) 8 | { 9 | unsigned thread_ind = (unsigned)(uintptr_t)arg; 10 | unsigned arena_ind; 11 | int r; 12 | void *p; 13 | size_t rsz, sz; 14 | 15 | sz = sizeof(arena_ind); 16 | if (mallctl("arenas.extend", &arena_ind, &sz, NULL, 0) 17 | != 0) { 18 | malloc_printf("Error in arenas.extend\n"); 19 | abort(); 20 | } 21 | 22 | if (thread_ind % 4 != 3) { 23 | size_t mib[3]; 24 | size_t miblen = sizeof(mib) / sizeof(size_t); 25 | const char *dss_precs[] = {"disabled", "primary", "secondary"}; 26 | const char *dss = dss_precs[thread_ind % 4]; 27 | if (mallctlnametomib("arena.0.dss", mib, &miblen) != 0) { 28 | malloc_printf("Error in mallctlnametomib()\n"); 29 | abort(); 30 | } 31 | mib[1] = arena_ind; 32 | if (mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss, 33 | sizeof(const char *))) { 34 | malloc_printf("Error in mallctlbymib()\n"); 35 | abort(); 36 | } 37 | } 38 | 39 | r = allocm(&p, &rsz, 1, ALLOCM_ARENA(arena_ind)); 40 | if (r != ALLOCM_SUCCESS) { 41 | malloc_printf("Unexpected allocm() error\n"); 42 | abort(); 43 | } 44 | 45 | return (NULL); 46 | } 47 | 48 | int 49 | main(void) 50 | { 51 | je_thread_t threads[NTHREADS]; 52 | unsigned i; 53 | 54 | malloc_printf("Test begin\n"); 55 | 56 | for (i = 0; i < NTHREADS; i++) { 57 | je_thread_create(&threads[i], je_thread_start, 58 | (void *)(uintptr_t)i); 59 | } 60 | 61 | for (i = 0; i < NTHREADS; i++) 62 | je_thread_join(threads[i], NULL); 63 | 64 | malloc_printf("Test end\n"); 65 | return (0); 66 | } 67 | -------------------------------------------------------------------------------- /deps/jemalloc/test/ALLOCM_ARENA.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Test end 3 | -------------------------------------------------------------------------------- /deps/jemalloc/test/aligned_alloc.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Alignment: 8 3 | Alignment: 16 4 | Alignment: 32 5 | Alignment: 64 6 | Alignment: 128 7 | Alignment: 256 8 | Alignment: 512 9 | Alignment: 1024 10 | Alignment: 2048 11 | Alignment: 4096 12 | Alignment: 8192 13 | Alignment: 16384 14 | Alignment: 32768 15 | Alignment: 65536 16 | Alignment: 131072 17 | Alignment: 262144 18 | Alignment: 524288 19 | Alignment: 1048576 20 | Alignment: 2097152 21 | Alignment: 4194304 22 | Alignment: 8388608 23 | Alignment: 16777216 24 | Alignment: 33554432 25 | Test end 26 | -------------------------------------------------------------------------------- /deps/jemalloc/test/allocated.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MANGLE 2 | #include "jemalloc_test.h" 3 | 4 | void * 5 | je_thread_start(void *arg) 6 | { 7 | int err; 8 | void *p; 9 | uint64_t a0, a1, d0, d1; 10 | uint64_t *ap0, *ap1, *dp0, *dp1; 11 | size_t sz, usize; 12 | 13 | sz = sizeof(a0); 14 | if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) { 15 | if (err == ENOENT) { 16 | #ifdef JEMALLOC_STATS 17 | assert(false); 18 | #endif 19 | goto label_return; 20 | } 21 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 22 | strerror(err)); 23 | exit(1); 24 | } 25 | sz = sizeof(ap0); 26 | if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) { 27 | if (err == ENOENT) { 28 | #ifdef JEMALLOC_STATS 29 | assert(false); 30 | #endif 31 | goto label_return; 32 | } 33 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 34 | strerror(err)); 35 | exit(1); 36 | } 37 | assert(*ap0 == a0); 38 | 39 | sz = sizeof(d0); 40 | if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) { 41 | if (err == ENOENT) { 42 | #ifdef JEMALLOC_STATS 43 | assert(false); 44 | #endif 45 | goto label_return; 46 | } 47 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 48 | strerror(err)); 49 | exit(1); 50 | } 51 | sz = sizeof(dp0); 52 | if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) { 53 | if (err == ENOENT) { 54 | #ifdef JEMALLOC_STATS 55 | assert(false); 56 | #endif 57 | goto label_return; 58 | } 59 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 60 | strerror(err)); 61 | exit(1); 62 | } 63 | assert(*dp0 == d0); 64 | 65 | p = malloc(1); 66 | if (p == NULL) { 67 | malloc_printf("%s(): Error in malloc()\n", __func__); 68 | exit(1); 69 | } 70 | 71 | sz = sizeof(a1); 72 | mallctl("thread.allocated", &a1, &sz, NULL, 0); 73 | sz = sizeof(ap1); 74 | mallctl("thread.allocatedp", &ap1, &sz, NULL, 0); 75 | assert(*ap1 == a1); 76 | assert(ap0 == ap1); 77 | 78 | usize = malloc_usable_size(p); 79 | assert(a0 + usize <= a1); 80 | 81 | free(p); 82 | 83 | sz = sizeof(d1); 84 | mallctl("thread.deallocated", &d1, &sz, NULL, 0); 85 | sz = sizeof(dp1); 86 | mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0); 87 | assert(*dp1 == d1); 88 | assert(dp0 == dp1); 89 | 90 | assert(d0 + usize <= d1); 91 | 92 | label_return: 93 | return (NULL); 94 | } 95 | 96 | int 97 | main(void) 98 | { 99 | int ret = 0; 100 | je_thread_t thread; 101 | 102 | malloc_printf("Test begin\n"); 103 | 104 | je_thread_start(NULL); 105 | 106 | je_thread_create(&thread, je_thread_start, NULL); 107 | je_thread_join(thread, (void *)&ret); 108 | 109 | je_thread_start(NULL); 110 | 111 | je_thread_create(&thread, je_thread_start, NULL); 112 | je_thread_join(thread, (void *)&ret); 113 | 114 | je_thread_start(NULL); 115 | 116 | malloc_printf("Test end\n"); 117 | return (ret); 118 | } 119 | -------------------------------------------------------------------------------- /deps/jemalloc/test/allocated.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Test end 3 | -------------------------------------------------------------------------------- /deps/jemalloc/test/allocm.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Alignment: 8 3 | Alignment: 16 4 | Alignment: 32 5 | Alignment: 64 6 | Alignment: 128 7 | Alignment: 256 8 | Alignment: 512 9 | Alignment: 1024 10 | Alignment: 2048 11 | Alignment: 4096 12 | Alignment: 8192 13 | Alignment: 16384 14 | Alignment: 32768 15 | Alignment: 65536 16 | Alignment: 131072 17 | Alignment: 262144 18 | Alignment: 524288 19 | Alignment: 1048576 20 | Alignment: 2097152 21 | Alignment: 4194304 22 | Alignment: 8388608 23 | Alignment: 16777216 24 | Alignment: 33554432 25 | Test end 26 | -------------------------------------------------------------------------------- /deps/jemalloc/test/bitmap.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Test end 3 | -------------------------------------------------------------------------------- /deps/jemalloc/test/jemalloc_test.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This header should be included by tests, rather than directly including 3 | * jemalloc/jemalloc.h, because --with-install-suffix may cause the header to 4 | * have a different name. 5 | */ 6 | #include "jemalloc/jemalloc@install_suffix@.h" 7 | #include "jemalloc/internal/jemalloc_internal.h" 8 | 9 | /* Abstraction layer for threading in tests */ 10 | #ifdef _WIN32 11 | #include 12 | 13 | typedef HANDLE je_thread_t; 14 | 15 | void 16 | je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg) 17 | { 18 | LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc; 19 | *thread = CreateThread(NULL, 0, routine, arg, 0, NULL); 20 | if (*thread == NULL) { 21 | malloc_printf("Error in CreateThread()\n"); 22 | exit(1); 23 | } 24 | } 25 | 26 | void 27 | je_thread_join(je_thread_t thread, void **ret) 28 | { 29 | WaitForSingleObject(thread, INFINITE); 30 | } 31 | 32 | #else 33 | #include 34 | 35 | typedef pthread_t je_thread_t; 36 | 37 | void 38 | je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg) 39 | { 40 | 41 | if (pthread_create(thread, NULL, proc, arg) != 0) { 42 | malloc_printf("Error in pthread_create()\n"); 43 | exit(1); 44 | } 45 | } 46 | 47 | void 48 | je_thread_join(je_thread_t thread, void **ret) 49 | { 50 | 51 | pthread_join(thread, ret); 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /deps/jemalloc/test/mremap.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MANGLE 2 | #include "jemalloc_test.h" 3 | 4 | int 5 | main(void) 6 | { 7 | int ret, err; 8 | size_t sz, lg_chunk, chunksize, i; 9 | char *p, *q; 10 | 11 | malloc_printf("Test begin\n"); 12 | 13 | sz = sizeof(lg_chunk); 14 | if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) { 15 | assert(err != ENOENT); 16 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 17 | strerror(err)); 18 | ret = 1; 19 | goto label_return; 20 | } 21 | chunksize = ((size_t)1U) << lg_chunk; 22 | 23 | p = (char *)malloc(chunksize); 24 | if (p == NULL) { 25 | malloc_printf("malloc(%zu) --> %p\n", chunksize, p); 26 | ret = 1; 27 | goto label_return; 28 | } 29 | memset(p, 'a', chunksize); 30 | 31 | q = (char *)realloc(p, chunksize * 2); 32 | if (q == NULL) { 33 | malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize * 2, 34 | q); 35 | ret = 1; 36 | goto label_return; 37 | } 38 | for (i = 0; i < chunksize; i++) { 39 | assert(q[i] == 'a'); 40 | } 41 | 42 | p = q; 43 | 44 | q = (char *)realloc(p, chunksize); 45 | if (q == NULL) { 46 | malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize, q); 47 | ret = 1; 48 | goto label_return; 49 | } 50 | for (i = 0; i < chunksize; i++) { 51 | assert(q[i] == 'a'); 52 | } 53 | 54 | free(q); 55 | 56 | ret = 0; 57 | label_return: 58 | malloc_printf("Test end\n"); 59 | return (ret); 60 | } 61 | -------------------------------------------------------------------------------- /deps/jemalloc/test/mremap.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Test end 3 | -------------------------------------------------------------------------------- /deps/jemalloc/test/posix_memalign.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Alignment: 8 3 | Alignment: 16 4 | Alignment: 32 5 | Alignment: 64 6 | Alignment: 128 7 | Alignment: 256 8 | Alignment: 512 9 | Alignment: 1024 10 | Alignment: 2048 11 | Alignment: 4096 12 | Alignment: 8192 13 | Alignment: 16384 14 | Alignment: 32768 15 | Alignment: 65536 16 | Alignment: 131072 17 | Alignment: 262144 18 | Alignment: 524288 19 | Alignment: 1048576 20 | Alignment: 2097152 21 | Alignment: 4194304 22 | Alignment: 8388608 23 | Alignment: 16777216 24 | Alignment: 33554432 25 | Test end 26 | -------------------------------------------------------------------------------- /deps/jemalloc/test/rallocm.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Test end 3 | -------------------------------------------------------------------------------- /deps/jemalloc/test/thread_arena.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MANGLE 2 | #include "jemalloc_test.h" 3 | 4 | #define NTHREADS 10 5 | 6 | void * 7 | je_thread_start(void *arg) 8 | { 9 | unsigned main_arena_ind = *(unsigned *)arg; 10 | void *p; 11 | unsigned arena_ind; 12 | size_t size; 13 | int err; 14 | 15 | p = malloc(1); 16 | if (p == NULL) { 17 | malloc_printf("%s(): Error in malloc()\n", __func__); 18 | return (void *)1; 19 | } 20 | 21 | size = sizeof(arena_ind); 22 | if ((err = mallctl("thread.arena", &arena_ind, &size, &main_arena_ind, 23 | sizeof(main_arena_ind)))) { 24 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 25 | strerror(err)); 26 | return (void *)1; 27 | } 28 | 29 | size = sizeof(arena_ind); 30 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 31 | 0))) { 32 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 33 | strerror(err)); 34 | return (void *)1; 35 | } 36 | assert(arena_ind == main_arena_ind); 37 | 38 | return (NULL); 39 | } 40 | 41 | int 42 | main(void) 43 | { 44 | int ret = 0; 45 | void *p; 46 | unsigned arena_ind; 47 | size_t size; 48 | int err; 49 | je_thread_t threads[NTHREADS]; 50 | unsigned i; 51 | 52 | malloc_printf("Test begin\n"); 53 | 54 | p = malloc(1); 55 | if (p == NULL) { 56 | malloc_printf("%s(): Error in malloc()\n", __func__); 57 | ret = 1; 58 | goto label_return; 59 | } 60 | 61 | size = sizeof(arena_ind); 62 | if ((err = mallctl("thread.arena", &arena_ind, &size, NULL, 0))) { 63 | malloc_printf("%s(): Error in mallctl(): %s\n", __func__, 64 | strerror(err)); 65 | ret = 1; 66 | goto label_return; 67 | } 68 | 69 | for (i = 0; i < NTHREADS; i++) { 70 | je_thread_create(&threads[i], je_thread_start, 71 | (void *)&arena_ind); 72 | } 73 | 74 | for (i = 0; i < NTHREADS; i++) 75 | je_thread_join(threads[i], (void *)&ret); 76 | 77 | label_return: 78 | malloc_printf("Test end\n"); 79 | return (ret); 80 | } 81 | -------------------------------------------------------------------------------- /deps/jemalloc/test/thread_arena.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Test end 3 | -------------------------------------------------------------------------------- /deps/jemalloc/test/thread_tcache_enabled.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MANGLE 2 | #include "jemalloc_test.h" 3 | 4 | void * 5 | je_thread_start(void *arg) 6 | { 7 | int err; 8 | size_t sz; 9 | bool e0, e1; 10 | 11 | sz = sizeof(bool); 12 | if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) { 13 | if (err == ENOENT) { 14 | #ifdef JEMALLOC_TCACHE 15 | assert(false); 16 | #endif 17 | } 18 | goto label_return; 19 | } 20 | 21 | if (e0) { 22 | e1 = false; 23 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) 24 | == 0); 25 | assert(e0); 26 | } 27 | 28 | e1 = true; 29 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 30 | assert(e0 == false); 31 | 32 | e1 = true; 33 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 34 | assert(e0); 35 | 36 | e1 = false; 37 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 38 | assert(e0); 39 | 40 | e1 = false; 41 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 42 | assert(e0 == false); 43 | 44 | free(malloc(1)); 45 | e1 = true; 46 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 47 | assert(e0 == false); 48 | 49 | free(malloc(1)); 50 | e1 = true; 51 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 52 | assert(e0); 53 | 54 | free(malloc(1)); 55 | e1 = false; 56 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 57 | assert(e0); 58 | 59 | free(malloc(1)); 60 | e1 = false; 61 | assert(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz) == 0); 62 | assert(e0 == false); 63 | 64 | free(malloc(1)); 65 | label_return: 66 | return (NULL); 67 | } 68 | 69 | int 70 | main(void) 71 | { 72 | int ret = 0; 73 | je_thread_t thread; 74 | 75 | malloc_printf("Test begin\n"); 76 | 77 | je_thread_start(NULL); 78 | 79 | je_thread_create(&thread, je_thread_start, NULL); 80 | je_thread_join(thread, (void *)&ret); 81 | 82 | je_thread_start(NULL); 83 | 84 | je_thread_create(&thread, je_thread_start, NULL); 85 | je_thread_join(thread, (void *)&ret); 86 | 87 | je_thread_start(NULL); 88 | 89 | malloc_printf("Test end\n"); 90 | return (ret); 91 | } 92 | -------------------------------------------------------------------------------- /deps/jemalloc/test/thread_tcache_enabled.exp: -------------------------------------------------------------------------------- 1 | Test begin 2 | Test end 3 | -------------------------------------------------------------------------------- /deps/linenoise/.gitignore: -------------------------------------------------------------------------------- 1 | linenoise_example* 2 | -------------------------------------------------------------------------------- /deps/linenoise/Makefile: -------------------------------------------------------------------------------- 1 | STD= 2 | WARN= -Wall 3 | OPT= -Os 4 | 5 | R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) 6 | R_LDFLAGS= $(LDFLAGS) 7 | DEBUG= -g 8 | 9 | R_CC=$(CC) $(R_CFLAGS) 10 | R_LD=$(CC) $(R_LDFLAGS) 11 | 12 | linenoise.o: linenoise.h linenoise.c 13 | 14 | linenoise_example: linenoise.o example.o 15 | $(R_LD) -o $@ $^ 16 | 17 | .c.o: 18 | $(R_CC) -c $< 19 | 20 | clean: 21 | rm -f linenoise_example *.o 22 | -------------------------------------------------------------------------------- /deps/linenoise/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "linenoise.h" 4 | 5 | 6 | void completion(const char *buf, linenoiseCompletions *lc) { 7 | if (buf[0] == 'h') { 8 | linenoiseAddCompletion(lc,"hello"); 9 | linenoiseAddCompletion(lc,"hello there"); 10 | } 11 | } 12 | 13 | int main(void) { 14 | char *line; 15 | 16 | linenoiseSetCompletionCallback(completion); 17 | linenoiseHistoryLoad("history.txt"); /* Load the history at startup */ 18 | while((line = linenoise("hello> ")) != NULL) { 19 | if (line[0] != '\0') { 20 | printf("echo: '%s'\n", line); 21 | linenoiseHistoryAdd(line); 22 | linenoiseHistorySave("history.txt"); /* Save every new entry */ 23 | } 24 | free(line); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /deps/linenoise/linenoise.h: -------------------------------------------------------------------------------- 1 | /* linenoise.h -- guerrilla line editing library against the idea that a 2 | * line editing lib needs to be 20,000 lines of C code. 3 | * 4 | * See linenoise.c for more information. 5 | * 6 | * ------------------------------------------------------------------------ 7 | * 8 | * Copyright (c) 2010, Salvatore Sanfilippo 9 | * Copyright (c) 2010, Pieter Noordhuis 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are 15 | * met: 16 | * 17 | * * Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 20 | * * Redistributions in binary form must reproduce the above copyright 21 | * notice, this list of conditions and the following disclaimer in the 22 | * documentation and/or other materials provided with the distribution. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef __LINENOISE_H 38 | #define __LINENOISE_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef struct linenoiseCompletions { 45 | size_t len; 46 | char **cvec; 47 | } linenoiseCompletions; 48 | 49 | typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *); 50 | void linenoiseSetCompletionCallback(linenoiseCompletionCallback *); 51 | void linenoiseAddCompletion(linenoiseCompletions *, const char *); 52 | 53 | char *linenoise(const char *prompt); 54 | int linenoiseHistoryAdd(const char *line); 55 | int linenoiseHistorySetMaxLen(int len); 56 | int linenoiseHistorySave(const char *filename); 57 | int linenoiseHistoryLoad(const char *filename); 58 | void linenoiseClearScreen(void); 59 | void linenoiseSetMultiLine(int ml); 60 | void linenoisePrintKeyCodes(void); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __LINENOISE_H */ 67 | -------------------------------------------------------------------------------- /deps/lua/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Lua License 2 | ----------- 3 | 4 | Lua is licensed under the terms of the MIT license reproduced below. 5 | This means that Lua is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | For details and rationale, see http://www.lua.org/license.html . 9 | 10 | =============================================================================== 11 | 12 | Copyright (C) 1994-2012 Lua.org, PUC-Rio. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | THE SOFTWARE. 31 | 32 | =============================================================================== 33 | 34 | (end of COPYRIGHT) 35 | -------------------------------------------------------------------------------- /deps/lua/README: -------------------------------------------------------------------------------- 1 | README for Lua 5.1 2 | 3 | See INSTALL for installation instructions. 4 | See HISTORY for a summary of changes since the last released version. 5 | 6 | * What is Lua? 7 | ------------ 8 | Lua is a powerful, light-weight programming language designed for extending 9 | applications. Lua is also frequently used as a general-purpose, stand-alone 10 | language. Lua is free software. 11 | 12 | For complete information, visit Lua's web site at http://www.lua.org/ . 13 | For an executive summary, see http://www.lua.org/about.html . 14 | 15 | Lua has been used in many different projects around the world. 16 | For a short list, see http://www.lua.org/uses.html . 17 | 18 | * Availability 19 | ------------ 20 | Lua is freely available for both academic and commercial purposes. 21 | See COPYRIGHT and http://www.lua.org/license.html for details. 22 | Lua can be downloaded at http://www.lua.org/download.html . 23 | 24 | * Installation 25 | ------------ 26 | Lua is implemented in pure ANSI C, and compiles unmodified in all known 27 | platforms that have an ANSI C compiler. In most Unix-like platforms, simply 28 | do "make" with a suitable target. See INSTALL for detailed instructions. 29 | 30 | * Origin 31 | ------ 32 | Lua is developed at Lua.org, a laboratory of the Department of Computer 33 | Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro 34 | in Brazil). 35 | For more information about the authors, see http://www.lua.org/authors.html . 36 | 37 | (end of README) 38 | -------------------------------------------------------------------------------- /deps/lua/doc/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/redis-3.0-annotated/8e60a75884e75503fb8be1a322406f21fb455f67/deps/lua/doc/cover.png -------------------------------------------------------------------------------- /deps/lua/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/redis-3.0-annotated/8e60a75884e75503fb8be1a322406f21fb455f67/deps/lua/doc/logo.gif -------------------------------------------------------------------------------- /deps/lua/doc/lua.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #000000 ; 3 | background-color: #FFFFFF ; 4 | font-family: Helvetica, Arial, sans-serif ; 5 | text-align: justify ; 6 | margin-right: 30px ; 7 | margin-left: 30px ; 8 | } 9 | 10 | h1, h2, h3, h4 { 11 | font-family: Verdana, Geneva, sans-serif ; 12 | font-weight: normal ; 13 | font-style: italic ; 14 | } 15 | 16 | h2 { 17 | padding-top: 0.4em ; 18 | padding-bottom: 0.4em ; 19 | padding-left: 30px ; 20 | padding-right: 30px ; 21 | margin-left: -30px ; 22 | background-color: #E0E0FF ; 23 | } 24 | 25 | h3 { 26 | padding-left: 0.5em ; 27 | border-left: solid #E0E0FF 1em ; 28 | } 29 | 30 | table h3 { 31 | padding-left: 0px ; 32 | border-left: none ; 33 | } 34 | 35 | a:link { 36 | color: #000080 ; 37 | background-color: inherit ; 38 | text-decoration: none ; 39 | } 40 | 41 | a:visited { 42 | background-color: inherit ; 43 | text-decoration: none ; 44 | } 45 | 46 | a:link:hover, a:visited:hover { 47 | color: #000080 ; 48 | background-color: #E0E0FF ; 49 | } 50 | 51 | a:link:active, a:visited:active { 52 | color: #FF0000 ; 53 | } 54 | 55 | hr { 56 | border: 0 ; 57 | height: 1px ; 58 | color: #a0a0a0 ; 59 | background-color: #a0a0a0 ; 60 | } 61 | 62 | :target { 63 | background-color: #F8F8F8 ; 64 | padding: 8px ; 65 | border: solid #a0a0a0 2px ; 66 | } 67 | 68 | .footer { 69 | color: gray ; 70 | font-size: small ; 71 | } 72 | 73 | input[type=text] { 74 | border: solid #a0a0a0 2px ; 75 | border-radius: 2em ; 76 | -moz-border-radius: 2em ; 77 | background-image: url('images/search.png') ; 78 | background-repeat: no-repeat; 79 | background-position: 4px center ; 80 | padding-left: 20px ; 81 | height: 2em ; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /deps/lua/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | float: right ; 12 | font-family: inherit ; 13 | font-style: normal ; 14 | font-size: small ; 15 | color: gray ; 16 | } 17 | 18 | p+h1, ul+h1 { 19 | padding-top: 0.4em ; 20 | padding-bottom: 0.4em ; 21 | padding-left: 30px ; 22 | margin-left: -30px ; 23 | background-color: #E0E0FF ; 24 | } 25 | -------------------------------------------------------------------------------- /deps/lua/doc/readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lua documentation 4 | 5 | 6 | 7 | 8 | 9 |
10 |

11 | Lua 12 | Documentation 13 |

14 | 15 | This is the documentation included in the source distribution of Lua 5.1.5. 16 | 17 | 25 | 26 | Lua's 27 | official web site 28 | contains updated documentation, 29 | especially the 30 | reference manual. 31 |

32 | 33 |


34 | 35 | Last update: 36 | Fri Feb 3 09:44:42 BRST 2012 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /deps/lua/etc/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua etc 2 | 3 | TOP= .. 4 | LIB= $(TOP)/src 5 | INC= $(TOP)/src 6 | BIN= $(TOP)/src 7 | SRC= $(TOP)/src 8 | TST= $(TOP)/test 9 | 10 | CC= gcc 11 | CFLAGS= -O2 -Wall -I$(INC) $(MYCFLAGS) 12 | MYCFLAGS= 13 | MYLDFLAGS= -Wl,-E 14 | MYLIBS= -lm 15 | #MYLIBS= -lm -Wl,-E -ldl -lreadline -lhistory -lncurses 16 | RM= rm -f 17 | 18 | default: 19 | @echo 'Please choose a target: min noparser one strict clean' 20 | 21 | min: min.c 22 | $(CC) $(CFLAGS) $@.c -L$(LIB) -llua $(MYLIBS) 23 | echo 'print"Hello there!"' | ./a.out 24 | 25 | noparser: noparser.o 26 | $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS) 27 | $(BIN)/luac $(TST)/hello.lua 28 | -./a.out luac.out 29 | -./a.out -e'a=1' 30 | 31 | one: 32 | $(CC) $(CFLAGS) all.c $(MYLIBS) 33 | ./a.out $(TST)/hello.lua 34 | 35 | strict: 36 | -$(BIN)/lua -e 'print(a);b=2' 37 | -$(BIN)/lua -lstrict -e 'print(a)' 38 | -$(BIN)/lua -e 'function f() b=2 end f()' 39 | -$(BIN)/lua -lstrict -e 'function f() b=2 end f()' 40 | 41 | clean: 42 | $(RM) a.out core core.* *.o luac.out 43 | 44 | .PHONY: default min noparser one strict clean 45 | -------------------------------------------------------------------------------- /deps/lua/etc/README: -------------------------------------------------------------------------------- 1 | This directory contains some useful files and code. 2 | Unlike the code in ../src, everything here is in the public domain. 3 | 4 | If any of the makes fail, you're probably not using the same libraries 5 | used to build Lua. Set MYLIBS in Makefile accordingly. 6 | 7 | all.c 8 | Full Lua interpreter in a single file. 9 | Do "make one" for a demo. 10 | 11 | lua.hpp 12 | Lua header files for C++ using 'extern "C"'. 13 | 14 | lua.ico 15 | A Lua icon for Windows (and web sites: save as favicon.ico). 16 | Drawn by hand by Markus Gritsch . 17 | 18 | lua.pc 19 | pkg-config data for Lua 20 | 21 | luavs.bat 22 | Script to build Lua under "Visual Studio .NET Command Prompt". 23 | Run it from the toplevel as etc\luavs.bat. 24 | 25 | min.c 26 | A minimal Lua interpreter. 27 | Good for learning and for starting your own. 28 | Do "make min" for a demo. 29 | 30 | noparser.c 31 | Linking with noparser.o avoids loading the parsing modules in lualib.a. 32 | Do "make noparser" for a demo. 33 | 34 | strict.lua 35 | Traps uses of undeclared global variables. 36 | Do "make strict" for a demo. 37 | 38 | -------------------------------------------------------------------------------- /deps/lua/etc/all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * all.c -- Lua core, libraries and interpreter in a single file 3 | */ 4 | 5 | #define luaall_c 6 | 7 | #include "lapi.c" 8 | #include "lcode.c" 9 | #include "ldebug.c" 10 | #include "ldo.c" 11 | #include "ldump.c" 12 | #include "lfunc.c" 13 | #include "lgc.c" 14 | #include "llex.c" 15 | #include "lmem.c" 16 | #include "lobject.c" 17 | #include "lopcodes.c" 18 | #include "lparser.c" 19 | #include "lstate.c" 20 | #include "lstring.c" 21 | #include "ltable.c" 22 | #include "ltm.c" 23 | #include "lundump.c" 24 | #include "lvm.c" 25 | #include "lzio.c" 26 | 27 | #include "lauxlib.c" 28 | #include "lbaselib.c" 29 | #include "ldblib.c" 30 | #include "liolib.c" 31 | #include "linit.c" 32 | #include "lmathlib.c" 33 | #include "loadlib.c" 34 | #include "loslib.c" 35 | #include "lstrlib.c" 36 | #include "ltablib.c" 37 | 38 | #include "lua.c" 39 | -------------------------------------------------------------------------------- /deps/lua/etc/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 | -------------------------------------------------------------------------------- /deps/lua/etc/lua.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/redis-3.0-annotated/8e60a75884e75503fb8be1a322406f21fb455f67/deps/lua/etc/lua.ico -------------------------------------------------------------------------------- /deps/lua/etc/lua.pc: -------------------------------------------------------------------------------- 1 | # lua.pc -- pkg-config data for Lua 2 | 3 | # vars from install Makefile 4 | 5 | # grep '^V=' ../Makefile 6 | V= 5.1 7 | # grep '^R=' ../Makefile 8 | R= 5.1.5 9 | 10 | # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' 11 | prefix= /usr/local 12 | INSTALL_BIN= ${prefix}/bin 13 | INSTALL_INC= ${prefix}/include 14 | INSTALL_LIB= ${prefix}/lib 15 | INSTALL_MAN= ${prefix}/man/man1 16 | INSTALL_LMOD= ${prefix}/share/lua/${V} 17 | INSTALL_CMOD= ${prefix}/lib/lua/${V} 18 | 19 | # canonical vars 20 | exec_prefix=${prefix} 21 | libdir=${exec_prefix}/lib 22 | includedir=${prefix}/include 23 | 24 | Name: Lua 25 | Description: An Extensible Extension Language 26 | Version: ${R} 27 | Requires: 28 | Libs: -L${libdir} -llua -lm 29 | Cflags: -I${includedir} 30 | 31 | # (end of lua.pc) 32 | -------------------------------------------------------------------------------- /deps/lua/etc/luavs.bat: -------------------------------------------------------------------------------- 1 | @rem Script to build Lua under "Visual Studio .NET Command Prompt". 2 | @rem Do not run from this directory; run it from the toplevel: etc\luavs.bat . 3 | @rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src. 4 | @rem (contributed by David Manura and Mike Pall) 5 | 6 | @setlocal 7 | @set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE 8 | @set MYLINK=link /nologo 9 | @set MYMT=mt /nologo 10 | 11 | cd src 12 | %MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c 13 | del lua.obj luac.obj 14 | %MYLINK% /DLL /out:lua51.dll l*.obj 15 | if exist lua51.dll.manifest^ 16 | %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2 17 | %MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c 18 | %MYLINK% /out:lua.exe lua.obj lua51.lib 19 | if exist lua.exe.manifest^ 20 | %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe 21 | %MYCOMPILE% l*.c print.c 22 | del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^ 23 | loslib.obj ltablib.obj lstrlib.obj loadlib.obj 24 | %MYLINK% /out:luac.exe *.obj 25 | if exist luac.exe.manifest^ 26 | %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe 27 | del *.obj *.manifest 28 | cd .. 29 | -------------------------------------------------------------------------------- /deps/lua/etc/min.c: -------------------------------------------------------------------------------- 1 | /* 2 | * min.c -- a minimal Lua interpreter 3 | * loads stdin only with minimal error handling. 4 | * no interaction, and no standard library, only a "print" function. 5 | */ 6 | 7 | #include 8 | 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | 12 | static int print(lua_State *L) 13 | { 14 | int n=lua_gettop(L); 15 | int i; 16 | for (i=1; i<=n; i++) 17 | { 18 | if (i>1) printf("\t"); 19 | if (lua_isstring(L,i)) 20 | printf("%s",lua_tostring(L,i)); 21 | else if (lua_isnil(L,i)) 22 | printf("%s","nil"); 23 | else if (lua_isboolean(L,i)) 24 | printf("%s",lua_toboolean(L,i) ? "true" : "false"); 25 | else 26 | printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); 27 | } 28 | printf("\n"); 29 | return 0; 30 | } 31 | 32 | int main(void) 33 | { 34 | lua_State *L=lua_open(); 35 | lua_register(L,"print",print); 36 | if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); 37 | lua_close(L); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /deps/lua/etc/noparser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The code below can be used to make a Lua core that does not contain the 3 | * parsing modules (lcode, llex, lparser), which represent 35% of the total core. 4 | * You'll only be able to load binary files and strings, precompiled with luac. 5 | * (Of course, you'll have to build luac with the original parsing modules!) 6 | * 7 | * To use this module, simply compile it ("make noparser" does that) and list 8 | * its object file before the Lua libraries. The linker should then not load 9 | * the parsing modules. To try it, do "make luab". 10 | * 11 | * If you also want to avoid the dump module (ldump.o), define NODUMP. 12 | * #define NODUMP 13 | */ 14 | 15 | #define LUA_CORE 16 | 17 | #include "llex.h" 18 | #include "lparser.h" 19 | #include "lzio.h" 20 | 21 | LUAI_FUNC void luaX_init (lua_State *L) { 22 | UNUSED(L); 23 | } 24 | 25 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { 26 | UNUSED(z); 27 | UNUSED(buff); 28 | UNUSED(name); 29 | lua_pushliteral(L,"parser not loaded"); 30 | lua_error(L); 31 | return NULL; 32 | } 33 | 34 | #ifdef NODUMP 35 | #include "lundump.h" 36 | 37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { 38 | UNUSED(f); 39 | UNUSED(w); 40 | UNUSED(data); 41 | UNUSED(strip); 42 | #if 1 43 | UNUSED(L); 44 | return 0; 45 | #else 46 | lua_pushliteral(L,"dumper not loaded"); 47 | lua_error(L); 48 | #endif 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /deps/lua/etc/strict.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- strict.lua 3 | -- checks uses of undeclared global variables 4 | -- All global variables must be 'declared' through a regular assignment 5 | -- (even assigning nil will do) in a main chunk before being used 6 | -- anywhere or assigned to inside a function. 7 | -- 8 | 9 | local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget 10 | 11 | local mt = getmetatable(_G) 12 | if mt == nil then 13 | mt = {} 14 | setmetatable(_G, mt) 15 | end 16 | 17 | mt.__declared = {} 18 | 19 | local function what () 20 | local d = getinfo(3, "S") 21 | return d and d.what or "C" 22 | end 23 | 24 | mt.__newindex = function (t, n, v) 25 | if not mt.__declared[n] then 26 | local w = what() 27 | if w ~= "main" and w ~= "C" then 28 | error("assign to undeclared variable '"..n.."'", 2) 29 | end 30 | mt.__declared[n] = true 31 | end 32 | rawset(t, n, v) 33 | end 34 | 35 | mt.__index = function (t, n) 36 | if not mt.__declared[n] and what() ~= "C" then 37 | error("variable '"..n.."' is not declared", 2) 38 | end 39 | return rawget(t, n) 40 | end 41 | 42 | -------------------------------------------------------------------------------- /deps/lua/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /deps/lua/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 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)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 25 | const TValue *p2); 26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 29 | LUAI_FUNC void luaG_errormsg (lua_State *L); 30 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 31 | LUAI_FUNC int luaG_checkopenop (Instruction i); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /deps/lua/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 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 | #define luaD_checkstack(L,n) \ 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ 18 | luaD_growstack(L, n); \ 19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); 20 | 21 | 22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 23 | 24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 26 | 27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 29 | 30 | 31 | /* results from luaD_precall */ 32 | #define PCRLUA 0 /* initiated a call to a Lua function */ 33 | #define PCRC 1 /* did a call to a C function */ 34 | #define PCRYIELD 2 /* C funtion yielded */ 35 | 36 | 37 | /* type of protected functions, to be ran by `runprotected' */ 38 | typedef void (*Pfunc) (lua_State *L, void *ud); 39 | 40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); 41 | LUAI_FUNC void luaD_callhook (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 int luaD_pcall (lua_State *L, Pfunc func, void *u, 45 | ptrdiff_t oldtop, ptrdiff_t ef); 46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); 48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 50 | 51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 53 | 54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /deps/lua/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 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 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 29 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 30 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 31 | int pc); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /deps/lua/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Initialization of libraries for lua.c 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | #include "lua.h" 12 | 13 | #include "lualib.h" 14 | #include "lauxlib.h" 15 | 16 | 17 | static const luaL_Reg lualibs[] = { 18 | {"", luaopen_base}, 19 | {LUA_LOADLIBNAME, luaopen_package}, 20 | {LUA_TABLIBNAME, luaopen_table}, 21 | {LUA_IOLIBNAME, luaopen_io}, 22 | {LUA_OSLIBNAME, luaopen_os}, 23 | {LUA_STRLIBNAME, luaopen_string}, 24 | {LUA_MATHLIBNAME, luaopen_math}, 25 | {LUA_DBLIBNAME, luaopen_debug}, 26 | {NULL, NULL} 27 | }; 28 | 29 | 30 | LUALIB_API void luaL_openlibs (lua_State *L) { 31 | const luaL_Reg *lib = lualibs; 32 | for (; lib->func; lib++) { 33 | lua_pushcfunction(L, lib->func); 34 | lua_pushstring(L, lib->name); 35 | lua_call(L, 1, 0); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /deps/lua/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | /* maximum length of a reserved word */ 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) 18 | 19 | 20 | /* 21 | * WARNING: if you change the order of this enumeration, 22 | * grep "ORDER RESERVED" 23 | */ 24 | enum RESERVED { 25 | /* terminal symbols denoted by reserved words */ 26 | TK_AND = FIRST_RESERVED, TK_BREAK, 27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 30 | /* other terminal symbols */ 31 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 32 | TK_NAME, TK_STRING, TK_EOS 33 | }; 34 | 35 | /* number of reserved words */ 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 37 | 38 | 39 | /* array with token `names' */ 40 | LUAI_DATA const char *const luaX_tokens []; 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | TString *ts; 46 | } SemInfo; /* semantics information */ 47 | 48 | 49 | typedef struct Token { 50 | int token; 51 | SemInfo seminfo; 52 | } Token; 53 | 54 | 55 | typedef struct LexState { 56 | int current; /* current character (charint) */ 57 | int linenumber; /* input line counter */ 58 | int lastline; /* line of last token `consumed' */ 59 | Token t; /* current token */ 60 | Token lookahead; /* look ahead token */ 61 | struct FuncState *fs; /* `FuncState' is private to the parser */ 62 | struct lua_State *L; 63 | ZIO *z; /* input stream */ 64 | Mbuffer *buff; /* buffer for tokens */ 65 | TString *source; /* current source name */ 66 | char decpoint; /* locale decimal point */ 67 | } LexState; 68 | 69 | 70 | LUAI_FUNC void luaX_init (lua_State *L); 71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 72 | TString *source); 73 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 74 | LUAI_FUNC void luaX_next (LexState *ls); 75 | LUAI_FUNC void luaX_lookahead (LexState *ls); 76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); 77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); 78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /deps/lua/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | /* 24 | ** About the realloc function: 25 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 26 | ** (`osize' is the old size, `nsize' is the new size) 27 | ** 28 | ** Lua ensures that (ptr == NULL) iff (osize == 0). 29 | ** 30 | ** * frealloc(ud, NULL, 0, x) creates a new block of size `x' 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL). 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *errormsg) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, errormsg); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | void *luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | return NULL; /* to avoid warnings */ 69 | } 70 | 71 | 72 | 73 | /* 74 | ** generic allocation routine. 75 | */ 76 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 77 | global_State *g = G(L); 78 | lua_assert((osize == 0) == (block == NULL)); 79 | block = (*g->frealloc)(g->ud, block, osize, nsize); 80 | if (block == NULL && nsize > 0) 81 | luaD_throw(L, LUA_ERRMEM); 82 | lua_assert((nsize == 0) == (block == NULL)); 83 | g->totalbytes = (g->totalbytes - osize) + nsize; 84 | return block; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /deps/lua/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | #define luaM_reallocv(L,b,on,n,e) \ 20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 22 | luaM_toobig(L)) 23 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 27 | 28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 30 | #define luaM_newvector(L,n,t) \ 31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 32 | 33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 34 | if ((nelems)+1 > (size)) \ 35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 36 | 37 | #define luaM_reallocvector(L, v,oldn,n,t) \ 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 39 | 40 | 41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 42 | size_t size); 43 | LUAI_FUNC void *luaM_toobig (lua_State *L); 44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 45 | size_t size_elem, int limit, 46 | const char *errormsg); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /deps/lua/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in `k' */ 25 | VKNUM, /* nval = numerical value */ 26 | VLOCAL, /* info = local register */ 27 | VUPVAL, /* info = index of upvalue in `upvalues' */ 28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 29 | VINDEXED, /* info = table register; aux = index register (or `k') */ 30 | VJMP, /* info = instruction pc */ 31 | VRELOCABLE, /* info = instruction pc */ 32 | VNONRELOC, /* info = result register */ 33 | VCALL, /* info = instruction pc */ 34 | VVARARG /* info = instruction pc */ 35 | } expkind; 36 | 37 | typedef struct expdesc { 38 | expkind k; 39 | union { 40 | struct { int info, aux; } s; 41 | lua_Number nval; 42 | } u; 43 | int t; /* patch list of `exit when true' */ 44 | int f; /* patch list of `exit when false' */ 45 | } expdesc; 46 | 47 | 48 | typedef struct upvaldesc { 49 | lu_byte k; 50 | lu_byte info; 51 | } upvaldesc; 52 | 53 | 54 | struct BlockCnt; /* defined in lparser.c */ 55 | 56 | 57 | /* state needed to generate code for a given function */ 58 | typedef struct FuncState { 59 | Proto *f; /* current function header */ 60 | Table *h; /* table to find (and reuse) elements in `k' */ 61 | struct FuncState *prev; /* enclosing function */ 62 | struct LexState *ls; /* lexical state */ 63 | struct lua_State *L; /* copy of the Lua state */ 64 | struct BlockCnt *bl; /* chain of current blocks */ 65 | int pc; /* next position to code (equivalent to `ncode') */ 66 | int lasttarget; /* `pc' of last `jump target' */ 67 | int jpc; /* list of pending jumps to `pc' */ 68 | int freereg; /* first free register */ 69 | int nk; /* number of elements in `k' */ 70 | int np; /* number of elements in `p' */ 71 | short nlocvars; /* number of elements in `locvars' */ 72 | lu_byte nactvar; /* number of active local variables */ 73 | upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ 74 | unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ 75 | } FuncState; 76 | 77 | 78 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 79 | const char *name); 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /deps/lua/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 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 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 25 | 26 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 27 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 28 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /deps/lua/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 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 gkey(n) (&(n)->i_key.nk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 28 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 29 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 31 | LUAI_FUNC int luaH_getn (Table *t); 32 | 33 | 34 | #if defined(LUA_DEBUG) 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 36 | LUAI_FUNC int luaH_isdummy (Node *n); 37 | #endif 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /deps/lua/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | 23 | const char *const luaT_typenames[] = { 24 | "nil", "boolean", "userdata", "number", 25 | "string", "table", "function", "userdata", "thread", 26 | "proto", "upval" 27 | }; 28 | 29 | 30 | void luaT_init (lua_State *L) { 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ 32 | "__index", "__newindex", 33 | "__gc", "__mode", "__eq", 34 | "__add", "__sub", "__mul", "__div", "__mod", 35 | "__pow", "__unm", "__len", "__lt", "__le", 36 | "__concat", "__call" 37 | }; 38 | int i; 39 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 41 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 42 | } 43 | } 44 | 45 | 46 | /* 47 | ** function to be used with macro "fasttm": optimized for absence of 48 | ** tag methods 49 | */ 50 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 51 | const TValue *tm = luaH_getstr(events, ename); 52 | lua_assert(event <= TM_EQ); 53 | if (ttisnil(tm)) { /* no tag method? */ 54 | events->flags |= cast_byte(1u<metatable; 66 | break; 67 | case LUA_TUSERDATA: 68 | mt = uvalue(o)->metatable; 69 | break; 70 | default: 71 | mt = G(L)->mt[ttype(o)]; 72 | } 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /deps/lua/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 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" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /deps/lua/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 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 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /deps/lua/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 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 "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (char* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | #ifdef luac_c 23 | /* print one chunk; from print.c */ 24 | LUAI_FUNC void luaU_print (const Proto* f, int full); 25 | #endif 26 | 27 | /* for header of binary files -- this is Lua 5.1 */ 28 | #define LUAC_VERSION 0x51 29 | 30 | /* for header of binary files -- this is the official format */ 31 | #define LUAC_FORMAT 0 32 | 33 | /* size of header of binary files */ 34 | #define LUAC_HEADERSIZE 12 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /deps/lua/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /deps/lua/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | memcpy(b, z->p, m); 65 | z->n -= m; 66 | z->p += m; 67 | b = (char *)b + m; 68 | n -= m; 69 | } 70 | return 0; 71 | } 72 | 73 | /* ------------------------------------------------------------------------ */ 74 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 75 | if (n > buff->buffsize) { 76 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 77 | luaZ_resizebuffer(L, buff, n); 78 | } 79 | return buff->buffer; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /deps/lua/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 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 char2int(c) cast(int, cast(unsigned char, (c))) 21 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 23 | 24 | typedef struct Mbuffer { 25 | char *buffer; 26 | size_t n; 27 | size_t buffsize; 28 | } Mbuffer; 29 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) 33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 | #define luaZ_bufflen(buff) ((buff)->n) 35 | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 | (buff)->buffsize = size) 42 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 | 45 | 46 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 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 | LUAI_FUNC int luaZ_lookahead (ZIO *z); 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; 60 | void* data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /deps/lua/test/README: -------------------------------------------------------------------------------- 1 | These are simple tests for Lua. Some of them contain useful code. 2 | They are meant to be run to make sure Lua is built correctly and also 3 | to be read, to see how Lua programs look. 4 | 5 | Here is a one-line summary of each program: 6 | 7 | bisect.lua bisection method for solving non-linear equations 8 | cf.lua temperature conversion table (celsius to farenheit) 9 | echo.lua echo command line arguments 10 | env.lua environment variables as automatic global variables 11 | factorial.lua factorial without recursion 12 | fib.lua fibonacci function with cache 13 | fibfor.lua fibonacci numbers with coroutines and generators 14 | globals.lua report global variable usage 15 | hello.lua the first program in every language 16 | life.lua Conway's Game of Life 17 | luac.lua bare-bones luac 18 | printf.lua an implementation of printf 19 | readonly.lua make global variables readonly 20 | sieve.lua the sieve of of Eratosthenes programmed with coroutines 21 | sort.lua two implementations of a sort function 22 | table.lua make table, grouping all data for the same item 23 | trace-calls.lua trace calls 24 | trace-globals.lua trace assigments to global variables 25 | xd.lua hex dump 26 | 27 | -------------------------------------------------------------------------------- /deps/lua/test/bisect.lua: -------------------------------------------------------------------------------- 1 | -- bisection method for solving non-linear equations 2 | 3 | delta=1e-6 -- tolerance 4 | 5 | function bisect(f,a,b,fa,fb) 6 | local c=(a+b)/2 7 | io.write(n," c=",c," a=",a," b=",b,"\n") 8 | if c==a or c==b or math.abs(a-b)y end) 58 | show("after reverse selection sort",x) 59 | qsort(x,1,n,function (x,y) return x>> ",string.rep(" ",level)) 9 | if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end 10 | t=debug.getinfo(2) 11 | if event=="call" then 12 | level=level+1 13 | else 14 | level=level-1 if level<0 then level=0 end 15 | end 16 | if t.what=="main" then 17 | if event=="call" then 18 | io.write("begin ",t.short_src) 19 | else 20 | io.write("end ",t.short_src) 21 | end 22 | elseif t.what=="Lua" then 23 | -- table.foreach(t,print) 24 | io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">") 25 | else 26 | io.write(event," ",t.name or "(C)"," [",t.what,"] ") 27 | end 28 | io.write("\n") 29 | end 30 | 31 | debug.sethook(hook,"cr") 32 | level=0 33 | -------------------------------------------------------------------------------- /deps/lua/test/trace-globals.lua: -------------------------------------------------------------------------------- 1 | -- trace assigments to global variables 2 | 3 | do 4 | -- a tostring that quotes strings. note the use of the original tostring. 5 | local _tostring=tostring 6 | local tostring=function(a) 7 | if type(a)=="string" then 8 | return string.format("%q",a) 9 | else 10 | return _tostring(a) 11 | end 12 | end 13 | 14 | local log=function (name,old,new) 15 | local t=debug.getinfo(3,"Sl") 16 | local line=t.currentline 17 | io.write(t.short_src) 18 | if line>=0 then io.write(":",line) end 19 | io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n") 20 | end 21 | 22 | local g={} 23 | local set=function (t,name,value) 24 | log(name,g[name],value) 25 | g[name]=value 26 | end 27 | setmetatable(getfenv(),{__index=g,__newindex=set}) 28 | end 29 | 30 | -- an example 31 | 32 | a=1 33 | b=2 34 | a=10 35 | b=20 36 | b=nil 37 | b=200 38 | print(a,b,c) 39 | -------------------------------------------------------------------------------- /deps/lua/test/xd.lua: -------------------------------------------------------------------------------- 1 | -- hex dump 2 | -- usage: lua xd.lua < file 3 | 4 | local offset=0 5 | while true do 6 | local s=io.read(16) 7 | if s==nil then return end 8 | io.write(string.format("%08X ",offset)) 9 | string.gsub(s,"(.)", 10 | function (c) io.write(string.format("%02X ",string.byte(c))) end) 11 | io.write(string.rep(" ",3*(16-string.len(s)))) 12 | io.write(" ",string.gsub(s,"%c","."),"\n") 13 | offset=offset+16 14 | end 15 | -------------------------------------------------------------------------------- /runtest: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | TCL_VERSIONS="8.5 8.6" 3 | TCLSH="" 4 | 5 | for VERSION in $TCL_VERSIONS; do 6 | TCL=`which tclsh$VERSION 2>/dev/null` && TCLSH=$TCL 7 | done 8 | 9 | if [ -z $TCLSH ] 10 | then 11 | echo "You need tcl 8.5 or newer in order to run the Redis test" 12 | exit 1 13 | fi 14 | $TCLSH tests/test_helper.tcl $* 15 | -------------------------------------------------------------------------------- /runtest-cluster: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | TCL_VERSIONS="8.5 8.6" 3 | TCLSH="" 4 | 5 | for VERSION in $TCL_VERSIONS; do 6 | TCL=`which tclsh$VERSION 2>/dev/null` && TCLSH=$TCL 7 | done 8 | 9 | if [ -z $TCLSH ] 10 | then 11 | echo "You need tcl 8.5 or newer in order to run the Redis Sentinel test" 12 | exit 1 13 | fi 14 | $TCLSH tests/cluster/run.tcl $* 15 | -------------------------------------------------------------------------------- /runtest-sentinel: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | TCL_VERSIONS="8.5 8.6" 3 | TCLSH="" 4 | 5 | for VERSION in $TCL_VERSIONS; do 6 | TCL=`which tclsh$VERSION 2>/dev/null` && TCLSH=$TCL 7 | done 8 | 9 | if [ -z $TCLSH ] 10 | then 11 | echo "You need tcl 8.5 or newer in order to run the Redis Sentinel test" 12 | exit 1 13 | fi 14 | $TCLSH tests/sentinel/run.tcl $* 15 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.gcda 2 | *.gcno 3 | *.gcov 4 | redis.info 5 | lcov-html 6 | -------------------------------------------------------------------------------- /src/asciilogo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 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 met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | char *ascii_logo = 31 | " _._ \n" 32 | " _.-``__ ''-._ \n" 33 | " _.-`` `. `_. ''-._ Redis %s (%s/%d) %s bit\n" 34 | " .-`` .-```. ```\\/ _.,_ ''-._ \n" 35 | " ( ' , .-` | `, ) Running in %s mode\n" 36 | " |`-._`-...-` __...-.``-._|'` _.-'| Port: %d\n" 37 | " | `-._ `._ / _.-' | PID: %ld\n" 38 | " `-._ `-._ `-./ _.-' _.-' \n" 39 | " |`-._`-._ `-.__.-' _.-'_.-'| \n" 40 | " | `-._`-._ _.-'_.-' | http://redis.io \n" 41 | " `-._ `-._`-.__.-'_.-' _.-' \n" 42 | " |`-._`-._ `-.__.-' _.-'_.-'| \n" 43 | " | `-._`-._ _.-'_.-' | \n" 44 | " `-._ `-._`-.__.-'_.-' _.-' \n" 45 | " `-._ `-.__.-' _.-' \n" 46 | " `-._ _.-' \n" 47 | " `-.__.-' \n\n"; 48 | -------------------------------------------------------------------------------- /src/bio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 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 met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /* Exported API */ 31 | void bioInit(void); 32 | void bioCreateBackgroundJob(int type, void *arg1, void *arg2, void *arg3); 33 | unsigned long long bioPendingJobsOfType(int type); 34 | void bioWaitPendingJobsLE(int type, unsigned long long num); 35 | time_t bioOlderJobOfType(int type); 36 | void bioKillThreads(void); 37 | 38 | /* Background job opcodes */ 39 | #define REDIS_BIO_CLOSE_FILE 0 /* Deferred close(2) syscall. */ 40 | #define REDIS_BIO_AOF_FSYNC 1 /* Deferred AOF fsync. */ 41 | #define REDIS_BIO_NUM_OPS 2 42 | -------------------------------------------------------------------------------- /src/crc64.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC64_H 2 | #define CRC64_H 3 | 4 | #include 5 | 6 | uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/fmacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 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 met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _REDIS_FMACRO_H 31 | #define _REDIS_FMACRO_H 32 | 33 | #define _BSD_SOURCE 34 | 35 | #if defined(__linux__) 36 | #define _GNU_SOURCE 37 | #endif 38 | 39 | #if defined(__linux__) || defined(__OpenBSD__) 40 | #define _XOPEN_SOURCE 700 41 | /* 42 | * On NetBSD, _XOPEN_SOURCE undefines _NETBSD_SOURCE and 43 | * thus hides inet_aton etc. 44 | */ 45 | #elif !defined(__NetBSD__) 46 | #define _XOPEN_SOURCE 47 | #endif 48 | 49 | #define _LARGEFILE_SOURCE 50 | #define _FILE_OFFSET_BITS 64 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/intset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Pieter Noordhuis 3 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef __INTSET_H 32 | #define __INTSET_H 33 | #include 34 | 35 | typedef struct intset { 36 | 37 | // 编码方式 38 | uint32_t encoding; 39 | 40 | // 集合包含的元素数量 41 | uint32_t length; 42 | 43 | // 保存元素的数组 44 | int8_t contents[]; 45 | 46 | } intset; 47 | 48 | intset *intsetNew(void); 49 | intset *intsetAdd(intset *is, int64_t value, uint8_t *success); 50 | intset *intsetRemove(intset *is, int64_t value, int *success); 51 | uint8_t intsetFind(intset *is, int64_t value); 52 | int64_t intsetRandom(intset *is); 53 | uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value); 54 | uint32_t intsetLen(intset *is); 55 | size_t intsetBlobLen(intset *is); 56 | 57 | #endif // __INTSET_H 58 | -------------------------------------------------------------------------------- /src/mkreleasehdr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | GIT_SHA1=`(git show-ref --head --hash=8 2> /dev/null || echo 00000000) | head -n1` 3 | GIT_DIRTY=`git diff --no-ext-diff 2> /dev/null | wc -l` 4 | BUILD_ID=`uname -n`"-"`date +%s` 5 | test -f release.h || touch release.h 6 | (cat release.h | grep SHA1 | grep $GIT_SHA1) && \ 7 | (cat release.h | grep DIRTY | grep $GIT_DIRTY) && exit 0 # Already up-to-date 8 | echo "#define REDIS_GIT_SHA1 \"$GIT_SHA1\"" > release.h 9 | echo "#define REDIS_GIT_DIRTY \"$GIT_DIRTY\"" >> release.h 10 | echo "#define REDIS_BUILD_ID \"$BUILD_ID\"" >> release.h 11 | touch release.c # Force recompile of release.c 12 | -------------------------------------------------------------------------------- /src/pqsort.h: -------------------------------------------------------------------------------- 1 | /* The following is the NetBSD libc qsort implementation modified in order to 2 | * support partial sorting of ranges for Redis. 3 | * 4 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of Redis nor the names of its contributors may be used 16 | * to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * See the pqsort.c file for the original copyright notice. */ 32 | 33 | #ifndef __PQSORT_H 34 | #define __PQSORT_H 35 | 36 | void 37 | pqsort(void *a, size_t n, size_t es, 38 | int (*cmp) (const void *, const void *), size_t lrange, size_t rrange); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/rand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 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 met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef REDIS_RANDOM_H 31 | #define REDIS_RANDOM_H 32 | 33 | int32_t redisLrand48(); 34 | void redisSrand48(int32_t seedval); 35 | 36 | #define REDIS_LRAND48_MAX INT32_MAX 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/redisassert.h: -------------------------------------------------------------------------------- 1 | /* redisassert.h -- Drop in replacemnet assert.h that prints the stack trace 2 | * in the Redis logs. 3 | * 4 | * This file should be included instead of "assert.h" inside libraries used by 5 | * Redis that are using assertions, so instead of Redis disappearing with 6 | * SIGABORT, we get the details and stack trace inside the log file. 7 | * 8 | * ---------------------------------------------------------------------------- 9 | * 10 | * Copyright (c) 2006-2012, Salvatore Sanfilippo 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * * Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * * Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * * Neither the name of Redis nor the names of its contributors may be used 22 | * to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #ifndef __REDIS_ASSERT_H__ 39 | #define __REDIS_ASSERT_H__ 40 | 41 | #include /* for _exit() */ 42 | 43 | #define assert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1))) 44 | 45 | void _redisAssert(char *estr, char *file, int line); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/release.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 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 met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /* Every time the Redis Git SHA1 or Dirty status changes only this small 31 | * file is recompiled, as we access this information in all the other 32 | * files using this functions. */ 33 | 34 | #include 35 | 36 | #include "release.h" 37 | #include "version.h" 38 | #include "crc64.h" 39 | 40 | char *redisGitSHA1(void) { 41 | return REDIS_GIT_SHA1; 42 | } 43 | 44 | char *redisGitDirty(void) { 45 | return REDIS_GIT_DIRTY; 46 | } 47 | 48 | uint64_t redisBuildId(void) { 49 | char *buildid = REDIS_VERSION REDIS_BUILD_ID REDIS_GIT_DIRTY REDIS_GIT_SHA1; 50 | 51 | return crc64(0,(unsigned char*)buildid,strlen(buildid)); 52 | } 53 | -------------------------------------------------------------------------------- /src/sha1.h: -------------------------------------------------------------------------------- 1 | /* ================ sha1.h ================ */ 2 | /* 3 | SHA-1 in C 4 | By Steve Reid 5 | 100% Public Domain 6 | */ 7 | 8 | typedef struct { 9 | u_int32_t state[5]; 10 | u_int32_t count[2]; 11 | unsigned char buffer[64]; 12 | } SHA1_CTX; 13 | 14 | void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]); 15 | void SHA1Init(SHA1_CTX* context); 16 | void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len); 17 | void SHA1Final(unsigned char digest[20], SHA1_CTX* context); 18 | -------------------------------------------------------------------------------- /src/slowlog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 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 met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #define SLOWLOG_ENTRY_MAX_ARGC 32 31 | #define SLOWLOG_ENTRY_MAX_STRING 128 32 | 33 | /* This structure defines an entry inside the slow log list */ 34 | /* 35 | * 慢查询日志 36 | */ 37 | typedef struct slowlogEntry { 38 | 39 | // 命令与命令参数 40 | robj **argv; 41 | 42 | // 命令与命令参数的数量 43 | int argc; 44 | 45 | // 唯一标识符 46 | long long id; /* Unique entry identifier. */ 47 | 48 | // 执行命令消耗的时间,以微秒为单位 49 | // 注释里说的 nanoseconds 是错误的 50 | long long duration; /* Time spent by the query, in nanoseconds. */ 51 | 52 | // 命令执行时的时间,格式为 UNIX 时间戳 53 | time_t time; /* Unix time at which the query was executed. */ 54 | 55 | } slowlogEntry; 56 | 57 | /* Exported API */ 58 | void slowlogInit(void); 59 | void slowlogPushEntryIfNeeded(robj **argv, int argc, long long duration); 60 | 61 | /* Exported commands */ 62 | void slowlogCommand(redisClient *c); 63 | -------------------------------------------------------------------------------- /src/solarisfixes.h: -------------------------------------------------------------------------------- 1 | /* Solaris specific fixes. 2 | * 3 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #if defined(__GNUC__) 32 | #include 33 | #undef isnan 34 | #define isnan(x) \ 35 | __extension__({ __typeof (x) __x_a = (x); \ 36 | __builtin_expect(__x_a != __x_a, 0); }) 37 | 38 | #undef isfinite 39 | #define isfinite(x) \ 40 | __extension__ ({ __typeof (x) __x_f = (x); \ 41 | __builtin_expect(!isnan(__x_f - __x_f), 1); }) 42 | 43 | #undef isinf 44 | #define isinf(x) \ 45 | __extension__ ({ __typeof (x) __x_i = (x); \ 46 | __builtin_expect(!isnan(__x_i) && !isfinite(__x_i), 0); }) 47 | 48 | #define u_int uint 49 | #define u_int32_t uint32_t 50 | #endif /* __GNUC__ */ 51 | -------------------------------------------------------------------------------- /src/testhelp.h: -------------------------------------------------------------------------------- 1 | /* This is a really minimal testing framework for C. 2 | * 3 | * Example: 4 | * 5 | * test_cond("Check if 1 == 1", 1==1) 6 | * test_cond("Check if 5 > 10", 5 > 10) 7 | * test_report() 8 | * 9 | * ---------------------------------------------------------------------------- 10 | * 11 | * Copyright (c) 2010-2012, Salvatore Sanfilippo 12 | * All rights reserved. 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions are met: 16 | * 17 | * * Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * * Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * * Neither the name of Redis nor the names of its contributors may be used 23 | * to endorse or promote products derived from this software without 24 | * specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef __TESTHELP_H 40 | #define __TESTHELP_H 41 | 42 | int __failed_tests = 0; 43 | int __test_num = 0; 44 | #define test_cond(descr,_c) do { \ 45 | __test_num++; printf("%d - %s: ", __test_num, descr); \ 46 | if(_c) printf("PASSED\n"); else {printf("FAILED\n"); __failed_tests++;} \ 47 | } while(0); 48 | #define test_report() do { \ 49 | printf("%d tests, %d passed, %d failed\n", __test_num, \ 50 | __test_num-__failed_tests, __failed_tests); \ 51 | if (__failed_tests) { \ 52 | printf("=== WARNING === We have failed tests here...\n"); \ 53 | exit(1); \ 54 | } \ 55 | } while(0); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 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 met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Redis nor the names of its contributors may be used 14 | * to endorse or promote products derived from this software without 15 | * specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef __REDIS_UTIL_H 31 | #define __REDIS_UTIL_H 32 | 33 | #include "sds.h" 34 | 35 | int stringmatchlen(const char *p, int plen, const char *s, int slen, int nocase); 36 | int stringmatch(const char *p, const char *s, int nocase); 37 | long long memtoll(const char *p, int *err); 38 | int ll2string(char *s, size_t len, long long value); 39 | int string2ll(const char *s, size_t slen, long long *value); 40 | int string2l(const char *s, size_t slen, long *value); 41 | int d2string(char *buf, size_t len, double value); 42 | sds getAbsolutePath(char *filename); 43 | int pathIsBaseName(char *path); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/valgrind.sup: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Cond 4 | fun:lzf_compress 5 | } 6 | 7 | { 8 | 9 | Memcheck:Value4 10 | fun:lzf_compress 11 | } 12 | 13 | { 14 | 15 | Memcheck:Value8 16 | fun:lzf_compress 17 | } 18 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | #define REDIS_VERSION "2.9.11" 2 | -------------------------------------------------------------------------------- /src/ziplist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012, Pieter Noordhuis 3 | * Copyright (c) 2009-2012, Salvatore Sanfilippo 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #define ZIPLIST_HEAD 0 32 | #define ZIPLIST_TAIL 1 33 | 34 | unsigned char *ziplistNew(void); 35 | unsigned char *ziplistPush(unsigned char *zl, unsigned char *s, unsigned int slen, int where); 36 | unsigned char *ziplistIndex(unsigned char *zl, int index); 37 | unsigned char *ziplistNext(unsigned char *zl, unsigned char *p); 38 | unsigned char *ziplistPrev(unsigned char *zl, unsigned char *p); 39 | unsigned int ziplistGet(unsigned char *p, unsigned char **sval, unsigned int *slen, long long *lval); 40 | unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen); 41 | unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p); 42 | unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num); 43 | unsigned int ziplistCompare(unsigned char *p, unsigned char *s, unsigned int slen); 44 | unsigned char *ziplistFind(unsigned char *p, unsigned char *vstr, unsigned int vlen, unsigned int skip); 45 | unsigned int ziplistLen(unsigned char *zl); 46 | size_t ziplistBlobLen(unsigned char *zl); 47 | -------------------------------------------------------------------------------- /src/zipmap.h: -------------------------------------------------------------------------------- 1 | /* String -> String Map data structure optimized for size. 2 | * 3 | * See zipmap.c for more info. 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Copyright (c) 2009-2010, Salvatore Sanfilippo 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * * Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * * Neither the name of Redis nor the names of its contributors may be used 19 | * to endorse or promote products derived from this software without 20 | * specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _ZIPMAP_H 36 | #define _ZIPMAP_H 37 | 38 | unsigned char *zipmapNew(void); 39 | unsigned char *zipmapSet(unsigned char *zm, unsigned char *key, unsigned int klen, unsigned char *val, unsigned int vlen, int *update); 40 | unsigned char *zipmapDel(unsigned char *zm, unsigned char *key, unsigned int klen, int *deleted); 41 | unsigned char *zipmapRewind(unsigned char *zm); 42 | unsigned char *zipmapNext(unsigned char *zm, unsigned char **key, unsigned int *klen, unsigned char **value, unsigned int *vlen); 43 | int zipmapGet(unsigned char *zm, unsigned char *key, unsigned int klen, unsigned char **value, unsigned int *vlen); 44 | int zipmapExists(unsigned char *zm, unsigned char *key, unsigned int klen); 45 | unsigned int zipmapLen(unsigned char *zm); 46 | size_t zipmapBlobLen(unsigned char *zm); 47 | void zipmapRepr(unsigned char *p); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /tests/assets/default.conf: -------------------------------------------------------------------------------- 1 | # Redis configuration for testing. 2 | 3 | notify-keyspace-events KEA 4 | daemonize no 5 | pidfile /var/run/redis.pid 6 | port 6379 7 | timeout 0 8 | bind 127.0.0.1 9 | loglevel verbose 10 | logfile '' 11 | databases 16 12 | 13 | save 900 1 14 | save 300 10 15 | save 60 10000 16 | 17 | rdbcompression yes 18 | dbfilename dump.rdb 19 | dir ./ 20 | 21 | slave-serve-stale-data yes 22 | appendonly no 23 | appendfsync everysec 24 | no-appendfsync-on-rewrite no 25 | activerehashing yes 26 | -------------------------------------------------------------------------------- /tests/assets/encodings.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/redis-3.0-annotated/8e60a75884e75503fb8be1a322406f21fb455f67/tests/assets/encodings.rdb -------------------------------------------------------------------------------- /tests/assets/hash-zipmap.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/redis-3.0-annotated/8e60a75884e75503fb8be1a322406f21fb455f67/tests/assets/hash-zipmap.rdb -------------------------------------------------------------------------------- /tests/cluster/cluster.tcl: -------------------------------------------------------------------------------- 1 | # Cluster-specific test functions. 2 | # 3 | # Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com 4 | # This softare is released under the BSD License. See the COPYING file for 5 | # more information. 6 | 7 | # Returns a parsed CLUSTER NODES output as a list of dictionaries. 8 | proc get_cluster_nodes id { 9 | set lines [split [R $id cluster nodes] "\r\n"] 10 | set nodes {} 11 | foreach l $lines { 12 | set l [string trim $l] 13 | if {$l eq {}} continue 14 | set args [split $l] 15 | set node [dict create \ 16 | id [lindex $args 0] \ 17 | addr [lindex $args 1] \ 18 | flags [split [lindex $args 2] ,] \ 19 | slaveof [lindex $args 3] \ 20 | ping_sent [lindex $args 4] \ 21 | pong_recv [lindex $args 5] \ 22 | config_epoch [lindex $args 6] \ 23 | linkstate [lindex $args 7] \ 24 | slots [lrange $args 8 -1] \ 25 | ] 26 | lappend nodes $node 27 | } 28 | return $nodes 29 | } 30 | 31 | # Test node for flag. 32 | proc has_flag {node flag} { 33 | expr {[lsearch -exact [dict get $node flags] $flag] != -1} 34 | } 35 | 36 | # Returns the parsed myself node entry as a dictionary. 37 | proc get_myself id { 38 | set nodes [get_cluster_nodes $id] 39 | foreach n $nodes { 40 | if {[has_flag $n myself]} {return $n} 41 | } 42 | return {} 43 | } 44 | 45 | # Return the value of the specified CLUSTER INFO field. 46 | proc CI {n field} { 47 | get_info_field [R $n cluster info] $field 48 | } 49 | 50 | # Assuming nodes are reest, this function performs slots allocation. 51 | # Only the first 'n' nodes are used. 52 | proc cluster_allocate_slots {n} { 53 | set slot 16383 54 | while {$slot >= 0} { 55 | # Allocate successive slots to random nodes. 56 | set node [randomInt $n] 57 | lappend slots_$node $slot 58 | incr slot -1 59 | } 60 | for {set j 0} {$j < $n} {incr j} { 61 | R $j cluster addslots {*}[set slots_${j}] 62 | } 63 | } 64 | 65 | # Check that cluster nodes agree about "state", or raise an error. 66 | proc assert_cluster_state {state} { 67 | foreach_redis_id id { 68 | if {[instance_is_killed redis $id]} continue 69 | wait_for_condition 1000 50 { 70 | [CI $id cluster_state] eq $state 71 | } else { 72 | fail "Cluster node $id cluster_state:[CI $id cluster_state]" 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/cluster/run.tcl: -------------------------------------------------------------------------------- 1 | # Cluster test suite. Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com 2 | # This softare is released under the BSD License. See the COPYING file for 3 | # more information. 4 | 5 | cd tests/cluster 6 | source cluster.tcl 7 | source ../instances.tcl 8 | source ../../support/cluster.tcl ; # Redis Cluster client. 9 | 10 | set ::instances_count 20 ; # How many instances we use at max. 11 | 12 | proc main {} { 13 | parse_options 14 | spawn_instance redis $::redis_base_port $::instances_count { 15 | "cluster-enabled yes" 16 | "appendonly yes" 17 | } 18 | run_tests 19 | cleanup 20 | } 21 | 22 | if {[catch main e]} { 23 | puts $::errorInfo 24 | cleanup 25 | } 26 | -------------------------------------------------------------------------------- /tests/cluster/tests/includes/init-tests.tcl: -------------------------------------------------------------------------------- 1 | # Initialization tests -- most units will start including this. 2 | 3 | test "(init) Restart killed instances" { 4 | foreach type {redis} { 5 | foreach_${type}_id id { 6 | if {[get_instance_attrib $type $id pid] == -1} { 7 | puts -nonewline "$type/$id " 8 | flush stdout 9 | restart_instance $type $id 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/helpers/bg_complex_data.tcl: -------------------------------------------------------------------------------- 1 | source tests/support/redis.tcl 2 | source tests/support/util.tcl 3 | 4 | proc bg_complex_data {host port db ops} { 5 | set r [redis $host $port] 6 | $r select $db 7 | createComplexDataset $r $ops 8 | } 9 | 10 | bg_complex_data [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] 11 | -------------------------------------------------------------------------------- /tests/helpers/gen_write_load.tcl: -------------------------------------------------------------------------------- 1 | source tests/support/redis.tcl 2 | 3 | proc gen_write_load {host port seconds} { 4 | set start_time [clock seconds] 5 | set r [redis $host $port 1] 6 | $r select 9 7 | while 1 { 8 | $r set [expr rand()] [expr rand()] 9 | if {[clock seconds]-$start_time > $seconds} { 10 | exit 0 11 | } 12 | } 13 | } 14 | 15 | gen_write_load [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] 16 | -------------------------------------------------------------------------------- /tests/integration/aof-race.tcl: -------------------------------------------------------------------------------- 1 | set defaults { appendonly {yes} appendfilename {appendonly.aof} } 2 | set server_path [tmpdir server.aof] 3 | set aof_path "$server_path/appendonly.aof" 4 | 5 | proc start_server_aof {overrides code} { 6 | upvar defaults defaults srv srv server_path server_path 7 | set config [concat $defaults $overrides] 8 | start_server [list overrides $config] $code 9 | } 10 | 11 | tags {"aof"} { 12 | # Specific test for a regression where internal buffers were not properly 13 | # cleaned after a child responsible for an AOF rewrite exited. This buffer 14 | # was subsequently appended to the new AOF, resulting in duplicate commands. 15 | start_server_aof [list dir $server_path] { 16 | set client [redis [srv host] [srv port]] 17 | set bench [open "|src/redis-benchmark -q -p [srv port] -c 20 -n 20000 incr foo" "r+"] 18 | after 100 19 | 20 | # Benchmark should be running by now: start background rewrite 21 | $client bgrewriteaof 22 | 23 | # Read until benchmark pipe reaches EOF 24 | while {[string length [read $bench]] > 0} {} 25 | 26 | # Check contents of foo 27 | assert_equal 20000 [$client get foo] 28 | } 29 | 30 | # Restart server to replay AOF 31 | start_server_aof [list dir $server_path] { 32 | set client [redis [srv host] [srv port]] 33 | assert_equal 20000 [$client get foo] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/integration/convert-zipmap-hash-on-load.tcl: -------------------------------------------------------------------------------- 1 | # Copy RDB with zipmap encoded hash to server path 2 | set server_path [tmpdir "server.convert-zipmap-hash-on-load"] 3 | 4 | exec cp -f tests/assets/hash-zipmap.rdb $server_path 5 | start_server [list overrides [list "dir" $server_path "dbfilename" "hash-zipmap.rdb"]] { 6 | test "RDB load zipmap hash: converts to ziplist" { 7 | r select 0 8 | 9 | assert_match "*ziplist*" [r debug object hash] 10 | assert_equal 2 [r hlen hash] 11 | assert_match {v1 v2} [r hmget hash f1 f2] 12 | } 13 | } 14 | 15 | exec cp -f tests/assets/hash-zipmap.rdb $server_path 16 | start_server [list overrides [list "dir" $server_path "dbfilename" "hash-zipmap.rdb" "hash-max-ziplist-entries" 1]] { 17 | test "RDB load zipmap hash: converts to hash table when hash-max-ziplist-entries is exceeded" { 18 | r select 0 19 | 20 | assert_match "*hashtable*" [r debug object hash] 21 | assert_equal 2 [r hlen hash] 22 | assert_match {v1 v2} [r hmget hash f1 f2] 23 | } 24 | } 25 | 26 | exec cp -f tests/assets/hash-zipmap.rdb $server_path 27 | start_server [list overrides [list "dir" $server_path "dbfilename" "hash-zipmap.rdb" "hash-max-ziplist-value" 1]] { 28 | test "RDB load zipmap hash: converts to hash table when hash-max-ziplist-value is exceeded" { 29 | r select 0 30 | 31 | assert_match "*hashtable*" [r debug object hash] 32 | assert_equal 2 [r hlen hash] 33 | assert_match {v1 v2} [r hmget hash f1 f2] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/integration/replication-2.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"repl"}} { 2 | start_server {} { 3 | test {First server should have role slave after SLAVEOF} { 4 | r -1 slaveof [srv 0 host] [srv 0 port] 5 | after 1000 6 | s -1 role 7 | } {slave} 8 | 9 | test {MASTER and SLAVE dataset should be identical after complex ops} { 10 | createComplexDataset r 10000 11 | after 500 12 | if {[r debug digest] ne [r -1 debug digest]} { 13 | set csv1 [csvdump r] 14 | set csv2 [csvdump {r -1}] 15 | set fd [open /tmp/repldump1.txt w] 16 | puts -nonewline $fd $csv1 17 | close $fd 18 | set fd [open /tmp/repldump2.txt w] 19 | puts -nonewline $fd $csv2 20 | close $fd 21 | puts "Master - Slave inconsistency" 22 | puts "Run diff -u against /tmp/repldump*.txt for more info" 23 | } 24 | assert_equal [r debug digest] [r -1 debug digest] 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/sentinel/run.tcl: -------------------------------------------------------------------------------- 1 | # Sentinel test suite. Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com 2 | # This softare is released under the BSD License. See the COPYING file for 3 | # more information. 4 | 5 | cd tests/sentinel 6 | source ../instances.tcl 7 | 8 | set ::instances_count 5 ; # How many instances we use at max. 9 | 10 | proc main {} { 11 | parse_options 12 | spawn_instance sentinel $::sentinel_base_port $::instances_count 13 | spawn_instance redis $::redis_base_port $::instances_count 14 | run_tests 15 | cleanup 16 | } 17 | 18 | if {[catch main e]} { 19 | puts $::errorInfo 20 | cleanup 21 | } 22 | -------------------------------------------------------------------------------- /tests/sentinel/tests/01-conf-update.tcl: -------------------------------------------------------------------------------- 1 | # Test Sentinel configuration consistency after partitions heal. 2 | 3 | source "../tests/includes/init-tests.tcl" 4 | 5 | test "We can failover with Sentinel 1 crashed" { 6 | set old_port [RI $master_id tcp_port] 7 | set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 8 | assert {[lindex $addr 1] == $old_port} 9 | 10 | # Crash Sentinel 1 11 | kill_instance sentinel 1 12 | 13 | kill_instance redis $master_id 14 | foreach_sentinel_id id { 15 | if {$id != 1} { 16 | wait_for_condition 1000 50 { 17 | [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port 18 | } else { 19 | fail "Sentinel $id did not received failover info" 20 | } 21 | } 22 | } 23 | restart_instance redis $master_id 24 | set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 25 | set master_id [get_instance_id_by_port redis [lindex $addr 1]] 26 | } 27 | 28 | test "After Sentinel 1 is restarted, its config gets updated" { 29 | restart_instance sentinel 1 30 | wait_for_condition 1000 50 { 31 | [lindex [S 1 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port 32 | } else { 33 | fail "Restarted Sentinel did not received failover info" 34 | } 35 | } 36 | 37 | test "New master [join $addr {:}] role matches" { 38 | assert {[RI $master_id role] eq {master}} 39 | } 40 | -------------------------------------------------------------------------------- /tests/sentinel/tests/02-slaves-reconf.tcl: -------------------------------------------------------------------------------- 1 | # Check that slaves are reconfigured at a latter time if they are partitioned. 2 | # 3 | # Here we should test: 4 | # 1) That slaves point to the new master after failover. 5 | # 2) That partitioned slaves point to new master when they are partitioned 6 | # away during failover and return at a latter time. 7 | 8 | source "../tests/includes/init-tests.tcl" 9 | 10 | proc 03_test_slaves_replication {} { 11 | uplevel 1 { 12 | test "Check that slaves replicate from current master" { 13 | set master_port [RI $master_id tcp_port] 14 | foreach_redis_id id { 15 | if {$id == $master_id} continue 16 | if {[instance_is_killed redis $id]} continue 17 | wait_for_condition 1000 50 { 18 | [RI $id master_port] == $master_port 19 | } else { 20 | fail "Redis slave $id is replicating from wrong master" 21 | } 22 | } 23 | } 24 | } 25 | } 26 | 27 | proc 03_crash_and_failover {} { 28 | uplevel 1 { 29 | test "Crash the master and force a failover" { 30 | set old_port [RI $master_id tcp_port] 31 | set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 32 | assert {[lindex $addr 1] == $old_port} 33 | kill_instance redis $master_id 34 | foreach_sentinel_id id { 35 | wait_for_condition 1000 50 { 36 | [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port 37 | } else { 38 | fail "At least one Sentinel did not received failover info" 39 | } 40 | } 41 | restart_instance redis $master_id 42 | set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 43 | set master_id [get_instance_id_by_port redis [lindex $addr 1]] 44 | } 45 | } 46 | } 47 | 48 | 03_test_slaves_replication 49 | 03_crash_and_failover 50 | 03_test_slaves_replication 51 | 52 | test "Kill a slave instance" { 53 | foreach_redis_id id { 54 | if {$id == $master_id} continue 55 | set killed_slave_id $id 56 | kill_instance redis $id 57 | break 58 | } 59 | } 60 | 61 | 03_crash_and_failover 62 | 03_test_slaves_replication 63 | 64 | test "Wait for failover to end" { 65 | set inprogress 1 66 | while {$inprogress} { 67 | set inprogress 0 68 | foreach_sentinel_id id { 69 | if {[dict exists [S $id SENTINEL MASTER mymaster] failover-state]} { 70 | incr inprogress 71 | } 72 | } 73 | if {$inprogress} {after 100} 74 | } 75 | } 76 | 77 | test "Restart killed slave and test replication of slaves again..." { 78 | restart_instance redis $killed_slave_id 79 | } 80 | 81 | # Now we check if the slave rejoining the partition is reconfigured even 82 | # if the failover finished. 83 | 03_test_slaves_replication 84 | -------------------------------------------------------------------------------- /tests/sentinel/tests/03-runtime-reconf.tcl: -------------------------------------------------------------------------------- 1 | # Test runtime reconfiguration command SENTINEL SET. 2 | -------------------------------------------------------------------------------- /tests/sentinel/tests/04-slave-selection.tcl: -------------------------------------------------------------------------------- 1 | # Test slave selection algorithm. 2 | # 3 | # This unit should test: 4 | # 1) That when there are no suitable slaves no failover is performed. 5 | # 2) That among the available slaves, the one with better offset is picked. 6 | -------------------------------------------------------------------------------- /tests/sentinel/tests/includes/init-tests.tcl: -------------------------------------------------------------------------------- 1 | # Initialization tests -- most units will start including this. 2 | 3 | test "(init) Restart killed instances" { 4 | foreach type {redis sentinel} { 5 | foreach_${type}_id id { 6 | if {[get_instance_attrib $type $id pid] == -1} { 7 | puts -nonewline "$type/$id " 8 | flush stdout 9 | restart_instance $type $id 10 | } 11 | } 12 | } 13 | } 14 | 15 | set redis_slaves 4 16 | test "(init) Create a master-slaves cluster of [expr $redis_slaves+1] instances" { 17 | create_redis_master_slave_cluster [expr {$redis_slaves+1}] 18 | } 19 | set master_id 0 20 | 21 | test "(init) Sentinels can start monitoring a master" { 22 | set sentinels [llength $::sentinel_instances] 23 | set quorum [expr {$sentinels/2+1}] 24 | foreach_sentinel_id id { 25 | catch {S $id SENTINEL REMOVE mymaster} 26 | S $id SENTINEL MONITOR mymaster \ 27 | [get_instance_attrib redis $master_id host] \ 28 | [get_instance_attrib redis $master_id port] $quorum 29 | } 30 | foreach_sentinel_id id { 31 | assert {[S $id sentinel master mymaster] ne {}} 32 | S $id SENTINEL SET mymaster down-after-milliseconds 2000 33 | S $id SENTINEL SET mymaster failover-timeout 20000 34 | S $id SENTINEL SET mymaster parallel-syncs 10 35 | } 36 | } 37 | 38 | test "(init) Sentinels can talk with the master" { 39 | foreach_sentinel_id id { 40 | wait_for_condition 100 50 { 41 | [catch {S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster}] == 0 42 | } else { 43 | fail "Sentinel $id can't talk with the master." 44 | } 45 | } 46 | } 47 | 48 | test "(init) Sentinels are able to auto-discover other sentinels" { 49 | set sentinels [llength $::sentinel_instances] 50 | foreach_sentinel_id id { 51 | wait_for_condition 100 50 { 52 | [dict get [S $id SENTINEL MASTER mymaster] num-other-sentinels] == ($sentinels-1) 53 | } else { 54 | fail "At least some sentinel can't detect some other sentinel" 55 | } 56 | } 57 | } 58 | 59 | test "(init) Sentinels are able to auto-discover slaves" { 60 | foreach_sentinel_id id { 61 | wait_for_condition 100 50 { 62 | [dict get [S $id SENTINEL MASTER mymaster] num-slaves] == $redis_slaves 63 | } else { 64 | fail "At least some sentinel can't detect some slave" 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/sentinel/tmp/.gitignore: -------------------------------------------------------------------------------- 1 | redis_* 2 | sentinel_* 3 | -------------------------------------------------------------------------------- /tests/support/tmpfile.tcl: -------------------------------------------------------------------------------- 1 | set ::tmpcounter 0 2 | set ::tmproot "./tests/tmp" 3 | file mkdir $::tmproot 4 | 5 | # returns a dirname unique to this process to write to 6 | proc tmpdir {basename} { 7 | set dir [file join $::tmproot $basename.[pid].[incr ::tmpcounter]] 8 | file mkdir $dir 9 | set _ $dir 10 | } 11 | 12 | # return a filename unique to this process to write to 13 | proc tmpfile {basename} { 14 | file join $::tmproot $basename.[pid].[incr ::tmpcounter] 15 | } 16 | -------------------------------------------------------------------------------- /tests/tmp/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | -------------------------------------------------------------------------------- /tests/unit/auth.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"auth"}} { 2 | test {AUTH fails if there is no password configured server side} { 3 | catch {r auth foo} err 4 | set _ $err 5 | } {ERR*no password*} 6 | } 7 | 8 | start_server {tags {"auth"} overrides {requirepass foobar}} { 9 | test {AUTH fails when a wrong password is given} { 10 | catch {r auth wrong!} err 11 | set _ $err 12 | } {ERR*invalid password} 13 | 14 | test {Arbitrary command gives an error when AUTH is required} { 15 | catch {r set foo bar} err 16 | set _ $err 17 | } {NOAUTH*} 18 | 19 | test {AUTH succeeds when the right password is given} { 20 | r auth foobar 21 | } {OK} 22 | 23 | test {Once AUTH succeeded we can actually send commands to the server} { 24 | r set foo 100 25 | r incr foo 26 | } {101} 27 | } 28 | -------------------------------------------------------------------------------- /tests/unit/introspection.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"introspection"}} { 2 | test {CLIENT LIST} { 3 | r client list 4 | } {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=* obl=0 oll=0 omem=0 events=r cmd=client*} 5 | 6 | test {MONITOR can log executed commands} { 7 | set rd [redis_deferring_client] 8 | $rd monitor 9 | r set foo bar 10 | r get foo 11 | list [$rd read] [$rd read] [$rd read] 12 | } {*OK*"set" "foo"*"get" "foo"*} 13 | 14 | test {MONITOR can log commands issued by the scripting engine} { 15 | set rd [redis_deferring_client] 16 | $rd monitor 17 | r eval {redis.call('set',KEYS[1],ARGV[1])} 1 foo bar 18 | $rd read ;# Discard the OK 19 | assert_match {*eval*} [$rd read] 20 | assert_match {*lua*"set"*"foo"*"bar"*} [$rd read] 21 | } 22 | 23 | test {CLIENT GETNAME should return NIL if name is not assigned} { 24 | r client getname 25 | } {} 26 | 27 | test {CLIENT LIST shows empty fields for unassigned names} { 28 | r client list 29 | } {*name= *} 30 | 31 | test {CLIENT SETNAME does not accept spaces} { 32 | catch {r client setname "foo bar"} e 33 | set e 34 | } {ERR*} 35 | 36 | test {CLIENT SETNAME can assign a name to this connection} { 37 | assert_equal [r client setname myname] {OK} 38 | r client list 39 | } {*name=myname*} 40 | 41 | test {CLIENT SETNAME can change the name of an existing connection} { 42 | assert_equal [r client setname someothername] {OK} 43 | r client list 44 | } {*name=someothername*} 45 | 46 | test {After CLIENT SETNAME, connection can still be closed} { 47 | set rd [redis_deferring_client] 48 | $rd client setname foobar 49 | assert_equal [$rd read] "OK" 50 | assert_match {*foobar*} [r client list] 51 | $rd close 52 | # Now the client should no longer be listed 53 | wait_for_condition 50 100 { 54 | [string match {*foobar*} [r client list]] == 0 55 | } else { 56 | fail "Client still listed in CLIENT LIST after SETNAME." 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/unit/limits.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"limits"} overrides {maxclients 10}} { 2 | test {Check if maxclients works refusing connections} { 3 | set c 0 4 | catch { 5 | while {$c < 50} { 6 | incr c 7 | set rd [redis_deferring_client] 8 | $rd ping 9 | $rd read 10 | after 100 11 | } 12 | } e 13 | assert {$c > 8 && $c <= 10} 14 | set e 15 | } {*ERR max*reached*} 16 | } 17 | -------------------------------------------------------------------------------- /tests/unit/memefficiency.tcl: -------------------------------------------------------------------------------- 1 | proc test_memory_efficiency {range} { 2 | r flushall 3 | set base_mem [s used_memory] 4 | set written 0 5 | for {set j 0} {$j < 10000} {incr j} { 6 | set key key:$j 7 | set val [string repeat A [expr {int(rand()*$range)}]] 8 | r set $key $val 9 | incr written [string length $key] 10 | incr written [string length $val] 11 | incr written 2 ;# A separator is the minimum to store key-value data. 12 | } 13 | set current_mem [s used_memory] 14 | set used [expr {$current_mem-$base_mem}] 15 | set efficiency [expr {double($written)/$used}] 16 | return $efficiency 17 | } 18 | 19 | start_server {tags {"memefficiency"}} { 20 | foreach {size_range expected_min_efficiency} { 21 | 32 0.15 22 | 64 0.25 23 | 128 0.35 24 | 1024 0.75 25 | 16384 0.82 26 | } { 27 | test "Memory efficiency with values in range $size_range" { 28 | set efficiency [test_memory_efficiency $size_range] 29 | assert {$efficiency >= $expected_min_efficiency} 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/unit/obuf-limits.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"obuf-limits"}} { 2 | test {Client output buffer hard limit is enforced} { 3 | r config set client-output-buffer-limit {pubsub 100000 0 0} 4 | set rd1 [redis_deferring_client] 5 | 6 | $rd1 subscribe foo 7 | set reply [$rd1 read] 8 | assert {$reply eq "subscribe foo 1"} 9 | 10 | set omem 0 11 | while 1 { 12 | r publish foo bar 13 | set clients [split [r client list] "\r\n"] 14 | set c [split [lindex $clients 1] " "] 15 | if {![regexp {omem=([0-9]+)} $c - omem]} break 16 | if {$omem > 200000} break 17 | } 18 | assert {$omem >= 90000 && $omem < 200000} 19 | $rd1 close 20 | } 21 | 22 | test {Client output buffer soft limit is not enforced if time is not overreached} { 23 | r config set client-output-buffer-limit {pubsub 0 100000 10} 24 | set rd1 [redis_deferring_client] 25 | 26 | $rd1 subscribe foo 27 | set reply [$rd1 read] 28 | assert {$reply eq "subscribe foo 1"} 29 | 30 | set omem 0 31 | set start_time 0 32 | set time_elapsed 0 33 | while 1 { 34 | r publish foo bar 35 | set clients [split [r client list] "\r\n"] 36 | set c [split [lindex $clients 1] " "] 37 | if {![regexp {omem=([0-9]+)} $c - omem]} break 38 | if {$omem > 100000} { 39 | if {$start_time == 0} {set start_time [clock seconds]} 40 | set time_elapsed [expr {[clock seconds]-$start_time}] 41 | if {$time_elapsed >= 5} break 42 | } 43 | } 44 | assert {$omem >= 100000 && $time_elapsed >= 5 && $time_elapsed <= 10} 45 | $rd1 close 46 | } 47 | 48 | test {Client output buffer soft limit is enforced if time is overreached} { 49 | r config set client-output-buffer-limit {pubsub 0 100000 3} 50 | set rd1 [redis_deferring_client] 51 | 52 | $rd1 subscribe foo 53 | set reply [$rd1 read] 54 | assert {$reply eq "subscribe foo 1"} 55 | 56 | set omem 0 57 | set start_time 0 58 | set time_elapsed 0 59 | while 1 { 60 | r publish foo bar 61 | set clients [split [r client list] "\r\n"] 62 | set c [split [lindex $clients 1] " "] 63 | if {![regexp {omem=([0-9]+)} $c - omem]} break 64 | if {$omem > 100000} { 65 | if {$start_time == 0} {set start_time [clock seconds]} 66 | set time_elapsed [expr {[clock seconds]-$start_time}] 67 | if {$time_elapsed >= 10} break 68 | } 69 | } 70 | assert {$omem >= 100000 && $time_elapsed < 6} 71 | $rd1 close 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/unit/printver.tcl: -------------------------------------------------------------------------------- 1 | start_server {} { 2 | set i [r info] 3 | regexp {redis_version:(.*?)\r\n} $i - version 4 | regexp {redis_git_sha1:(.*?)\r\n} $i - sha1 5 | puts "Testing Redis version $version ($sha1)" 6 | } 7 | -------------------------------------------------------------------------------- /tests/unit/quit.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"quit"}} { 2 | proc format_command {args} { 3 | set cmd "*[llength $args]\r\n" 4 | foreach a $args { 5 | append cmd "$[string length $a]\r\n$a\r\n" 6 | } 7 | set _ $cmd 8 | } 9 | 10 | test "QUIT returns OK" { 11 | reconnect 12 | assert_equal OK [r quit] 13 | assert_error * {r ping} 14 | } 15 | 16 | test "Pipelined commands after QUIT must not be executed" { 17 | reconnect 18 | r write [format_command quit] 19 | r write [format_command set foo bar] 20 | r flush 21 | assert_equal OK [r read] 22 | assert_error * {r read} 23 | 24 | reconnect 25 | assert_equal {} [r get foo] 26 | } 27 | 28 | test "Pipelined commands after QUIT that exceed read buffer size" { 29 | reconnect 30 | r write [format_command quit] 31 | r write [format_command set foo [string repeat "x" 1024]] 32 | r flush 33 | assert_equal OK [r read] 34 | assert_error * {r read} 35 | 36 | reconnect 37 | assert_equal {} [r get foo] 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/unit/slowlog.tcl: -------------------------------------------------------------------------------- 1 | start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} { 2 | test {SLOWLOG - check that it starts with an empty log} { 3 | r slowlog len 4 | } {0} 5 | 6 | test {SLOWLOG - only logs commands taking more time than specified} { 7 | r config set slowlog-log-slower-than 100000 8 | r ping 9 | assert_equal [r slowlog len] 0 10 | r debug sleep 0.2 11 | assert_equal [r slowlog len] 1 12 | } 13 | 14 | test {SLOWLOG - max entries is correctly handled} { 15 | r config set slowlog-log-slower-than 0 16 | r config set slowlog-max-len 10 17 | for {set i 0} {$i < 100} {incr i} { 18 | r ping 19 | } 20 | r slowlog len 21 | } {10} 22 | 23 | test {SLOWLOG - GET optional argument to limit output len works} { 24 | llength [r slowlog get 5] 25 | } {5} 26 | 27 | test {SLOWLOG - RESET subcommand works} { 28 | r config set slowlog-log-slower-than 100000 29 | r slowlog reset 30 | r slowlog len 31 | } {0} 32 | 33 | test {SLOWLOG - logged entry sanity check} { 34 | r debug sleep 0.2 35 | set e [lindex [r slowlog get] 0] 36 | assert_equal [llength $e] 4 37 | assert_equal [lindex $e 0] 105 38 | assert_equal [expr {[lindex $e 2] > 100000}] 1 39 | assert_equal [lindex $e 3] {debug sleep 0.2} 40 | } 41 | 42 | test {SLOWLOG - commands with too many arguments are trimmed} { 43 | r config set slowlog-log-slower-than 0 44 | r slowlog reset 45 | r sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 46 | set e [lindex [r slowlog get] 0] 47 | lindex $e 3 48 | } {sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 {... (2 more arguments)}} 49 | 50 | test {SLOWLOG - too long arguments are trimmed} { 51 | r config set slowlog-log-slower-than 0 52 | r slowlog reset 53 | set arg [string repeat A 129] 54 | r sadd set foo $arg 55 | set e [lindex [r slowlog get] 0] 56 | lindex $e 3 57 | } {sadd set foo {AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... (1 more bytes)}} 58 | 59 | test {SLOWLOG - EXEC is not logged, just executed commands} { 60 | r config set slowlog-log-slower-than 100000 61 | r slowlog reset 62 | assert_equal [r slowlog len] 0 63 | r multi 64 | r debug sleep 0.2 65 | r exec 66 | assert_equal [r slowlog len] 1 67 | set e [lindex [r slowlog get] 0] 68 | assert_equal [lindex $e 3] {debug sleep 0.2} 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/unit/type/list-2.tcl: -------------------------------------------------------------------------------- 1 | start_server { 2 | tags {"list"} 3 | overrides { 4 | "list-max-ziplist-value" 16 5 | "list-max-ziplist-entries" 256 6 | } 7 | } { 8 | source "tests/unit/type/list-common.tcl" 9 | 10 | foreach {type large} [array get largevalue] { 11 | tags {"slow"} { 12 | test "LTRIM stress testing - $type" { 13 | set mylist {} 14 | set startlen 32 15 | r del mylist 16 | 17 | # Start with the large value to ensure the 18 | # right encoding is used. 19 | r rpush mylist $large 20 | lappend mylist $large 21 | 22 | for {set i 0} {$i < $startlen} {incr i} { 23 | set str [randomInt 9223372036854775807] 24 | r rpush mylist $str 25 | lappend mylist $str 26 | } 27 | 28 | for {set i 0} {$i < 1000} {incr i} { 29 | set min [expr {int(rand()*$startlen)}] 30 | set max [expr {$min+int(rand()*$startlen)}] 31 | set mylist [lrange $mylist $min $max] 32 | r ltrim mylist $min $max 33 | assert_equal $mylist [r lrange mylist 0 -1] 34 | 35 | for {set j [r llen mylist]} {$j < $startlen} {incr j} { 36 | set str [randomInt 9223372036854775807] 37 | r rpush mylist $str 38 | lappend mylist $str 39 | } 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/unit/type/list-common.tcl: -------------------------------------------------------------------------------- 1 | # We need a value larger than list-max-ziplist-value to make sure 2 | # the list has the right encoding when it is swapped in again. 3 | array set largevalue {} 4 | set largevalue(ziplist) "hello" 5 | set largevalue(linkedlist) [string repeat "hello" 4] 6 | -------------------------------------------------------------------------------- /utils/build-static-symbols.tcl: -------------------------------------------------------------------------------- 1 | # Build a symbol table for static symbols of redis.c 2 | # Useful to get stack traces on segfault without a debugger. See redis.c 3 | # for more information. 4 | # 5 | # Copyright(C) 2009 Salvatore Sanfilippo, under the BSD license. 6 | 7 | set fd [open redis.c] 8 | set symlist {} 9 | while {[gets $fd line] != -1} { 10 | if {[regexp {^static +[A-z0-9]+[ *]+([A-z0-9]*)\(} $line - sym]} { 11 | lappend symlist $sym 12 | } 13 | } 14 | set symlist [lsort -unique $symlist] 15 | puts "static struct redisFunctionSym symsTable\[\] = {" 16 | foreach sym $symlist { 17 | puts "{\"$sym\",(unsigned long)$sym}," 18 | } 19 | puts "{NULL,0}" 20 | puts "};" 21 | 22 | close $fd 23 | -------------------------------------------------------------------------------- /utils/generate-command-help.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | GROUPS = [ 4 | "generic", 5 | "string", 6 | "list", 7 | "set", 8 | "sorted_set", 9 | "hash", 10 | "pubsub", 11 | "transactions", 12 | "connection", 13 | "server", 14 | "scripting", 15 | "hyperloglog" 16 | ].freeze 17 | 18 | GROUPS_BY_NAME = Hash[* 19 | GROUPS.each_with_index.map do |n,i| 20 | [n,i] 21 | end.flatten 22 | ].freeze 23 | 24 | def argument arg 25 | name = arg["name"].is_a?(Array) ? arg["name"].join(" ") : arg["name"] 26 | name = arg["enum"].join "|" if "enum" == arg["type"] 27 | name = arg["command"] + " " + name if arg["command"] 28 | if arg["multiple"] 29 | name = "#{name} [#{name} ...]" 30 | end 31 | if arg["optional"] 32 | name = "[#{name}]" 33 | end 34 | name 35 | end 36 | 37 | def arguments command 38 | return "-" unless command["arguments"] 39 | command["arguments"].map do |arg| 40 | argument arg 41 | end.join " " 42 | end 43 | 44 | def commands 45 | return @commands if @commands 46 | 47 | require "rubygems" 48 | require "net/http" 49 | require "net/https" 50 | require "json" 51 | require "uri" 52 | 53 | url = URI.parse "https://raw.github.com/antirez/redis-doc/master/commands.json" 54 | client = Net::HTTP.new url.host, url.port 55 | client.use_ssl = true 56 | response = client.get url.path 57 | if response.is_a?(Net::HTTPSuccess) 58 | @commands = JSON.parse(response.body) 59 | else 60 | response.error! 61 | end 62 | end 63 | 64 | def generate_groups 65 | GROUPS.map do |n| 66 | "\"#{n}\"" 67 | end.join(",\n "); 68 | end 69 | 70 | def generate_commands 71 | commands.to_a.sort do |x,y| 72 | x[0] <=> y[0] 73 | end.map do |key, command| 74 | group = GROUPS_BY_NAME[command["group"]] 75 | if group.nil? 76 | STDERR.puts "Please update groups array in #{__FILE__}" 77 | raise "Unknown group #{command["group"]}" 78 | end 79 | 80 | ret = <<-SPEC 81 | { "#{key}", 82 | "#{arguments(command)}", 83 | "#{command["summary"]}", 84 | #{group}, 85 | "#{command["since"]}" } 86 | SPEC 87 | ret.strip 88 | end.join(",\n ") 89 | end 90 | 91 | # Write to stdout 92 | puts <<-HELP_H 93 | /* Automatically generated by #{__FILE__}, do not edit. */ 94 | 95 | #ifndef __REDIS_HELP_H 96 | #define __REDIS_HELP_H 97 | 98 | static char *commandGroups[] = { 99 | #{generate_groups} 100 | }; 101 | 102 | struct commandHelp { 103 | char *name; 104 | char *params; 105 | char *summary; 106 | int group; 107 | char *since; 108 | } commandHelp[] = { 109 | #{generate_commands} 110 | }; 111 | 112 | #endif 113 | HELP_H 114 | 115 | -------------------------------------------------------------------------------- /utils/hyperloglog/.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | -------------------------------------------------------------------------------- /utils/hyperloglog/hll-err.rb: -------------------------------------------------------------------------------- 1 | # hll-err.rb - Copyright (C) 2014 Salvatore Sanfilippo 2 | # BSD license, See the COPYING file for more information. 3 | # 4 | # Check error of HyperLogLog Redis implementation for different set sizes. 5 | 6 | require 'rubygems' 7 | require 'redis' 8 | require 'digest/sha1' 9 | 10 | r = Redis.new 11 | r.del('hll') 12 | i = 0 13 | while true do 14 | 100.times { 15 | elements = [] 16 | 1000.times { 17 | ele = Digest::SHA1.hexdigest(i.to_s) 18 | elements << ele 19 | i += 1 20 | } 21 | r.pfadd('hll',*elements) 22 | } 23 | approx = r.pfcount('hll') 24 | abs_err = (approx-i).abs 25 | rel_err = 100.to_f*abs_err/i 26 | puts "#{i} vs #{approx}: #{rel_err}%" 27 | end 28 | -------------------------------------------------------------------------------- /utils/lru/README: -------------------------------------------------------------------------------- 1 | The test-lru.rb program can be used in order to check the behavior of the 2 | Redis approximated LRU algorithm against the theoretical output of true 3 | LRU algorithm. 4 | 5 | In order to use the program you need to recompile Redis setting the define 6 | REDIS_LRU_CLOCK_RESOLUTION to 1, by editing redis.h. 7 | This allows to execute the program in a fast way since the 1 ms resolution 8 | is enough for all the objects to have a different enough time stamp during 9 | the test. 10 | 11 | The program is executed like this: 12 | 13 | ruby test-lru.rb > /tmp/lru.html 14 | -------------------------------------------------------------------------------- /utils/lru/test-lru.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'redis' 3 | 4 | r = Redis.new 5 | r.config("SET","maxmemory","2000000") 6 | r.config("SET","maxmemory-policy","allkeys-lru") 7 | r.config("SET","maxmemory-samples",5) 8 | r.config("RESETSTAT") 9 | r.flushall 10 | 11 | puts < 13 | 14 | 34 |
 35 | EOF
 36 | 
 37 | # Fill
 38 | oldsize = r.dbsize
 39 | id = 0
 40 | while true
 41 |     id += 1
 42 |     r.set(id,"foo")
 43 |     newsize = r.dbsize
 44 |     break if newsize == oldsize
 45 |     oldsize = newsize
 46 | end
 47 | 
 48 | inserted = r.dbsize
 49 | first_set_max_id = id
 50 | puts "#{r.dbsize} keys inserted"
 51 | 
 52 | # Access keys sequencially
 53 | 
 54 | puts "Access keys sequencially"
 55 | (1..first_set_max_id).each{|id|
 56 |     r.get(id)
 57 | #    sleep 0.001
 58 | }
 59 | 
 60 | # Insert more 50% keys. We expect that the new keys
 61 | half = inserted/2
 62 | puts "Insert enough keys to evict half the keys we inserted"
 63 | add = 0
 64 | while true
 65 |     add += 1
 66 |     id += 1
 67 |     r.set(id,"foo")
 68 |     break if r.info['evicted_keys'].to_i >= half
 69 | end
 70 | 
 71 | puts "#{add} additional keys added."
 72 | puts "#{r.dbsize} keys in DB"
 73 | 
 74 | # Check if evicted keys respect LRU
 75 | # We consider errors from 1 to N progressively more serious as they violate
 76 | # more the access pattern.
 77 | 
 78 | errors = 0
 79 | e = 1
 80 | edecr = 1.0/(first_set_max_id/2)
 81 | (1..(first_set_max_id/2)).each{|id|
 82 |     e -= edecr if e > 0
 83 |     e = 0 if e < 0
 84 |     if r.exists(id)
 85 |         errors += e
 86 |     end
 87 | }
 88 | 
 89 | puts "#{errors} errors!"
 90 | puts "
" 91 | 92 | # Generate the graphical representation 93 | (1..id).each{|id| 94 | # Mark first set and added items in a different way. 95 | c = "box" 96 | if id <= first_set_max_id 97 | c << " old" 98 | else 99 | c << " new" 100 | end 101 | 102 | # Add class if exists 103 | c << " ex" if r.exists(id) 104 | puts "
" 105 | } 106 | 107 | # Close HTML page 108 | 109 | puts < 111 | 112 | EOF 113 | -------------------------------------------------------------------------------- /utils/mkrelease.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ $# != "1" ] 3 | then 4 | echo "Usage: ./mkrelease.sh " 5 | exit 1 6 | fi 7 | 8 | TAG=$1 9 | TARNAME="redis-${TAG}.tar" 10 | echo "Generating /tmp/${TARNAME}" 11 | git archive $TAG --prefix redis-${TAG}/ > /tmp/$TARNAME || exit 1 12 | echo "Gizipping the archive" 13 | rm -f /tmp/$TARNAME.gz 14 | gzip -9 /tmp/$TARNAME 15 | -------------------------------------------------------------------------------- /utils/redis-copy.rb: -------------------------------------------------------------------------------- 1 | # redis-copy.rb - Copyright (C) 2009-2010 Salvatore Sanfilippo 2 | # BSD license, See the COPYING file for more information. 3 | # 4 | # Copy the whole dataset from one Redis instance to another one 5 | # 6 | # WARNING: this utility is deprecated and serves as a legacy adapter 7 | # for the more-robust redis-copy gem. 8 | 9 | require 'shellwords' 10 | 11 | def redisCopy(opts={}) 12 | src = "#{opts[:srchost]}:#{opts[:srcport]}" 13 | dst = "#{opts[:dsthost]}:#{opts[:dstport]}" 14 | `redis-copy #{src.shellescape} #{dst.shellescape}` 15 | rescue Errno::ENOENT 16 | $stderr.puts 'This utility requires the redis-copy executable', 17 | 'from the redis-copy gem on https://rubygems.org', 18 | 'To install it, run `gem install redis-copy`.' 19 | exit 1 20 | end 21 | 22 | $stderr.puts "This utility is deprecated. Use the redis-copy gem instead." 23 | if ARGV.length != 4 24 | puts "Usage: redis-copy.rb " 25 | exit 1 26 | end 27 | puts "WARNING: it's up to you to FLUSHDB the destination host before to continue, press any key when ready." 28 | STDIN.gets 29 | srchost = ARGV[0] 30 | srcport = ARGV[1] 31 | dsthost = ARGV[2] 32 | dstport = ARGV[3] 33 | puts "Copying #{srchost}:#{srcport} into #{dsthost}:#{dstport}" 34 | redisCopy(:srchost => srchost, :srcport => srcport.to_i, 35 | :dsthost => dsthost, :dstport => dstport.to_i) 36 | -------------------------------------------------------------------------------- /utils/redis-sha1.rb: -------------------------------------------------------------------------------- 1 | # redis-sha1.rb - Copyright (C) 2009 Salvatore Sanfilippo 2 | # BSD license, See the COPYING file for more information. 3 | # 4 | # Performs the SHA1 sum of the whole datset. 5 | # This is useful to spot bugs in persistence related code and to make sure 6 | # Slaves and Masters are in SYNC. 7 | # 8 | # If you hack this code make sure to sort keys and set elements as this are 9 | # unsorted elements. Otherwise the sum may differ with equal dataset. 10 | 11 | require 'rubygems' 12 | require 'redis' 13 | require 'digest/sha1' 14 | 15 | def redisSha1(opts={}) 16 | sha1="" 17 | r = Redis.new(opts) 18 | r.keys('*').sort.each{|k| 19 | vtype = r.type?(k) 20 | if vtype == "string" 21 | len = 1 22 | sha1 = Digest::SHA1.hexdigest(sha1+k) 23 | sha1 = Digest::SHA1.hexdigest(sha1+r.get(k)) 24 | elsif vtype == "list" 25 | len = r.llen(k) 26 | if len != 0 27 | sha1 = Digest::SHA1.hexdigest(sha1+k) 28 | sha1 = Digest::SHA1.hexdigest(sha1+r.list_range(k,0,-1).join("\x01")) 29 | end 30 | elsif vtype == "set" 31 | len = r.scard(k) 32 | if len != 0 33 | sha1 = Digest::SHA1.hexdigest(sha1+k) 34 | sha1 = Digest::SHA1.hexdigest(sha1+r.set_members(k).to_a.sort.join("\x02")) 35 | end 36 | elsif vtype == "zset" 37 | len = r.zcard(k) 38 | if len != 0 39 | sha1 = Digest::SHA1.hexdigest(sha1+k) 40 | sha1 = Digest::SHA1.hexdigest(sha1+r.zrange(k,0,-1).join("\x01")) 41 | end 42 | end 43 | # puts "#{k} => #{sha1}" if len != 0 44 | } 45 | sha1 46 | end 47 | 48 | host = ARGV[0] || "127.0.0.1" 49 | port = ARGV[1] || "6379" 50 | db = ARGV[2] || "0" 51 | puts "Performing SHA1 of Redis server #{host} #{port} DB: #{db}" 52 | p "Dataset SHA1: #{redisSha1(:host => host, :port => port.to_i, :db => db)}" 53 | -------------------------------------------------------------------------------- /utils/redis_init_script: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Simple Redis init.d script conceived to work on Linux systems 4 | # as it does use of the /proc filesystem. 5 | 6 | REDISPORT=6379 7 | EXEC=/usr/local/bin/redis-server 8 | CLIEXEC=/usr/local/bin/redis-cli 9 | 10 | PIDFILE=/var/run/redis_${REDISPORT}.pid 11 | CONF="/etc/redis/${REDISPORT}.conf" 12 | 13 | case "$1" in 14 | start) 15 | if [ -f $PIDFILE ] 16 | then 17 | echo "$PIDFILE exists, process is already running or crashed" 18 | else 19 | echo "Starting Redis server..." 20 | $EXEC $CONF 21 | fi 22 | ;; 23 | stop) 24 | if [ ! -f $PIDFILE ] 25 | then 26 | echo "$PIDFILE does not exist, process is not running" 27 | else 28 | PID=$(cat $PIDFILE) 29 | echo "Stopping ..." 30 | $CLIEXEC -p $REDISPORT shutdown 31 | while [ -x /proc/${PID} ] 32 | do 33 | echo "Waiting for Redis to shutdown ..." 34 | sleep 1 35 | done 36 | echo "Redis stopped" 37 | fi 38 | ;; 39 | *) 40 | echo "Please use start or stop as first argument" 41 | ;; 42 | esac 43 | -------------------------------------------------------------------------------- /utils/redis_init_script.tpl: -------------------------------------------------------------------------------- 1 | 2 | case "$1" in 3 | start) 4 | if [ -f $PIDFILE ] 5 | then 6 | echo "$PIDFILE exists, process is already running or crashed" 7 | else 8 | echo "Starting Redis server..." 9 | $EXEC $CONF 10 | fi 11 | ;; 12 | stop) 13 | if [ ! -f $PIDFILE ] 14 | then 15 | echo "$PIDFILE does not exist, process is not running" 16 | else 17 | PID=$(cat $PIDFILE) 18 | echo "Stopping ..." 19 | $CLIEXEC -p $REDISPORT shutdown 20 | while [ -x /proc/${PID} ] 21 | do 22 | echo "Waiting for Redis to shutdown ..." 23 | sleep 1 24 | done 25 | echo "Redis stopped" 26 | fi 27 | ;; 28 | status) 29 | if [ ! -f $PIDFILE ] 30 | then 31 | echo 'Redis is not running' 32 | else 33 | echo "Redis is running ($(<$PIDFILE))" 34 | fi 35 | ;; 36 | restart) 37 | $0 stop 38 | $0 start 39 | ;; 40 | *) 41 | echo "Please use start, stop, restart or status as first argument" 42 | ;; 43 | esac 44 | -------------------------------------------------------------------------------- /utils/whatisdoing.sh: -------------------------------------------------------------------------------- 1 | # This script is from http://poormansprofiler.org/ 2 | 3 | #!/bin/bash 4 | nsamples=1 5 | sleeptime=0 6 | pid=$(pidof redis-server) 7 | 8 | for x in $(seq 1 $nsamples) 9 | do 10 | gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid 11 | sleep $sleeptime 12 | done | \ 13 | awk ' 14 | BEGIN { s = ""; } 15 | /Thread/ { print s; s = ""; } 16 | /^\#/ { if (s != "" ) { s = s "," $4} else { s = $4 } } 17 | END { print s }' | \ 18 | sort | uniq -c | sort -r -n -k 1,1 19 | --------------------------------------------------------------------------------