fix memory being freed too early

This commit is contained in:
William Bell
2025-08-10 04:39:50 +01:00
parent 49b1c1858a
commit c71375c7a4
12 changed files with 126 additions and 73 deletions

View File

@@ -63,6 +63,7 @@ ArgonObject *get_field_for_class_l(ArgonObject *target, char *name,
ArgonObject *get_field_l(ArgonObject *target, char *name, size_t length,
bool recursive, bool disable_method_wrapper) {
if(!target|| !target->dict) return NULL;
char *field = "__class__";
size_t field_size = strlen(field);
ArgonObject *object = hashmap_lookup_GC(

View File

@@ -0,0 +1,28 @@
/*
* SPDX-FileCopyrightText: 2025 William Bell
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "term.h"
#include <stddef.h>
#include <stdio.h>
#include "../../call/call.h"
ArgonObject *term_log(size_t argc, ArgonObject **argv, ArErr *err,
RuntimeState *state) {
for (size_t i = 0; i < argc; i++) {
if (i != 0)
printf(" ");
ArgonObject *string_convert_method = get_field_for_class(
get_field(argv[i], "__class__", false, false), "__string__", argv[i]);
if (string_convert_method) {
ArgonObject *string_object =
argon_call(string_convert_method, 0, NULL, err, state);
fwrite(string_object->value.as_str.data, sizeof(char),
string_object->value.as_str.length, stdout);
}
}
printf("\n");
return ARGON_NULL;
}

View File

@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: 2025 William Bell
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef runtime_term_H
#define runtime_term_H
#include "../../objects/literals/literals.h"
#include "../../objects/object.h"
#include "../../runtime.h"
ArgonObject *term_log(size_t argc, ArgonObject **argv, ArErr *err,
RuntimeState *state);
#endif // runtime_term_H