summaryrefslogtreecommitdiffstats
path: root/apcu-upstream.patch
blob: b21aeb67cc3bcc551a565e1dbc5e50fc3721260c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
diff --git a/apc_globals.h b/apc_globals.h
index 40509f0..a0de234 100644
--- a/apc_globals.h
+++ b/apc_globals.h
@@ -41,12 +41,12 @@
 ZEND_BEGIN_MODULE_GLOBALS(apcu)
     /* configuration parameters */
     zend_bool enabled;      /* if true, apc is enabled (defaults to true) */
-    long shm_segments;      /* number of shared memory segments to use */
-    long shm_size;          /* size of each shared memory segment (in MB) */
-    long entries_hint;      /* hint at the number of entries expected */
-    long gc_ttl;            /* parameter to apc_cache_create */
-    long ttl;               /* parameter to apc_cache_create */
-	long smart;             /* smart value */
+    zend_long shm_segments;      /* number of shared memory segments to use */
+    zend_long shm_size;          /* size of each shared memory segment (in MB) */
+    zend_long entries_hint;      /* hint at the number of entries expected */
+    zend_long gc_ttl;            /* parameter to apc_cache_create */
+    zend_long ttl;               /* parameter to apc_cache_create */
+	zend_long smart;             /* smart value */
 
 #if APC_MMAP
     char *mmap_file_mask;   /* mktemp-style file-mask to pass to mmap */
diff --git a/php_apc.c b/php_apc.c
index c35ede1..83fd758 100644
--- a/php_apc.c
+++ b/php_apc.c
@@ -118,11 +118,11 @@ static PHP_INI_MH(OnUpdateShmSize) /* {{{ */
         return FAILURE;
     }
 
-    if (s < 1048576L) {
+    if (s < Z_L(1048576)) {
         /* if it's less than 1Mb, they are probably using the old syntax */
         php_error_docref(	
 			NULL, E_WARNING, "apc.shm_size now uses M/G suffixes, please update your ini files");
-        s = s * 1048576L;
+        s = s * Z_L(1048576);
     }
 
     APCG(shm_size) = s;
@@ -526,60 +526,46 @@ PHP_FUNCTION(apcu_add) {
 /* {{{ php_inc_updater */
 
 struct php_inc_updater_args {
-    zend_long step;
-    zend_long lval;
+    zval step;
+    zval rval;
 };
 
 static zend_bool php_inc_updater(apc_cache_t* cache, apc_cache_entry_t* entry, void* data) {
     struct php_inc_updater_args *args = (struct php_inc_updater_args*) data;
 
     if (Z_TYPE(entry->val) == IS_LONG) {
-        while (args->step--) {
-			fast_long_increment_function(&entry->val);
-		}
-        args->lval = Z_LVAL(entry->val);
+        fast_long_add_function(&entry->val, &entry->val, &args->step);
+        ZVAL_COPY_VALUE(&args->rval, &entry->val);
         return 1;
     }
 
     return 0;
 }
 
-static zend_bool php_dec_updater(apc_cache_t* cache, apc_cache_entry_t* entry, void* data) {
-    struct php_inc_updater_args *args = (struct php_inc_updater_args*) data;
-
-    if (Z_TYPE(entry->val) == IS_LONG) {
-        while (args->step--) {
-			fast_long_decrement_function(&entry->val);
-		}
-        args->lval = Z_LVAL(entry->val);
-        return 1;
-    }
-
-    return 0;
-}
-/* }}} */
-
 /* {{{ proto long apc_inc(string key [, long step [, bool& success]])
  */
 PHP_FUNCTION(apcu_inc) {
     zend_string *key;
-    struct php_inc_updater_args args = {1L, -1};
+    struct php_inc_updater_args args;
+    zend_long step = 1;
     zval *success = NULL;
 
-    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lz", &key, &(args.step), &success) == FAILURE) {
+    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lz", &key, &step, &success) == FAILURE) {
         return;
     }
-    
+
 	if (success) {
 		ZVAL_DEREF(success);
 		zval_ptr_dtor(success);
 	}
 
+	ZVAL_LONG(&args.step, step);
+
     if (php_apc_update(key, php_inc_updater, &args)) {
         if (success) {
 			ZVAL_TRUE(success);
 		}
-        RETURN_LONG(args.lval);
+        RETURN_ZVAL(&args.rval, 0, 0);
     }
     
     if (success) {
@@ -594,24 +580,27 @@ PHP_FUNCTION(apcu_inc) {
  */
 PHP_FUNCTION(apcu_dec) {
     zend_string *key;
-    struct php_inc_updater_args args = {1L, -1};
+    struct php_inc_updater_args args;
+    zend_long step = 1;
     zval *success = NULL;
 
-    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lz", &key, &(args.step), &success) == FAILURE) {
+    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lz", &key, &step, &success) == FAILURE) {
         return;
     }
-    
+
 	if (success) {
 		ZVAL_DEREF(success);
 		zval_ptr_dtor(success);
 	}
 
-    if (php_apc_update(key, php_dec_updater, &args)) {
+	ZVAL_LONG(&args.step, 0 - step);
+
+    if (php_apc_update(key, php_inc_updater, &args)) {
         if (success) {
 			ZVAL_TRUE(success);
 		}
 
-        RETURN_LONG(args.lval);
+        RETURN_ZVAL(&args.rval, 0, 0);
     }
     
     if (success) {
@@ -662,9 +651,7 @@ PHP_FUNCTION(apcu_cas) {
 PHP_FUNCTION(apcu_fetch) {
     zval *key;
     zval *success = NULL;
-    apc_cache_entry_t* entry;
     time_t t;
-    apc_context_t ctxt = {0,};
 
     if (!APCG(enabled)) {
 		RETURN_FALSE;
diff --git a/tests/apc_012.phpt b/tests/apc_012.phpt
index e7844ef..0d3b050 100644
--- a/tests/apc_012.phpt
+++ b/tests/apc_012.phpt
@@ -10,25 +10,28 @@ apc.enable_cli=1
 $key="testkey";
 $i=PHP_INT_MAX;
 apcu_store($key, $i);
-$j=apcu_fetch($key);
+var_dump($j=apcu_fetch($key));
 var_dump($i==$j);
 
 apcu_inc($key, 1);
 $i++;
-$j=apcu_fetch($key);
+var_dump($j=apcu_fetch($key));
 var_dump($i==$j);
 
 $i=PHP_INT_MIN;
 apcu_store($key, $i);
 apcu_dec($key, 1);
 $i--;
-$j=apcu_fetch($key);
+var_dump($j=apcu_fetch($key));
 var_dump($i==$j);
 ?>
 ===DONE===
 <?php exit(0); ?>
---EXPECT--
+--EXPECTF--
+int(%d)
 bool(true)
+float(%s)
 bool(true)
+float(%s)
 bool(true)
 ===DONE===
diff --git a/tests/apc_inc_perf.phpt b/tests/apc_inc_perf.phpt
new file mode 100644
index 0000000..8f082f1
--- /dev/null
+++ b/tests/apc_inc_perf.phpt
@@ -0,0 +1,28 @@
+--TEST--
+APC: apcu_inc/apcu_dec performance test (gh#164)
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--INI--
+apc.enabled=1
+apc.enable_cli=1
+apc.file_update_protection=0
+--FILE--
+<?php
+apcu_store('foobar', 1);
+$t = microtime(true);
+var_dump(apcu_inc('foobar', 0x76543210));
+var_dump(apcu_dec('foobar', 0x76543210));
+var_dump(apcu_dec('foobar', -999999999));
+var_dump(apcu_inc('foobar', -999999999));
+$t = microtime(true) - $t;
+var_dump($t < 0.1 ? true : $t);
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+int(1985229329)
+int(1)
+int(1000000000)
+int(1)
+bool(true)
+===DONE===