Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix versioned symbols from nm #128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ctypeslib.egg-info/
ctypeslib2.egg-info/
*.gitignore~
*.so
.*.swp
30 changes: 17 additions & 13 deletions ctypeslib/codegen/codegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ def Macro(self, macro):
body = float_value
# what about integers you ask ? body token that represents token are Integer here.
# either it's just a thing we gonna print, or we need to have a registered item
print("%s = %s # macro" % (macro.name, body), file=self.stream)
if sum(x=='(' for x in body) != sum(x==')' for x in body):
# unbalanced parens means comment
print("# %s = %s # macro" % (macro.name, body), file=self.stream)
else:
print("%s = %s # macro" % (macro.name, body), file=self.stream)
self.macros += 1
self.names.append(macro.name)
# This is why we need to have token types all the way here.
Expand Down Expand Up @@ -515,10 +519,10 @@ def _get_undefined_head_dependencies(self, struct):
"""Return head dependencies on other record types.
Head dependencies is exclusive of body dependency. It's one or the other.
"""
r = set()
r = dict()
for m in struct.members:
if isinstance(m.type, typedesc.PointerType) and typedesc.is_record(m.type.typ):
r.add(m.type)
r[m.type] = None
# remove all already defined heads
r = [_ for _ in r if _.name not in self.head_generated]
return r
Expand All @@ -527,14 +531,14 @@ def _get_undefined_body_dependencies(self, struct):
"""Return head dependencies on other record types.
Head dependencies is exclusive of body dependency. It's one or the other.
"""
r = set()
r = dict()
for m in struct.members:
if isinstance(m.type, typedesc.ArrayType) and typedesc.is_record(m.type.typ):
r.add(m.type.typ)
r[m.type.typ] = None
elif typedesc.is_record(m.type):
r.add(m.type)
r[m.type] = None
elif m.type not in self.done:
r.add(m.type)
r[m.type] = None
# remove all already defined bodies
r = [_ for _ in r if _.name not in self.body_generated]
return r
Expand Down Expand Up @@ -850,14 +854,14 @@ class LibraryStub:
if self.generate_locations and func.location:
print("# %s %s" % func.location, file=self.stream)
# Generate the function decl code
print("%s = %s.%s" % (func.name, libname, func.name), file=self.stream)
print(
"%s.restype = %s" % (func.name, self.type_name(func.returns)),
file=self.stream,
)
print("try:", file=self.stream)
print(" %s = %s.%s" % (func.name, libname, func.name), file=self.stream)
print(" %s.restype = %s" % (func.name, self.type_name(func.returns)), file=self.stream)
if self.generate_comments:
print("# %s(%s)" % (func.name, ", ".join(argnames)), file=self.stream)
print("%s.argtypes = [%s]" % (func.name, ", ".join(args)), file=self.stream)
print(" %s.argtypes = [%s]" % (func.name, ", ".join(args)), file=self.stream)
print("except AttributeError:", file=self.stream)
print(" pass", file=self.stream)

if self.generate_docstrings:

Expand Down
1 change: 1 addition & 0 deletions ctypeslib/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _get_symbols(self, nm):
for line in output.split('\n'):
fields = line.split(' ', 2)
if len(fields) >= 3 and fields[1] in ("T", "D", "G", "R", "S"):
if '@@' in fields[2]: fields[2] = fields[2].split('@@')[0]
self.__symbols[fields[2]] = fields[0]

def __getattr__(self, name):
Expand Down