Skip to content

Commit db75a4d

Browse files
committed
modify
1 parent 954b326 commit db75a4d

File tree

10 files changed

+402
-1
lines changed

10 files changed

+402
-1
lines changed

003.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@
2626
zend_uchar is_ref__gc; /* 是否引用 */
2727
};
2828

29-
3,宏
29+
3,zval类型
30+
31+
#define IS_NULL 0
32+
#define IS_LONG 1
33+
#define IS_DOUBLE 2
34+
#define IS_BOOL 3
35+
#define IS_ARRAY 4
36+
#define IS_OBJECT 5
37+
#define IS_STRING 6
38+
#define IS_RESOURCE 7
39+
#define IS_CONSTANT 8
40+
#define IS_CONSTANT_ARRAY 9
41+
#define IS_CALLABLE 10
42+
43+
4,宏
3044

3145
#宏的名字的规则,Z_XXXX -> zvale, Z_XXXX_P -> *zval, Z_XXXX_PP -> **zval
3246

codes/zval1/.svnignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.deps
2+
*.lo
3+
*.la

codes/zval1/CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zval1

codes/zval1/EXPERIMENTAL

Whitespace-only changes.

codes/zval1/config.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
dnl PHP_ARG_WITH(zval1, for zval1 support,
3+
dnl Make sure that the comment is aligned:
4+
dnl [ --with-zval1 Include zval1 support])
5+
6+
7+
PHP_ARG_ENABLE(zval1, whether to enable zval1 support,
8+
[ --enable-zval1 Enable zval1 support])
9+
10+
if test "$PHP_ZVAL1" != "no"; then
11+
PHP_NEW_EXTENSION(zval1, zval1.c, $ext_shared)
12+
fi

codes/zval1/config.w32

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
// If your extension references something external, use ARG_WITH
5+
// ARG_WITH("zval1", "for zval1 support", "no");
6+
7+
// Otherwise, use ARG_ENABLE
8+
// ARG_ENABLE("zval1", "enable zval1 support", "no");
9+
10+
if (PHP_ZVAL1 != "no") {
11+
EXTENSION("zval1", "zval1.c");
12+
}
13+

codes/zval1/php_zval1.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2015 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.txt |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifndef PHP_ZVAL1_H
22+
#define PHP_ZVAL1_H
23+
24+
extern zend_module_entry zval1_module_entry;
25+
#define phpext_zval1_ptr &zval1_module_entry
26+
27+
#define PHP_ZVAL1_VERSION "0.1.0" /* Replace with version number for your extension */
28+
29+
#ifdef PHP_WIN32
30+
# define PHP_ZVAL1_API __declspec(dllexport)
31+
#elif defined(__GNUC__) && __GNUC__ >= 4
32+
# define PHP_ZVAL1_API __attribute__ ((visibility("default")))
33+
#else
34+
# define PHP_ZVAL1_API
35+
#endif
36+
37+
#ifdef ZTS
38+
#include "TSRM.h"
39+
#endif
40+
41+
PHP_MINIT_FUNCTION(zval1);
42+
PHP_MSHUTDOWN_FUNCTION(zval1);
43+
PHP_RINIT_FUNCTION(zval1);
44+
PHP_RSHUTDOWN_FUNCTION(zval1);
45+
PHP_MINFO_FUNCTION(zval1);
46+
47+
PHP_FUNCTION(dump_zval_type);
48+
PHP_FUNCTION(dump_zval_value);
49+
50+
51+
/*
52+
Declare any global variables you may need between the BEGIN
53+
and END macros here:
54+
55+
ZEND_BEGIN_MODULE_GLOBALS(zval1)
56+
long global_value;
57+
char *global_string;
58+
ZEND_END_MODULE_GLOBALS(zval1)
59+
*/
60+
61+
/* In every utility function you add that needs to use variables
62+
in php_zval1_globals, call TSRMLS_FETCH(); after declaring other
63+
variables used by that function, or better yet, pass in TSRMLS_CC
64+
after the last function argument and declare your utility function
65+
with TSRMLS_DC after the last declared argument. Always refer to
66+
the globals in your function as ZVAL1_G(variable). You are
67+
encouraged to rename these macros something shorter, see
68+
examples in any other php module directory.
69+
*/
70+
71+
#ifdef ZTS
72+
#define ZVAL1_G(v) TSRMG(zval1_globals_id, zend_zval1_globals *, v)
73+
#else
74+
#define ZVAL1_G(v) (zval1_globals.v)
75+
#endif
76+
77+
#endif /* PHP_ZVAL1_H */
78+
79+
80+
/*
81+
* Local variables:
82+
* tab-width: 4
83+
* c-basic-offset: 4
84+
* End:
85+
* vim600: noet sw=4 ts=4 fdm=marker
86+
* vim<600: noet sw=4 ts=4
87+
*/

codes/zval1/tests/001.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Check for zval1 presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("zval1")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
echo "zval1 extension is available";
8+
/*
9+
you can add regression tests for your extension here
10+
11+
the output of your test code has to be equal to the
12+
text in the --EXPECT-- section below for the tests
13+
to pass, differences between the output and the
14+
expected text are interpreted as failure
15+
16+
see php5/README.TESTING for further information on
17+
writing regression tests
18+
*/
19+
?>
20+
--EXPECT--
21+
zval1 extension is available

codes/zval1/zval1.c

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2015 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.txt |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifdef HAVE_CONFIG_H
22+
#include "config.h"
23+
#endif
24+
25+
#include "php.h"
26+
#include "php_ini.h"
27+
#include "ext/standard/info.h"
28+
#include "php_zval1.h"
29+
30+
31+
ZEND_BEGIN_ARG_INFO(DUMP_ZVAL_TYPE_ARGINFO, 0)
32+
ZEND_ARG_INFO(0, zv)
33+
ZEND_END_ARG_INFO()
34+
35+
36+
ZEND_BEGIN_ARG_INFO(DUMP_ZVAL_VALUE_ARGINFO, 0)
37+
ZEND_ARG_INFO(0, zv)
38+
ZEND_END_ARG_INFO()
39+
40+
/* If you declare any globals in php_zval1.h uncomment this:
41+
ZEND_DECLARE_MODULE_GLOBALS(zval1)
42+
*/
43+
44+
/* True global resources - no need for thread safety here */
45+
static int le_zval1;
46+
47+
/* {{{ zval1_functions[]
48+
*
49+
* Every user visible function must have an entry in zval1_functions[].
50+
*/
51+
const zend_function_entry zval1_functions[] = {
52+
PHP_FE(dump_zval_type, DUMP_ZVAL_TYPE_ARGINFO)
53+
PHP_FE(dump_zval_value, DUMP_ZVAL_VALUE_ARGINFO)
54+
PHP_FE_END /* Must be the last line in zval1_functions[] */
55+
};
56+
/* }}} */
57+
58+
/* {{{ zval1_module_entry
59+
*/
60+
zend_module_entry zval1_module_entry = {
61+
#if ZEND_MODULE_API_NO >= 20010901
62+
STANDARD_MODULE_HEADER,
63+
#endif
64+
"zval1",
65+
zval1_functions,
66+
PHP_MINIT(zval1),
67+
PHP_MSHUTDOWN(zval1),
68+
PHP_RINIT(zval1), /* Replace with NULL if there's nothing to do at request start */
69+
PHP_RSHUTDOWN(zval1), /* Replace with NULL if there's nothing to do at request end */
70+
PHP_MINFO(zval1),
71+
#if ZEND_MODULE_API_NO >= 20010901
72+
PHP_ZVAL1_VERSION,
73+
#endif
74+
STANDARD_MODULE_PROPERTIES
75+
};
76+
/* }}} */
77+
78+
#ifdef COMPILE_DL_ZVAL1
79+
ZEND_GET_MODULE(zval1)
80+
#endif
81+
82+
/* {{{ PHP_INI
83+
*/
84+
/* Remove comments and fill if you need to have entries in php.ini
85+
PHP_INI_BEGIN()
86+
STD_PHP_INI_ENTRY("zval1.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_zval1_globals, zval1_globals)
87+
STD_PHP_INI_ENTRY("zval1.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_zval1_globals, zval1_globals)
88+
PHP_INI_END()
89+
*/
90+
/* }}} */
91+
92+
/* {{{ php_zval1_init_globals
93+
*/
94+
/* Uncomment this function if you have INI entries
95+
static void php_zval1_init_globals(zend_zval1_globals *zval1_globals)
96+
{
97+
zval1_globals->global_value = 0;
98+
zval1_globals->global_string = NULL;
99+
}
100+
*/
101+
/* }}} */
102+
103+
/* {{{ PHP_MINIT_FUNCTION
104+
*/
105+
PHP_MINIT_FUNCTION(zval1)
106+
{
107+
/* If you have INI entries, uncomment these lines
108+
REGISTER_INI_ENTRIES();
109+
*/
110+
return SUCCESS;
111+
}
112+
/* }}} */
113+
114+
/* {{{ PHP_MSHUTDOWN_FUNCTION
115+
*/
116+
PHP_MSHUTDOWN_FUNCTION(zval1)
117+
{
118+
/* uncomment this line if you have INI entries
119+
UNREGISTER_INI_ENTRIES();
120+
*/
121+
return SUCCESS;
122+
}
123+
/* }}} */
124+
125+
/* Remove if there's nothing to do at request start */
126+
/* {{{ PHP_RINIT_FUNCTION
127+
*/
128+
PHP_RINIT_FUNCTION(zval1)
129+
{
130+
return SUCCESS;
131+
}
132+
/* }}} */
133+
134+
/* Remove if there's nothing to do at request end */
135+
/* {{{ PHP_RSHUTDOWN_FUNCTION
136+
*/
137+
PHP_RSHUTDOWN_FUNCTION(zval1)
138+
{
139+
return SUCCESS;
140+
}
141+
/* }}} */
142+
143+
/* {{{ PHP_MINFO_FUNCTION
144+
*/
145+
PHP_MINFO_FUNCTION(zval1)
146+
{
147+
php_info_print_table_start();
148+
php_info_print_table_header(2, "zval1 support", "enabled");
149+
php_info_print_table_end();
150+
151+
/* Remove comments if you have entries in php.ini
152+
DISPLAY_INI_ENTRIES();
153+
*/
154+
}
155+
/* }}} */
156+
157+
158+
/* Remove the following function when you have successfully modified config.m4
159+
so that your module can be compiled into PHP, it exists only for testing
160+
purposes. */
161+
162+
/* Every user-visible function in PHP should document itself in the source */
163+
/* {{{ proto string confirm_zval1_compiled(string arg)
164+
Return a string to confirm that the module is compiled in */
165+
PHP_FUNCTION(dump_zval_type)
166+
{
167+
zval *zv;
168+
169+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zv) == FAILURE) {
170+
return;
171+
}
172+
173+
RETURN_LONG(Z_TYPE_P(zv));
174+
}
175+
/* }}} */
176+
177+
PHP_FUNCTION(dump_zval_value)
178+
{
179+
zval *zv;
180+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zv) == FAILURE) {
181+
return;
182+
}
183+
184+
switch(Z_TYPE_P(zv)) {
185+
case IS_NULL:
186+
RETURN_NULL();
187+
break;
188+
189+
case IS_LONG:
190+
RETURN_LONG(Z_LVAL_P(zv));
191+
break;
192+
193+
case IS_DOUBLE:
194+
RETURN_DOUBLE(Z_DVAL_P(zv));
195+
break;
196+
197+
case IS_BOOL:
198+
RETURN_BOOL(Z_BVAL_P(zv));
199+
break;
200+
201+
case IS_ARRAY:
202+
RETURN_ZVAL(zv, 1, 0);
203+
break;
204+
205+
case IS_STRING:
206+
RETURN_STRING(Z_STRVAL_P(zv), 0)
207+
break;
208+
209+
case IS_OBJECT:
210+
RETURN_ZVAL(zv, 1, 0);
211+
break;
212+
213+
}
214+
215+
}
216+
217+
218+
219+
/*
220+
* Local variables:
221+
* tab-width: 4
222+
* c-basic-offset: 4
223+
* End:
224+
* vim600: noet sw=4 ts=4 fdm=marker
225+
* vim<600: noet sw=4 ts=4
226+
*/

0 commit comments

Comments
 (0)