@@ -138,31 +138,6 @@ def fail(
138
138
warn_or_fail (* args , filename = filename , line_number = line_number , fail = True )
139
139
140
140
141
- is_legal_c_identifier = re .compile ('^[A-Za-z_][A-Za-z0-9_]*$' ).match
142
-
143
- def is_legal_py_identifier (s : str ) -> bool :
144
- return all (is_legal_c_identifier (field ) for field in s .split ('.' ))
145
-
146
- # identifiers that are okay in Python but aren't a good idea in C.
147
- # so if they're used Argument Clinic will add "_value" to the end
148
- # of the name in C.
149
- c_keywords = set ("""
150
- asm auto break case char const continue default do double
151
- else enum extern float for goto if inline int long
152
- register return short signed sizeof static struct switch
153
- typedef typeof union unsigned void volatile while
154
- """ .strip ().split ())
155
-
156
- def ensure_legal_c_identifier (s : str ) -> str :
157
- # for now, just complain if what we're given isn't legal
158
- if not is_legal_c_identifier (s ):
159
- fail ("Illegal C identifier:" , s )
160
- # but if we picked a C keyword, pick something else
161
- if s in c_keywords :
162
- return s + "_value"
163
- return s
164
-
165
-
166
141
class CRenderData :
167
142
def __init__ (self ) -> None :
168
143
@@ -2954,7 +2929,7 @@ def __init__(self,
2954
2929
unused : bool = False ,
2955
2930
** kwargs : Any
2956
2931
) -> None :
2957
- self .name = ensure_legal_c_identifier (name )
2932
+ self .name = libclinic . ensure_legal_c_identifier (name )
2958
2933
self .py_name = py_name
2959
2934
self .unused = unused
2960
2935
self .includes : list [Include ] = []
@@ -5083,9 +5058,9 @@ def parse_function_names(self, line: str) -> FunctionNames:
5083
5058
if fields [- 1 ] == '__new__' :
5084
5059
fields .pop ()
5085
5060
c_basename = "_" .join (fields )
5086
- if not is_legal_py_identifier (full_name ):
5061
+ if not libclinic . is_legal_py_identifier (full_name ):
5087
5062
fail (f"Illegal function name: { full_name !r} " )
5088
- if not is_legal_c_identifier (c_basename ):
5063
+ if not libclinic . is_legal_c_identifier (c_basename ):
5089
5064
fail (f"Illegal C basename: { c_basename !r} " )
5090
5065
names = FunctionNames (full_name = full_name , c_basename = c_basename )
5091
5066
self .normalize_function_kind (names .full_name )
@@ -5207,7 +5182,7 @@ def state_modulename_name(self, line: str) -> None:
5207
5182
before , equals , existing = line .rpartition ('=' )
5208
5183
if equals :
5209
5184
existing = existing .strip ()
5210
- if is_legal_py_identifier (existing ):
5185
+ if libclinic . is_legal_py_identifier (existing ):
5211
5186
# we're cloning!
5212
5187
names = self .parse_function_names (before )
5213
5188
return self .parse_cloned_function (names , existing )
0 commit comments