Revision: 76655
          http://sourceforge.net/p/brlcad/code/76655
Author:   starseeker
Date:     2020-08-03 21:17:01 +0000 (Mon, 03 Aug 2020)
Log Message:
-----------
r76624 broke rt command in Archer on Windows.  Switch to using a semantic enum 
to specifiy I/O channel in the API, rather than any sort of int.

Modified Paths:
--------------
    brlcad/trunk/include/bu/process.h
    brlcad/trunk/include/ged/defines.h
    brlcad/trunk/include/tclcad.h
    brlcad/trunk/src/libbu/process.c
    brlcad/trunk/src/libtclcad/tclcad_obj.c

Modified: brlcad/trunk/include/bu/process.h
===================================================================
--- brlcad/trunk/include/bu/process.h   2020-08-03 18:16:00 UTC (rev 76654)
+++ brlcad/trunk/include/bu/process.h   2020-08-03 21:17:01 UTC (rev 76655)
@@ -48,11 +48,12 @@
 /* Wrappers for using subprocess execution */
 struct bu_process;
 
-#define BU_PROCESS_STDIN 0
-#define BU_PROCESS_STDOUT 1
-#define BU_PROCESS_STDERR 2
+typedef enum {
+    BU_PROCESS_STDIN,
+    BU_PROCESS_STDOUT,
+    BU_PROCESS_STDERR
+} bu_process_io_t;
 
-
 /**
  * Open and return a FILE pointer associated with the specified file
  * descriptor for input (0), output (1), or error (2) respectively.
@@ -66,7 +67,7 @@
  * FIXME: misnomer, this does not open a process.  Probably doesn't
  * need to exist; just call fdopen().
  */
-BU_EXPORT extern FILE *bu_process_open(struct bu_process *pinfo, int fd);
+BU_EXPORT extern FILE *bu_process_open(struct bu_process *pinfo, 
bu_process_io_t d);
 
 
 /**
@@ -75,19 +76,20 @@
  * FIXME: misnomer, this does not close a process.  Probably doesn't
  * need to exist; just call fclose().
  */
-BU_EXPORT extern void bu_process_close(struct bu_process *pinfo, int fd);
+BU_EXPORT extern void bu_process_close(struct bu_process *pinfo, 
bu_process_io_t d);
 
 
 /**
- * Retrieve the pointer to the input (0), output (1), or error (2) file
- * descriptor associated with the process.  To use this in calling code, the
- * caller must cast the supplied pointer to the file handle type of the
- * calling code's specific platform.
+ * Retrieve the pointer to the input (BU_PROCESS_STDIN), output
+ * (BU_PROCESS_STDOUT), or error (BU_PROCESS_STDERR) file descriptor associated
+ * with the process.  To use this in calling code, the caller must cast the
+ * supplied pointer to the file handle type of the calling code's specific
+ * platform.
  *
  * FIXME: void pointer casting is bad.  this function probably
  * shouldn't exist.
  */
-BU_EXPORT void *bu_process_fd(struct bu_process *pinfo, int fd);
+BU_EXPORT void *bu_process_fd(struct bu_process *pinfo, bu_process_io_t d);
 
 
 /**
@@ -127,7 +129,7 @@
  * FIXME: arg ordering and input/output grouping is wrong.  partially
  * redundant with bu_process_fd() and/or bu_process_open().
  */
-BU_EXPORT extern int bu_process_read(char *buff, int *count, struct bu_process 
*pinfo, int fd, int n);
+BU_EXPORT extern int bu_process_read(char *buff, int *count, struct bu_process 
*pinfo, bu_process_io_t d, int n);
 
 
 /**

Modified: brlcad/trunk/include/ged/defines.h
===================================================================
--- brlcad/trunk/include/ged/defines.h  2020-08-03 18:16:00 UTC (rev 76654)
+++ brlcad/trunk/include/ged/defines.h  2020-08-03 21:17:01 UTC (rev 76655)
@@ -268,8 +268,8 @@
      * can't know about as it is application specific) lives.  It should be 
assigned in the
      * applications gedp before any calls to ged_create_io_handler are made.
      * */
-    void (*ged_create_io_handler)(struct ged_subprocess *gp, int fd, 
ged_io_func_t callback, void *data);
-    void (*ged_delete_io_handler)(struct ged_subprocess *gp, int fd);
+    void (*ged_create_io_handler)(struct ged_subprocess *gp, bu_process_io_t 
d, ged_io_func_t callback, void *data);
+    void (*ged_delete_io_handler)(struct ged_subprocess *gp, bu_process_io_t 
fd);
     void *ged_io_data;  /**< brief caller supplied data */
 
     // Other callbacks...

Modified: brlcad/trunk/include/tclcad.h
===================================================================
--- brlcad/trunk/include/tclcad.h       2020-08-03 18:16:00 UTC (rev 76654)
+++ brlcad/trunk/include/tclcad.h       2020-08-03 21:17:01 UTC (rev 76655)
@@ -34,6 +34,7 @@
 
 #include "common.h"
 #include "bu/cmd.h"
+#include "bu/process.h"
 #include "tcl.h"
 #include "dm.h"
 #include "ged.h"
@@ -522,9 +523,9 @@
     int io_mode;
 };
 TCLCAD_EXPORT void
-tclcad_create_io_handler(struct ged_subprocess *p, int fd, ged_io_func_t 
callback, void *data);
+tclcad_create_io_handler(struct ged_subprocess *p, bu_process_io_t d, 
ged_io_func_t callback, void *data);
 TCLCAD_EXPORT void
-tclcad_delete_io_handler(struct ged_subprocess *p, int fd);
+tclcad_delete_io_handler(struct ged_subprocess *p, bu_process_io_t d);
 
 
 /* dm_tcl.c */

Modified: brlcad/trunk/src/libbu/process.c
===================================================================
--- brlcad/trunk/src/libbu/process.c    2020-08-03 18:16:00 UTC (rev 76654)
+++ brlcad/trunk/src/libbu/process.c    2020-08-03 21:17:01 UTC (rev 76655)
@@ -76,12 +76,12 @@
 
 
 void
-bu_process_close(struct bu_process *pinfo, int fd)
+bu_process_close(struct bu_process *pinfo, bu_process_io_t d)
 {
     if (!pinfo)
        return;
 
-    if (fd == fileno(stdin)) {
+    if (d == BU_PROCESS_STDIN) {
        if (!pinfo->fp_in)
            return;
        (void)fclose(pinfo->fp_in);
@@ -88,7 +88,7 @@
        pinfo->fp_in = NULL;
        return;
     }
-    if (fd == fileno(stdout)) {
+    if (d == BU_PROCESS_STDOUT) {
        if (!pinfo->fp_out)
            return;
        (void)fclose(pinfo->fp_out);
@@ -95,7 +95,7 @@
        pinfo->fp_out = NULL;
        return;
     }
-    if (fd == fileno(stderr)) {
+    if (d == BU_PROCESS_STDERR) {
        if (!pinfo->fp_err)
            return;
        (void)fclose(pinfo->fp_err);
@@ -106,14 +106,14 @@
 
 
 FILE *
-bu_process_open(struct bu_process *pinfo, int fd)
+bu_process_open(struct bu_process *pinfo, bu_process_io_t d)
 {
     if (!pinfo)
        return NULL;
 
-    bu_process_close(pinfo, fd);
+    bu_process_close(pinfo, d);
 
-    if (fd == fileno(stdin)) {
+    if (d == BU_PROCESS_STDIN) {
 #ifndef _WIN32
        pinfo->fp_in = fdopen(pinfo->fd_in, "wb");
 #else
@@ -121,7 +121,7 @@
 #endif
        return pinfo->fp_in;
     }
-    if (fd == fileno(stdout)) {
+    if (d == BU_PROCESS_STDOUT) {
 #ifndef _WIN32
        pinfo->fp_out = fdopen(pinfo->fd_out, "rb");
 #else
@@ -129,7 +129,7 @@
 #endif
        return pinfo->fp_out;
     }
-    if (fd == fileno(stderr)) {
+    if (d == BU_PROCESS_STDERR) {
 #ifndef _WIN32
        pinfo->fp_err = fdopen(pinfo->fd_err, "rb");
 #else
@@ -143,16 +143,16 @@
 
 
 void *
-bu_process_fd(struct bu_process *pinfo, int fd)
+bu_process_fd(struct bu_process *pinfo, bu_process_io_t d)
 {
-    if (!pinfo || fd < 0)
+    if (!pinfo)
        return NULL;
 
-    if (fd == fileno(stdin))
+    if (d == BU_PROCESS_STDIN)
        return (void *)(&(pinfo->fd_in));
-    if (fd == fileno(stdout))
+    if (d == BU_PROCESS_STDOUT)
        return (void *)(&(pinfo->fd_out));
-    if (fd == fileno(stderr))
+    if (d == BU_PROCESS_STDERR)
        return (void *)(&(pinfo->fd_err));
 
     return NULL;
@@ -184,13 +184,13 @@
 
 
 int
-bu_process_read(char *buff, int *count, struct bu_process *pinfo, int fd, int 
n)
+bu_process_read(char *buff, int *count, struct bu_process *pinfo, 
bu_process_io_t d, int n)
 {
     int ret = 1;
-    if (!pinfo || !buff || !n || !count || fd < 1)
+    if (!pinfo || !buff || !n || !count)
        return -1;
 
-    if (fd == fileno(stdout)) {
+    if (d == BU_PROCESS_STDOUT) {
 #ifndef _WIN32
        (*count) = read((int)pinfo->fd_out, buff, n);
        if ((*count) <= 0) {
@@ -205,7 +205,7 @@
        (*count) = (int)dcount;
 #endif
     }
-    if (fd == fileno(stderr)) {
+    if (d == BU_PROCESS_STDERR) {
 #ifndef _WIN32
        (*count) = read((int)pinfo->fd_err, buff, n);
        if ((*count) <= 0) {
@@ -308,17 +308,17 @@
        setpgid(0, 0);
 
        /* Redirect stdin and stderr */
-       (void)close(fileno(stdin));
+       (void)close(BU_PROCESS_STDIN);
        pret = dup(pipe_in[0]);
        if (pret < 0) {
            perror("dup");
        }
-       (void)close(fileno(stdout));
+       (void)close(BU_PROCESS_STDOUT);
        pret = dup(pipe_out[1]);
        if (pret < 0) {
            perror("dup");
        }
-       (void)close(fileno(stderr));
+       (void)close(BU_PROCESS_STDERR);
        pret = dup(pipe_err[1]);
        if (pret < 0) {
            perror("dup");
@@ -522,8 +522,8 @@
     }
 
     /* Clean up */
-    bu_process_close(pinfo, fileno(stdout));
-    bu_process_close(pinfo, fileno(stderr));
+    bu_process_close(pinfo, BU_PROCESS_STDOUT);
+    bu_process_close(pinfo, BU_PROCESS_STDERR);
 
     /* Free copy of exec args */
     if (pinfo->cmd) {

Modified: brlcad/trunk/src/libtclcad/tclcad_obj.c
===================================================================
--- brlcad/trunk/src/libtclcad/tclcad_obj.c     2020-08-03 18:16:00 UTC (rev 
76654)
+++ brlcad/trunk/src/libtclcad/tclcad_obj.c     2020-08-03 21:17:01 UTC (rev 
76655)
@@ -1182,11 +1182,11 @@
 /* Wrappers for setting up/tearing down IO handler */
 #ifndef _WIN32
 void
-tclcad_create_io_handler(struct ged_subprocess *p, int fd, ged_io_func_t 
callback, void *data)
+tclcad_create_io_handler(struct ged_subprocess *p, bu_process_io_t d, 
ged_io_func_t callback, void *data)
 {
     if (!p || !p->p || !p->gedp || !p->gedp->ged_io_data)
                return;
-    int *fdp = (int *)bu_process_fd(p->p, fd);
+    int *fdp = (int *)bu_process_fd(p->p, d);
     if (fdp) {
        struct tclcad_io_data *t_iod = (struct tclcad_io_data 
*)p->gedp->ged_io_data;
        Tcl_CreateFileHandler(*fdp, t_iod->io_mode, callback, (ClientData)data);
@@ -1194,10 +1194,10 @@
 }
 
 void
-tclcad_delete_io_handler(struct ged_subprocess *p, int fd)
+tclcad_delete_io_handler(struct ged_subprocess *p, bu_process_io_t d)
 {
     if (!p) return;
-    int *fdp = (int *)bu_process_fd(p->p, fd);
+    int *fdp = (int *)bu_process_fd(p->p, d);
     if (fdp) {
        Tcl_DeleteFileHandler(*fdp);
        close(*fdp);
@@ -1206,12 +1206,12 @@
 
 #else
 void
-tclcad_create_io_handler(struct ged_subprocess *p, int fd, ged_io_func_t 
callback, void *data)
+tclcad_create_io_handler(struct ged_subprocess *p, bu_process_io_t d, 
ged_io_func_t callback, void *data)
 {
     if (!p || !p->p || !p->gedp || !p->gedp->ged_io_data)
                return;
     struct tclcad_io_data *t_iod = (struct tclcad_io_data 
*)p->gedp->ged_io_data;
-    HANDLE *fdp = (HANDLE *)bu_process_fd(p->p, fd);
+    HANDLE *fdp = (HANDLE *)bu_process_fd(p->p, d);
     if (fdp) {
        t_iod->chan = Tcl_MakeFileChannel(*fdp, t_iod->io_mode);
        Tcl_CreateChannelHandler(t_iod->chan, t_iod->io_mode, callback, 
(ClientData)data);
@@ -1219,7 +1219,7 @@
 }
 
 void
-tclcad_delete_io_handler(struct ged_subprocess *p, int fd)
+tclcad_delete_io_handler(struct ged_subprocess *p, bu_process_io_t d)
 {
     if (!p || !p->p || !p->gedp || !p->gedp->ged_io_data)
                return;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to