Skip to content

Commit 7aa0036

Browse files
nikicGirgias
authored andcommitted
Switch bound_param_map to zend_string
1 parent 1b31a76 commit 7aa0036

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

ext/pdo/pdo_sql_parser.re

+7-9
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct placeholder {
7676
};
7777

7878
static void free_param_name(zval *el) {
79-
efree(Z_PTR_P(el));
79+
zend_string_release(Z_PTR_P(el));
8080
}
8181

8282
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, zend_string *inquery, zend_string **outquery)
@@ -352,7 +352,7 @@ rewrite:
352352

353353
for (plc = placeholders; plc; plc = plc->next) {
354354
int skip_map = 0;
355-
char *p;
355+
zend_string *p;
356356
zend_string *idxbuf;
357357

358358
if (plc->bindno == PDO_PARSER_BINDNO_ESCAPED_CHAR) {
@@ -365,7 +365,7 @@ rewrite:
365365
if (!strcmp(name, "?") || (p = zend_hash_str_find_ptr(stmt->bound_param_map, name, plc->len)) == NULL) {
366366
idxbuf = zend_strpprintf(0, tmpl, bind_no++);
367367
} else {
368-
idxbuf = zend_string_init(p, strlen(p), 0);
368+
idxbuf = zend_string_copy(p);
369369
skip_map = 1;
370370
}
371371

@@ -374,11 +374,11 @@ rewrite:
374374

375375
if (!skip_map && stmt->named_rewrite_template) {
376376
/* create a mapping */
377-
zend_hash_str_update_mem(stmt->bound_param_map, name, plc->len, ZSTR_VAL(plc->quoted), ZSTR_LEN(plc->quoted) + 1);
377+
zend_hash_str_update_ptr(stmt->bound_param_map, name, plc->len, zend_string_copy(plc->quoted));
378378
}
379379

380380
/* map number to name */
381-
zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, ZSTR_VAL(plc->quoted), ZSTR_LEN(plc->quoted) + 1);
381+
zend_hash_index_update_ptr(stmt->bound_param_map, plc->bindno, zend_string_copy(plc->quoted));
382382

383383
efree(name);
384384
}
@@ -396,10 +396,8 @@ rewrite:
396396
}
397397

398398
for (plc = placeholders; plc; plc = plc->next) {
399-
char *name;
400-
name = estrndup(plc->pos, plc->len);
401-
zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1);
402-
efree(name);
399+
zend_string *name = zend_string_init(plc->pos, plc->len, 0);
400+
zend_hash_index_update_ptr(stmt->bound_param_map, plc->bindno, name);
403401
plc->quoted = ZSTR_CHAR('?');
404402
newbuffer_len -= plc->len - 1;
405403
}

ext/pdo/pdo_stmt.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p
5050
* we will raise an error, as we can't be sure that it is safe
5151
* to bind multiple parameters onto the same zval in the underlying
5252
* driver */
53-
char *name;
53+
zend_string *name;
5454
int position = 0;
5555

5656
if (stmt->named_rewrite_template) {
@@ -60,7 +60,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p
6060
if (!param->name) {
6161
/* do the reverse; map the parameter number to the name */
6262
if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) {
63-
param->name = zend_string_init(name, strlen(name), 0);
63+
param->name = zend_string_copy(name);
6464
return 1;
6565
}
6666
/* TODO Error? */
@@ -69,7 +69,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p
6969
}
7070

7171
ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) {
72-
if (strncmp(name, ZSTR_VAL(param->name), ZSTR_LEN(param->name) + 1)) {
72+
if (!zend_string_equals(name, param->name)) {
7373
position++;
7474
continue;
7575
}

ext/pdo_pgsql/pgsql_statement.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
275275
ZEND_ATOL(param->paramno, ZSTR_VAL(param->name) + 1);
276276
} else {
277277
/* resolve parameter name to rewritten name */
278-
char *namevar;
278+
zend_string *namevar;
279279

280280
if (stmt->bound_param_map && (namevar = zend_hash_find_ptr(stmt->bound_param_map,
281281
param->name)) != NULL) {
282-
ZEND_ATOL(param->paramno, namevar + 1);
282+
ZEND_ATOL(param->paramno, ZSTR_VAL(namevar) + 1);
283283
param->paramno--;
284284
} else {
285285
pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", ZSTR_VAL(param->name));

0 commit comments

Comments
 (0)