aboutsummaryrefslogtreecommitdiff
path: root/src/prog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/prog.c')
-rw-r--r--src/prog.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/prog.c b/src/prog.c
index 83401ef3..75b52284 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -381,13 +381,13 @@ static void env_register_auto(eval_environ_t env, void *ptr);
381 381
382void 382void
383env_get_locus(eval_environ_t env, struct mu_locus_range *locus) 383env_get_locus(eval_environ_t env, struct mu_locus_range *locus)
384{ 384{
385 mu_locus_range_init(locus); 385 mu_locus_range_init(locus);
386 locus->beg.mu_file = (char*)(env->dataseg + env->locus.file); 386 locus->beg.mu_file = (char*)(env->dataseg + env->locus.file);
387 env_register_auto(env, (void*) locus->beg.mu_file); 387 env_register_auto(env, (void*) &locus->beg.mu_file);
388 locus->beg.mu_line = env->locus.line; 388 locus->beg.mu_line = env->locus.line;
389#if 0 389#if 0
390 locus->beg.mu_col = env->locus.point; 390 locus->beg.mu_col = env->locus.point;
391 ... 391 ...
392#endif 392#endif
393} 393}
@@ -490,38 +490,45 @@ env_function_cleanup_add(eval_environ_t env, void *data,
490 The auto_ptr array is cleared (by calling env_unregister_autos) after 490 The auto_ptr array is cleared (by calling env_unregister_autos) after
491 executing each instruction (see eval_environment). 491 executing each instruction (see eval_environment).
492 */ 492 */
493static void 493static void
494env_register_auto(eval_environ_t env, void *ptr) 494env_register_auto(eval_environ_t env, void *ptr)
495{ 495{
496 char *addr = *(char**)ptr;
497
496 if (env->numautos == MAX_AUTO_PTR) 498 if (env->numautos == MAX_AUTO_PTR)
497 runtime_error(env, "INTERNAL ERROR at %s:%d, please report", 499 runtime_error(env, "INTERNAL ERROR at %s:%d, please report",
498 __FILE__, __LINE__); 500 __FILE__, __LINE__);
501 /* Check if address is within the dataseg */
502 if (!(addr >= (char*) env->dataseg
503 && (addr < (char*) (env->dataseg + datasize + env->stack_size))))
504 ptr = NULL;
499 env->auto_ptr[env->numautos++] = ptr; 505 env->auto_ptr[env->numautos++] = ptr;
500} 506}
501 507
502/* Pop the last registered auto variable */ 508/* Pop the last registered auto variable */
503void 509static void
504env_pop_auto(eval_environ_t env) 510env_pop_auto(eval_environ_t env)
505{ 511{
506 env->numautos--; 512 env->numautos--;
507} 513}
508 514
509void 515static void
510env_unregister_autos(eval_environ_t env) 516env_unregister_autos(eval_environ_t env)
511{ 517{
512 env->numautos = 0; 518 env->numautos = 0;
513} 519}
514 520
515void 521static void
516env_fixup_autos(eval_environ_t env, ptrdiff_t offset) 522env_fixup_autos(eval_environ_t env, ptrdiff_t offset)
517{ 523{
518 int i; 524 int i;
519 for (i = 0; i < env->numautos; i++) { 525 for (i = 0; i < env->numautos; i++) {
520 STKVAL *pptr = env->auto_ptr[i]; 526 STKVAL *pptr = env->auto_ptr[i];
521 mf_c_val(*pptr,str) += offset; /*FIXME*/ 527 if (pptr)
528 mf_c_val(*pptr,str) += offset; /*FIXME*/
522 } 529 }
523} 530}
524 531
525 532
526int 533int
527expand_dataseg(eval_environ_t env, size_t count, const char *errtext) 534expand_dataseg(eval_environ_t env, size_t count, const char *errtext)
@@ -796,13 +803,13 @@ heap_obstack_finish(eval_environ_t env)
796void * 803void *
797heap_obstack_grow(eval_environ_t env, void * MFL_DATASEG ptr, size_t size) 804heap_obstack_grow(eval_environ_t env, void * MFL_DATASEG ptr, size_t size)
798{ 805{
799 size_t words = B2STACK(size); 806 size_t words = B2STACK(size);
800 char *ret; 807 char *ret;
801 808
802 env_register_auto(env, ptr); 809 env_register_auto(env, (void*) &ptr);
803 if (env->tos - env->toh < words + B2STACK(env->temp_size)) 810 if (env->tos - env->toh < words + B2STACK(env->temp_size))
804 expand_dataseg(env, words, 811 expand_dataseg(env, words,
805 _("memory chunk too big to fit into heap")); 812 _("memory chunk too big to fit into heap"));
806 ret = (char*) env_data_ref(env, env->temp_start) + env->temp_size; 813 ret = (char*) env_data_ref(env, env->temp_start) + env->temp_size;
807 if (ptr) 814 if (ptr)
808 memmove(ret, ptr, size); 815 memmove(ret, ptr, size);
@@ -826,13 +833,13 @@ env_data_ref(eval_environ_t env, size_t off)
826 833
827void 834void
828pushs(eval_environ_t env, const char * MFL_DATASEG s) 835pushs(eval_environ_t env, const char * MFL_DATASEG s)
829{ 836{
830 size_t off; 837 size_t off;
831 838
832 env_register_auto(env, (void*) s); 839 env_register_auto(env, (void*) &s);
833 off = heap_reserve(env, strlen(s) + 1); 840 off = heap_reserve(env, strlen(s) + 1);
834 strcpy((char*) env_data_ref(env, off), s); 841 strcpy((char*) env_data_ref(env, off), s);
835 env_pop_auto(env); 842 env_pop_auto(env);
836 push(env, (STKVAL) off); 843 push(env, (STKVAL) off);
837} 844}
838 845

Return to:

Send suggestions and report system problems to the System administrator.