Skip to content

Commit af111b6

Browse files
committed
Merge pull request #41 from chrisws/0_11_20
0 12 6
2 parents e14b006 + a67be63 commit af111b6

File tree

28 files changed

+338
-312
lines changed

28 files changed

+338
-312
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2016-04-26 (0.12.6)
2+
Fixes for unit case sensitivity
3+
4+
2016-04-24 (0.12.6)
5+
Fixes for RUN/EXEC
6+
7+
2016-04-20 (0.12.6)
8+
Fixed memory handling issues with UNITs
9+
Fixed memory issue related to SUB/FUNC pointers
10+
111
2016-03-29 (0.12.6)
212
Removed TICKSPERSEC
313
Removed BALLOC, MALLOC and VADR keywords. Removed duplicate ENVIRON
@@ -32,6 +42,7 @@
3242
Fixed issues with CHAIN
3343
Fixed TLOAD to work correctly with TRY/CATCH
3444
Fixed XPOS and YPOS to return 0 based values
45+
Fixed compiler checking for redundant symbols, for example: let a = 1 2 3
3546

3647
2016-02-11
3748
Added export to mobile command (SDL)

Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ deb:
1313
test:
1414
(cd @TEST_DIR@ && make test)
1515

16+
leak-test:
17+
(cd src/platform/unix && make leak-test)
18+
1619
release:
1720
(cd $(SUBDIRS) && make release)
1821

configure.ac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ function buildConsole() {
336336
dnl preconfigured values for unix console build
337337
TARGET="Building Unix console version."
338338
AC_DEFINE(_UnixOS, 1, [Building under Unix like systems.])
339-
AC_DEFINE(USE_TERM_IO, 0, [Uses terminal-io functions.])
340339
AC_DEFINE(DEV_EVENTS_OSD, 0, [dev_events() implemented using osd_events().])
341340
PACKAGE_LIBS="${PACKAGE_LIBS} -lm -ldl -lpthread"
342341
BUILD_SUBDIRS="src/common src/platform/unix"
@@ -367,6 +366,9 @@ PACKAGE_CFLAGS="${PACKAGE_CFLAGS} -Wall -Wno-unused-result"
367366
BUILD_DATE=`date +"%a, %d %b %Y"`
368367
AC_DEFINE_UNQUOTED([BUILD_DATE],["$BUILD_DATE"],[Build date])
369368

369+
SB_DWORD_VER=`awk -F "." '{printf "0x%02d%02d%02d", $1,$2,$3}' <<< ${PACKAGE_VERSION}`
370+
AC_DEFINE_UNQUOTED([SB_DWORD_VER],[$SB_DWORD_VER],[SB_DWORD_VER])
371+
370372
AC_SUBST(PACKAGE_CFLAGS)
371373
AC_SUBST(PACKAGE_LIBS)
372374

ide/android/assets/main.bas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ sub do_okay_button()
5656
button.x = xmax / 2
5757
button.y = -1
5858
button.label = "Close"
59-
button.backgroundColor = "green"
60-
button.color = "white"
59+
button.backgroundColor = 8
60+
button.color = 10
6161
frm.inputs << button
6262
frm = form(frm)
6363
print
@@ -73,7 +73,7 @@ sub do_about()
7373
print
7474
print "Version "; sbver
7575
print
76-
print "Copyright (c) 2002-2015 Chris Warren-Smith"
76+
print "Copyright (c) 2002-2016 Chris Warren-Smith"
7777
print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10)
7878
print "http://smallbasic.sourceforge.net" + chr(10)
7979
print "SmallBASIC comes with ABSOLUTELY NO WARRANTY. ";

samples/distro-examples/tests/iifs.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ goto 200
3636
? "label 600 - Ok"
3737
goto 210
3838

39+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Hello world!
2+
I read: [Hello]+[ world!]
3+
NL=[Hello, world!]
4+
NL=[One more text line]

src/common/blib_func.c

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,49 +1451,8 @@ void cmd_strN(long funcCode, var_t *r) {
14511451
// Win32: use & at the end of the command to run-it in background
14521452
//
14531453
par_getstr(&arg1);
1454-
1455-
if (!prog_error) {
1456-
#if defined(_Win32)
1457-
char *buf;
1458-
#else
1459-
int bytes = 0, total = 0;
1460-
char buf[256];
1461-
#endif
1462-
1463-
#if defined(_Win32)
1464-
if ((buf = pw_shell(arg1.v.p.ptr)) != NULL) {
1465-
r->type = V_STR;
1466-
r->v.p.ptr = buf;
1467-
r->v.p.size = strlen(buf) + 1;
1468-
}
1469-
#else
1470-
/**
1471-
* default popen/pclose
1472-
*/
1473-
r->type = V_STR;
1474-
r->v.p.ptr = malloc(256);
1475-
*r->v.p.ptr = '\0';
1476-
r->v.p.size = 256;
1477-
1478-
FILE *fin = popen(arg1.v.p.ptr, "r");
1479-
if (fin) {
1480-
while (!feof(fin)) {
1481-
bytes = fread(buf, 1, 255, fin);
1482-
total += bytes;
1483-
buf[bytes] = '\0';
1484-
strcat(r->v.p.ptr, buf);
1485-
if (total + 256 >= r->v.p.size) {
1486-
r->v.p.size += 256;
1487-
r->v.p.ptr = realloc(r->v.p.ptr, r->v.p.size);
1488-
}
1489-
}
1490-
pclose(fin);
1491-
}
1492-
#endif // bcb or not
1493-
else {
1494-
v_zerostr(r);
1495-
rt_raise(ERR_RUNFUNC_FILE, arg1.v.p.ptr);
1496-
}
1454+
if (!prog_error && !dev_run(arg1.v.p.ptr, r, 1)) {
1455+
rt_raise(ERR_RUNFUNC_FILE, arg1.v.p.ptr);
14971456
}
14981457
break;
14991458

src/common/brun.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ void cmd_chain(void) {
469469
*/
470470
void cmd_run(int retf) {
471471
var_t var;
472-
473472
v_init(&var);
474473
eval(&var);
475474
IF_ERR_RETURN;
@@ -482,7 +481,7 @@ void cmd_run(int retf) {
482481
v_free(&var);
483482
}
484483

485-
if (!dev_run(fileName, retf)) {
484+
if (!dev_run(fileName, NULL, retf)) {
486485
err_run_err(fileName);
487486
}
488487
}
@@ -1196,7 +1195,9 @@ int brun_create_task(const char *filename, byte *preloaded_bc, int libf) {
11961195
lseek(h, sizeof(unit_sym_t) * uft.sym_count, SEEK_CUR);
11971196
}
11981197
read(h, &hdr, sizeof(bc_head_t));
1199-
1198+
if (hdr.sbver != SB_DWORD_VER) {
1199+
panic("File '%s' version incorrect", fname);
1200+
}
12001201
source = malloc(hdr.size + 4);
12011202
lseek(h, 0, SEEK_SET);
12021203
read(h, source, hdr.size);
@@ -1263,6 +1264,7 @@ int brun_create_task(const char *filename, byte *preloaded_bc, int libf) {
12631264
cp += sizeof(bc_lib_rec_t);
12641265
}
12651266
}
1267+
12661268
// build import-symbol table
12671269
if (prog_symcount) {
12681270
prog_symtable = (bc_symbol_rec_t *)malloc(prog_symcount * sizeof(bc_symbol_rec_t));
@@ -1271,21 +1273,22 @@ int brun_create_task(const char *filename, byte *preloaded_bc, int libf) {
12711273
cp += sizeof(bc_symbol_rec_t);
12721274
}
12731275
}
1276+
12741277
// create system stack
12751278
prog_stack_alloc = SB_EXEC_STACK_SIZE;
12761279
prog_stack = malloc(sizeof(stknode_t) * prog_stack_alloc);
12771280
prog_stack_count = 0;
12781281
prog_timer = NULL;
12791282

12801283
// create eval's stack
1281-
eval_size = 64;
1284+
eval_size = SB_EVAL_STACK_SIZE;
12821285
eval_stk = malloc(sizeof(var_t) * eval_size);
1286+
memset(eval_stk, 0, sizeof(var_t) * eval_size);
12831287
eval_sp = 0;
12841288

12851289
// initialize the rest tasks globals
12861290
prog_error = 0;
12871291
prog_line = 0;
1288-
12891292
prog_dp = data_org = hdr.data_ip;
12901293
prog_length = hdr.bc_count;
12911294
prog_source = cp;
@@ -1385,7 +1388,6 @@ int brun_create_task(const char *filename, byte *preloaded_bc, int libf) {
13851388
int exec_close_task() {
13861389
word i;
13871390
stknode_t node;
1388-
13891391
if (ctask->bytecode) {
13901392
// clean up - format list
13911393
free_format();
@@ -1402,15 +1404,14 @@ int exec_close_task() {
14021404
free(prog_stack);
14031405
// clean up - variables
14041406
for (i = 0; i < (int) prog_varcount; i++) {
1405-
int j, shared;
14061407
// do not free imported variables
1407-
shared = -1;
1408+
int shared = -1;
1409+
int j;
14081410
for (j = 0; j < prog_symcount; j++) {
1409-
if (prog_symtable[j].type == stt_variable) {
1410-
if (prog_symtable[j].var_id == i) {
1411-
shared = i;
1412-
break;
1413-
}
1411+
if (prog_symtable[j].type == stt_variable &&
1412+
prog_symtable[j].var_id == i) {
1413+
shared = j;
1414+
break;
14141415
}
14151416
}
14161417

@@ -1503,8 +1504,13 @@ void exec_sync_variables(int dir) {
15031504
activate_task(ps->task_id);
15041505
vp = tvar[us->vid];
15051506

1507+
// pointer assignment (shared var_t pointer)
15061508
activate_task(tid);
1507-
tvar[ps->var_id] = vp; // pointer assignment (shared var_t pointer)
1509+
if (tvar[ps->var_id] != vp) {
1510+
v_free(tvar[ps->var_id]);
1511+
free(tvar[ps->var_id]);
1512+
}
1513+
tvar[ps->var_id] = vp;
15081514
} else {
15091515
activate_task(tid);
15101516
vp = tvar[ps->var_id];

src/common/ceval.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ void cev_prim_args() {
141141
}
142142
}
143143

144+
// test for repeated primatives
145+
void cev_check_dup_prim() {
146+
switch (CODE(IP)) {
147+
case kwTYPE_INT:
148+
case kwTYPE_NUM:
149+
case kwTYPE_STR:
150+
case kwTYPE_VAR:
151+
case kwTYPE_CALLF:
152+
cev_opr_err();
153+
break;
154+
default:
155+
break;
156+
}
157+
}
158+
144159
/*
145160
* prim
146161
*/
@@ -153,25 +168,31 @@ void cev_prim() {
153168
case kwTYPE_INT:
154169
bc_add_n(bc_out, bc_in->ptr + bc_in->cp, OS_INTSZ);
155170
IP += OS_INTSZ;
171+
cev_check_dup_prim();
156172
break;
157173
case kwTYPE_NUM:
158174
bc_add_n(bc_out, bc_in->ptr + bc_in->cp, OS_REALSZ);
159175
IP += OS_REALSZ;
176+
cev_check_dup_prim();
160177
break;
161178
case kwTYPE_STR:
162179
cev_prim_str();
180+
cev_check_dup_prim();
163181
break;
164182
case kwTYPE_CALL_UDP:
165183
cev_udp();
184+
cev_check_dup_prim();
166185
break;
167186
case kwTYPE_PTR:
168187
bc_add_n(bc_out, bc_in->ptr + bc_in->cp, ADDRSZ); // addr
169188
IP += ADDRSZ;
170189
bc_add_n(bc_out, bc_in->ptr + bc_in->cp, ADDRSZ); // return var
171190
IP += ADDRSZ;
191+
cev_check_dup_prim();
172192
break;
173193
case kwTYPE_VAR:
174194
cev_prim_var();
195+
cev_check_dup_prim();
175196
break;
176197
case kwTYPE_CALL_UDF: // [udf1][addr2]
177198
case kwTYPE_CALLEXTF: // [lib][index]
@@ -188,6 +209,9 @@ void cev_prim() {
188209
cev_prim_args();
189210
}
190211
}
212+
if (code != kwBYREF) {
213+
cev_check_dup_prim();
214+
}
191215
break;
192216
};
193217
}

src/common/device.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@
1818
#define usleep(s) Sleep((DWORD)((s+500)/1000))
1919
#endif
2020

21-
/**
22-
* break signal
23-
*/
24-
#if defined(_UnixOS) || defined(_DOS)
25-
void termination_handler(int signum) {
26-
static int ctrlc_count;
27-
28-
prog_error = -2;
29-
ctrlc_count++;
30-
if (ctrlc_count == 1) {
31-
dev_printf("\n\n\033[0m\033[7m\a * %s %d * \033[0m\n", WORD_BREAK_AT, prog_line);
32-
} else if (ctrlc_count == 3) {
33-
dev_restore();
34-
exit(1);
35-
}
36-
}
37-
#endif
38-
3921
/**
4022
* initialize all drivers
4123
*/
@@ -398,26 +380,31 @@ void dev_printf(const char *fmt, ...) {
398380
* prints to the output device as per dev_printf
399381
*/
400382
void log_printf(const char *format, ...) {
401-
char buf[4096], *p = buf;
402383
va_list args;
403-
404384
va_start(args, format);
405-
p += vsnprintf(p, sizeof buf - 1, format, args);
385+
unsigned size = vsnprintf(NULL, 0, format, args);
406386
va_end(args);
407387

408-
while (p > buf && isspace(p[-1])) {
409-
*--p = '\0';
410-
}
388+
if (size) {
389+
char *buf = malloc(size + 3);
390+
va_start(args, format);
391+
vsnprintf(buf, size + 1, format, args);
392+
va_end(args);
411393

412-
*p++ = '\r';
413-
*p++ = '\n';
414-
*p = '\0';
394+
buf[size] = '\0';
395+
int i = size - 1;
396+
while (i >= 0 && isspace(buf[i])) {
397+
buf[i--] = '\0';
398+
}
399+
strcat(buf, "\r\n");
415400

416401
#if defined(IMPL_LOG_WRITE)
417-
lwrite(buf);
402+
lwrite(buf);
418403
#else
419-
dev_print(buf);
404+
dev_print(buf);
420405
#endif
406+
free(buf);
407+
}
421408
}
422409

423410
#if defined(BUILD_CONSOLE)

0 commit comments

Comments
 (0)