@@ -18,13 +18,15 @@ piped_processt::piped_processt(const std::string &command)
18
18
// This should use the new error state from PR #6131 once that is done
19
19
INVARIANT (false , " New SMT2 backend WIP: Windows piped_process constructor." );
20
20
#else
21
+
21
22
if (pipe (pipe_input) == -1 ) {
22
23
throw std::runtime_error (" Input pipe creation failed" );
23
24
}
24
25
25
26
if (pipe (pipe_output) == -1 ) {
26
27
throw std::runtime_error (" Output pipe creation failed" );
27
28
}
29
+
28
30
// Default state
29
31
process_state = process_statet::NOT_CREATED;
30
32
@@ -74,19 +76,23 @@ bool piped_processt::send(const std::string &message)
74
76
// This should use the new error state from PR #6131 once that is done
75
77
INVARIANT (false , " New SMT2 backend WIP: Windows piped_processt::send." );
76
78
#else
79
+
77
80
if (process_state != process_statet::CREATED)
78
81
{
79
82
return false ;
80
83
}
84
+
81
85
// send message to solver process
82
86
int send_status = fputs (message.c_str (), command_stream);
83
87
fflush (command_stream);
88
+
84
89
if (send_status == EOF)
85
90
{
86
91
// Some kind of error occured, maybe we should update the
87
92
// solver status here?
88
93
return false ;
89
94
}
95
+
90
96
return true ;
91
97
#endif
92
98
}
@@ -97,11 +103,14 @@ std::string piped_processt::receive()
97
103
// This should use the new error state from PR #6131 once that is done
98
104
INVARIANT (false , " New SMT2 backend WIP: Windows piped_processt::receive." );
99
105
#else
106
+
100
107
if (process_state != process_statet::CREATED)
101
108
return NULL ;
109
+
102
110
std::string response = std::string (" " );
103
111
int nbytes;
104
112
char buff[BUFSIZE];
113
+
105
114
while (true )
106
115
{
107
116
nbytes = read (pipe_output[0 ], buff, BUFSIZE);
@@ -121,6 +130,7 @@ std::string piped_processt::receive()
121
130
response.append (buff, nbytes);
122
131
}
123
132
}
133
+
124
134
UNREACHABLE;
125
135
#endif
126
136
}
@@ -131,6 +141,7 @@ char ** piped_processt::split_command_args(const std::string &command)
131
141
char ** res = NULL ;
132
142
int n_spaces = 0 ;
133
143
char *p = strtok (strdup (command.c_str ()), " " );
144
+
134
145
while (p)
135
146
{
136
147
res = (char **)realloc (res, sizeof (char *) * ++n_spaces);
@@ -139,16 +150,8 @@ char ** piped_processt::split_command_args(const std::string &command)
139
150
res[n_spaces-1 ] = p;
140
151
p = strtok (NULL , " " );
141
152
}
153
+
142
154
res = (char **)realloc (res, sizeof (char *) * (n_spaces+1 ));
143
155
res[n_spaces] = 0 ;
144
156
return res;
145
157
}
146
-
147
- // Below is simple testing code to see that things (mostly) work.
148
- // int main(int argc, char *argv[])
149
- // {
150
- // piped_processt subp = piped_processt("/usr/local/bin/z3 --help");
151
- // std::string data = subp.receive();
152
- // std::cout << data << std::endl;
153
- // return 0;
154
- // }
0 commit comments