Skip to content

Commit 2368d87

Browse files
committed
COMMON: fix crash on osx
1 parent a91b156 commit 2368d87

File tree

10 files changed

+39
-34
lines changed

10 files changed

+39
-34
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2018-01-13 (0.12.12)
2+
Fix osx crash
3+
14
2017-11-28 (0.12.11)
25
Fix img.save(dat) to build correct indexes
36
Fix ESCm implementation bug

src/common/blib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ void cmd_print(int output) {
513513
byte last_op = 0;
514514
byte exitf = 0;
515515
byte use_format = 0;
516-
int handle = 0;
516+
intptr_t handle = 0;
517517
var_t var;
518518

519519
// prefix - # (file)
@@ -654,7 +654,7 @@ void cmd_input(int input) {
654654
byte print_crlf = 1;
655655
var_t prompt;
656656
var_t *vuser_p = NULL;
657-
int handle = 0;
657+
intptr_t handle = 0;
658658
char *inps = NULL;
659659

660660
v_init(&prompt);

src/common/blib_db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ void cmd_floadln() {
672672
void cmd_fsaveln() {
673673
var_t file_name, *array_p = NULL, *var_p = NULL;
674674
int flags = DEV_FILE_OUTPUT;
675-
int handle;
675+
intptr_t handle;
676676

677677
if (code_peek() == kwTYPE_SEP) {
678678
// "filename" is an already open file number

src/common/fmt.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int fmt_cdig(char *fmt);
4141
char *fmt_getnumfmt(char *dest, char *source);
4242
char *fmt_getstrfmt(char *dest, char *source);
4343
void fmt_addfmt(const char *fmt, int type);
44-
void fmt_printL(int output, int handle);
44+
void fmt_printL(int output, intptr_t handle);
4545

4646
typedef struct {
4747
char *fmt; // the format or a string
@@ -787,7 +787,7 @@ void build_format(const char *fmt_cnst) {
787787
/*
788788
* print simple strings (parts of format)
789789
*/
790-
void fmt_printL(int output, int handle) {
790+
void fmt_printL(int output, intptr_t handle) {
791791
if (fmt_count == 0) {
792792
return;
793793
} else {
@@ -808,15 +808,16 @@ void fmt_printL(int output, int handle) {
808808
/*
809809
* print formated number
810810
*/
811-
void fmt_printN(var_num_t x, int output, int handle) {
811+
void fmt_printN(var_num_t x, int output, intptr_t handle) {
812812
if (fmt_count == 0) {
813813
rt_raise(ERR_FORMAT_INVALID_FORMAT);
814814
} else {
815815
fmt_printL(output, handle);
816816
fmt_node_t *node = &fmt_stack[fmt_cur];
817817
fmt_cur++;
818-
if (fmt_cur >= fmt_count)
818+
if (fmt_cur >= fmt_count) {
819819
fmt_cur = 0;
820+
}
820821
if (node->type == 1) {
821822
char *buf = format_num(node->fmt, x);
822823
pv_write(buf, output, handle);
@@ -833,7 +834,7 @@ void fmt_printN(var_num_t x, int output, int handle) {
833834
/*
834835
* print formated string
835836
*/
836-
void fmt_printS(const char *str, int output, int handle) {
837+
void fmt_printS(const char *str, int output, intptr_t handle) {
837838
if (fmt_count == 0) {
838839
rt_raise(ERR_FORMAT_INVALID_FORMAT);
839840
} else {

src/common/fmt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void free_format(void);
118118
* @param output is the output-set-of-routines code (see PV_xxx macros)
119119
* @param handle is the output handle (depented on output-code)
120120
*/
121-
void fmt_printN(var_num_t x, int output, int handle);
121+
void fmt_printN(var_num_t x, int output, intptr_t handle);
122122

123123
/**
124124
* @ingroup str
@@ -131,7 +131,7 @@ void fmt_printN(var_num_t x, int output, int handle);
131131
* @param output is the output-set-of-routines code (see PV_xxx macros)
132132
* @param handle is the output handle (depented on output-code)
133133
*/
134-
void fmt_printS(const char *str, int output, int handle);
134+
void fmt_printS(const char *str, int output, intptr_t handle);
135135

136136
#if defined(__cplusplus)
137137
}

src/common/pproc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void set_dataip(uint16_t label_id);
7979
*
8080
* @note avoid to use it
8181
*/
82-
void pv_write(char *str, int method, int handle);
82+
void pv_write(char *str, int method, intptr_t handle);
8383

8484
/**
8585
* @ingroup exec
@@ -88,7 +88,7 @@ void pv_write(char *str, int method, int handle);
8888
*
8989
* @note avoid to use it
9090
*/
91-
void pv_writevar(var_t *var, int method, int handle);
91+
void pv_writevar(var_t *var, int method, intptr_t handle);
9292

9393
/**
9494
* @ingroup exec
@@ -107,7 +107,7 @@ void print_var(var_t *var);
107107
* @param var is the variable
108108
* @param handle is the file-handle
109109
*/
110-
void fprint_var(int handle, var_t *var);
110+
void fprint_var(intptr_t handle, var_t *var);
111111

112112
/**
113113
* @ingroup exec

src/common/proc.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,33 +163,34 @@ void exec_usefunc2(var_t *var1, var_t *var2, bcip_t ip) {
163163
v_detach(old_y);
164164
}
165165

166+
void pv_write_str(char *str, var_t *vp) {
167+
vp->v.p.length += strlen(str);
168+
if (vp->v.p.ptr == NULL) {
169+
vp->v.p.ptr = malloc(vp->v.p.length + 1);
170+
vp->v.p.owner = 1;
171+
strcpy((char *)vp->v.p.ptr, str);
172+
} else {
173+
vp->v.p.ptr = realloc(vp->v.p.ptr, vp->v.p.length + 1);
174+
strcat((char *)vp->v.p.ptr, str);
175+
}
176+
}
177+
166178
/*
167179
* Write string to output device
168180
*/
169-
void pv_write(char *str, int method, int handle) {
170-
var_t *vp;
171-
181+
void pv_write(char *str, int method, intptr_t handle) {
172182
switch (method) {
173183
case PV_FILE:
174-
dev_fwrite(handle, (byte *)str, strlen(str));
184+
dev_fwrite((int)handle, (byte *)str, strlen(str));
175185
break;
176186
case PV_LOG:
177187
lwrite(str);
178188
break;
179189
case PV_STRING:
180-
vp = (var_t*)(intptr_t)handle;
181-
vp->v.p.length += strlen(str);
182-
if (vp->v.p.ptr == NULL) {
183-
vp->v.p.ptr = malloc(vp->v.p.length + 1);
184-
vp->v.p.owner = 1;
185-
strcpy((char *)vp->v.p.ptr, str);
186-
} else {
187-
vp->v.p.ptr = realloc(vp->v.p.ptr, vp->v.p.length + 1);
188-
strcat((char *)vp->v.p.ptr, str);
189-
}
190+
pv_write_str(str, (var_t *)handle);
190191
break;
191192
case PV_NET:
192-
net_print((socket_t) handle, (const char *)str);
193+
net_print((socket_t)handle, (const char *)str);
193194
break;
194195
default:
195196
dev_print(str);
@@ -199,7 +200,7 @@ void pv_write(char *str, int method, int handle) {
199200
/*
200201
* just prints the value of variable 'var'
201202
*/
202-
void pv_writevar(var_t *var, int method, int handle) {
203+
void pv_writevar(var_t *var, int method, intptr_t handle) {
203204
char tmpsb[64];
204205

205206
// start with a clean buffer
@@ -244,7 +245,7 @@ void print_var(var_t *v) {
244245
/*
245246
* write a variable to a file
246247
*/
247-
void fprint_var(int handle, var_t *v) {
248+
void fprint_var(intptr_t handle, var_t *v) {
248249
pv_writevar(v, PV_FILE, handle);
249250
}
250251

src/common/var_map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ char *map_to_str(const var_p_t var_p) {
404404
/**
405405
* Print the contents of the structure
406406
*/
407-
void map_write(const var_p_t var_p, int method, int handle) {
407+
void map_write(const var_p_t var_p, int method, intptr_t handle) {
408408
if (var_p->type == V_MAP || var_p->type == V_ARRAY) {
409409
char *buffer = map_to_str(var_p);
410410
pv_write(buffer, method, handle);

src/common/var_map.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void map_get_value(var_p_t base, var_p_t key, var_p_t *result);
3535
void map_set(var_p_t dest, const var_p_t src);
3636
void map_set_int(var_p_t base, const char *name, var_int_t n);
3737
char *map_to_str(const var_p_t var_p);
38-
void map_write(const var_p_t var_p, int method, int handle);
38+
void map_write(const var_p_t var_p, int method, intptr_t handle);
3939
void map_parse_str(const char *js, size_t len, var_p_t dest);
4040
void map_from_str(var_p_t var_p);
4141
void map_from_codearray(var_p_t var_p);

src/platform/console/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ int process_options(int argc, char *argv[]) {
253253
return 1;
254254
}
255255

256-
#if defined(__GNUC__)
256+
#if defined(__GNUC__) && !defined(__MACH__)
257257
// for analysing excessive malloc calls using kdbg
258258
extern void *__libc_malloc(size_t size);
259-
void* malloc (size_t size) {
259+
void *malloc(size_t size) {
260260
return __libc_malloc(size);
261261
}
262262
#endif

0 commit comments

Comments
 (0)