Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commit094bf2c

Browse files
committed
Fix geninterop script and regenerate interop39.cs
- Only record structs when they are defined, not when they are declared- If a struct was only declared when a typedef was created, it won't contain its member declarations. Those have to be drawn from the recorded structs instead.- Rename internal members of AstParser to make it easier to debug
1 parentfd4f9bc commit094bf2c

File tree

2 files changed

+98
-42
lines changed

2 files changed

+98
-42
lines changed

‎src/runtime/interop39.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,57 @@ namespace Python.Runtime
1818
internalstaticpartialclassTypeOffset
1919
{
2020
// Auto-generated from PyHeapTypeObject in Python.h
21+
publicstaticintob_refcnt=0;
22+
publicstaticintob_type=0;
23+
publicstaticintob_size=0;
24+
publicstaticinttp_name=0;
25+
publicstaticinttp_basicsize=0;
26+
publicstaticinttp_itemsize=0;
27+
publicstaticinttp_dealloc=0;
28+
publicstaticinttp_vectorcall_offset=0;
29+
publicstaticinttp_getattr=0;
30+
publicstaticinttp_setattr=0;
31+
publicstaticinttp_as_async=0;
32+
publicstaticinttp_repr=0;
33+
publicstaticinttp_as_number=0;
34+
publicstaticinttp_as_sequence=0;
35+
publicstaticinttp_as_mapping=0;
36+
publicstaticinttp_hash=0;
37+
publicstaticinttp_call=0;
38+
publicstaticinttp_str=0;
39+
publicstaticinttp_getattro=0;
40+
publicstaticinttp_setattro=0;
41+
publicstaticinttp_as_buffer=0;
42+
publicstaticinttp_flags=0;
43+
publicstaticinttp_doc=0;
44+
publicstaticinttp_traverse=0;
45+
publicstaticinttp_clear=0;
46+
publicstaticinttp_richcompare=0;
47+
publicstaticinttp_weaklistoffset=0;
48+
publicstaticinttp_iter=0;
49+
publicstaticinttp_iternext=0;
50+
publicstaticinttp_methods=0;
51+
publicstaticinttp_members=0;
52+
publicstaticinttp_getset=0;
53+
publicstaticinttp_base=0;
54+
publicstaticinttp_dict=0;
55+
publicstaticinttp_descr_get=0;
56+
publicstaticinttp_descr_set=0;
57+
publicstaticinttp_dictoffset=0;
58+
publicstaticinttp_init=0;
59+
publicstaticinttp_alloc=0;
60+
publicstaticinttp_new=0;
61+
publicstaticinttp_free=0;
62+
publicstaticinttp_is_gc=0;
63+
publicstaticinttp_bases=0;
64+
publicstaticinttp_mro=0;
65+
publicstaticinttp_cache=0;
66+
publicstaticinttp_subclasses=0;
67+
publicstaticinttp_weaklist=0;
68+
publicstaticinttp_del=0;
69+
publicstaticinttp_version_tag=0;
70+
publicstaticinttp_finalize=0;
71+
publicstaticinttp_vectorcall=0;
2172
publicstaticintam_await=0;
2273
publicstaticintam_aiter=0;
2374
publicstaticintam_anext=0;
@@ -174,4 +225,3 @@ internal static partial class SlotTypes
174225

175226
}
176227
#endif
177-

‎tools/geninterop/geninterop.py

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@ class AstParser(object):
5353
"""Walk an AST and determine the members of all structs"""
5454

5555
def__init__(self):
56-
self.__typedefs= {}
57-
self.__typedecls= {}
58-
self.__structs= {}
59-
self.__struct_stack= []
60-
self.__struct_members_stack= []
61-
self.__ptr_decl_depth=0
62-
self.__struct_members= {}
63-
self.__decl_names= {}
56+
self._typedefs= {}
57+
self._typedecls= {}
58+
self._structs= {}
59+
self._struct_stack= []
60+
self._struct_members_stack= []
61+
self._ptr_decl_depth=0
62+
self._struct_members= {}
63+
self._decl_names= {}
6464

6565
defget_struct_members(self,name):
6666
"""return a list of (name, type) of struct members"""
67-
defs=self.__typedefs.get(name)
67+
defs=self._typedefs.get(name)
6868
ifdefsisNone:
6969
returnNone
70-
node=self.__get_leaf_node(defs)
70+
node=self._get_leaf_node(defs)
7171
name=node.name
7272
ifnameisNone:
7373
name=defs.declname
74-
returnself.__struct_members.get(name)
74+
returnself._struct_members.get(name)
7575

7676
defvisit(self,node):
7777
ifisinstance(node,c_ast.FileAST):
@@ -96,27 +96,27 @@ def visit_ast(self, ast):
9696
self.visit(node)
9797

9898
defvisit_typedef(self,typedef):
99-
self.__typedefs[typedef.name]=typedef.type
99+
self._typedefs[typedef.name]=typedef.type
100100
self.visit(typedef.type)
101101

102102
defvisit_typedecl(self,typedecl):
103-
self.__decl_names[typedecl.type]=typedecl.declname
103+
self._decl_names[typedecl.type]=typedecl.declname
104104
self.visit(typedecl.type)
105105

106106
defvisit_struct(self,struct):
107-
self.__structs[self.__get_struct_name(struct)]=struct
108107
ifstruct.decls:
108+
self._structs[self._get_struct_name(struct)]=struct
109109
# recurse into the struct
110-
self.__struct_stack.insert(0,struct)
110+
self._struct_stack.insert(0,struct)
111111
fordeclinstruct.decls:
112-
self.__struct_members_stack.insert(0,decl.name)
112+
self._struct_members_stack.insert(0,decl.name)
113113
self.visit(decl)
114-
self.__struct_members_stack.pop(0)
115-
self.__struct_stack.pop(0)
116-
elifself.__ptr_decl_depth:
114+
self._struct_members_stack.pop(0)
115+
self._struct_stack.pop(0)
116+
elifself._ptr_decl_depth:
117117
# the struct is empty, but add it as a member to the current
118118
# struct as the current member maybe a pointer to it.
119-
self.__add_struct_member(struct.name)
119+
self._add_struct_member(struct.name)
120120

121121
defvisit_decl(self,decl):
122122
self.visit(decl.type)
@@ -125,51 +125,57 @@ def visit_funcdecl(self, funcdecl):
125125
self.visit(funcdecl.type)
126126

127127
defvisit_ptrdecl(self,ptrdecl):
128-
self.__ptr_decl_depth+=1
128+
self._ptr_decl_depth+=1
129129
self.visit(ptrdecl.type)
130-
self.__ptr_decl_depth-=1
130+
self._ptr_decl_depth-=1
131131

132132
defvisit_identifier(self,identifier):
133133
type_name=" ".join(identifier.names)
134-
self.__add_struct_member(type_name)
134+
self._add_struct_member(type_name)
135135

136-
def__add_struct_member(self,type_name):
137-
ifnot (self.__struct_stackandself.__struct_members_stack):
136+
def_add_struct_member(self,type_name):
137+
ifnot (self._struct_stackandself._struct_members_stack):
138138
return
139139

140140
# add member to current struct
141-
current_struct=self.__struct_stack[0]
142-
member_name=self.__struct_members_stack[0]
143-
struct_members=self.__struct_members.setdefault(
144-
self.__get_struct_name(current_struct), [])
141+
current_struct=self._struct_stack[0]
142+
member_name=self._struct_members_stack[0]
143+
struct_members=self._struct_members.setdefault(
144+
self._get_struct_name(current_struct), [])
145145

146146
# get the node associated with this type
147147
node=None
148-
iftype_nameinself.__typedefs:
149-
node=self.__get_leaf_node(self.__typedefs[type_name])
150-
eliftype_nameinself.__structs:
151-
node=self.__structs[type_name]
148+
iftype_nameinself._typedefs:
149+
node=self._get_leaf_node(self._typedefs[type_name])
150+
# If the struct was only declared when the typedef was created, its member
151+
# information will not have been recorded and we have to look it up in the
152+
# structs
153+
ifisinstance(node,c_ast.Struct)andnode.declsisNone:
154+
ifnode.nameinself._structs:
155+
node=self._structs[node.name]
156+
eliftype_nameinself._structs:
157+
node=self._structs[type_name]
152158

153159
# If it's a struct (and not a pointer to a struct) expand
154160
# it into the current struct definition
155-
ifnotself.__ptr_decl_depthandisinstance(node,c_ast.Struct):
161+
ifnotself._ptr_decl_depthandisinstance(node,c_ast.Struct):
156162
fordeclinnode.declsor []:
157-
self.__struct_members_stack.insert(0,decl.name)
163+
self._struct_members_stack.insert(0,decl.name)
158164
self.visit(decl)
159-
self.__struct_members_stack.pop(0)
165+
self._struct_members_stack.pop(0)
160166
else:
161167
# otherwise add it as a single member
162168
struct_members.append((member_name,type_name))
163169

164-
def__get_leaf_node(self,node):
170+
def_get_leaf_node(self,node):
165171
ifisinstance(node,c_ast.Typedef):
166-
returnself.__get_leaf_node(node.type)
172+
returnself._get_leaf_node(node.type)
167173
ifisinstance(node,c_ast.TypeDecl):
168-
returnself.__get_leaf_node(node.type)
174+
returnself._get_leaf_node(node.type)
169175
returnnode
170176

171-
def__get_struct_name(self,node):
172-
returnnode.nameorself.__decl_names.get(node)or"_struct_%d"%id(node)
177+
def_get_struct_name(self,node):
178+
returnnode.nameorself._decl_names.get(node)or"_struct_%d"%id(node)
173179

174180

175181
classWriter(object):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp