Improve memory by not duplicating mstdnt perl strings

FossilOrigin-Name: aaa960e3a3c6c89429dbb2210b9693bfbd79f84e824053cee9b5d2eb7dde7f8b
This commit is contained in:
nekobit 2022-10-15 21:05:44 +00:00
parent 4ad40369e9
commit 8fdb143303
2 changed files with 8 additions and 7 deletions

View File

@ -22,9 +22,12 @@
#include <perl.h>
#include <pthread.h>
// hv_stores(ssn_hv, "id", newSVpv(acct->id, 0));
// TODO use sv_usepvn_flags soon
#define hvstores_str(hv, key, val) if ((val)) { hv_stores((hv), key, newSVpvn((val), strlen(val))); }
// Note: val MUST be a pointer to a value, and must end with a \0 (hence SvSETMAGIC)
#define hvstores_str(hv, key, val) if (val) { \
SV* tmpsv = newSV(0); \
sv_usepvn_flags(tmpsv, val, strlen(val), SvSETMAGIC); \
hv_stores((hv), key, tmpsv); \
}
#define hvstores_int(hv, key, val) hv_stores((hv), key, newSViv((val)))
#define hvstores_ref(hv, key, val) if (1) { \
SV* tmp = (SV*)(val); \

View File

@ -16,8 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <EXTERN.h>
#include <perl.h>
#include "global_perl.h"
#include <pthread.h>
#include <string.h>
@ -251,10 +249,10 @@ int main(int argc, char **argv, char **env)
init_template_files(aTHX);
// Setup mstdnt hooks
// Setup mstdnt hooks to use Perl functions
struct mstdnt_hooks hooks = {
.malloc = safemalloc,
// Not sure how this differs from Safefree?
// Not sure how this differs from Safefree? That's undefined... (but used elsewhere in the code just fine)
.free = safefree,
.calloc = safecalloc,
.realloc = saferealloc,