Skip to content

Commit d63adf7

Browse files
authored
Merge pull request #197 from chrisws/12_27
12 27
2 parents e55c8c7 + e2413b1 commit d63adf7

File tree

24 files changed

+227
-106
lines changed

24 files changed

+227
-106
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2023-06-18 (12.27)
2+
COMMON: Fix redim regression
3+
PLUGINS: Added mechanism for cleaning up resources when the associated map falls out of scope
4+
5+
2023-05-12 (12.27)
6+
CONSOLE: Fix image save
7+
ANDROID: Fix download error when there are duplicate scratch.bas files
8+
19
2023-03-26 (12.26)
210
ANDROID: Fix setenv error #187
311
ANDROID: update web UI dependencies

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [12.26])
10+
AC_INIT([smallbasic], [12.27])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

samples/distro-examples/tests/array.bas

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,4 +426,15 @@ p(asc("|")) = 1
426426
p(asc("}")) = 1
427427
p(asc("~")) = 1
428428

429+
'
430+
' https://www.syntaxbomb.com/smallbasic/redim-why-to-keep-old-versons/
431+
'
432+
a = [0,1,2,3,4,5,6,7,8,9,10,11]
433+
redim a(11) : if a != [0,1,2,3,4,5,6,7,8,9,10,11] then throw str(a)
434+
redim a(1, 11) : if a != [0,1,2,3,4,5,6,7,8,9,10,11;0,0,0,0,0,0,0,0,0,0,0,0] then throw str(a)
435+
redim a(2, 10) : if a != [0,1,2,3,4,5,6,7,8,9,10;11,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0] then throw str(a)
436+
redim a(1, 11) : if a != [0,1,2,3,4,5,6,7,8,9,10,11;0,0,0,0,0,0,0,0,0,0,0,0] then throw str(a)
437+
redim a(10) : if a != [0,1,2,3,4,5,6,7,8,9,10] then throw str(a)
438+
redim a(0 to 7): if a != [0,1,2,3,4,5,6,7] then throw str(a)
439+
redim a(0 to 1): if a != [0,1] then throw str(a)
429440

src/common/blib.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ void cmd_dim(int preserve) {
210210
}
211211
if (!preserve || var_p->type != V_ARRAY) {
212212
v_new_array(var_p, size);
213-
} else if (v_maxdim(var_p) != dimensions) {
214-
err_matdim();
215213
} else {
216214
// preserve previous array contents
217215
v_resize_array(var_p, size);

src/common/hashmap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ void hashmap_create(var_p_t map, int size) {
126126
map->type = V_MAP;
127127
map->v.m.count = 0;
128128
map->v.m.id = -1;
129+
map->v.m.lib_id = -1;
130+
map->v.m.cls_id = -1;
129131
if (size == 0) {
130132
map->v.m.size = MAP_SIZE;
131133
} else {

src/common/plugins.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typedef int (*sblib_exec_fn)(int, int, slib_par_t *, var_t *);
3939
typedef int (*sblib_getname_fn) (int, char *);
4040
typedef int (*sblib_count_fn) (void);
4141
typedef int (*sblib_init_fn) (const char *);
42+
typedef int (*sblib_free_fn) (int, int);
4243
typedef void (*sblib_close_fn) (void);
4344

4445
typedef struct {
@@ -47,6 +48,7 @@ typedef struct {
4748
void *_handle;
4849
sblib_exec_fn _sblib_proc_exec;
4950
sblib_exec_fn _sblib_func_exec;
51+
sblib_free_fn _sblib_free;
5052
ext_func_node_t *_func_list;
5153
ext_proc_node_t *_proc_list;
5254
uint32_t _id;
@@ -304,6 +306,7 @@ static void slib_import_routines(slib_t *lib, int comp) {
304306

305307
lib->_sblib_func_exec = slib_getoptptr(lib, "sblib_func_exec");
306308
lib->_sblib_proc_exec = slib_getoptptr(lib, "sblib_proc_exec");
309+
lib->_sblib_free = slib_getoptptr(lib, "sblib_free");
307310
sblib_count_fn fcount = slib_getoptptr(lib, "sblib_proc_count");
308311
sblib_getname_fn fgetname = slib_getoptptr(lib, "sblib_proc_getname");
309312

@@ -471,6 +474,10 @@ static int slib_exec(slib_t *lib, var_t *ret, int index, int proc) {
471474
free(ptable);
472475
}
473476

477+
if (success && v_is_type(ret, V_MAP)) {
478+
map_set_lib_id(ret, lib->_id);
479+
}
480+
474481
return success;
475482
}
476483

@@ -598,6 +605,13 @@ int plugin_funcexec(int lib_id, int index, var_t *ret) {
598605
return result;
599606
}
600607

608+
void plugin_free(int lib_id, int cls_id, int id) {
609+
slib_t *lib = get_lib(lib_id);
610+
if (lib && lib->_sblib_free) {
611+
lib->_sblib_free(cls_id, id);
612+
}
613+
}
614+
601615
void plugin_close() {
602616
for (int i = 0; i < MAX_SLIBS; i++) {
603617
if (plugins[i]) {
@@ -626,5 +640,6 @@ int plugin_get_kid(int lib_id, const char *keyword) { return -1; }
626640
void *plugin_get_func(const char *name) { return 0; }
627641
int plugin_procexec(int lib_id, int index) { return -1; }
628642
int plugin_funcexec(int lib_id, int index, var_t *ret) { return -1; }
643+
void plugin_free(int lib_id, int cls_id, int id) {}
629644
void plugin_close() {}
630645
#endif

src/common/plugins.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ int plugin_procexec(int lib_id, int index);
5555
//
5656
int plugin_funcexec(int lib_id, int index, var_t *ret);
5757

58+
//
59+
// cleanup any resources held against the map data
60+
//
61+
void plugin_free(int lib_id, int cls_id, int id);
62+
5863
//
5964
// closes the plugin system
6065
//

src/common/var.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ void v_move(var_t *dest, const var_t *src) {
555555
break;
556556
case V_ARRAY:
557557
memcpy(&dest->v.a, &src->v.a, sizeof(src->v.a));
558+
v_maxdim(dest) = v_maxdim(src);
558559
break;
559560
case V_PTR:
560561
dest->v.ap.p = src->v.ap.p;
@@ -565,6 +566,8 @@ void v_move(var_t *dest, const var_t *src) {
565566
dest->v.m.count = src->v.m.count;
566567
dest->v.m.size = src->v.m.size;
567568
dest->v.m.id = src->v.m.id;
569+
dest->v.m.lib_id = src->v.m.lib_id;
570+
dest->v.m.cls_id = src->v.m.cls_id;
568571
break;
569572
case V_REF:
570573
dest->v.ref = src->v.ref;

0 commit comments

Comments
 (0)