Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1b13e1

Browse files
committed
Fix swig target extension when swig target is not defined by the .i file but should be c++.
1 parent ff0822c commit a1b13e1

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

numpy/distutils/command/build_src.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ def swig_sources(self, sources, extension):
656656
for source in sources:
657657
(base, ext) = os.path.splitext(source)
658658
if ext == '.i': # SWIG interface file
659+
# the code below assumes that the sources list
660+
# contains not more than one .i SWIG interface file
659661
if self.inplace:
660662
target_dir = os.path.dirname(base)
661663
py_target_dir = self.ext_target_dir
@@ -671,10 +673,16 @@ def swig_sources(self, sources, extension):
671673
if typ is None:
672674
typ = get_swig_target(source)
673675
is_cpp = typ=='c++'
674-
if is_cpp: target_ext = '.cpp'
676+
if is_cpp:
677+
target_ext = '.cpp'
675678
else:
676679
typ2 = get_swig_target(source)
677-
if typ!=typ2:
680+
if typ2 is None:
681+
log.warn('source %r does not define swig target, assuming %s swig target' \
682+
% (source, typ))
683+
if is_cpp:
684+
target_ext = '.cpp'
685+
elif typ!=typ2:
678686
log.warn('expected %r but source %r defines %r swig target' \
679687
% (typ, source, typ2))
680688
if typ2=='c++':
@@ -750,7 +758,7 @@ def swig_sources(self, sources, extension):
750758

751759
def get_swig_target(source):
752760
f = open(source,'r')
753-
result = 'c'
761+
result = None
754762
line = f.readline()
755763
if _has_cpp_header(line):
756764
result = 'c++'

0 commit comments

Comments
 (0)