<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Jacob,<br>
<br>
Thanks for the patch. This does indeed seem to be the problem and
affects older versions of gcc (and other compilers?). I only have
boxes with 3.3.x or later so I haven't properly tested on older ones.
I'll roll this fix into the next release. I actually had another email
off list from someone else with the same problem, but they ended up
just upgrading gcc.<br>
<br>
John<br>
<br>
Jacob Coby wrote:
<blockquote cite="mid426D031C.1080404@listingbook.com" type="cite">Jon
Valvatne wrote:
<br>
<blockquote type="cite">Hello list,
<br>
<br>
I'm having some trouble compiling php-mcache with php-4.3.11 and
<br>
libmemcache-1.2.4. Now I suspect this is somehow caused by some aspect
of
<br>
my PHP installation, but I have no idea how PHP extensions work, so I'm
lost.
<br>
</blockquote>
<br>
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?)
<br>
<br>
diff attached that fixes the problem and should compile for you. I did
not test if the resulting mcache.o works.
<br>
<br>
> Any ideas?
<br>
>
<br>
> $ phpize
<br>
> Configuring for:
<br>
> PHP Api Version: 20020918
<br>
> Zend Module Api No: 20020429
<br>
> Zend Extension Api No: 20021010
<br>
>
<br>
> $ ./configure --with-mcache=/usr/src/libmemcache-1.2.4
<br>
> creating cache ./config.cache
<br>
> checking host system type... i686-pc-linux-gnu
<br>
> checking for gcc... gcc
<br>
> checking whether the C compiler (gcc ) works... yes
<br>
> checking whether the C compiler (gcc ) is a cross-compiler... no
<br>
> checking whether we are using GNU C... yes
<br>
> checking whether gcc accepts -g... yes
<br>
> checking whether gcc and cc understand -c and -o together... yes
<br>
> checking if compiler supports -R... no
<br>
> checking if compiler supports -Wl,-rpath,... yes
<br>
> checking for PHP prefix... /usr/local
<br>
> 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
<br>
> checking for PHP extension directory...
/usr/local/lib/php/extensions/no-debug-non-zts-20020429
<br>
> checking for re2c... exit 0;
<br>
> checking for mawk... mawk
<br>
> checking for mcache support... yes, shared
<br>
> checking for Cygwin environment... no
<br>
> checking for mingw32 environment... no
<br>
> checking how to run the C preprocessor... gcc -E
<br>
> checking build system type... i686-pc-linux-gnu
<br>
> checking for ld used by GCC... /usr/bin/ld
<br>
> checking if the linker (/usr/bin/ld) is GNU ld... yes
<br>
> checking for /usr/bin/ld option to reload object files... -r
<br>
> checking for BSD-compatible nm... /usr/bin/nm -B
<br>
> checking for a sed that does not truncate output... /bin/sed
<br>
> checking whether ln -s works... yes
<br>
> checking how to recognise dependent libraries... pass_all
<br>
> checking for object suffix... o
<br>
> checking for executable suffix... no
<br>
> checking command to parse /usr/bin/nm -B output... ok
<br>
> checking for dlfcn.h... yes
<br>
> checking for ranlib... ranlib
<br>
> checking for strip... strip
<br>
> checking for objdir... .libs
<br>
> checking for gcc option to produce PIC... -fPIC
<br>
> checking if gcc PIC flag -fPIC works... yes
<br>
> checking if gcc static flag -static works... yes
<br>
> checking if gcc supports -c -o file.o... yes
<br>
> checking if gcc supports -c -o file.lo... yes
<br>
> checking if gcc supports -fno-rtti -fno-exceptions... yes
<br>
> checking whether the linker (/usr/bin/ld) supports shared
libraries... yes
<br>
> checking how to hardcode library paths into programs... immediate
<br>
> checking whether stripping libraries is possible... yes
<br>
> checking dynamic linker characteristics... GNU/Linux ld.so
<br>
> checking if libtool supports shared libraries... yes
<br>
> checking whether to build shared libraries... yes
<br>
> checking whether to build static libraries... no
<br>
> checking whether -lc should be explicitly linked in... no
<br>
> creating libtool
<br>
> updating cache ./config.cache
<br>
> creating ./config.status
<br>
> creating config.h
<br>
>
<br>
> $ make
<br>
> /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
<br>
> 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
<br>
> In file included from /usr/src/php-mcache-ext-1.1.4/mcache.c:33:
<br>
> <snip> standard libmemcache warnings ("assignment discards
qualifiers from pointer target type")
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function
`zm_startup_mcache':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:158: parse error before
`mcache_class_entry'
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:159: `mcache_class_entry'
undeclared (first use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:159: (Each undeclared
identifier is reported only once
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:159: for each function it
appears in.)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function
`zif_memcache':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:386: parse error before
`new_le'
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:391: `mc' undeclared (first
use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:402: `id' undeclared (first
use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_get':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:589: parse error before
`int'
<br>
> /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
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:598: `i' undeclared (first
use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_set':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:667: parse error before
`int'
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:670: `ret' undeclared
(first use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_add':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:699: parse error before
`int'
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:702: `ret' undeclared
(first use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_replace':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:731: parse error before
`int'
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:734: `ret' undeclared
(first use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_incr':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:762: parse error before
`int'
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:764: `ret' undeclared
(first use in this function)
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c: In function `zif_decr':
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:787: parse error before
`int'
<br>
> /usr/src/php-mcache-ext-1.1.4/mcache.c:789: `ret' undeclared
(first use in this function)
<br>
> make: *** [mcache.lo] Error 1
<br>
>
<br>
> $ cat /proc/version
<br>
> Linux version 2.4.25-bf2.4 (root@oss) (gcc version 3.2.3 (Debian))
#1 SMP Wed Mar 10 10:35:09 PST 2004
<br>
>
<br>
>
<br>
<br>
<pre wrap="">
<hr size="4" width="90%">
--- 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);
}
</pre>
</blockquote>
<br>
</body>
</html>