2
2
3
3
import os
4
4
import os .path
5
+ import six
5
6
import subprocess
6
7
import sys
7
8
@@ -212,7 +213,7 @@ def visit_TypeDecl(self, node):
212
213
if not decls :
213
214
return
214
215
assert len (decls ) == 1
215
- if isinstance (decls [0 ], basestring ):
216
+ if isinstance (decls [0 ], six . string_types ):
216
217
self .append (IdentifierType (node .declname , decls [0 ]))
217
218
else :
218
219
self .append (decls [0 ])
@@ -222,7 +223,7 @@ def visit_Decl(self, node):
222
223
if not decls :
223
224
return
224
225
assert len (decls ) == 1
225
- if isinstance (decls [0 ], basestring ):
226
+ if isinstance (decls [0 ], six . string_types ):
226
227
self .append (IdentifierType (node .name , decls [0 ]))
227
228
else :
228
229
self .append (decls [0 ])
@@ -248,7 +249,7 @@ def visit_FuncDecl(self, node):
248
249
def visit_PtrDecl (self , node ):
249
250
decls = self .collect (node )
250
251
assert len (decls ) == 1
251
- if isinstance (decls [0 ], basestring ):
252
+ if isinstance (decls [0 ], six . string_types ):
252
253
self .append (decls [0 ])
253
254
else :
254
255
self .append (Ptr (decls [0 ]))
@@ -306,12 +307,12 @@ def preprocess(code, extra_cpp_args=[]):
306
307
'cpp' , '-nostdinc' , '-D__attribute__(x)=' , '-I' , BUILTIN_HEADERS_DIR ,
307
308
] + extra_cpp_args + ['-' ], stdin = subprocess .PIPE , stdout = subprocess .PIPE )
308
309
result = []
309
- result .append (proc .communicate (input = code )[0 ])
310
+ result .append (proc .communicate (input = code . encode ( 'utf-8' ) )[0 ])
310
311
while proc .poll () is None :
311
312
result .append (proc .communicate ()[0 ])
312
313
if proc .returncode :
313
314
raise Exception ('Invoking C preprocessor failed' )
314
- return '' .join (result )
315
+ return b '' .join (result ). decode ( 'utf-8' )
315
316
316
317
317
318
def parse (code , extra_cpp_args = []):
0 commit comments