4
4
#include <assert.h>
5
5
#include <stdbool.h>
6
6
#include <stdlib.h>
7
- #include <winpty_constants.h>
8
7
9
8
#include "nvim/ascii.h"
10
9
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8
@@ -23,11 +22,7 @@ static void CALLBACK pty_process_finish1(void *context, BOOLEAN unused)
23
22
PtyProcess * ptyproc = (PtyProcess * )context ;
24
23
Process * proc = (Process * )ptyproc ;
25
24
26
- if (ptyproc -> type == kConpty
27
- && ptyproc -> object .conpty != NULL ) {
28
- os_conpty_free (ptyproc -> object .conpty );
29
- ptyproc -> object .conpty = NULL ;
30
- }
25
+ os_conpty_free (ptyproc -> conpty );
31
26
uv_timer_init (& proc -> loop -> uv , & ptyproc -> wait_eof_timer );
32
27
ptyproc -> wait_eof_timer .data = (void * )ptyproc ;
33
28
uv_timer_start (& ptyproc -> wait_eof_timer , wait_eof_timer_cb , 200 , 200 );
@@ -39,10 +34,6 @@ int pty_process_spawn(PtyProcess *ptyproc)
39
34
{
40
35
Process * proc = (Process * )ptyproc ;
41
36
int status = 0 ;
42
- winpty_error_ptr_t err = NULL ;
43
- winpty_config_t * cfg = NULL ;
44
- winpty_spawn_config_t * spawncfg = NULL ;
45
- winpty_t * winpty_object = NULL ;
46
37
conpty_t * conpty_object = NULL ;
47
38
char * in_name = NULL ;
48
39
char * out_name = NULL ;
@@ -56,38 +47,11 @@ int pty_process_spawn(PtyProcess *ptyproc)
56
47
57
48
assert (proc -> err .closed );
58
49
59
- if (os_has_conpty_working ()) {
60
- if ((conpty_object =
61
- os_conpty_init (& in_name , & out_name , ptyproc -> width , ptyproc -> height )) != NULL ) {
62
- ptyproc -> type = kConpty ;
63
- }
64
- }
65
-
66
- if (ptyproc -> type == kWinpty ) {
67
- cfg = winpty_config_new (WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION , & err );
68
- if (cfg == NULL ) {
69
- emsg = "winpty_config_new failed" ;
70
- goto cleanup ;
71
- }
72
-
73
- winpty_config_set_initial_size (cfg , ptyproc -> width , ptyproc -> height );
74
- winpty_object = winpty_open (cfg , & err );
75
- if (winpty_object == NULL ) {
76
- emsg = "winpty_open failed" ;
77
- goto cleanup ;
78
- }
79
-
80
- status = utf16_to_utf8 (winpty_conin_name (winpty_object ), -1 , & in_name );
81
- if (status != 0 ) {
82
- emsg = "utf16_to_utf8(winpty_conin_name) failed" ;
83
- goto cleanup ;
84
- }
85
-
86
- status = utf16_to_utf8 (winpty_conout_name (winpty_object ), -1 , & out_name );
87
- if (status != 0 ) {
88
- emsg = "utf16_to_utf8(winpty_conout_name) failed" ;
89
- goto cleanup ;
90
- }
50
+ if (!os_has_conpty_working ()
51
+ || (conpty_object =
52
+ os_conpty_init (& in_name , & out_name , ptyproc -> width , ptyproc -> height )) == NULL ) {
53
+ status = UV_ENOSYS ;
54
+ goto cleanup ;
91
55
}
92
56
93
57
if (!proc -> in .closed ) {
@@ -130,44 +94,15 @@ int pty_process_spawn(PtyProcess *ptyproc)
130
94
goto cleanup ;
131
95
}
132
96
133
- if (ptyproc -> type == kConpty ) {
134
- if (!os_conpty_spawn (conpty_object ,
135
- & process_handle ,
136
- NULL ,
137
- cmd_line ,
138
- cwd ,
139
- env )) {
140
- emsg = "os_conpty_spawn failed" ;
141
- status = (int )GetLastError ();
142
- goto cleanup ;
143
- }
144
- } else {
145
- spawncfg = winpty_spawn_config_new (WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN ,
146
- NULL , // Optional application name
147
- cmd_line ,
148
- cwd ,
149
- env ,
150
- & err );
151
- if (spawncfg == NULL ) {
152
- emsg = "winpty_spawn_config_new failed" ;
153
- goto cleanup ;
154
- }
155
-
156
- DWORD win_err = 0 ;
157
- if (!winpty_spawn (winpty_object ,
158
- spawncfg ,
159
- & process_handle ,
160
- NULL , // Optional thread handle
161
- & win_err ,
162
- & err )) {
163
- if (win_err ) {
164
- status = (int )win_err ;
165
- emsg = "failed to spawn process" ;
166
- } else {
167
- emsg = "winpty_spawn failed" ;
168
- }
169
- goto cleanup ;
170
- }
97
+ if (!os_conpty_spawn (conpty_object ,
98
+ & process_handle ,
99
+ NULL ,
100
+ cmd_line ,
101
+ cwd ,
102
+ env )) {
103
+ emsg = "os_conpty_spawn failed" ;
104
+ status = (int )GetLastError ();
105
+ goto cleanup ;
171
106
}
172
107
proc -> pid = (int )GetProcessId (process_handle );
173
108
@@ -186,11 +121,8 @@ int pty_process_spawn(PtyProcess *ptyproc)
186
121
uv_run (& proc -> loop -> uv , UV_RUN_ONCE );
187
122
}
188
123
189
- (ptyproc -> type == kConpty ) ?
190
- (void * )(ptyproc -> object .conpty = conpty_object ) :
191
- (void * )(ptyproc -> object .winpty = winpty_object );
124
+ ptyproc -> conpty = conpty_object ;
192
125
ptyproc -> process_handle = process_handle ;
193
- winpty_object = NULL ;
194
126
conpty_object = NULL ;
195
127
process_handle = NULL ;
196
128
@@ -200,16 +132,7 @@ int pty_process_spawn(PtyProcess *ptyproc)
200
132
ELOG ("pty_process_spawn(%s): %s: error code: %d" ,
201
133
proc -> argv [0 ], emsg , status );
202
134
status = os_translate_sys_error (status );
203
- } else if (err != NULL ) {
204
- status = (int )winpty_error_code (err );
205
- ELOG ("pty_process_spawn(%s): %s: error code: %d" ,
206
- proc -> argv [0 ], emsg , status );
207
- status = translate_winpty_error (status );
208
135
}
209
- winpty_error_free (err );
210
- winpty_config_free (cfg );
211
- winpty_spawn_config_free (spawncfg );
212
- winpty_free (winpty_object );
213
136
os_conpty_free (conpty_object );
214
137
xfree (in_name );
215
138
xfree (out_name );
@@ -232,12 +155,7 @@ const char *pty_process_tty_name(PtyProcess *ptyproc)
232
155
void pty_process_resize (PtyProcess * ptyproc , uint16_t width , uint16_t height )
233
156
FUNC_ATTR_NONNULL_ALL
234
157
{
235
- if (ptyproc -> type == kConpty
236
- && ptyproc -> object .conpty != NULL ) {
237
- os_conpty_set_size (ptyproc -> object .conpty , width , height );
238
- } else if (ptyproc -> object .winpty != NULL ) {
239
- winpty_set_size (ptyproc -> object .winpty , width , height , NULL );
240
- }
158
+ os_conpty_set_size (ptyproc -> conpty , width , height );
241
159
}
242
160
243
161
void pty_process_close (PtyProcess * ptyproc )
@@ -255,11 +173,6 @@ void pty_process_close(PtyProcess *ptyproc)
255
173
void pty_process_close_master (PtyProcess * ptyproc )
256
174
FUNC_ATTR_NONNULL_ALL
257
175
{
258
- if (ptyproc -> type == kWinpty
259
- && ptyproc -> object .winpty != NULL ) {
260
- winpty_free (ptyproc -> object .winpty );
261
- ptyproc -> object .winpty = NULL ;
262
- }
263
176
}
264
177
265
178
void pty_process_teardown (Loop * loop )
@@ -434,40 +347,6 @@ static void quote_cmd_arg(char *dest, size_t dest_remaining, const char *src)
434
347
}
435
348
}
436
349
437
- /// Translate winpty error code to libuv error.
438
- ///
439
- /// @param[in] winpty_errno Winpty error code returned by winpty_error_code
440
- /// function.
441
- ///
442
- /// @returns Error code of libuv error.
443
- int translate_winpty_error (int winpty_errno )
444
- {
445
- if (winpty_errno <= 0 ) {
446
- return winpty_errno ; // If < 0 then it's already a libuv error.
447
- }
448
-
449
- switch (winpty_errno ) {
450
- case WINPTY_ERROR_OUT_OF_MEMORY :
451
- return UV_ENOMEM ;
452
- case WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED :
453
- return UV_EAI_FAIL ;
454
- case WINPTY_ERROR_LOST_CONNECTION :
455
- return UV_ENOTCONN ;
456
- case WINPTY_ERROR_AGENT_EXE_MISSING :
457
- return UV_ENOENT ;
458
- case WINPTY_ERROR_UNSPECIFIED :
459
- return UV_UNKNOWN ;
460
- case WINPTY_ERROR_AGENT_DIED :
461
- return UV_ESRCH ;
462
- case WINPTY_ERROR_AGENT_TIMEOUT :
463
- return UV_ETIMEDOUT ;
464
- case WINPTY_ERROR_AGENT_CREATION_FAILED :
465
- return UV_EAI_FAIL ;
466
- default :
467
- return UV_UNKNOWN ;
468
- }
469
- }
470
-
471
350
typedef struct EnvNode {
472
351
wchar_t * str ;
473
352
size_t len ;
@@ -484,7 +363,7 @@ static int build_env_block(dict_T *denv, wchar_t **env_block)
484
363
{
485
364
const size_t denv_size = (size_t )tv_dict_len (denv );
486
365
size_t env_block_len = 0 ;
487
- int rc ;
366
+ int rc = 0 ;
488
367
char * * env = tv_dict_to_env (denv );
489
368
490
369
QUEUE * q ;
0 commit comments