From b9c48027fc73aa9de7d8b78217a24344787b2da2 Mon Sep 17 00:00:00 2001 From: "David P. Chassin" Date: Wed, 14 Oct 2020 15:03:53 -0700 Subject: [PATCH 1/3] Update main.cpp --- gldcore/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gldcore/main.cpp b/gldcore/main.cpp index 87b2b8055..1cbfc928e 100644 --- a/gldcore/main.cpp +++ b/gldcore/main.cpp @@ -596,10 +596,10 @@ int pcloses(FILE *iop, bool wait=true) int GldMain::subcommand(const char *format, ...) { - char *command; + char *command = NULL; va_list ptr; va_start(ptr,format); - if ( vasprintf(&command,format,ptr) < 0 ) + if ( vasprintf(&command,format,ptr) < 0 || command == NULL ) { output_error("GldMain::subcommand(format='%s',...): memory allocation failed",format); return -1; @@ -658,6 +658,7 @@ int GldMain::subcommand(const char *format, ...) } output_verbose("subcommand '%s' -> status = %d",command,rc); } + free(command); return rc; } From cebb2b1f7f002e638392ae75b5ea6e8e18064d77 Mon Sep 17 00:00:00 2001 From: "David P. Chassin" Date: Wed, 14 Oct 2020 15:03:55 -0700 Subject: [PATCH 2/3] Update save.cpp --- gldcore/save.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gldcore/save.cpp b/gldcore/save.cpp index 4f4fbc149..7b32155be 100644 --- a/gldcore/save.cpp +++ b/gldcore/save.cpp @@ -59,7 +59,6 @@ int saveall(const char *filename) } if ( ! known_format ) { - char converter_command[1024]; int rc; char converter_name[1024]; char input_name[1024]; @@ -72,13 +71,12 @@ int saveall(const char *filename) return 0; } sprintf(converter_name,"glm2%s.py",ext); - const char *converter_path = find_file(converter_name,NULL,R_OK); - if ( ! converter_path ) + char converter_path[1024]; + if ( ! find_file(converter_name,NULL,R_OK,converter_path,sizeof(converter_path)) ) { /* try using python output converter through json */ sprintf(converter_name,"json2%s.py",ext); - const char *converter_path = find_file(converter_name,NULL,R_OK); - if ( ! converter_path ) + if ( ! find_file(converter_name,NULL,R_OK,converter_path,sizeof(converter_path)) ) { output_error("saveall: extension '.%s' not a known format", ext); /* TROUBLESHOOT @@ -131,7 +129,7 @@ int saveall(const char *filename) save_options++; buffer[strlen(buffer)-1] = '\0'; } - rc = my_instance->subcommand(converter_command,"/usr/local/bin/python3 %s -i %s -o %s %s",converter_path,input_name,filename,save_options?save_options:""); + rc = my_instance->subcommand("/usr/local/bin/python3 %s -i %s -o %s %s",converter_path,input_name,filename,save_options?save_options:""); if ( rc != 0 ) { output_error("conversion from '%s' to output file '%s' failed (code %d)", input_name, filename, rc); From 15d697fa7131625695187712477563986550fd81 Mon Sep 17 00:00:00 2001 From: aivanova5 Date: Fri, 23 Oct 2020 16:28:24 -0700 Subject: [PATCH 3/3] Revert "Update object.cpp (#777)" This reverts commit 4376e342b9b560b7f94f7e2b7115a48c60e9679e. Reverting problematic PR --- gldcore/exec.cpp | 45 ++++++++++++++++++----------------------- gldcore/object.cpp | 13 ++---------- tape/group_recorder.cpp | 2 +- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/gldcore/exec.cpp b/gldcore/exec.cpp index 6819b579f..6e000d6e9 100644 --- a/gldcore/exec.cpp +++ b/gldcore/exec.cpp @@ -2499,39 +2499,34 @@ STATUS GldExec::exec_start(void) if ( global_run_realtime > 0 && iteration_counter > 0 ) { double metric=0; - struct timeval tv; - gettimeofday(&tv, NULL); - unsigned int udiff = 1000000 - tv.tv_usec; - if ( global_run_realtime == 1 ) // lock onto system clock +#ifdef WIN32 + struct timeb tv; + ftime(&tv); + if ( 1000-tv.millitm >= 0 ) { - int diff = global_clock - tv.tv_sec; - if ( diff < 0 ) - { - IN_MYCONTEXT output_verbose("skipping %d seconds to catch up", -diff); - global_realtime_metric = 0.0; - } - else if ( diff > 0 ) - { - global_realtime_metric = 1.0; - IN_MYCONTEXT output_verbose("sleeping %d seconds to catch up", diff); - sleep(diff); - gettimeofday(&tv, NULL); - udiff = 1000000 - tv.tv_usec; - } - global_clock = tv.tv_sec + 1; + IN_MYCONTEXT output_verbose("waiting %d msec", 1000-tv.millitm); + Sleep(1000-tv.millitm ); + metric = (1000-tv.millitm)/1000.0; } else + output_error("simulation failed to keep up with real time"); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + if ( 1000000-tv.tv_usec >= 0 ) { - global_clock++; - metric = (udiff)/1000000.0; - global_realtime_metric = global_realtime_metric*realtime_metric_decay + metric*(1-realtime_metric_decay); + IN_MYCONTEXT output_verbose("waiting %d usec", 1000000-tv.tv_usec); + usleep(1000000-tv.tv_usec); + metric = (1000000-tv.tv_usec)/1000000.0; } - if ( udiff >= 0 ) + else { - IN_MYCONTEXT output_verbose("waiting %d usec to synchronize", udiff); - usleep(udiff); + output_error("simulation failed to keep up with real time"); } +#endif wlock_sync(); + global_clock += global_run_realtime; + global_realtime_metric = global_realtime_metric*realtime_metric_decay + metric*(1-realtime_metric_decay); sync_reset(NULL); sync_set(NULL,global_clock,false); IN_MYCONTEXT output_verbose("realtime clock advancing to %d", (int)global_clock); diff --git a/gldcore/object.cpp b/gldcore/object.cpp index 8752c42ed..ed3540b3b 100644 --- a/gldcore/object.cpp +++ b/gldcore/object.cpp @@ -1933,7 +1933,7 @@ TIMESTAMP _object_sync(OBJECT *obj, /**< the object to synchronize */ sync_time = plc_time; /* compute valid_to time */ - if ( sync_time > TS_MAX ) + if(sync_time>TS_MAX) obj->valid_to = TS_NEVER; else obj->valid_to = sync_time; // NOTE, this can be negative @@ -1996,19 +1996,10 @@ TIMESTAMP object_sync(OBJECT *obj, /**< the object to synchronize */ char *event = NULL; if ( obj->oclass->sync != NULL ) { - unsigned int iter = 0; - TIMESTAMP tt; do { /* don't call sync beyond valid horizon */ t2 = _object_sync(obj,(ts<(obj->valid_to>0?obj->valid_to:TS_NEVER)?ts:obj->valid_to),pass); - if ( iter++ > global_iteration_limit ) - { - output_error("maximum iteration limit reached on valid_to sync update"); - return TS_INVALID; - } - tt = ( t2 < 0 ? -t2 : t2 ); - } while ( tt > global_clock && tt < ts ); - //} while (t2>0 && ts>(t2<0?-t2:t2) && t20 && ts>(t2<0?-t2:t2) && t2 gl_globalclock ? next_write : gl_globalclock+1; + return next_write; } else { // on-change intervals simply short-circuit return TS_NEVER;