Skip to content

Commit 31d3875

Browse files
committed
ext/dba: switch dba_handlers full_info path to zend_string API
1 parent a22c56c commit 31d3875

14 files changed

Lines changed: 24 additions & 21 deletions

ext/dba/dba.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,10 +1282,8 @@ PHP_FUNCTION(dba_handlers)
12821282

12831283
for (const dba_handler *hptr = handler; hptr->name; hptr++) {
12841284
if (full_info) {
1285-
// TODO: avoid reallocation ???
1286-
char *str = hptr->info(hptr, NULL);
1287-
add_assoc_string(return_value, hptr->name, str);
1288-
efree(str);
1285+
zend_string *str = hptr->info(hptr, NULL);
1286+
add_assoc_str(return_value, hptr->name, str);
12891287
} else {
12901288
add_next_index_string(return_value, hptr->name);
12911289
}

ext/dba/dba_cdb.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,16 @@ DBA_SYNC_FUNC(cdb)
318318
DBA_INFO_FUNC(cdb)
319319
{
320320
#ifdef DBA_CDB_BUILTIN
321+
char* version_str = NULL;
321322
if (!strcmp(hnd->name, "cdb")) {
322-
return estrdup(cdb_version());
323+
version_str = cdb_version();
324+
return zend_string_init(cdb_version, strlen(cdb_version), false);
323325
} else {
324-
return estrdup(cdb_make_version());
326+
version_str = cdb_make_version();
327+
return zend_string_init(cdb_version, strlen(cdb_version), false);
325328
}
326329
#else
327-
return estrdup("External");
330+
return zend_string_init("External", strlen("External"), false);
328331
#endif
329332
}
330333

ext/dba/dba_db1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ DBA_SYNC_FUNC(db1)
177177

178178
DBA_INFO_FUNC(db1)
179179
{
180-
return estrdup(DB1_VERSION);
180+
return zend_string_init(DB1_VERSION, strlen(DB1_VERSION), false);
181181
}
182182

183183
#endif

ext/dba/dba_db2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ DBA_SYNC_FUNC(db2)
187187

188188
DBA_INFO_FUNC(db2)
189189
{
190-
return estrdup(DB_VERSION_STRING);
190+
return zend_string_init(DB_VERSION_STRING, strlen(DB_VERSION_STRING), false);
191191
}
192192

193193
#endif

ext/dba/dba_db3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ DBA_SYNC_FUNC(db3)
225225

226226
DBA_INFO_FUNC(db3)
227227
{
228-
return estrdup(DB_VERSION_STRING);
228+
return zend_string_init(DB_VERSION_STRING, strlen(DB_VERSION_STRING), false);
229229
}
230230

231231
#endif

ext/dba/dba_db4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ DBA_SYNC_FUNC(db4)
282282

283283
DBA_INFO_FUNC(db4)
284284
{
285-
return estrdup(DB_VERSION_STRING);
285+
return zend_string_init(DB_VERSION_STRING, strlen(DB_VERSION_STRING), false);
286286
}
287287

288288
#endif

ext/dba/dba_dbm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ DBA_INFO_FUNC(dbm)
192192
return dba_info_gdbm(hnd, info);
193193
}
194194
#endif
195-
return estrdup(DBM_VERSION);
195+
return zend_string_init(DBM_VERSION, strlen(DBM_VERSION), false);
196196
}
197197

198198
#endif

ext/dba/dba_flatfile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ DBA_SYNC_FUNC(flatfile)
166166
}
167167

168168
DBA_INFO_FUNC(flatfile)
169-
{
170-
return estrdup(flatfile_version());
169+
{
170+
char* version = flatfile_version();
171+
return zend_string_init(version, strlen(version), false);
171172
}
172173

173174
#endif

ext/dba/dba_inifile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ DBA_SYNC_FUNC(inifile)
186186

187187
DBA_INFO_FUNC(inifile)
188188
{
189-
return estrdup(inifile_version());
189+
const char* version = inifile_version();
190+
return zend_string_init(version, strlen(version), false);
190191
}
191192

192193
#endif

ext/dba/dba_lmdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ DBA_SYNC_FUNC(lmdb)
360360

361361
DBA_INFO_FUNC(lmdb)
362362
{
363-
return estrdup(MDB_VERSION_STRING);
363+
return zend_string_init(MDB_VERSION_STRING, strlen(MDB_VERSION_STRING), false);
364364
}
365365

366366
#endif

0 commit comments

Comments
 (0)