Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Squashed 'deps/ccommon/' changes from bb298bc..a2d5c01
Browse files Browse the repository at this point in the history
a2d5c01 add a function that will reject all pending incoming connections (twitter#154)
dd56abd break up ASSERT in buf_sock_read (twitter#153)
727905b adding a new API to duration timer (twitter#152)
9406717 add missing "extern C" qualifiers to a few headers for C++ linking; (twitter#150)
a0aafdf Add missing semicolon to ring array example code in documentation. (twitter#149)
9264bbb Zero byte (twitter#147) (emergency fix needed for pelikan)
d4002d7 simplify cc_print_int64 (twitter#146)
b164fcf Clean-up hash functions and introduce MurmurHash3 (twitter#145)
b1babb2 change wheel's sleep timer to make it less flaky (twitter#143)
ce0b9ea allow printing negative integers in cc_print (twitter#141)
ab0edc8 add metrics to track buf_sock objects (twitter#138)
ae02038 add travis ci (copied from pelikan) (twitter#139)
964645a Merge pull request twitter#135 from paegun/fix_cmake_install
70710c2 fixed and re-added cmake install instructions, w/ following notes: include directory made proper relative; opened pattern match b/c include directory should only contain files meant for inclusion.
5b095bc Merge pull request twitter#126 from kevyang/kevyang/120
426d56a return NULL when cc_alloc/cc_realloc is called with size == 0
ad271d4 Merge pull request twitter#133 from kevyang/132
47dbdba suppress unused parameter warning in debug_log_flush
648d19e Merge pull request twitter#127 from kevyang/56
780941a Merge pull request twitter#130 from kevyang/129
b8af6c0 Merge pull request twitter#131 from kevyang/128
6ecc318 fix duplicate symbols in cc_signal
080c41d cc_array - stop doing arithmetic on void *
d526f7a add debug oriented memory management
a4fb927 Update bool member rules in style guide
05c6e1e explicitly make ccommon a C project to avoid checking for CXX related variables

git-subtree-dir: deps/ccommon
git-subtree-split: a2d5c01
  • Loading branch information
Yao Yue committed Jul 4, 2018
1 parent fdc7370 commit 73baaa1
Show file tree
Hide file tree
Showing 36 changed files with 980 additions and 581 deletions.
101 changes: 101 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
sudo: required
language: c

# using anchor to import sources into linux builds
addons:
apt: &apt
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
- llvm-toolchain-precise-3.7
- llvm-toolchain-precise

# travis currently does not support directly setting gcc/clang with versions
# (e.g. gcc-4.8) as value for the compiler key. So we will have to manually
# request these packages and use environment varibles to create the matrix.
#
# In the case of osx, use brew to install the paritcular versions, instead of
# specifying with packages.
matrix:
include:
# gcc 4.8 on linux
- env: C_COMPILER=gcc-4.8
addons:
apt:
<<: *apt
packages: gcc-4.8

# gcc 4.9 on linux
- env: C_COMPILER=gcc-4.9
addons:
apt:
<<: *apt
packages: gcc-4.9

# gcc 5 on linux
- env: C_COMPILER=gcc-5
addons:
apt:
<<: *apt
packages: gcc-5

# clang 3.6 on linux
- env: C_COMPILER=clang-3.6
addons:
apt:
<<: *apt
packages: clang-3.6

# clang 3.7 on linux
- env: C_COMPILER=clang-3.7
addons:
apt:
<<: *apt
packages: clang-3.7

## gcc 4.8 on osx
#- os: osx
# env: FORMULA=gcc48 COMPILER=gcc C_COMPILER=gcc-4.8
#
## gcc 4.9 on osx
#- os: osx
# env: FORMULA=gcc49 COMPILER=gcc C_COMPILER=gcc-4.9
#
## gcc 5 on osx
#- os: osx
# env: FORMULA=gcc5 COMPILER=gcc C_COMPILER=gcc-5

# clang 3.6 on osx
- os: osx
osx_image: xcode6.4
env: C_COMPILER=clang

# clang 3.7 on osx
- os: osx
osx_image: xcode7.1
env: C_COMPILER=clang

# # clang 4.2 on osx
# - os: osx
# osx_image: xcode8.2
# env: C_COMPILER=clang


before_install:
# for osx: 0. update brew; 1. install cmake if missing; 2. (gcc) unlink pre-installed gcc; 3. (gcc) install desired version of gcc
- 'if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi'
- 'if [[ "$TRAVIS_OS_NAME" == "osx" && -z "$(which cmake)" ]]; then brew install cmake; fi' # xcode 7.1 is missing cmake
- 'if [[ "$TRAVIS_OS_NAME" == "osx" && "$COMPILER" == "gcc" ]]; then brew unlink gcc || true; fi' # ignore unlink errors
- 'if [[ "$TRAVIS_OS_NAME" == "osx" && "$COMPILER" == "gcc" ]]; then brew unlink $FORMULA || true; fi' # ignore unlink errors
- 'if [[ "$TRAVIS_OS_NAME" == "osx" && "$COMPILER" == "gcc" ]]; then brew install $FORMULA; fi'
- export CC=$C_COMPILER
- wget https://github.com/libcheck/check/releases/download/0.11.0/check-0.11.0.tar.gz
- tar xvfz check-0.11.0.tar.gz
- cd check-0.11.0 && ./configure && make && sudo make install && cd ..

script:
- mkdir _build && cd _build
- cmake ..
- make -j
- make check
- egrep -r ":F:|:E:" . || true
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.6)
project(ccommon)
project(ccommon C)

enable_testing()

Expand Down Expand Up @@ -37,8 +37,8 @@ endif()

# version info
set(${PROJECT_NAME}_VERSION_MAJOR 1)
set(${PROJECT_NAME}_VERSION_MINOR 0)
set(${PROJECT_NAME}_VERSION_PATCH 2)
set(${PROJECT_NAME}_VERSION_MINOR 2)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}
)
Expand All @@ -51,6 +51,7 @@ option(HAVE_ASSERT_LOG "assert_log enabled by default" ON)
option(HAVE_ASSERT_PANIC "assert_panic disabled by default" OFF)
option(HAVE_LOGGING "logging enabled by default" ON)
option(HAVE_STATS "stats enabled by default" ON)
option(HAVE_DEBUG_MM "debugging oriented memory management disabled by default" OFF)
option(COVERAGE "code coverage" OFF)

include(CheckIncludeFiles)
Expand Down
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
#cmakedefine HAVE_LOGGING

#cmakedefine HAVE_STATS

#cmakedefine HAVE_DEBUG_MM
6 changes: 4 additions & 2 deletions docs/c-styleguide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
<stdint.h>. However, when interfacing with system calls and libraries
you cannot get away from using int and char.
- Use bool for boolean variables. You have to include <stdbool.h>
- Avoid using a bool as type for struct member names. Instead use unsigned
1-bit bit field. Eg:
- If memory usage or alignment is a concern, avoid using a bool as type for
struct member names. Instead use unsigned 1-bit bit field. e.g.
struct foo {
unsigned is_bar:1;
};
However, if neither memory usage or alignment will be significantly impacted
by the struct, opt for using bool for the sake of readability.
- Always use size_t type when dealing with sizes of objects or memory ranges.
- Your code should be 64-bit and 32-bit friendly. Bear in mind problems
of printing, comparisons, and structure alignment. You have to include
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/cc_ring_array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Hello World! with ccommon ``ring_array``:
if (status != CC_OK) {
printf("Could not pop entire message!");
exit(1)
exit(1);
}
printf("%c", c);
Expand Down
4 changes: 4 additions & 0 deletions include/buffer/cc_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ buf_read(char *dst, struct buf *src, uint32_t count)
static inline uint32_t
buf_write(struct buf *dst, char *src, uint32_t count)
{
if (count == 0) {
return 0;
}

ASSERT(dst != NULL && src != NULL);

uint32_t len = MIN(buf_wsize(dst), count);
Expand Down
4 changes: 2 additions & 2 deletions include/cc_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct array {
uint32_t nalloc; /* # allocated element */
size_t size; /* element size */
uint32_t nelem; /* # element */
void *data; /* elements */
uint8_t *data; /* elements */
};


Expand Down Expand Up @@ -93,7 +93,7 @@ array_data_assign(struct array *arr, uint32_t nalloc, size_t size, void *data)
* element is out of bounds, return -1.
*/
static inline int
array_locate(struct array *arr, void *elem) {
array_locate(struct array *arr, uint8_t *elem) {
int idx;

idx = (elem - arr->data) / arr->size;
Expand Down
7 changes: 3 additions & 4 deletions include/cc_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ extern "C" {
# define CC_BACKTRACE 1
#endif

/* TODO: add compile time option to turn chaining on/off */
/*#ifdef HAVE_CHAINED*/
# define CC_HAVE_CHAINED 1
/*#endif*/
#ifdef HAVE_DEBUG_MM
#define CC_DEBUG_MM 1
#endif

#define CC_OK 0
#define CC_ERROR -1
Expand Down
38 changes: 0 additions & 38 deletions include/cc_lookup3.h

This file was deleted.

16 changes: 16 additions & 0 deletions include/cc_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <cc_define.h>

#include <stddef.h>

/*
Expand All @@ -41,8 +47,13 @@
#define cc_calloc(_n, _s) \
_cc_calloc((size_t)(_n), (size_t)(_s), __FILE__, __LINE__)

#if defined CC_DEBUG_MM && CC_DEBUG_MM == 1
#define cc_realloc(_p, _s) \
_cc_realloc_move(_p, (size_t)(_s), __FILE__, __LINE__)
#else
#define cc_realloc(_p, _s) \
_cc_realloc(_p, (size_t)(_s), __FILE__, __LINE__)
#endif

#define cc_free(_p) do { \
_cc_free(_p, __FILE__, __LINE__); \
Expand All @@ -59,6 +70,11 @@ void * _cc_alloc(size_t size, const char *name, int line);
void * _cc_zalloc(size_t size, const char *name, int line);
void * _cc_calloc(size_t nmemb, size_t size, const char *name, int line);
void * _cc_realloc(void *ptr, size_t size, const char *name, int line);
void * _cc_realloc_move(void *ptr, size_t size, const char *name, int line);
void _cc_free(void *ptr, const char *name, int line);
void * _cc_mmap(size_t size, const char *name, int line);
int _cc_munmap(void *p, size_t size, const char *name, int line);

#ifdef __cplusplus
}
#endif
3 changes: 3 additions & 0 deletions include/cc_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ extern "C" {

/* behavior undefined if there isn't enough space in buf */
size_t cc_print_uint64_unsafe(char *buf, uint64_t n);
size_t cc_print_int64_unsafe(char *buf, int64_t n);

size_t cc_print_uint64(char *buf, size_t size, uint64_t n);
size_t cc_print_int64(char *buf, size_t size, int64_t n);

size_t _scnprintf(char *buf, size_t size, const char *fmt, ...);
size_t _vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
Expand Down
8 changes: 8 additions & 0 deletions include/cc_rbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <cc_metric.h>

#include <stdint.h>
Expand Down Expand Up @@ -86,3 +90,7 @@ size_t rbuf_wcap(struct rbuf *buf);
size_t rbuf_read(void *dst, struct rbuf *src, size_t n);
/* write from a buffer in memory to the rbuf */
size_t rbuf_write(struct rbuf *dst, void *src, size_t n);

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions include/cc_ring_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <cc_define.h>

#include <stddef.h>
Expand Down Expand Up @@ -53,4 +57,9 @@ rstatus_i ring_array_pop(void *elem, struct ring_array *arr);

/* creation/destruction */
struct ring_array *ring_array_create(size_t elem_size, uint32_t cap);

void ring_array_destroy(struct ring_array *arr);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion include/cc_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct signal {
* - SIGSEGV(debug): print stacktrace before reraise segfault again
* - SIGPIPE(channel): ignored, this prevents service from exiting when pipe closes
*/
struct signal signals[SIGNAL_MAX]; /* there are only 31 signals from 1 to 31 */
extern struct signal signals[SIGNAL_MAX]; /* there are only 31 signals from 1 to 31 */

int signal_override(int signo, char *info, int flags, uint32_t mask, sig_fn handler);

Expand Down
4 changes: 4 additions & 0 deletions include/cc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ extern "C" {
* # define UINT16_MAX (65535)
* # define UINT32_MAX (4294967295U)
* # define UINT64_MAX (__UINT64_C(18446744073709551615))
*
* # define INT64_MIN -9223372036854775808LL
*/
#define CC_UINT8_MAXLEN (3 + 1)
#define CC_UINT16_MAXLEN (5 + 1)
#define CC_UINT32_MAXLEN (10 + 1)
#define CC_UINT64_MAXLEN (20 + 1)
#define CC_UINTMAX_MAXLEN CC_UINT64_MAXLEN

#define CC_INT64_MAXLEN (1 + 19 + 1)

/* alignment */
/* Make data 'd' or pointer 'p', n-byte aligned, where n is a power of 2 */
#define CC_ALIGNMENT sizeof(unsigned long) /* platform word */
Expand Down
3 changes: 2 additions & 1 deletion include/channel/cc_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ ssize_t tcp_recvv(struct tcp_conn *c, struct array *bufv, size_t nbyte);
ssize_t tcp_sendv(struct tcp_conn *c, struct array *bufv, size_t nbyte);

bool tcp_accept(struct tcp_conn *sc, struct tcp_conn *c); /* channel_accept_fn */
void tcp_reject(struct tcp_conn *sc); /* channel_reject_fn */
void tcp_reject(struct tcp_conn *sc); /* channel_reject_fn */
void tcp_reject_all(struct tcp_conn *sc); /* channel_reject_fn */

/* functions getting/setting connection attribute */
int tcp_set_blocking(int sd);
Expand Down
2 changes: 1 addition & 1 deletion include/cc_hash.h → include/hash/cc_lookup3.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>

uint32_t hash(const void *key, size_t length, const uint32_t initval);
uint32_t hash_lookup3(const void *key, size_t length, const uint32_t initval);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 73baaa1

Please sign in to comment.