Skip to content

Commit 3166610

Browse files
authored
Merge pull request #128 from geohot/master
Fix versioned symbols from nm
2 parents c995397 + 44830a6 commit 3166610

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ ctypeslib.egg-info/
77
ctypeslib2.egg-info/
88
*.gitignore~
99
*.so
10+
.*.swp

ctypeslib/codegen/codegenerator.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ def Macro(self, macro):
226226
body = float_value
227227
# what about integers you ask ? body token that represents token are Integer here.
228228
# either it's just a thing we gonna print, or we need to have a registered item
229-
print("%s = %s # macro" % (macro.name, body), file=self.stream)
229+
if sum(x=='(' for x in body) != sum(x==')' for x in body):
230+
# unbalanced parens means comment
231+
print("# %s = %s # macro" % (macro.name, body), file=self.stream)
232+
else:
233+
print("%s = %s # macro" % (macro.name, body), file=self.stream)
230234
self.macros += 1
231235
self.names.append(macro.name)
232236
# This is why we need to have token types all the way here.
@@ -515,10 +519,10 @@ def _get_undefined_head_dependencies(self, struct):
515519
"""Return head dependencies on other record types.
516520
Head dependencies is exclusive of body dependency. It's one or the other.
517521
"""
518-
r = set()
522+
r = dict()
519523
for m in struct.members:
520524
if isinstance(m.type, typedesc.PointerType) and typedesc.is_record(m.type.typ):
521-
r.add(m.type)
525+
r[m.type] = None
522526
# remove all already defined heads
523527
r = [_ for _ in r if _.name not in self.head_generated]
524528
return r
@@ -527,14 +531,14 @@ def _get_undefined_body_dependencies(self, struct):
527531
"""Return head dependencies on other record types.
528532
Head dependencies is exclusive of body dependency. It's one or the other.
529533
"""
530-
r = set()
534+
r = dict()
531535
for m in struct.members:
532536
if isinstance(m.type, typedesc.ArrayType) and typedesc.is_record(m.type.typ):
533-
r.add(m.type.typ)
537+
r[m.type.typ] = None
534538
elif typedesc.is_record(m.type):
535-
r.add(m.type)
539+
r[m.type] = None
536540
elif m.type not in self.done:
537-
r.add(m.type)
541+
r[m.type] = None
538542
# remove all already defined bodies
539543
r = [_ for _ in r if _.name not in self.body_generated]
540544
return r
@@ -850,14 +854,14 @@ class LibraryStub:
850854
if self.generate_locations and func.location:
851855
print("# %s %s" % func.location, file=self.stream)
852856
# Generate the function decl code
853-
print("%s = %s.%s" % (func.name, libname, func.name), file=self.stream)
854-
print(
855-
"%s.restype = %s" % (func.name, self.type_name(func.returns)),
856-
file=self.stream,
857-
)
857+
print("try:", file=self.stream)
858+
print(" %s = %s.%s" % (func.name, libname, func.name), file=self.stream)
859+
print(" %s.restype = %s" % (func.name, self.type_name(func.returns)), file=self.stream)
858860
if self.generate_comments:
859861
print("# %s(%s)" % (func.name, ", ".join(argnames)), file=self.stream)
860-
print("%s.argtypes = [%s]" % (func.name, ", ".join(args)), file=self.stream)
862+
print(" %s.argtypes = [%s]" % (func.name, ", ".join(args)), file=self.stream)
863+
print("except AttributeError:", file=self.stream)
864+
print(" pass", file=self.stream)
861865

862866
if self.generate_docstrings:
863867

ctypeslib/library.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _get_symbols(self, nm):
4747
for line in output.split('\n'):
4848
fields = line.split(' ', 2)
4949
if len(fields) >= 3 and fields[1] in ("T", "D", "G", "R", "S"):
50+
if '@@' in fields[2]: fields[2] = fields[2].split('@@')[0]
5051
self.__symbols[fields[2]] = fields[0]
5152

5253
def __getattr__(self, name):

0 commit comments

Comments
 (0)