Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/BufferReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BufferReader {

char* getWritePtr();
void commitWrite(size_t len);
void write(char* ptr, size_t len, bool copying = true);
void write(const char* ptr, size_t len, bool copying = true);

size_t capacity();
size_t size();
Expand All @@ -84,7 +84,7 @@ class BufferReader {
size_t getNextPreferedDataBlockSize();

protected:
const char charAtCursor(DataCursor& cur) const;
const char charAtCursor(const DataCursor& cur) const;

DataBlockList m_dataBlockList;
size_t m_capacity;
Expand All @@ -96,7 +96,7 @@ class BufferReader {
};


inline const char BufferReader::charAtCursor(DataCursor& cur) const {
inline const char BufferReader::charAtCursor(const DataCursor& cur) const {
// NOTE: make sure cur is valid
/**
* DataBlock& db = *cur.iterator;
Expand Down
10 changes: 5 additions & 5 deletions include/llvm/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace llvm {

protected:
SmallVectorBase(size_t Size)
: BeginX(&FirstEl), EndX(&FirstEl), CapacityX((char*)&FirstEl+Size) {}
: BeginX(&FirstEl), EndX(&FirstEl), CapacityX(static_cast<char*>(&FirstEl)+Size) {}

/// isSmall - Return true if this is a smallvector which has not had dynamic
/// memory allocated for it.
Expand All @@ -63,12 +63,12 @@ namespace llvm {

/// size_in_bytes - This returns size()*sizeof(T).
size_t size_in_bytes() const {
return size_t((char*)EndX - (char*)BeginX);
return size_t(static_cast<char*>(EndX) - static_cast<char*>(BeginX));
}

/// capacity_in_bytes - This returns capacity()*sizeof(T).
size_t capacity_in_bytes() const {
return size_t((char*)CapacityX - (char*)BeginX);
return size_t(static_cast<char*>(CapacityX) - static_cast<char*>(BeginX));
}

/// grow_pod - This is an implementation of the grow() method which only works
Expand Down Expand Up @@ -830,9 +830,9 @@ namespace llvm {
if (!this->isSmall())
operator delete(this->BeginX);

this->EndX = (char*)NewElts+CurSizeBytes;
this->EndX = static_cast<char*>(NewElts)+CurSizeBytes;
this->BeginX = NewElts;
this->CapacityX = (char*)this->BeginX + NewCapacityInBytes;
this->CapacityX = static_cast<char*>(this->BeginX) + NewCapacityInBytes;
}
} // namespace llvm

Expand Down
4 changes: 2 additions & 2 deletions libmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
__file__ as _libmc_so_file
)

__VERSION__ = "1.4.8"
__version__ = "1.4.8"
__VERSION__ = "1.5.0"
__version__ = "1.5.0"
__author__ = "mckelvin"
__email__ = "mckelvin@users.noreply.github.com"
__date__ = "Fri Jun 7 06:16:00 2024 +0800"
Expand Down
59 changes: 28 additions & 31 deletions libmc/_client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ from libcpp.string cimport string
from libcpp.vector cimport vector
from cpython.mem cimport PyMem_Malloc, PyMem_Free
from cpython.version cimport PY_MAJOR_VERSION
from cpython cimport Py_INCREF, Py_DECREF, PyInt_AsLong, PyInt_FromLong
from cpython cimport Py_INCREF, Py_DECREF, PyLong_AsLong, PyLong_FromLong
from ctypes import c_long as long

if PY_MAJOR_VERSION < 3:
from cpython cimport PyString_AsStringAndSize, PyString_AsString
import cPickle as pickle
else:
from cpython cimport PyBytes_AsStringAndSize as PyString_AsStringAndSize, PyBytes_AsString as PyString_AsString, PyUnicode_AsUTF8String
import pickle
from cpython cimport PyBytes_AsStringAndSize as PyString_AsStringAndSize, PyBytes_AsString as PyString_AsString, PyUnicode_AsUTF8String
import pickle

import os
import sys
Expand Down Expand Up @@ -257,33 +254,33 @@ cdef flags_t _FLAG_DOUBAN_CHUNKED = 1 << 12
cdef int _DOUBAN_CHUNK_SIZE = 1000000


MC_DEFAULT_EXPTIME = PyInt_FromLong(DEFAULT_EXPTIME)
MC_POLL_TIMEOUT = PyInt_FromLong(CFG_POLL_TIMEOUT)
MC_CONNECT_TIMEOUT = PyInt_FromLong(CFG_CONNECT_TIMEOUT)
MC_RETRY_TIMEOUT = PyInt_FromLong(CFG_RETRY_TIMEOUT)
MC_MAX_RETRIES = PyInt_FromLong(CFG_MAX_RETRIES)
MC_SET_FAILOVER = PyInt_FromLong(CFG_SET_FAILOVER)
MC_INITIAL_CLIENTS = PyInt_FromLong(CFG_INITIAL_CLIENTS)
MC_MAX_CLIENTS = PyInt_FromLong(CFG_MAX_CLIENTS)
MC_MAX_GROWTH = PyInt_FromLong(CFG_MAX_GROWTH)
MC_DEFAULT_EXPTIME = PyLong_FromLong(DEFAULT_EXPTIME)
MC_POLL_TIMEOUT = PyLong_FromLong(CFG_POLL_TIMEOUT)
MC_CONNECT_TIMEOUT = PyLong_FromLong(CFG_CONNECT_TIMEOUT)
MC_RETRY_TIMEOUT = PyLong_FromLong(CFG_RETRY_TIMEOUT)
MC_MAX_RETRIES = PyLong_FromLong(CFG_MAX_RETRIES)
MC_SET_FAILOVER = PyLong_FromLong(CFG_SET_FAILOVER)
MC_INITIAL_CLIENTS = PyLong_FromLong(CFG_INITIAL_CLIENTS)
MC_MAX_CLIENTS = PyLong_FromLong(CFG_MAX_CLIENTS)
MC_MAX_GROWTH = PyLong_FromLong(CFG_MAX_GROWTH)


MC_HASH_MD5 = PyInt_FromLong(OPT_HASH_MD5)
MC_HASH_FNV1_32 = PyInt_FromLong(OPT_HASH_FNV1_32)
MC_HASH_FNV1A_32 = PyInt_FromLong(OPT_HASH_FNV1A_32)
MC_HASH_CRC_32 = PyInt_FromLong(OPT_HASH_CRC_32)
MC_HASH_MD5 = PyLong_FromLong(OPT_HASH_MD5)
MC_HASH_FNV1_32 = PyLong_FromLong(OPT_HASH_FNV1_32)
MC_HASH_FNV1A_32 = PyLong_FromLong(OPT_HASH_FNV1A_32)
MC_HASH_CRC_32 = PyLong_FromLong(OPT_HASH_CRC_32)


MC_RETURN_SEND_ERR = PyInt_FromLong(RET_SEND_ERR)
MC_RETURN_RECV_ERR = PyInt_FromLong(RET_RECV_ERR)
MC_RETURN_CONN_POLL_ERR = PyInt_FromLong(RET_CONN_POLL_ERR)
MC_RETURN_POLL_TIMEOUT_ERR = PyInt_FromLong(RET_POLL_TIMEOUT_ERR)
MC_RETURN_POLL_ERR = PyInt_FromLong(RET_POLL_ERR)
MC_RETURN_MC_SERVER_ERR = PyInt_FromLong(RET_MC_SERVER_ERR)
MC_RETURN_PROGRAMMING_ERR = PyInt_FromLong(RET_PROGRAMMING_ERR)
MC_RETURN_INVALID_KEY_ERR = PyInt_FromLong(RET_INVALID_KEY_ERR)
MC_RETURN_INCOMPLETE_BUFFER_ERR = PyInt_FromLong(RET_INCOMPLETE_BUFFER_ERR)
MC_RETURN_OK = PyInt_FromLong(RET_OK)
MC_RETURN_SEND_ERR = PyLong_FromLong(RET_SEND_ERR)
MC_RETURN_RECV_ERR = PyLong_FromLong(RET_RECV_ERR)
MC_RETURN_CONN_POLL_ERR = PyLong_FromLong(RET_CONN_POLL_ERR)
MC_RETURN_POLL_TIMEOUT_ERR = PyLong_FromLong(RET_POLL_TIMEOUT_ERR)
MC_RETURN_POLL_ERR = PyLong_FromLong(RET_POLL_ERR)
MC_RETURN_MC_SERVER_ERR = PyLong_FromLong(RET_MC_SERVER_ERR)
MC_RETURN_PROGRAMMING_ERR = PyLong_FromLong(RET_PROGRAMMING_ERR)
MC_RETURN_INVALID_KEY_ERR = PyLong_FromLong(RET_INVALID_KEY_ERR)
MC_RETURN_INCOMPLETE_BUFFER_ERR = PyLong_FromLong(RET_INCOMPLETE_BUFFER_ERR)
MC_RETURN_OK = PyLong_FromLong(RET_OK)



Expand Down Expand Up @@ -419,7 +416,7 @@ cdef _update_servers(Configurable* imp, list servers, bool_t init):
if c_split.port == NULL:
c_ports[i] = MC_DEFAULT_PORT
else:
c_ports[i] = PyInt_AsLong(int(<bytes>c_split.port))
c_ports[i] = PyLong_AsLong(int(<bytes>c_split.port))

if init:
rv = imp.init(c_hosts, c_ports, n, c_aliases)
Expand Down
34 changes: 4 additions & 30 deletions misc/.cppcheck-supp
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,9 @@
*:include/llvm/SmallVector.h:796
constParameter:include/BufferReader.h:99
unreadVariable:include/LockPool.h
unusedFunction:src/Client.cpp:239
unusedFunction:src/c_client.cpp:8
unusedFunction:src/c_client.cpp:13
unusedFunction:src/c_client.cpp:25
unusedFunction:src/c_client.cpp:31
unusedFunction:src/c_client.cpp:37
unusedFunction:src/c_client.cpp:43
unusedFunction:src/c_client.cpp:50
unusedFunction:src/c_client.cpp:56
unusedFunction:src/c_client.cpp:67
unusedFunction:src/c_client.cpp:68
unusedFunction:src/c_client.cpp:72
unusedFunction:src/c_client.cpp:89
unusedFunction:src/c_client.cpp:90
unusedFunction:src/c_client.cpp:91
unusedFunction:src/c_client.cpp:92
unusedFunction:src/c_client.cpp:93
unusedFunction:src/c_client.cpp:94
unusedFunction:src/c_client.cpp:98
unusedFunction:src/c_client.cpp:106
unusedFunction:src/c_client.cpp:112
unusedFunction:src/c_client.cpp:120
unusedFunction:src/c_client.cpp:128
unusedFunction:src/c_client.cpp:135
unusedFunction:src/c_client.cpp:140
unusedFunction:src/c_client.cpp:145
unusedFunction:src/c_client.cpp:149
unusedFunction:src/c_client.cpp:154
unusedFunction:src/c_client.cpp:159
unusedFunction:src/Utility.cpp:43
unreadVariable:src/HashkitKetama.cpp:49
unusedFunction:*
*:src/Connection.cpp:32
*:src/Connection.cpp:37
missingIncludeSystem:*
normalCheckLevelMaxBranches:*
2 changes: 1 addition & 1 deletion misc/travis/cppcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -ex
# https://github.com/danmar/cppcheck/pull/1026
cppcheck --enable=all --error-exitcode=1 \
-UMSG_MORE -UNI_MAXHOST -UNI_MAXSERV -UUIO_MAXIOV \
--suppressions-list=misc/.cppcheck-supp -Iinclude src tests
--suppressions-list=misc/.cppcheck-supp -Iinclude src
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def find_version(*file_paths):
"License :: OSI Approved :: BSD License",
"Topic :: Software Development :: Libraries",
],
# Support for the basestring type is new in Cython 0.20.
setup_requires=["Cython >= 0.20"],
# upgrade cython to a higher version to avoid conflicts
setup_requires=["Cython >= 3.1.0"],
ext_modules=[
Extension(
"libmc._client",
Expand Down
10 changes: 7 additions & 3 deletions src/BufferReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ size_t BufferReader::prepareWriteBlock(size_t len) {
++m_blockWriteIterator;
}

assert(m_blockWriteIterator == m_dataBlockList.end() ||
m_blockWriteIterator->getWriteLeft() > 0);
// Store the result to avoid side effects in assert
size_t writeLeft = (m_blockWriteIterator == m_dataBlockList.end()) ?
0 : m_blockWriteIterator->getWriteLeft();
assert(m_blockWriteIterator == m_dataBlockList.end() || writeLeft > 0);

DataBlock *dbPtr = NULL;

Expand Down Expand Up @@ -111,7 +113,9 @@ char* BufferReader::getWritePtr() {


void BufferReader::commitWrite(size_t len) {
assert(m_blockWriteIterator->size() + len <= m_blockWriteIterator->capacity());
// Store the result to avoid side effects in assert
size_t currentCapacity = m_blockWriteIterator->capacity();
assert(m_blockWriteIterator->size() + len <= currentCapacity);
m_blockWriteIterator->occupy(len);
if (m_blockWriteIterator->size() + len == m_blockWriteIterator->capacity()) {
++m_blockWriteIterator;
Expand Down
7 changes: 3 additions & 4 deletions src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ int Connection::connect() {

try_next_ai:
::close(fd);
continue;
}

if (server_addrinfo) {
Expand All @@ -147,7 +146,7 @@ int Connection::unixSocketConnect() {
return -1;
}

setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&opt_keepalive, sizeof opt_keepalive);
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, static_cast<void*>(&opt_keepalive), sizeof opt_keepalive);

struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
Expand All @@ -156,7 +155,7 @@ int Connection::unixSocketConnect() {
// storing the unix path as a host doesn't limit the input but can overflow
strncpy(addr.sun_path, m_host, sizeof(addr.sun_path) - 1);
assert(strcmp(addr.sun_path, m_host) == 0);
if (connectPoll(fd, (const struct sockaddr *)&addr, sizeof addr) != 0) {
if (connectPoll(fd, reinterpret_cast<const struct sockaddr*>(&addr), sizeof addr) != 0) {
return -1;
}
m_socketFd = fd;
Expand Down Expand Up @@ -240,7 +239,7 @@ void Connection::markDead(const char* reason, int delay) {
if (strcmp(reason, keywords::kCONN_QUIT) != 0) {
log_warn("Connection %s is dead(reason: %s, delay: %d), next check at %lu",
m_name, reason, delay, m_deadUntil);
struct iovec* key = m_parser.currentRequestKey();
const struct iovec* key = m_parser.currentRequestKey();
if (key != NULL) {
log_warn("%s: first request key: %.*s", m_name,
static_cast<int>(key->iov_len),
Expand Down
4 changes: 2 additions & 2 deletions src/DataBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ size_t DataBlock::getWriteLeft() {


size_t DataBlock::find(char c, size_t since) {
char *p = std::find(m_data + since, m_data + m_size, c);
const char *p = std::find(m_data + since, m_data + m_size, c);
return p - m_data;
}

Expand All @@ -102,7 +102,7 @@ bool is_not_digit(int c) {


size_t DataBlock::findNotNumeric(size_t since) {
char *p = std::find_if(m_data + since, m_data + m_size, is_not_digit);
const char *p = std::find_if(m_data + since, m_data + m_size, is_not_digit);
return p - m_data;
}

Expand Down
6 changes: 3 additions & 3 deletions src/HashkitMd5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen )

if( left && ilen >= fill )
{
memcpy( (void *) (ctx->buffer + left), input, fill );
memcpy( ctx->buffer + left, input, fill );
md5_process( ctx, ctx->buffer );
input += fill;
ilen -= fill;
Expand All @@ -234,7 +234,7 @@ void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen )

if( ilen > 0 )
{
memcpy( (void *) (ctx->buffer + left), input, ilen );
memcpy( ctx->buffer + left, input, ilen );
}
}

Expand Down Expand Up @@ -293,7 +293,7 @@ uint32_t hash_md5(const char *key, size_t key_length)
{
unsigned char results[16];

md5((unsigned char*)key, (size_t)key_length, results);
md5(reinterpret_cast<const unsigned char*>(key), key_length, results);

return ((uint32_t) (results[3] & 0xFF) << 24)
| ((uint32_t) (results[2] & 0xFF) << 16)
Expand Down
3 changes: 1 addition & 2 deletions src/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ void fprintBuffer(std::FILE* file, const char *data_buffer_, const unsigned int
const unsigned char* data_buffer = reinterpret_cast<const unsigned char*>(data_buffer_);
unsigned int i, j;
for (i = 0; i < length; i++) {
unsigned char byte = data_buffer[i];
fprintf(file, "%02x ", data_buffer[i]);
if (((i%16) == 15) || (i == length-1)) {
for (j = 0; j < 15-(i%16); j++) {
fprintf(file, " ");
}
fprintf(file, "| ");
for (j=(i-(i%16)); j <= i; j++) {
byte = data_buffer[j];
unsigned char byte = data_buffer[j];
if ((byte > 31) && (byte < 127)) {
fprintf(file, "%c", byte);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package golibmc

const _Version = "1.4.8"
const _Version = "1.5.0"
const _Author = "mckelvin"
const _Email = "mckelvin@users.noreply.github.com"
const _Date = "Fri Jun 7 06:16:00 2024 +0800"
Expand Down
Loading