Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a build for php 5.6, fix crash due to misuse of 'inline' across c files #1

Open
wants to merge 2 commits into
base: BRANCH-3.0.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions memcache_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@

ZEND_DECLARE_MODULE_GLOBALS(memcache)

inline void mmc_buffer_alloc(mmc_buffer_t *buffer, unsigned int size) /*
void mmc_buffer_alloc(mmc_buffer_t *buffer, unsigned int size) /*
ensures space for an additional size bytes {{{ */
{
register size_t newlen;
smart_str_alloc((&(buffer->value)), size, 0);
}
/* }}} */

inline void mmc_buffer_free(mmc_buffer_t *buffer) /* {{{ */
void mmc_buffer_free(mmc_buffer_t *buffer) /* {{{ */
{
if (buffer->value.c != NULL) {
smart_str_free(&(buffer->value));
Expand Down Expand Up @@ -177,7 +177,7 @@ void mmc_request_free(mmc_request_t *request) /* {{{ */
}
/* }}} */

static inline int mmc_request_send(mmc_t *mmc, mmc_request_t *request TSRMLS_DC) /* {{{ */
static int mmc_request_send(mmc_t *mmc, mmc_request_t *request TSRMLS_DC) /* {{{ */
{
int count, bytes;

Expand Down Expand Up @@ -784,7 +784,7 @@ static int mmc_server_connect(mmc_pool_t *pool, mmc_t *mmc, mmc_stream_t *io, in
io->read = mmc_stream_read_wrapper;
io->readline = mmc_stream_readline_wrapper;
}

#ifdef SO_NOSIGPIPE
/* Mac OS X doesn't have MSG_NOSIGNAL */
{
Expand Down Expand Up @@ -1061,7 +1061,7 @@ static int mmc_pool_response_handler_null(mmc_t *mmc, mmc_request_t *request, in
}
/* }}}*/

static inline mmc_request_t *mmc_pool_request_alloc(mmc_pool_t *pool, int protocol,
static mmc_request_t *mmc_pool_request_alloc(mmc_pool_t *pool, int protocol,
mmc_request_failover_handler failover_handler, void *failover_handler_param TSRMLS_DC) /* {{{ */
{
mmc_request_t *request = mmc_queue_pop(&(pool->free_requests));
Expand Down Expand Up @@ -1314,7 +1314,7 @@ int mmc_pool_schedule_get(
}
/* }}} */

static inline void mmc_pool_switch(mmc_pool_t *pool) {
static void mmc_pool_switch(mmc_pool_t *pool) {
/* switch sending and reading queues */
if (pool->sending == &(pool->_sending1)) {
pool->sending = &(pool->_sending2);
Expand Down Expand Up @@ -1441,7 +1441,7 @@ void mmc_pool_select(mmc_pool_t *pool TSRMLS_DC) /*
if (result <= 0) {
for (i=0; i < sending->len; i++) {
mmc = (mmc_t *)mmc_queue_item(sending, i);

/* remove sending request */
if (!FD_ISSET(mmc->sendreq->io->fd, &(pool->wfds))) {
mmc_queue_remove(sending, mmc);
Expand All @@ -1457,7 +1457,7 @@ void mmc_pool_select(mmc_pool_t *pool TSRMLS_DC) /*

for (i=0; i < reading->len; i++) {
mmc = (mmc_t *)mmc_queue_item(reading, i);

/* remove reading request */
if (!FD_ISSET(mmc->readreq->io->fd, &(pool->rfds))) {
mmc_queue_remove(sending, mmc);
Expand Down Expand Up @@ -1676,7 +1676,7 @@ void mmc_pool_run(mmc_pool_t *pool TSRMLS_DC) /*
}
/* }}} */

inline int mmc_prepare_key_ex(const char *key, unsigned int key_len, char *result, unsigned int *result_len) /* {{{ */
int mmc_prepare_key_ex(const char *key, unsigned int key_len, char *result, unsigned int *result_len) /* {{{ */
{
unsigned int i;
if (key_len == 0) {
Expand All @@ -1694,7 +1694,7 @@ inline int mmc_prepare_key_ex(const char *key, unsigned int key_len, char *resul
}
/* }}} */

inline int mmc_prepare_key(zval *key, char *result, unsigned int *result_len) /* {{{ */
int mmc_prepare_key(zval *key, char *result, unsigned int *result_len) /* {{{ */
{
if (Z_TYPE_P(key) == IS_STRING) {
return mmc_prepare_key_ex(Z_STRVAL_P(key), Z_STRLEN_P(key), result, result_len);
Expand Down
10 changes: 5 additions & 5 deletions memcache_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

/*
* Mac OS X has no MSG_NOSIGNAL but >= 10.2 comes with SO_NOSIGPIPE which is a setsockopt() option
* and not a send() parameter as MSG_NOSIGNAL. OpenBSD has none of the options so we need to ignore
* and not a send() parameter as MSG_NOSIGNAL. OpenBSD has none of the options so we need to ignore
* SIGPIPE events
*/
#ifndef MSG_NOSIGNAL
Expand Down Expand Up @@ -135,8 +135,8 @@ typedef struct mmc_buffer {
#define mmc_buffer_release(b) memset((b), 0, sizeof(*(b)))
#define mmc_buffer_reset(b) (b)->value.len = (b)->idx = 0

inline void mmc_buffer_alloc(mmc_buffer_t *, unsigned int);
inline void mmc_buffer_free(mmc_buffer_t *);
void mmc_buffer_alloc(mmc_buffer_t *, unsigned int);
void mmc_buffer_free(mmc_buffer_t *);

/* stream handlers */
typedef struct mmc_stream mmc_stream_t;
Expand Down Expand Up @@ -391,8 +391,8 @@ int mmc_unpack_value(mmc_t *, mmc_request_t *, mmc_buffer_t *, const char *, uns
double timeval_to_double(struct timeval tv);
struct timeval double_to_timeval(double sec);

inline int mmc_prepare_key_ex(const char *, unsigned int, char *, unsigned int *);
inline int mmc_prepare_key(zval *, char *, unsigned int *);
int mmc_prepare_key_ex(const char *, unsigned int, char *, unsigned int *);
int mmc_prepare_key(zval *, char *, unsigned int *);

#define mmc_str_left(h, n, hlen, nlen) ((hlen) >= (nlen) ? memcmp((h), (n), (nlen)) == 0 : 0)

Expand Down
6 changes: 1 addition & 5 deletions memcache_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ typedef struct mmc_queue {

#define mmc_queue_release(q) memset((q), 0, sizeof(*(q)))
#define mmc_queue_reset(q) (q)->len = (q)->head = (q)->tail = 0
#define mmc_queue_item(q, i) ((q)->tail + (i) < (q)->alloc ? (q)->items[(q)->tail + (i)] : (q)->items[(i) - ((q)->alloc - (q)->tail)])
#define mmc_queue_item(q, i) ((q)->tail + (i) < (q)->alloc ? (q)->items[(q)->tail + (i)] : (q)->items[(i) - ((q)->alloc - (q)->tail)])

#ifdef PHP_WIN32
#define MMC_QUEUE_INLINE
#else
#define MMC_QUEUE_INLINE inline
#endif

MMC_QUEUE_INLINE void mmc_queue_push(mmc_queue_t *, void *);
MMC_QUEUE_INLINE void *mmc_queue_pop(mmc_queue_t *);
Expand Down
97 changes: 97 additions & 0 deletions tests/connect.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

if (!extension_loaded("memcache")) {
die("skip");
}

error_reporting(E_ALL);

/*
* Please change host & port to match your configuration
*/

$host = "localhost";
$port = 11211;
//$udpPort = 11211;

$host2 = "localhost";
$port2 = 11212;
//$udpPort2 = 11212;

//ini_set('memcache.hash_strategy', 'standard');
//ini_set('memcache.hash_function', 'fnv');
//ini_set('memcache.protocol', 'binary');

if (ini_get('memcache.protocol') == 'binary') {
$udpPort = 0;
$udpPort2 = 0;
}

/* Start a server listening to a unix domain socket
*
* mkdir /var/run/memcached
* chown memcached:memcached /var/run/memcached
* memcached -d -u memcached -s /var/run/memcached/memcached.sock
* chmod a+w /var/run/memcached/memcached.sock
*/
$domainsocket = 'unix:///var/run/memcached/memcached.sock';

// A server which is guaranteed to fail immediatly
$nonExistingHost = "localhost";
$nonExistingPort = 11213;

// A server which times out when attempting to connect to
$unreachableHost = '10.254.254.254';
$unreachablePort = 11211;

$udpPacketSize = 1400;

$balanceKeys = array(
'consistent' => array(
'crc32' => array('key1_abc', 'key2_abcde'),
'fnv' => array('key1_a', 'key2_2534534'),
),
'standard' => array(
'crc32' => array('load_test_key1', 'load_test_key2'),
'fnv' => array('key1_ab', 'key2_a'),
),
);

$strat = strtolower(ini_get('memcache.hash_strategy'));
$func = strtolower(ini_get('memcache.hash_function'));
list ($balanceKey1, $balanceKey2) = $balanceKeys[$strat][$func];

if (!isset($udpPort))
$udpPort = 0;
if (!isset($udpPort2))
$udpPort2 = 0;

$memcache = memcache_connect($host, $port);

function test_connect1() {
global $host, $port, $udpPort;
$memcache = new MemcachePool();
$memcache->connect($host, $port, isset($udpPort) ? $udpPort : 0);
return $memcache;
}

function test_connect2() {
global $host2, $port2, $udpPort2;
$memcache = new MemcachePool();
$memcache->connect($host2, $port2, isset($udpPort2) ? $udpPort2 : 0);
return $memcache;
}

function test_connect_pool() {
global $host, $port, $udpPort, $host2, $port2, $udpPort2;
$memcache = new MemcachePool();
$memcache->addServer($host, $port, isset($udpPort) ? $udpPort : 0);
$memcache->addServer($host2, $port2, isset($udpPort2) ? $udpPort2 : 0);
return $memcache;
}

if (!$memcache) {
die('skip Connection to memcached failed');
}

?>