diff options
| author | Greg Ercolano <erco@seriss.com> | 2020-06-18 18:24:45 -0700 |
|---|---|---|
| committer | Greg Ercolano <erco@seriss.com> | 2020-06-18 18:24:45 -0700 |
| commit | db07cea7580fbe6a92a62c9045e8877827d73d61 (patch) | |
| tree | 3a229d6665a77eb911976bee1ed7014ba985f36f /fluid/ExternalCodeEditor_WIN32.cxx | |
| parent | 76da518b9782c56f7f0f1d215c8d0161cd8ee95a (diff) | |
Fix problem with Windows pids being unsigned DWORDs
Had to get away from overloading PIDs with error codes,
so now error codes are returned separately from the PID.
Diffstat (limited to 'fluid/ExternalCodeEditor_WIN32.cxx')
| -rw-r--r-- | fluid/ExternalCodeEditor_WIN32.cxx | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/fluid/ExternalCodeEditor_WIN32.cxx b/fluid/ExternalCodeEditor_WIN32.cxx index 105eaf702..4890b1b08 100644 --- a/fluid/ExternalCodeEditor_WIN32.cxx +++ b/fluid/ExternalCodeEditor_WIN32.cxx @@ -137,6 +137,8 @@ void ExternalCodeEditor::close_editor() { // Wait until editor is closed + reaped while ( is_editing() ) { switch ( reap_editor() ) { + case -2: // no editor running (unlikely to happen) + return; case -1: // error fl_alert("Error reaping external editor\n" "pid=%ld file=%s", long(pinfo_.dwProcessId), filename()); @@ -154,7 +156,7 @@ void ExternalCodeEditor::close_editor() { continue; } break; - default: // process reaped + case 1: // process reaped return; } } @@ -176,7 +178,7 @@ void ExternalCodeEditor::kill_editor() { } case 0: { // success -- process reaped DWORD pid = pinfo_.dwProcessId; // save pid - reap_cleanup(); + reap_cleanup(); // clears pinfo_ if ( G_debug ) printf("*** kill_editor() REAP pid=%ld #open=%ld\n", long(pid), long(L_editors_open)); @@ -445,7 +447,7 @@ int ExternalCodeEditor::start_editor(const char *editor_cmd, // [Protected] Cleanup after editor reaped: // > Remove tmpfile, zeroes mtime/size/filename // > Close process handles -// > Zero out process info +// > Zeroes out pinfo_ // > Decrease editor count // void ExternalCodeEditor::reap_cleanup() { @@ -458,15 +460,19 @@ void ExternalCodeEditor::reap_cleanup() { } // [Public] Try to reap external editor process +// If 'pid_reaped' not NULL, returns PID of reaped editor. // Returns: // -2 -- editor not open // -1 -- WaitForSingleObject() failed (get_ms_errmsg() has reason) // 0 -- process still running -// >0 -- process finished + reaped (value is pid) +// 1 -- process finished + reaped ('pid_reaped' has pid), pinfo_ set to 0. // Handles removing tmpfile/zeroing file_mtime/file_size/filename // -DWORD ExternalCodeEditor::reap_editor() { - if ( pinfo_.dwProcessId == 0 ) return -2; +// If return value <=0, 'pid_reaped' is set to zero. +// +int ExternalCodeEditor::reap_editor(DWORD *pid_reaped) { + if ( pid_reaped ) *pid_reaped = 0; + if ( !is_editing() ) return -2; int err; DWORD msecs_wait = 50; // .05 sec switch ( err = WaitForSingleObject(pinfo_.hProcess, msecs_wait) ) { @@ -474,11 +480,12 @@ DWORD ExternalCodeEditor::reap_editor() { return 0; } case WAIT_OBJECT_0: { // reaped - DWORD pid = pinfo_.dwProcessId; // save pid - reap_cleanup(); + DWORD wpid = pinfo_.dwProcessId; // save pid + reap_cleanup(); // clears pinfo_ + if ( pid_reaped ) *pid_reaped = wpid; // return pid to caller if ( G_debug ) printf("*** EDITOR REAPED: pid=%ld #open=%d\n", - long(pid), L_editors_open); - return pid; + long(wpid), L_editors_open); + return 1; } case WAIT_FAILED: { // failed return -1; @@ -506,8 +513,10 @@ int ExternalCodeEditor::open_editor(const char *editor_cmd, if ( is_file(filename()) ) { if ( is_editing() ) { // See if editor recently closed but not reaped; try to reap - DWORD wpid = reap_editor(); - switch (wpid) { + DWORD wpid; + switch ( reap_editor(&wpid) ) { + case -2: // no editor running (unlikely to happen) + break; case -1: // wait failed fl_alert("ERROR: WaitForSingleObject() failed: %s\nfile='%s', pid=%ld", get_ms_errmsg(), filename(), long(pinfo_.dwProcessId)); @@ -516,7 +525,7 @@ int ExternalCodeEditor::open_editor(const char *editor_cmd, fl_alert("Editor Already Open\n file='%s'\n pid=%ld", filename(), long(pinfo_.dwProcessId)); return 0; - default: // process reaped, wpid is pid reaped + case 1: // process reaped, wpid is pid reaped if ( G_debug ) printf("*** REAPED EXTERNAL EDITOR: PID %ld\n", long(wpid)); break; // fall thru to open new editor instance |
