• R/O
  • SSH
  • HTTPS

molby: Commit


Commit MetaInfo

Revision598 (tree)
Time2016-05-09 21:58:20
Authortoshinagata1964

Log Message

Ruby: Kernel#backquote now sets the exit status of the subprocess (although it does not always work as expected)

Change Summary

Incremental Difference

--- trunk/wxSources/MyApp.cpp (revision 597)
+++ trunk/wxSources/MyApp.cpp (revision 598)
@@ -1310,7 +1310,7 @@
13101310 }
13111311
13121312 int
1313-MyApp::CallSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *fpout, FILE *fperr)
1313+MyApp::CallSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *fpout, FILE *fperr, int *exitstatus_p, int *pid_p)
13141314 {
13151315 int status = 0;
13161316 int callback_result = 0;
@@ -1366,6 +1366,8 @@
13661366 #endif
13671367 return -1;
13681368 }
1369+ if (pid_p != NULL)
1370+ *pid_p = pid;
13691371 #if LOG_SUBPROCESS
13701372 fprintf(fplog, "[DEBUG]pid = %ld\n", pid);
13711373 fflush(fplog);
@@ -1434,10 +1436,14 @@
14341436 }
14351437 if (m_processTerminated) {
14361438 // OnEndProcess has been called
1439+ if (exitstatus_p != NULL)
1440+ *exitstatus_p = m_processExitCode;
14371441 if (m_processExitCode != 0) {
14381442 /* Error from subprocess */
14391443 status = (m_processExitCode & 255);
1440- } else status = 0;
1444+ } else {
1445+ status = 0;
1446+ }
14411447 break;
14421448 }
14431449
@@ -1541,6 +1547,8 @@
15411547 }
15421548 m_process->Detach();
15431549 m_process = NULL;
1550+ if (exitstatus_p != NULL)
1551+ *exitstatus_p = status;
15441552 break;
15451553 }
15461554 }
@@ -2063,9 +2071,9 @@
20632071 }
20642072 }
20652073
2066-int MyAppCallback_callSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *output, FILE *errout)
2074+int MyAppCallback_callSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *output, FILE *errout, int *exitstatus_p, int *pid_p)
20672075 {
2068- return wxGetApp().CallSubProcess(cmdline, procname, callback, callback_data, output, errout);
2076+ return wxGetApp().CallSubProcess(cmdline, procname, callback, callback_data, output, errout, exitstatus_p, pid_p);
20692077 }
20702078
20712079 void MyAppCallback_showConsoleWindow(void)
--- trunk/wxSources/MyApp.h (revision 597)
+++ trunk/wxSources/MyApp.h (revision 598)
@@ -173,7 +173,7 @@
173173 void OnBringAllWindowsToFront(wxCommandEvent &event);
174174
175175 void OnEndProcess(wxProcessEvent &event);
176- int CallSubProcess(const char *cmdline, const char *procname, int (*callback)(void *) = NULL, void *callback_data = NULL, FILE *fpout = NULL, FILE *fperr = NULL);
176+ int CallSubProcess(const char *cmdline, const char *procname, int (*callback)(void *) = NULL, void *callback_data = NULL, FILE *fpout = NULL, FILE *fperr = NULL, int *exitstatus_p = NULL, int *pid_p = NULL);
177177
178178 void OnActivate(wxActivateEvent &event);
179179
--- trunk/MolLib/cmdtool_stubs.c (revision 597)
+++ trunk/MolLib/cmdtool_stubs.c (revision 598)
@@ -173,7 +173,7 @@
173173 }
174174
175175 int
176-MyAppCallback_callSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *output, FILE *errout)
176+MyAppCallback_callSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *output, FILE *errout, int *exitstatus_p, int *pid_p)
177177 {
178178 return system(cmdline);
179179 }
--- trunk/MolLib/Ruby_bind/Molby_extern.h (revision 597)
+++ trunk/MolLib/Ruby_bind/Molby_extern.h (revision 598)
@@ -72,7 +72,7 @@
7272 STUB int MyAppCallback_registerScriptMenu(const char *title);
7373 STUB int MyAppCallback_lookupScriptMenu(const char *title);
7474 STUB RubyValue MyAppCallback_executeScriptFromFile(const char *path, int *status);
75-STUB int MyAppCallback_callSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *output, FILE *errout);
75+STUB int MyAppCallback_callSubProcess(const char *cmdline, const char *procname, int (*callback)(void *), void *callback_data, FILE *output, FILE *errout, int *exitstatus_p, int *pid_p);
7676 STUB void MyAppCallback_beginUndoGrouping(void);
7777 STUB void MyAppCallback_endUndoGrouping(void);
7878 STUB int MyAppCallback_switchToFilterMode(void);
--- trunk/MolLib/Ruby_bind/ruby_bind.c (revision 597)
+++ trunk/MolLib/Ruby_bind/ruby_bind.c (revision 598)
@@ -925,7 +925,7 @@
925925 s_Kernel_CallSubProcess(int argc, VALUE *argv, VALUE self)
926926 {
927927 VALUE cmd, procname, cproc, stdout_val, stderr_val;
928- int n;
928+ int n, exitstatus, pid;
929929 char *sout, *serr;
930930 FILE *fpout, *fperr;
931931
@@ -970,7 +970,7 @@
970970 }
971971 }
972972
973- n = MyAppCallback_callSubProcess(StringValuePtr(cmd), StringValuePtr(procname), (cproc == Qnil ? NULL : s_Kernel_CallSubProcess_Callback), (cproc == Qnil ? NULL : (void *)cproc), fpout, fperr);
973+ n = MyAppCallback_callSubProcess(StringValuePtr(cmd), StringValuePtr(procname), (cproc == Qnil ? NULL : s_Kernel_CallSubProcess_Callback), (cproc == Qnil ? NULL : (void *)cproc), fpout, fperr, &exitstatus, &pid);
974974
975975 if (fpout != NULL && fpout != (FILE *)1)
976976 fclose(fpout);
@@ -992,17 +992,17 @@
992992 s_Kernel_Backquote(VALUE self, VALUE cmd)
993993 {
994994 char *buf;
995- int n;
995+ int n, exitstatus, pid;
996996 VALUE val;
997- n = MyAppCallback_callSubProcess(StringValuePtr(cmd), NULL, DUMMY_CALLBACK, &buf, NULL, NULL);
998- if (n != 0)
999- rb_raise(rb_eMolbyError, "Cannot invoke command '%s'", StringValuePtr(cmd));
1000- if (buf != NULL) {
997+ n = MyAppCallback_callSubProcess(StringValuePtr(cmd), NULL, DUMMY_CALLBACK, &buf, NULL, NULL, &exitstatus, &pid);
998+ fprintf(stderr, "n = %d, exitstatus = %d, pid = %d\n", n, exitstatus, pid);
999+ if (n >= 0 && buf != NULL) {
10011000 val = Ruby_NewEncodedStringValue(buf, 0);
10021001 free(buf);
10031002 } else {
10041003 val = Ruby_NewEncodedStringValue("", 0);
10051004 }
1005+ rb_last_status_set(exitstatus, pid);
10061006 return val;
10071007 }
10081008
Show on old repository browser