-
Notifications
You must be signed in to change notification settings - Fork 0
/
gwalker.c
165 lines (135 loc) · 3.3 KB
/
gwalker.c
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
/* gwalker extension for PHP */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "ext/standard/info.h"
#include "php_gwalker.h"
/* For compatibility with older PHP versions */
#ifndef ZEND_PARSE_PARAMETERS_NONE
#define ZEND_PARSE_PARAMETERS_NONE() \
ZEND_PARSE_PARAMETERS_START(0, 0) \
ZEND_PARSE_PARAMETERS_END()
#endif
/* {{{ void gwalker_test1()
*/
PHP_FUNCTION(gwalker_test1)
{
ZEND_PARSE_PARAMETERS_NONE();
php_printf("The extension %s is loaded and working!\r\n", "gwalker");
}
/* }}} */
/* {{{ string gwalker_test2( [ string $var ] )
*/
PHP_FUNCTION(gwalker_test2)
{
char *var = "World";
size_t var_len = sizeof("World") - 1;
zend_string *retval;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STRING(var, var_len)
ZEND_PARSE_PARAMETERS_END();
retval = strpprintf(0, "Hello %s", var);
RETURN_STR(retval);
}
/* }}}*/
PHP_FUNCTION(getSolutionOVQE)
{
double a = 0;
double b = 0;
double c = 0;
double x1 = 0;
double x2 = 0;
double detal = 0;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_DOUBLE(a)
Z_PARAM_DOUBLE(b)
Z_PARAM_OPTIONAL
Z_PARAM_DOUBLE(c)
ZEND_PARSE_PARAMETERS_END();
if (a == 0 && b == 0)
{
RETURN_FALSE;
}
array_init(return_value);
if (a == 0)
{
x1 = -1 * (c/b);
add_index_double(return_value, 0, x1);
return;
}
detal = pow(b, 2) - 4 * a * c;
if (detal == 0)
{
x1 = (-b + sqrt(detal)) / (2 * a);
add_index_double(return_value, 0, x1);
return;
}
else if (detal > 0)
{
x1 = (-b + sqrt(detal)) / (2 * a);
x2 = (-b - sqrt(detal)) / (2 * a);
add_index_double(return_value, 0, x1);
add_index_double(return_value, 1, x2);
return;
}
RETURN_FALSE;
}
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(gwalker)
{
#if defined(ZTS) && defined(COMPILE_DL_GWALKER)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(gwalker)
{
php_info_print_table_start();
php_info_print_table_header(2, "gwalker support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ arginfo
*/
ZEND_BEGIN_ARG_INFO(arginfo_gwalker_test1, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_gwalker_test2, 0)
ZEND_ARG_INFO(0, str)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ gwalker_functions[]
*/
static const zend_function_entry gwalker_functions[] = {
PHP_FE(gwalker_test1, arginfo_gwalker_test1)
PHP_FE(gwalker_test2, arginfo_gwalker_test2)
PHP_FE(getSolutionOVQE, NULL)
PHP_FE_END
};
/* }}} */
/* {{{ gwalker_module_entry
*/
zend_module_entry gwalker_module_entry = {
STANDARD_MODULE_HEADER,
"gwalker", /* Extension name */
gwalker_functions, /* zend_function_entry */
NULL, /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(gwalker), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(gwalker), /* PHP_MINFO - Module info */
PHP_GWALKER_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_GWALKER
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(gwalker)
#endif