Skip to content

Commit 44de304

Browse files
author
Andrei Zmievski
committed
Modified to work with the new parameter parsing API as a demonstration.
1 parent 55f4d00 commit 44de304

File tree

1 file changed

+34
-43
lines changed

1 file changed

+34
-43
lines changed

ext/wddx/wddx.c

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -990,30 +990,22 @@ int php_wddx_deserialize_ex(char *value, int vallen, zval *return_value)
990990
Creates a new packet and serializes the given value */
991991
PHP_FUNCTION(wddx_serialize_value)
992992
{
993-
int argc;
994-
zval **var,
995-
**comment;
993+
zval *var;
994+
char *comment = NULL;
995+
int comment_len = 0;
996996
wddx_packet *packet;
997997

998-
argc = ZEND_NUM_ARGS();
999-
if(argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &var, &comment) == FAILURE) {
1000-
WRONG_PARAM_COUNT;
1001-
}
998+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|s",
999+
&var, &comment, &comment_len) == FAILURE)
1000+
return;
10021001

10031002
packet = php_wddx_constructor();
10041003
if (!packet) {
10051004
RETURN_FALSE;
10061005
}
10071006

1008-
if (argc == 2)
1009-
{
1010-
convert_to_string_ex(comment);
1011-
php_wddx_packet_start(packet, Z_STRVAL_PP(comment), Z_STRLEN_PP(comment));
1012-
}
1013-
else
1014-
php_wddx_packet_start(packet, NULL, 0);
1015-
1016-
php_wddx_serialize_var(packet, (*var), NULL, 0);
1007+
php_wddx_packet_start(packet, comment, comment_len);
1008+
php_wddx_serialize_var(packet, var, NULL, 0);
10171009
php_wddx_packet_end(packet);
10181010

10191011
ZVAL_STRINGL(return_value, packet->c, packet->len, 1);
@@ -1031,6 +1023,12 @@ PHP_FUNCTION(wddx_serialize_vars)
10311023
zval ***args;
10321024

10331025
argc = ZEND_NUM_ARGS();
1026+
if (argc < 1) {
1027+
php_error(E_WARNING, "%s() requires at least 1 argument, 0 given",
1028+
get_active_function_name());
1029+
return;
1030+
}
1031+
10341032
/* Allocate arguments array and get the arguments, checking for errors. */
10351033
args = (zval ***)emalloc(argc * sizeof(zval **));
10361034
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
@@ -1089,28 +1087,21 @@ void php_wddx_destructor(wddx_packet *packet)
10891087
Starts a WDDX packet with optional comment and returns the packet id */
10901088
PHP_FUNCTION(wddx_packet_start)
10911089
{
1092-
int argc;
1093-
zval **comment;
1090+
char *comment = NULL;
1091+
int comment_len = 0;
10941092
wddx_packet *packet;
10951093

10961094
comment = NULL;
1097-
argc = ZEND_NUM_ARGS();
10981095

1099-
if (argc > 1 || (argc == 1 && zend_get_parameters_ex(1, &comment)==FAILURE)) {
1100-
WRONG_PARAM_COUNT;
1101-
}
1096+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &comment, &comment_len) == FAILURE)
1097+
return;
11021098

11031099
packet = php_wddx_constructor();
11041100
if (!packet) {
11051101
RETURN_FALSE;
11061102
}
11071103

1108-
if (argc == 1) {
1109-
convert_to_string_ex(comment);
1110-
php_wddx_packet_start(packet, Z_STRVAL_PP(comment), Z_STRLEN_PP(comment));
1111-
} else
1112-
php_wddx_packet_start(packet, NULL, 0);
1113-
1104+
php_wddx_packet_start(packet, comment, comment_len);
11141105
php_wddx_add_chunk_static(packet, WDDX_STRUCT_S);
11151106

11161107
ZEND_REGISTER_RESOURCE(return_value, packet, le_wddx);
@@ -1121,26 +1112,25 @@ PHP_FUNCTION(wddx_packet_start)
11211112
Ends specified WDDX packet and returns the string containing the packet */
11221113
PHP_FUNCTION(wddx_packet_end)
11231114
{
1124-
zval **packet_id;
1115+
zval *packet_id;
11251116
wddx_packet *packet = NULL;
11261117

1127-
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &packet_id)==FAILURE) {
1128-
WRONG_PARAM_COUNT;
1129-
}
1118+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &packet_id) == FAILURE)
1119+
return;
11301120

1131-
ZEND_FETCH_RESOURCE(packet, wddx_packet *, packet_id, -1, "WDDX packet ID", le_wddx);
1121+
ZEND_FETCH_RESOURCE(packet, wddx_packet *, &packet_id, -1, "WDDX packet ID", le_wddx);
11321122

11331123
php_wddx_add_chunk_static(packet, WDDX_STRUCT_E);
11341124

11351125
php_wddx_packet_end(packet);
11361126

11371127
ZVAL_STRINGL(return_value, packet->c, packet->len, 1);
11381128

1139-
zend_list_delete(Z_LVAL_PP(packet_id));
1129+
zend_list_delete(Z_LVAL_P(packet_id));
11401130
}
11411131
/* }}} */
11421132

1143-
/* {{{ proto int wddx_add_vars(int packet_id [, mixed var_names [, mixed ...]])
1133+
/* {{{ proto int wddx_add_vars(int packet_id, mixed var_names [, mixed ...])
11441134
Serializes given variables and adds them to packet given by packet_id */
11451135
PHP_FUNCTION(wddx_add_vars)
11461136
{
@@ -1151,7 +1141,9 @@ PHP_FUNCTION(wddx_add_vars)
11511141

11521142
argc = ZEND_NUM_ARGS();
11531143
if (argc < 2) {
1154-
WRONG_PARAM_COUNT;
1144+
php_error(E_WARNING, "%s() requires at least 2 arguments, %d given",
1145+
get_active_function_name(), ZEND_NUM_ARGS());
1146+
return;
11551147
}
11561148

11571149
/* Allocate arguments array and get the arguments, checking for errors. */
@@ -1185,17 +1177,16 @@ PHP_FUNCTION(wddx_add_vars)
11851177
Deserializes given packet and returns a PHP value */
11861178
PHP_FUNCTION(wddx_deserialize)
11871179
{
1188-
zval **packet;
1180+
char *packet;
1181+
int packet_len;
11891182

1190-
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &packet) == FAILURE) {
1191-
WRONG_PARAM_COUNT;
1192-
}
1183+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &packet, &packet_len) == FAILURE)
1184+
return;
11931185

1194-
convert_to_string_ex(packet);
1195-
if (Z_STRLEN_PP(packet) == 0)
1186+
if (packet_len == 0)
11961187
return;
11971188

1198-
php_wddx_deserialize(*packet, return_value);
1189+
php_wddx_deserialize_ex(packet, packet_len, return_value);
11991190
}
12001191
/* }}} */
12011192

0 commit comments

Comments
 (0)