nutcracker 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/README.md +22 -0
  2. data/Rakefile +55 -0
  3. data/bin/nutcracker +2 -0
  4. data/ext/nutcracker/ChangeLog +66 -0
  5. data/ext/nutcracker/LICENSE +177 -0
  6. data/ext/nutcracker/Makefile.am +7 -0
  7. data/ext/nutcracker/Makefile.in +726 -0
  8. data/ext/nutcracker/NOTICE +124 -0
  9. data/ext/nutcracker/README.md +240 -0
  10. data/ext/nutcracker/aclocal.m4 +956 -0
  11. data/ext/nutcracker/conf/nutcracker.leaf.yml +10 -0
  12. data/ext/nutcracker/conf/nutcracker.root.yml +8 -0
  13. data/ext/nutcracker/conf/nutcracker.yml +67 -0
  14. data/ext/nutcracker/config.h.in +316 -0
  15. data/ext/nutcracker/config/config.guess +1561 -0
  16. data/ext/nutcracker/config/config.sub +1686 -0
  17. data/ext/nutcracker/config/depcomp +630 -0
  18. data/ext/nutcracker/config/install-sh +520 -0
  19. data/ext/nutcracker/config/ltmain.sh +8413 -0
  20. data/ext/nutcracker/config/missing +376 -0
  21. data/ext/nutcracker/configure +18862 -0
  22. data/ext/nutcracker/configure.ac +155 -0
  23. data/ext/nutcracker/contrib/Makefile.am +3 -0
  24. data/ext/nutcracker/contrib/Makefile.in +560 -0
  25. data/ext/nutcracker/contrib/yaml-0.1.4.tar.gz +0 -0
  26. data/ext/nutcracker/contrib/yaml-0.1.4/LICENSE +19 -0
  27. data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.am +20 -0
  28. data/ext/nutcracker/contrib/yaml-0.1.4/Makefile.in +736 -0
  29. data/ext/nutcracker/contrib/yaml-0.1.4/README +27 -0
  30. data/ext/nutcracker/contrib/yaml-0.1.4/aclocal.m4 +956 -0
  31. data/ext/nutcracker/contrib/yaml-0.1.4/config.h.in +80 -0
  32. data/ext/nutcracker/contrib/yaml-0.1.4/config/config.guess +1561 -0
  33. data/ext/nutcracker/contrib/yaml-0.1.4/config/config.sub +1686 -0
  34. data/ext/nutcracker/contrib/yaml-0.1.4/config/depcomp +630 -0
  35. data/ext/nutcracker/contrib/yaml-0.1.4/config/install-sh +520 -0
  36. data/ext/nutcracker/contrib/yaml-0.1.4/config/ltmain.sh +8406 -0
  37. data/ext/nutcracker/contrib/yaml-0.1.4/config/missing +376 -0
  38. data/ext/nutcracker/contrib/yaml-0.1.4/configure +13085 -0
  39. data/ext/nutcracker/contrib/yaml-0.1.4/configure.ac +75 -0
  40. data/ext/nutcracker/contrib/yaml-0.1.4/doc/doxygen.cfg +222 -0
  41. data/ext/nutcracker/contrib/yaml-0.1.4/include/yaml.h +1971 -0
  42. data/ext/nutcracker/contrib/yaml-0.1.4/m4/libtool.m4 +7357 -0
  43. data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltoptions.m4 +368 -0
  44. data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltsugar.m4 +123 -0
  45. data/ext/nutcracker/contrib/yaml-0.1.4/m4/ltversion.m4 +23 -0
  46. data/ext/nutcracker/contrib/yaml-0.1.4/m4/lt~obsolete.m4 +92 -0
  47. data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.am +4 -0
  48. data/ext/nutcracker/contrib/yaml-0.1.4/src/Makefile.in +484 -0
  49. data/ext/nutcracker/contrib/yaml-0.1.4/src/api.c +1392 -0
  50. data/ext/nutcracker/contrib/yaml-0.1.4/src/dumper.c +394 -0
  51. data/ext/nutcracker/contrib/yaml-0.1.4/src/emitter.c +2329 -0
  52. data/ext/nutcracker/contrib/yaml-0.1.4/src/loader.c +432 -0
  53. data/ext/nutcracker/contrib/yaml-0.1.4/src/parser.c +1374 -0
  54. data/ext/nutcracker/contrib/yaml-0.1.4/src/reader.c +465 -0
  55. data/ext/nutcracker/contrib/yaml-0.1.4/src/scanner.c +3570 -0
  56. data/ext/nutcracker/contrib/yaml-0.1.4/src/writer.c +141 -0
  57. data/ext/nutcracker/contrib/yaml-0.1.4/src/yaml_private.h +640 -0
  58. data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.am +8 -0
  59. data/ext/nutcracker/contrib/yaml-0.1.4/tests/Makefile.in +675 -0
  60. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor-alt.c +800 -0
  61. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-deconstructor.c +1130 -0
  62. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter-alt.c +217 -0
  63. data/ext/nutcracker/contrib/yaml-0.1.4/tests/example-reformatter.c +202 -0
  64. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-dumper.c +311 -0
  65. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-emitter.c +327 -0
  66. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-loader.c +63 -0
  67. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-parser.c +63 -0
  68. data/ext/nutcracker/contrib/yaml-0.1.4/tests/run-scanner.c +63 -0
  69. data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-reader.c +354 -0
  70. data/ext/nutcracker/contrib/yaml-0.1.4/tests/test-version.c +29 -0
  71. data/ext/nutcracker/extconf.rb +5 -0
  72. data/ext/nutcracker/m4/libtool.m4 +7376 -0
  73. data/ext/nutcracker/m4/ltoptions.m4 +368 -0
  74. data/ext/nutcracker/m4/ltsugar.m4 +123 -0
  75. data/ext/nutcracker/m4/ltversion.m4 +23 -0
  76. data/ext/nutcracker/m4/lt~obsolete.m4 +92 -0
  77. data/ext/nutcracker/notes/c-styleguide.txt +425 -0
  78. data/ext/nutcracker/notes/debug.txt +96 -0
  79. data/ext/nutcracker/notes/memcache.txt +123 -0
  80. data/ext/nutcracker/notes/recommendation.md +118 -0
  81. data/ext/nutcracker/notes/redis.md +415 -0
  82. data/ext/nutcracker/notes/socket.txt +131 -0
  83. data/ext/nutcracker/scripts/multi_get.sh +26 -0
  84. data/ext/nutcracker/scripts/nutcracker.init +73 -0
  85. data/ext/nutcracker/scripts/nutcracker.spec +52 -0
  86. data/ext/nutcracker/scripts/pipelined_read.sh +23 -0
  87. data/ext/nutcracker/scripts/pipelined_write.sh +29 -0
  88. data/ext/nutcracker/scripts/populate_memcached.sh +24 -0
  89. data/ext/nutcracker/scripts/redis-check.py +23 -0
  90. data/ext/nutcracker/scripts/redis-check.sh +564 -0
  91. data/ext/nutcracker/src/Makefile.am +46 -0
  92. data/ext/nutcracker/src/Makefile.in +726 -0
  93. data/ext/nutcracker/src/hashkit/Makefile.am +22 -0
  94. data/ext/nutcracker/src/hashkit/Makefile.in +501 -0
  95. data/ext/nutcracker/src/hashkit/nc_crc32.c +105 -0
  96. data/ext/nutcracker/src/hashkit/nc_fnv.c +82 -0
  97. data/ext/nutcracker/src/hashkit/nc_hashkit.h +74 -0
  98. data/ext/nutcracker/src/hashkit/nc_hsieh.c +93 -0
  99. data/ext/nutcracker/src/hashkit/nc_jenkins.c +230 -0
  100. data/ext/nutcracker/src/hashkit/nc_ketama.c +240 -0
  101. data/ext/nutcracker/src/hashkit/nc_md5.c +379 -0
  102. data/ext/nutcracker/src/hashkit/nc_modula.c +144 -0
  103. data/ext/nutcracker/src/hashkit/nc_murmur.c +99 -0
  104. data/ext/nutcracker/src/hashkit/nc_one_at_a_time.c +51 -0
  105. data/ext/nutcracker/src/hashkit/nc_random.c +146 -0
  106. data/ext/nutcracker/src/nc.c +573 -0
  107. data/ext/nutcracker/src/nc_array.c +204 -0
  108. data/ext/nutcracker/src/nc_array.h +73 -0
  109. data/ext/nutcracker/src/nc_client.c +189 -0
  110. data/ext/nutcracker/src/nc_client.h +28 -0
  111. data/ext/nutcracker/src/nc_conf.c +1766 -0
  112. data/ext/nutcracker/src/nc_conf.h +134 -0
  113. data/ext/nutcracker/src/nc_connection.c +392 -0
  114. data/ext/nutcracker/src/nc_connection.h +99 -0
  115. data/ext/nutcracker/src/nc_core.c +334 -0
  116. data/ext/nutcracker/src/nc_core.h +131 -0
  117. data/ext/nutcracker/src/nc_event.c +214 -0
  118. data/ext/nutcracker/src/nc_event.h +39 -0
  119. data/ext/nutcracker/src/nc_log.c +254 -0
  120. data/ext/nutcracker/src/nc_log.h +120 -0
  121. data/ext/nutcracker/src/nc_mbuf.c +285 -0
  122. data/ext/nutcracker/src/nc_mbuf.h +67 -0
  123. data/ext/nutcracker/src/nc_message.c +828 -0
  124. data/ext/nutcracker/src/nc_message.h +253 -0
  125. data/ext/nutcracker/src/nc_proxy.c +359 -0
  126. data/ext/nutcracker/src/nc_proxy.h +34 -0
  127. data/ext/nutcracker/src/nc_queue.h +788 -0
  128. data/ext/nutcracker/src/nc_rbtree.c +348 -0
  129. data/ext/nutcracker/src/nc_rbtree.h +47 -0
  130. data/ext/nutcracker/src/nc_request.c +588 -0
  131. data/ext/nutcracker/src/nc_response.c +332 -0
  132. data/ext/nutcracker/src/nc_server.c +841 -0
  133. data/ext/nutcracker/src/nc_server.h +143 -0
  134. data/ext/nutcracker/src/nc_signal.c +131 -0
  135. data/ext/nutcracker/src/nc_signal.h +34 -0
  136. data/ext/nutcracker/src/nc_stats.c +1188 -0
  137. data/ext/nutcracker/src/nc_stats.h +206 -0
  138. data/ext/nutcracker/src/nc_string.c +109 -0
  139. data/ext/nutcracker/src/nc_string.h +112 -0
  140. data/ext/nutcracker/src/nc_util.c +619 -0
  141. data/ext/nutcracker/src/nc_util.h +214 -0
  142. data/ext/nutcracker/src/proto/Makefile.am +14 -0
  143. data/ext/nutcracker/src/proto/Makefile.in +482 -0
  144. data/ext/nutcracker/src/proto/nc_memcache.c +1306 -0
  145. data/ext/nutcracker/src/proto/nc_proto.h +155 -0
  146. data/ext/nutcracker/src/proto/nc_redis.c +2102 -0
  147. data/lib/nutcracker.rb +7 -0
  148. data/lib/nutcracker/version.rb +3 -0
  149. metadata +194 -0
@@ -0,0 +1,23 @@
1
+ # ltversion.m4 -- version numbers -*- Autoconf -*-
2
+ #
3
+ # Copyright (C) 2004 Free Software Foundation, Inc.
4
+ # Written by Scott James Remnant, 2004
5
+ #
6
+ # This file is free software; the Free Software Foundation gives
7
+ # unlimited permission to copy and/or distribute it, with or without
8
+ # modifications, as long as this notice is preserved.
9
+
10
+ # Generated from ltversion.in.
11
+
12
+ # serial 3012 ltversion.m4
13
+ # This file is part of GNU Libtool
14
+
15
+ m4_define([LT_PACKAGE_VERSION], [2.2.6])
16
+ m4_define([LT_PACKAGE_REVISION], [1.3012])
17
+
18
+ AC_DEFUN([LTVERSION_VERSION],
19
+ [macro_version='2.2.6'
20
+ macro_revision='1.3012'
21
+ _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
22
+ _LT_DECL(, macro_revision, 0)
23
+ ])
@@ -0,0 +1,92 @@
1
+ # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*-
2
+ #
3
+ # Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
4
+ # Written by Scott James Remnant, 2004.
5
+ #
6
+ # This file is free software; the Free Software Foundation gives
7
+ # unlimited permission to copy and/or distribute it, with or without
8
+ # modifications, as long as this notice is preserved.
9
+
10
+ # serial 4 lt~obsolete.m4
11
+
12
+ # These exist entirely to fool aclocal when bootstrapping libtool.
13
+ #
14
+ # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
15
+ # which have later been changed to m4_define as they aren't part of the
16
+ # exported API, or moved to Autoconf or Automake where they belong.
17
+ #
18
+ # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN
19
+ # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
20
+ # using a macro with the same name in our local m4/libtool.m4 it'll
21
+ # pull the old libtool.m4 in (it doesn't see our shiny new m4_define
22
+ # and doesn't know about Autoconf macros at all.)
23
+ #
24
+ # So we provide this file, which has a silly filename so it's always
25
+ # included after everything else. This provides aclocal with the
26
+ # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
27
+ # because those macros already exist, or will be overwritten later.
28
+ # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6.
29
+ #
30
+ # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
31
+ # Yes, that means every name once taken will need to remain here until
32
+ # we give up compatibility with versions before 1.7, at which point
33
+ # we need to keep only those names which we still refer to.
34
+
35
+ # This is to help aclocal find these macros, as it can't see m4_define.
36
+ AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
37
+
38
+ m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
39
+ m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])])
40
+ m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
41
+ m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])])
42
+ m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
43
+ m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])])
44
+ m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])])
45
+ m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
46
+ m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])])
47
+ m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])])
48
+ m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])])
49
+ m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
50
+ m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
51
+ m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
52
+ m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
53
+ m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])])
54
+ m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])])
55
+ m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
56
+ m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
57
+ m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])])
58
+ m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])])
59
+ m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
60
+ m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
61
+ m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
62
+ m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
63
+ m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
64
+ m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
65
+ m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
66
+ m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])])
67
+ m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])])
68
+ m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])])
69
+ m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
70
+ m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])])
71
+ m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])])
72
+ m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])])
73
+ m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])])
74
+ m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
75
+ m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])])
76
+ m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
77
+ m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])])
78
+ m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])])
79
+ m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])])
80
+ m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])])
81
+ m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
82
+ m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
83
+ m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
84
+ m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
85
+ m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
86
+ m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
87
+ m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
88
+ m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
89
+ m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
90
+ m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
91
+ m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])])
92
+ m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
@@ -0,0 +1,425 @@
1
+ - No literal tabs. Expand tabs to 4 spaces.
2
+ - Indentation is 4 spaces.
3
+ - No more than 3 levels of indentation, otherwise you should think about
4
+ refactoring your code.
5
+ - Use one statement per line.
6
+ - Make sure that your editor does not leave space at the end of the line.
7
+ - snake_case for variable, function and file names.
8
+ - Use your own judgment when naming variables and functions. Be as Spartan
9
+ as possible. Eg: Using name like this_variable_is_a_temporary_counter
10
+ will usually be frowned upon.
11
+ - Don’t use local variables or parameters that shadow global identifiers.
12
+ GCC’s ‘-Wshadow’ option can help you to detect this problem.
13
+
14
+ - Avoid using int, char, short, long. Instead use int8_t uint8_t, int16_t,
15
+ uint16_t, int32_t, uint32_t, int64_t, uint64_t, which are available in
16
+ <stdint.h>. However, when interfacing with system calls and libraries
17
+ you cannot get away from using int and char.
18
+ - Use bool for boolean variables. You have to include <stdbool.h>
19
+ - Avoid using a bool as type for struct member names. Instead use unsigned
20
+ 1-bit bit field. Eg:
21
+ struct foo {
22
+ unsigned is_bar:1;
23
+ };
24
+ - Always use size_t type when dealing with sizes of objects or memory ranges.
25
+ - Your code should be 64-bit and 32-bit friendly. Bear in mind problems
26
+ of printing, comparisons, and structure alignment. You have to include
27
+ <intyptes.h> to get generic format specifier macros for printing.
28
+
29
+ - 80 column line limit.
30
+ - If you have to wrap a long statement (> 80 column), put the operator at the
31
+ end of the line and indent the next line at the same column as the arguments
32
+ in the previous column. Eg:
33
+ while (cnt < 20 && this_variable_name_is_too_long &&
34
+ ep != NULL) {
35
+ z = a + really + long + statement + that + needs + three + lines +
36
+ gets + indented + on + the + same + column + as + the +
37
+ previous + column
38
+ }
39
+
40
+ and:
41
+
42
+ int a = function(param_a, param_b, param_c, param_d, param_e, param_f,
43
+ param_g, param_h, param_i, param_j, param_k, param_l);
44
+
45
+ - Always use braces for all conditional blocks (if, switch, for, while, do).
46
+ This holds good even for single statement conditional blocks. Eg:
47
+ if (cond) {
48
+ stmt;
49
+ }
50
+ - Placement of braces for non-function statement blocks - put opening brace
51
+ last on the line and closing brace first. Eg:
52
+ if (x is true) {
53
+ we do y
54
+ }
55
+ - Placement of brace for functions - put the opening brace at the beginning
56
+ of the next line and closing brace first. This is useful because several
57
+ tools look for opening brace in column one to find beginning of C
58
+ functions. Eg:
59
+ int
60
+ function(int x)
61
+ {
62
+ body of the function
63
+ }
64
+
65
+ - Closing brace is empty on a line of its own, except in cases where it is
66
+ followed by a continuation of the same statement, i.e. a "while" in a
67
+ do-statement or an "else" in an if-statement, like this:
68
+ do {
69
+ body of do-loop
70
+ } while (condition);
71
+
72
+ and,
73
+
74
+ if (x == y) {
75
+ ..
76
+ } else if (x > y) {
77
+ ...
78
+ } else {
79
+ ....
80
+ }
81
+
82
+ - Column align switch keyword and the corresponding case/default keyword. Eg:
83
+ switch (alphabet) {
84
+ case 'a':
85
+ case 'b':
86
+ printf("I am a or b\n");
87
+ break;
88
+
89
+ default:
90
+ break;
91
+ }
92
+
93
+ - Forever loops are done with for, and not while. Eg:
94
+ for (;;) {
95
+ stmt;
96
+ }
97
+
98
+ - Don't use a space after a function name.
99
+ - Do not needlessly surround the return expression with parentheses.
100
+ - Use space after keywords. Exceptions are sizeof, typeof, alignof and
101
+ __attribute__, which look like functions.
102
+ - Do not add spaces around (inside) parenthesized expressions.
103
+ s = sizeof( sizeof(*p)) ); /* bad example */
104
+ s = sizeof(sizeof(*p)); /* good example */
105
+ - Casts should not be followed by space. Eg:
106
+ int q = *(int *)&p
107
+ - There is no need to type cast when assigning a void pointer to a non-void
108
+ pointer, or vice versa.
109
+ - Avoid using goto statements. However there are some exceptions to this rule
110
+ when a single goto label within a function and one or more goto statements
111
+ come in handy when a function exits from multiple locations and some common
112
+ work such as cleanup has to be done. Eg:
113
+ int
114
+ fun(void)
115
+ {
116
+ int result = 0;
117
+ char *buffer;
118
+
119
+ buffer = malloc(1024);
120
+ if (buffer == NULL) {
121
+ return -1;
122
+ }
123
+
124
+ if (condition1) {
125
+ while (loop1) {
126
+ ...
127
+ }
128
+ result = 1;
129
+ goto out;
130
+ }
131
+
132
+ ...
133
+ out:
134
+ free(buffer);
135
+ return result;
136
+ }
137
+ - When declaring pointer data, use '*' adjacent to the data name and not
138
+ adjacent to the type name. Eg:
139
+ int
140
+ function(int *p)
141
+ {
142
+ char *p;
143
+ <body of the function>
144
+ }
145
+ - Use one space around (on each side of) most binary and ternary operators,
146
+ such as any of these:
147
+ = + - < > * / % | & ^ <= >= == != ? :
148
+ but no space after unary operators:
149
+ & * + - ~ ! sizeof typeof alignof __attribute__ defined
150
+ no space before the postfix increment & decrement unary operators:
151
+ ++ --
152
+ and no space around the '.' and "->" structure member operators.
153
+
154
+ - 0 and NULL; use 0 for integers, 0.0 for doubles, NULL for pointers, and
155
+ '\0' for chars.
156
+ - Test pointers against NULL. E.g, use:
157
+ if (p == NULL)
158
+
159
+ not:
160
+
161
+ !(p)
162
+
163
+ - Do not use ! for tests unless it is a boolean. E.g. use:
164
+ if (*p == '\0')
165
+
166
+ not:
167
+
168
+ if (!*p)
169
+
170
+ - Don't use assignments inside if or while-conditions. E.g, use:
171
+
172
+ struct foo *foo;
173
+ foo = malloc(sizeof(*foo));
174
+ if (foo == NULL) {
175
+ return -1
176
+ }
177
+
178
+ not:
179
+
180
+ struct foo *foo;
181
+ if ((foo = malloc(sizeof(*foo))) == NULL) {
182
+ return -1;
183
+ }
184
+
185
+ - Don't ever use typedef for structure types. Typedefs are problematic
186
+ because they do not properly hide their underlying type; for example you
187
+ need to know if the typedef is the structure itself or a pointer to the
188
+ structure. In addition they must be declared exactly once, whereas an
189
+ incomplete structure type can be mentioned as many times as necessary.
190
+ Typedefs are difficult to use in stand-alone header files: the header
191
+ that defines the typedef must be included before the header that uses it,
192
+ or by the header that uses it (which causes namespace pollution), or
193
+ there must be a back-door mechanism for obtaining the typedef.
194
+ - The only exception for using a typedef is when you are defining a type
195
+ for a function pointer or a type for an enum. Eg:
196
+
197
+ typedef void (*foo_handler_t)(int, void *);
198
+
199
+ or:
200
+
201
+ typedef enum types {
202
+ TYPE_1,
203
+ TYPE_2
204
+ } types_t;
205
+
206
+ - Use just one variable declaration per line when variables are part of a
207
+ struct. This leaves you room for a small comment on each item, explaining
208
+ its use. Declarations should also be aligned. Eg, use:
209
+
210
+ struct foo {
211
+ int *foo_a; /* comment for foo_a */
212
+ int foo_b; /* comment for foo_b */
213
+ unsigned foo_c:1; /* comment for foo_c */
214
+ };
215
+
216
+ and not:
217
+
218
+ struct foo {
219
+ int *foo_a, foo_b;
220
+ unsigned foo_c:1;
221
+ };
222
+
223
+ - For variable declaration outside a struct, either collect all the
224
+ declarations of the same type on a single line, or use one variable
225
+ per line if the variables purpose needs to be commented. Eg:
226
+ char *a, *b, c;
227
+
228
+ or:
229
+
230
+ char *a, *b;
231
+ char c; /* comments for c */
232
+
233
+ - Avoid magic numbers because no-one has a clue (including the author) of
234
+ what it means after a month.
235
+
236
+ - Function definitions should start the name of the function in column
237
+ one. This is useful because it makes searching for function definitions
238
+ fairly trivial. Eg:
239
+ static char *
240
+ concat(char *s1, char *s2)
241
+ {
242
+ body of the function
243
+ }
244
+
245
+ - Function and variables local to a file should be static.
246
+ - Separate two successive functions with one blank line.
247
+ - Include parameter names with their datypes in function declaration. Eg:
248
+ void function(int param);
249
+
250
+ - Functions should be short and sweet, and do just one thing. They should
251
+ fit on one or two screenfuls of text (80 x 24 screen size), and do one
252
+ thing and do that well.
253
+ The maximum length of a function is inversely proportional to the
254
+ complexity and indentation level of that function. So, if you have a
255
+ conceptually simple function that is just one long (but simple)
256
+ case-statement, where you have to do lots of small things for a lot of
257
+ different cases, it's OK to have a longer function.
258
+ Another measure of the function is the number of local variables. They
259
+ shouldn't exceed 5-10, or you're doing something wrong. Re-think the
260
+ function, and split it into smaller pieces. A human brain can
261
+ generally easily keep track of about 7 different things, anything more
262
+ and it gets confused. You know you're brilliant, but maybe you'd like
263
+ to understand what you did 2 weeks from now.
264
+ - Use const for function parameters passed by reference, if the passed
265
+ pointer has no side effect.
266
+
267
+ - C style comments only. Don't use // for single line comments. Instead
268
+ use /* ... */ style.
269
+ - For multi-line comments use the following style
270
+ /*
271
+ * This is the preferred style for multi-line
272
+ * comments in the Linux kernel source code.
273
+ * Please use it consistently.
274
+ *
275
+ * Description: A column of asterisks on the left side,
276
+ * with beginning and ending almost-blank lines.
277
+ */
278
+
279
+ - To comment out block of code spanning several lines use preprocessor
280
+ directive "#ifdef 0 ... #endif"
281
+
282
+ - Please write a brief comment at the start of each source file, with the
283
+ file name and a line or two about the overall purpose of the file.
284
+
285
+ - All major functions should have comments describing what they do at the
286
+ head of the function. Avoid putting comments in the function body unless
287
+ absolutely needed. If possible, add a comment on what sorts of arguments
288
+ the function gets, and what the possible values of arguments mean and
289
+ what they are used for and the significance of return value if there is
290
+ one. It is not necessary to duplicate in words the meaning of the C
291
+ argument declarations, if a C type is being used in its customary fashion.
292
+ If there is anything nonstandard about its use (such as an argument of
293
+ type char * which is really the address of the second character of a
294
+ string, not the first), or any possible values that would not work the
295
+ way one would expect (such as, that strings containing newlines are not
296
+ guaranteed to work), be sure to say so. Eg:
297
+
298
+ /*
299
+ * Try to acquire a physical address lock while a pmap is locked. If we
300
+ * fail to trylock we unlock and lock the pmap directly and cache the
301
+ * locked pa in *locked. The caller should then restart their loop in case
302
+ * the virtual to physical mapping has changed.
303
+ *
304
+ * Returns 0 on success and -1 on failure.
305
+ */
306
+ int
307
+ vm_page_pa_tryrelock(pmap_t pmap, vm_paddr_t pa, vm_paddr_t *locked)
308
+ {
309
+ ...
310
+
311
+ - The comment on a function is much clearer if you use the argument names
312
+ to speak about the argument values. The variable name itself should be
313
+ lower case, but write it in upper case when you are speaking about the
314
+ value rather than the variable itself. Thus, “the inode number NODE_NUM”
315
+ rather than “an inode”.
316
+
317
+ - Every struct definition should have an accompanying comment that
318
+ describes what it is for and how it should be used.
319
+
320
+ - Finally, while comments are absolutely important to keep the code readable,
321
+ remember that the best code is self-documenting. Giving sensible names to
322
+ types and variables is much better than using obscure names that you must
323
+ then explain through comments.
324
+
325
+ - Recommend using UPPERCASE for macro names. However, sometimes using
326
+ lowercase for macro names makes sense when macros masquerade as well-known
327
+ function calls. Eg, it makes sense to write the wrapper for the
328
+ standard free() function in lowercase to keep the readability
329
+ consistent:
330
+
331
+ #define my_free(_p) do { \
332
+ free(_p); \
333
+ (_p) = NULL; \
334
+ } while (0)
335
+
336
+ - Use enums when defining more than one related constants. All enumeration
337
+ values are in UPPERCASE.
338
+ - Avoid macros as much as possible and use inline functions, enums and const
339
+ variables wherever you can.
340
+ - For macros encapsulating compound statements, right justify the backslashes
341
+ and enclose it in do { ... } while (0)
342
+ - For parameterized macros, all the parameters used in the macro body must
343
+ be surrounded by parentheses. Eg:
344
+ #define ADD_1(_x) ((_x) + 1)
345
+
346
+ - Use sizeof(varname) instead of sizeof(type) whenever possible. Eg:
347
+ char *p;
348
+ p = malloc(sizeof(*p)); /* good example */
349
+ p = malloc(sizeof(char)); /* bad example */
350
+
351
+ - All variables should be declared at the beginning of a scope block {..}.
352
+ It is even preferred to declare all variables at the beginning of the
353
+ function so that all the local variable declarations is in one place and
354
+ we can see the comprehensive list in one glance.
355
+ - Global structs should be declared at the top of the file in which they
356
+ are used, or in separate header files if they are used in multiple
357
+ source files.
358
+ - Declarations of external functions and functions to appear later in the
359
+ source file should all go in one place near the beginning of the file,
360
+ somewhere before the first function definition in the file or else
361
+ should go in a header file.
362
+ - Use of extern should be considered as evil, if it is used in header files
363
+ to reference global variables.
364
+ - Don’t put extern declarations inside functions.
365
+
366
+ - Usually every *.c file should have an associated *.h file. There are some
367
+ exceptions to this rule, such as unit tests and small *.c files containing
368
+ just the main() function.
369
+ - Every header file in the source code must have preprocessor conditional
370
+ to prevent the header file from being scanned multiple times and avoiding
371
+ mutual dependency cycles. Alternatively you can use #pragma once directive,
372
+ as it avoids name clashes and increases the compile speed. Eg, for a
373
+ header file named foo.h, the entire contents of the header file must be
374
+ between the guard macros as follows:
375
+
376
+ #ifndef _FOO_H_
377
+ #define _FOO_H_
378
+ ...
379
+ #endif /* _FOO_H_ */
380
+
381
+ Or,
382
+
383
+ #pragma once
384
+ #ifndef _FOO_H_
385
+ #define _FOO_H_
386
+ ...
387
+ #endif /* _FOO_H_ */
388
+
389
+ - Don't use #include when a forward declaration would suffice.
390
+ - Functions defined in header files should be static inline.
391
+
392
+ - Don’t make the program ugly just to placate GCC when extra warnings options
393
+ such as ‘-Wconversion’ or ‘-Wundef’ are used. These options can help in
394
+ finding bugs, but they can also generate so many false alarms that that
395
+ it hurts readability to silence them with unnecessary casts, wrappers, and
396
+ other complications.
397
+
398
+ - Conditional compilation: when supporting configuration options already
399
+ known when building your program we prefer using if (... ) over conditional
400
+ compilation, as in the former case the compiler is able to perform more
401
+ extensive checking of all possible code paths. Eg, use:
402
+
403
+ if (HAS_FOO)
404
+ ...
405
+ else
406
+ ...
407
+
408
+ instead of:
409
+
410
+ #ifdef HAS_FOO
411
+ ...
412
+ #else
413
+ ...
414
+ #endif
415
+
416
+ A modern compiler such as GCC will generate exactly the same code in both
417
+ cases and of course, the former method assumes that HAS_FOO is defined as
418
+ either 0 or 1.
419
+
420
+ - Finally, rules are rules. Sometimes they are sensible and sometimes not
421
+ and regardless of your preference, we would like you to follow them.
422
+ A project is easier to follow if all project contributors follow the style
423
+ rules so that they can all read and understand everyone's code easily. But
424
+ remember, like all good rules, they are exceptions where it makes sense not
425
+ to be too rigid on the grounds of common sense and consistency!