Problems compiling php-mcache

Jacob Coby jcoby at listingbook.com
Mon Apr 25 07:47:56 PDT 2005


Jon Valvatne wrote:
> Hello list,
> 
> I'm having some trouble compiling php-mcache with php-4.3.11 and
> libmemcache-1.2.4. Now I suspect this is somehow caused by some aspect of
> my PHP installation, but I have no idea how PHP extensions work, so I'm lost.

Yeah, mcache.c declares variables after calling functions inside of a 
block.  This isn't allowed by gcc (AFAIK; there may be a compiler switch?)

diff attached that fixes the problem and should compile for you.  I did 
not test if the resulting mcache.o works.

 > Any ideas?
 >
 > $ phpize
 > Configuring for:
 > PHP Api Version:         20020918
 > Zend Module Api No:      20020429
 > Zend Extension Api No:   20021010
 >
 > $ ./configure --with-mcache=/usr/src/libmemcache-1.2.4
 > creating cache ./config.cache
 > checking host system type... i686-pc-linux-gnu
 > checking for gcc... gcc
 > checking whether the C compiler (gcc  ) works... yes
 > checking whether the C compiler (gcc  ) is a cross-compiler... no
 > checking whether we are using GNU C... yes
 > checking whether gcc accepts -g... yes
 > checking whether gcc and cc understand -c and -o together... yes
 > checking if compiler supports -R... no
 > checking if compiler supports -Wl,-rpath,... yes
 > checking for PHP prefix... /usr/local
 > checking for PHP includes... -I/usr/local/include/php 
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM 
-I/usr/local/include/php/Zend
 > checking for PHP extension directory... 
/usr/local/lib/php/extensions/no-debug-non-zts-20020429
 > checking for re2c... exit 0;
 > checking for mawk... mawk
 > checking for mcache support... yes, shared
 > checking for Cygwin environment... no
 > checking for mingw32 environment... no
 > checking how to run the C preprocessor... gcc -E
 > checking build system type... i686-pc-linux-gnu
 > checking for ld used by GCC... /usr/bin/ld
 > checking if the linker (/usr/bin/ld) is GNU ld... yes
 > checking for /usr/bin/ld option to reload object files... -r
 > checking for BSD-compatible nm... /usr/bin/nm -B
 > checking for a sed that does not truncate output... /bin/sed
 > checking whether ln -s works... yes
 > checking how to recognise dependent libraries... pass_all
 > checking for object suffix... o
 > checking for executable suffix... no
 > checking command to parse /usr/bin/nm -B output... ok
 > checking for dlfcn.h... yes
 > checking for ranlib... ranlib
 > checking for strip... strip
 > checking for objdir... .libs
 > checking for gcc option to produce PIC... -fPIC
 > checking if gcc PIC flag -fPIC works... yes
 > checking if gcc static flag -static works... yes
 > checking if gcc supports -c -o file.o... yes
 > checking if gcc supports -c -o file.lo... yes
 > checking if gcc supports -fno-rtti -fno-exceptions... yes
 > checking whether the linker (/usr/bin/ld) supports shared 
libraries... yes
 > checking how to hardcode library paths into programs... immediate
 > checking whether stripping libraries is possible... yes
 > checking dynamic linker characteristics... GNU/Linux ld.so
 > checking if libtool supports shared libraries... yes
 > checking whether to build shared libraries... yes
 > checking whether to build static libraries... no
 > checking whether -lc should be explicitly linked in... no
 > creating libtool
 > updating cache ./config.cache
 > creating ./config.status
 > creating config.h
 >
 > $ make
 > /bin/sh /usr/src/php-mcache-ext-1.1.4/libtool --mode=compile gcc  -I. 
-I/usr/src/php-mcache-ext-1.1.4 -DPHP_ATOM_INC 
-I/usr/src/php-mcache-ext-1.1.4/include 
-I/usr/src/php-mcache-ext-1.1.4/main -I/usr/src/php-mcache-ext-1.1.4 
-I/usr/local/include/php -I/usr/local/include/php/main 
-I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend 
-I/usr/src/libmemcache-1.2.4  -DHAVE_CONFIG_H  -g -O2   -c 
/usr/src/php-mcache-ext-1.1.4/mcache.c -o mcache.lo
 > gcc -I. -I/usr/src/php-mcache-ext-1.1.4 -DPHP_ATOM_INC 
-I/usr/src/php-mcache-ext-1.1.4/include 
-I/usr/src/php-mcache-ext-1.1.4/main -I/usr/src/php-mcache-ext-1.1.4 
-I/usr/local/include/php -I/usr/local/include/php/main 
-I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend 
-I/usr/src/libmemcache-1.2.4 -DHAVE_CONFIG_H -g -O2 -c 
/usr/src/php-mcache-ext-1.1.4/mcache.c   -fPIC -DPIC -o mcache.lo
 > In file included from /usr/src/php-mcache-ext-1.1.4/mcache.c:33:
 > <snip> standard libmemcache warnings ("assignment discards qualifiers 
from pointer target type")
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zm_startup_mcache':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:158: parse error before 
`mcache_class_entry'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:159: `mcache_class_entry' 
undeclared (first use in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:159: (Each undeclared 
identifier is reported only once
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:159: for each function it 
appears in.)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_memcache':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:386: parse error before `new_le'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:391: `mc' undeclared (first 
use in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:402: `id' undeclared (first 
use in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_get':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:589: parse error before `int'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:592: warning: passing arg 4 of 
`zend_hash_get_current_key_ex' from incompatible pointer type
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:598: `i' undeclared (first use 
in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_set':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:667: parse error before `int'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:670: `ret' undeclared (first 
use in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_add':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:699: parse error before `int'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:702: `ret' undeclared (first 
use in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_replace':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:731: parse error before `int'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:734: `ret' undeclared (first 
use in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_incr':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:762: parse error before `int'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:764: `ret' undeclared (first 
use in this function)
 > /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_decr':
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:787: parse error before `int'
 > /usr/src/php-mcache-ext-1.1.4/mcache.c:789: `ret' undeclared (first 
use in this function)
 > make: *** [mcache.lo] Error 1
 >
 > $ cat /proc/version
 > Linux version 2.4.25-bf2.4 (root at oss) (gcc version 3.2.3 (Debian)) #1 
SMP Wed Mar 10 10:35:09 PST 2004
 >
 >

-- 
-Jacob
-------------- next part --------------
--- mcache.c	Tue Mar 22 18:45:34 2005
+++ mcache.c.new	Mon Apr 25 10:31:53 2005
@@ -149,14 +149,14 @@
  */
 PHP_MINIT_FUNCTION(mcache)
 {
+	zend_class_entry mcache_class_entry;
 	mcMemSetupCtxt(&persist_ctx, xpefree, (mcMallocFunc)xpemalloc, NULL, (mcReallocFunc)xperealloc);
 	mcMemSetupCtxt(&standard_ctx, xefree, (mcMallocFunc)xemalloc, NULL, (mcReallocFunc)xerealloc);
 	mcMemSetup(xefree, (mcMallocFunc)xemalloc, NULL, (mcReallocFunc)xerealloc);
 	le_mcache = zend_register_list_destructors_ex(mc_resource_list_dtor, NULL, "memcache object", module_number);
 	le_pmcache = zend_register_list_destructors_ex(NULL, mc_persistent_resource_list_dtor, "persistent memcache object", module_number);

-	zend_class_entry mcache_class_entry;
-    INIT_CLASS_ENTRY(mcache_class_entry, "Memcache", mcache_class_functions);
+	INIT_CLASS_ENTRY(mcache_class_entry, "Memcache", mcache_class_functions);
     mcache_class_entry_ptr = zend_register_internal_class(&mcache_class_entry TSRMLS_CC);

 #ifdef ZTS
@@ -379,14 +379,14 @@
 /* {{{ proto object memcache()
    Creates new Memcache object */
 PHP_FUNCTION(memcache) {
-	if(ZEND_NUM_ARGS()!=0) {
-		WRONG_PARAM_COUNT;
-	}
-
 	list_entry new_le;
 	int id;

 	struct memcache_wrapper *mc;
+
+	if(ZEND_NUM_ARGS()!=0) {
+		WRONG_PARAM_COUNT;
+	}

 	mc = emalloc(sizeof(struct memcache_wrapper));
 	mc->is_initialized = 0;
@@ -575,7 +575,10 @@
 		zval **data, *tmp;
 		struct memcache_res **res_pp, *cur_res;
 		HashTable *htable;
-
+		int i = 0;
+		char *hkey;
+		ulong index;
+
 		array_init(return_value);
 		cnt = zend_hash_num_elements(Z_ARRVAL_P(arg));

@@ -586,9 +589,6 @@
 		htable = HASH_OF(arg);
 		zend_hash_internal_pointer_reset(htable);

-		int i = 0;
-		char *hkey;
-		ulong index;
 		while(zend_hash_get_current_key(htable, &key, &index, 0) == HASH_KEY_IS_LONG) {
 			zend_hash_get_current_data(htable, (void **)&data);
 			convert_to_string(*data);
@@ -655,6 +655,7 @@
 	char *key, *data;
 	int key_len, data_len;
 	long flags, expire;
+	int ret;

 	if((resource = mc_get_resource(mc_obj, &mc TSRMLS_CC))==0) {
 		RETURN_FALSE;
@@ -664,7 +665,7 @@
 		RETURN_FALSE;
 	}

-	int ret=mcm_set(mc->ctxt, mc->mc, key, key_len, data, data_len, expire, flags);
+	ret=mcm_set(mc->ctxt, mc->mc, key, key_len, data, data_len, expire, flags);
 	smart_str_free(&buf);

 	if(ret==0) {
@@ -687,6 +688,7 @@
 	char *key, *data;
 	int key_len, data_len;
 	long flags, expire;
+	int ret;

 	if((resource = mc_get_resource(mc_obj, &mc TSRMLS_CC))==0) {
 		RETURN_FALSE;
@@ -696,7 +698,7 @@
 		RETURN_FALSE;
 	}

-	int ret=mcm_add(mc->ctxt, mc->mc, key, key_len, data, data_len, expire, flags);
+	ret=mcm_add(mc->ctxt, mc->mc, key, key_len, data, data_len, expire, flags);
 	smart_str_free(&buf);

 	if(ret==0) {
@@ -719,6 +721,7 @@
 	char *key, *data;
 	int key_len, data_len;
 	long flags, expire;
+	int ret;

 	if((resource = mc_get_resource(mc_obj, &mc TSRMLS_CC))==0) {
 		RETURN_FALSE;
@@ -728,7 +731,7 @@
 		RETURN_FALSE;
 	}

-	int ret=mcm_replace(mc->ctxt, mc->mc, key, key_len, data, data_len, expire, flags);
+	ret=mcm_replace(mc->ctxt, mc->mc, key, key_len, data, data_len, expire, flags);
 	smart_str_free(&buf);

 	if(ret==0) {
@@ -750,6 +753,8 @@
 	char *key;
 	int key_len;
 	long value = 1;
+	int ret;
+
 	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
 				&key, &key_len, &value)) {
 		return;
@@ -759,7 +764,7 @@
 		RETURN_FALSE;
 	}

-	int ret=mcm_incr(mc->ctxt, mc->mc, key, key_len, value);
+	ret=mcm_incr(mc->ctxt, mc->mc, key, key_len, value);

 	RETURN_LONG(ret);
 }
@@ -775,6 +780,8 @@
 	char *key;
 	int key_len;
 	long value = 1;
+	int ret;
+
 	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
 				&key, &key_len, &value)) {
 		return;
@@ -784,7 +791,7 @@
 		RETURN_FALSE;
 	}

-	int ret=mcm_decr(mc->ctxt, mc->mc, key, key_len, value);
+	ret=mcm_decr(mc->ctxt, mc->mc, key, key_len, value);

 	RETURN_LONG(ret);
 }


More information about the memcached mailing list