* namespace (string): C++ namespace of the source (`None` for C
objects, set if the symbol is external)
* cdef_flag (boolean): Symbol (data) has a C definition.
- * extern (boolean): Symbol is defined elsewhere (otherwise a local
- defition is created).
- * visibility ('private'|'public'|'ignore'):
+ * visibility ('private'|'public'|'extern'|'ignore'):
* private: Symbol is not accessible to external C code
* public: Symbol is accessible to external C code
+ * extern: Symbol is defined elsewhere (otherwise a local
+ definition is created).
* ignore: ? something about symbol re-definition?
* const (boolean): Symbol data is readonly.
cname = None
namespace = None
cdef_flag = 0
- extern = 0
c_visibility = 'private'
const = 0
api = 0
"Combine all binding attributes in a single, flat namespace."
def visibility_string(self):
"Summarize binding visibility in a single string"
- if self.extern:
- extern_string = ' (extern)'
- else:
- extern_string = ''
- return 'C: %s%s, Python: %s' % (
- self.c_visibility, extern_string, self.visibility)
-
+ return 'C: %s, Python: %s' % (
+ self.c_visibility, self.visibility)
if sig is None:
sig = Signature(self.args, self.ret_type)
func_type = sig.function_type()
- binding = Binding(name = self.py_name, cname = self.cname, extern = 1)
+ binding = Binding(
+ name = self.py_name, cname = self.cname,
+ c_visibility = 'extern')
scope.declare_builtin_cfunction(
binding, type = func_type, python_equiv = self.py_equiv,
utility_code = self.utility_code)
self_arg = PyrexTypes.CFuncTypeArg("", self_type, None)
self_arg.not_none = True
method_type = sig.function_type(self_arg)
- binding = Binding(name = self.py_name, cname = self.cname, extern = 1)
+ binding = Binding(
+ name = self.py_name, cname = self.cname,
+ c_visibility = 'extern')
self_type.scope.declare_builtin_cfunction(
binding, type = method_type, utility_code = self.utility_code)
else:
objstruct_cname = 'Py%sObject' % name.capitalize()
binding = Binding(
- name = name, cname = cname, extern = 1, c_visibility = 'public')
+ name = name, cname = cname, c_visibility = 'extern')
the_type = builtin_scope.declare_builtin_type(
binding, objstruct_cname = objstruct_cname, utility_code = utility)
builtin_types[name] = the_type
#print "not used and private, skipping", entry.cname ###
return
storage_class = ""
- if entry.extern:
+ if entry.c_visibility == 'extern':
storage_class = Naming.extern_c_macro
elif entry.c_visibility == 'public':
if not definition:
storage_class = "static"
if storage_class:
self.put("%s " % storage_class)
- if (entry.extern or entry.c_visibility != 'public'):
+ if entry.c_visibility != 'public':
dll_linkage = None
self.put(entry.type.declaration_code(entry.cname,
dll_linkage = dll_linkage))
return_type = PyrexTypes.CFuncType(type, [])
return_type = PyrexTypes.CPtrType(return_type)
binding = Binding(
- name = u'<init>', extern = True, c_visibility = 'public')
+ name = u'<init>', c_visibility = 'extern')
type.scope.declare_cfunction(
binding, type = return_type, pos = self.pos)
constructor = type.scope.lookup(u'<init>')
def generate_h_code(self, env, options, result):
def h_entries(entries, pxd = 0):
return [entry for entry in entries
- if (entry.c_visibility == 'public' and
- not entry.extern)
+ if entry.c_visibility == 'public'
or pxd and entry.defined_in_pxd]
h_types = h_entries(env.type_entries)
h_vars = h_entries(env.var_entries)
code.putln("")
name = entry.type.typeobj_cname
if name:
- if entry.extern and not entry.in_cinclude:
+ if entry.c_visibility == 'extern' and not entry.in_cinclude:
code.putln("%s DL_IMPORT(PyTypeObject) %s;" % (
Naming.extern_c_macro,
name))
def generate_cfunction_predeclarations(self, env, code, definition):
for entry in env.cfunc_entries:
if entry.inline_func_in_pxd or (not entry.in_cinclude and (definition
- or entry.defined_in_pxd or entry.extern)):
- if entry.extern or entry.c_visibility == 'public':
+ or entry.defined_in_pxd or entry.c_visibility == 'extern')):
+ if entry.c_visibility in ('extern', 'public'):
dll_linkage = "DL_EXPORT"
else:
dll_linkage = None
dll_linkage = dll_linkage)
if entry.c_visibility == 'private':
storage_class = "static "
- elif (entry.c_visibility == 'public' and not entry.extern):
+ elif entry.c_visibility == 'public':
storage_class = ""
else:
storage_class = "%s " % Naming.extern_c_macro
for entry in env.c_class_entries:
#print "generate_typeobj_definitions:", entry.name
#print "...c_visibility =", entry.c_visibility
- if not entry.extern:
+ if entry.c_visibility != 'extern':
type = entry.type
scope = type.scope
if scope: # could be None if there was an error
rev_entries = list(env.var_entries)
rev_entries.reverse()
for entry in rev_entries:
- if not entry.extern:
+ if entry.c_visibility != 'extern':
if entry.type.is_pyobject and entry.used:
code.putln("Py_DECREF(%s); %s = 0;" % (
code.entry_as_pyobject(entry), entry.cname))
# Generate code to initialise global PyObject *
# variables to None.
for entry in env.var_entries:
- if not entry.extern:
+ if entry.c_visibility != 'extern':
if entry.type.is_pyobject and entry.used:
code.put_init_var_to_py_none(entry, nanny=False)
# Generate type import code for extern extension types
# and type ready code for non-extern ones.
for entry in env.c_class_entries:
- if entry.extern:
+ if entry.c_visibility == 'extern':
self.generate_type_import_code(env, entry.type, entry.pos, code)
else:
self.generate_base_type_import_code(env, entry, code)
typeobj_cname = type.typeobj_cname
scope = type.scope
if scope: # could be None if there was an error
- if not entry.extern:
+ if entry.c_visibility != 'extern':
for slot in TypeSlots.slot_table:
slot.generate_dynamic_init_code(scope, code)
code.putln(
class CVarDefNode(StatNode):
# C variable definition or forward/extern function declaration.
#
- # extern (same as Binding.extern)
# c_visibility (same as Binding.c_visibility)
# visibility (same as Binding.visibility)
# base_type CBaseTypeNode
for declarator in self.declarators:
name_declarator, type = declarator.analyse(base_type, env)
if not type.is_complete():
- if not (self.extern and type.is_array):
+ if not (self.c_visibility == 'extern' and type.is_array):
error(declarator.pos,
"Variable type '%s' is incomplete" % type)
- if self.extern and type.is_pyobject:
+ if self.c_visibility == 'extern' and type.is_pyobject:
error(declarator.pos,
"Python object cannot be declared extern")
name = name_declarator.name
else:
if self.directive_locals:
error(self.pos, "Decorators can only be followed by functions")
- if self.in_pxd and not self.extern:
+ if self.in_pxd and self.c_visibility != 'extern':
error(self.pos,
"Only 'extern' C variable declaration allowed in .pxd file")
entry = dest_scope.declare_var(
# cname (same as Binding.cname)
# kind "struct" or "union"
# typedef_flag boolean
- # extern (same as Binding.extern)
# c_visibility (same as Binding.c_visibility)
# visibility (same as Binding.visibility)
# in_pxd boolean
def analyse_declarations(self, env):
scope = None
- if self.extern and self.packed:
+ if self.c_visibility == 'extern' and self.packed:
error(self.pos, "Cannot declare extern struct as 'packed'")
if self.attributes is not None:
scope = StructOrUnionScope(self.name)
self.entry.defined_in_pxd = 1
for attr in self.attributes:
attr.analyse_declarations(env, scope)
- if not self.extern:
+ if self.c_visibility != 'extern':
need_typedef_indirection = False
for attr in scope.var_entries:
type = attr.type
class CppClassNode(CStructOrUnionDefNode):
# name (same as Binding.name)
# cname (same as Binding.cname)
- # extern 1 (same meaning as Binding.extern)
- # c_visibility "public" (same as Binding.c_visibility)
+ # c_visibility 'extern' (same as Binding.c_visibility)
# visibility (same as Binding.visibility)
# in_pxd boolean
# attributes [CVarDefNode] or None
# cname (same as Binding.cname)
# items [CEnumDefItemNode]
# typedef_flag boolean
- # extern (same meaning as Binding.extern)
# c_visibility (same as Binding.c_visibility)
# visibility (same as Binding.visibility)
# in_pxd boolean
# C function definition.
#
# modifiers ['inline']
- # extern (same as Binding.extern)
# c_visibility (same as Binding.c_visibility)
# visibility (same as Binding.visibility)
# base_type CBaseTypeNode
modifiers = self.modifiers, pos = self.pos)
self.entry.inline_func_in_pxd = self.inline_in_pxd
self.return_type = type.return_type
- if self.return_type.is_array and not self.extern:
+ if self.return_type.is_array and self.c_visibility != 'extern':
error(self.pos,
"Function cannot return an array")
if cname is None:
cname = self.entry.func_cname
entity = type.function_header_code(cname, ', '.join(arg_decls))
- if (self.entry.c_visibility == 'public' and
- not self.entry.extern):
+ if self.entry.c_visibility == 'public':
dll_linkage = "DL_EXPORT"
else:
dll_linkage = None
header = self.return_type.declaration_code(entity,
dll_linkage = dll_linkage)
- if self.entry.extern:
+ if self.entry.c_visibility == 'extern':
storage_class = "%s " % Naming.extern_c_macro
elif self.entry.c_visibility == 'public':
storage_class = ""
type = cfunc_type,
with_gil = cfunc_type.with_gil,
nogil = cfunc_type.nogil,
- extern = 0,
c_visibility = 'private',
visibility = 'public',
api = False,
warning(self.pos, "Overriding cdef method with def method.", 5)
binding = Binding(name = name)
if env.is_c_class_scope:
- binding.extern = True
+ binding.c_visibility = 'extern'
entry = env.declare_pyfunction(
binding, allow_redefine=not self.is_wrapper, pos = self.pos)
self.entry = entry
return None
return CClassDefNode(self.pos,
- extern = 0,
c_visibility = 'private',
visibility = 'public',
module_name = None,
class CClassDefNode(ClassDefNode):
# An extension type definition.
#
- # extern (same as Binding.extern)
# c_visibility (same as Binding.c_visibility)
# visibility (same as Binding.visibility)
# typedef_flag boolean
else:
self.base_type = base_class_entry.type
has_body = self.body is not None
- if self.module_name and not self.extern:
+ if self.module_name and self.c_visibility != 'extern':
module_path = self.module_name.split(".")
home_scope = env.find_imported_module(module_path, self.pos)
if not home_scope:
else:
home_scope = env
- if self.extern:
+ if self.c_visibility == 'extern':
if (self.module_name == '__builtin__' and
self.class_name in Builtin.builtin_types and
env.qualified_name[:8] != 'cpython.'): # allow overloaded names for cimporting from cpython
pos = self.pos)
if self.shadow:
home_scope.lookup(self.class_name).as_variable = self.entry
- if home_scope is not env and self.extern:
+ if home_scope is not env and self.c_visibility == 'extern':
env.add_imported_entry(self.entry, self.class_name, pos = self.pos)
self.scope = scope = self.entry.type.scope
if scope is not None:
def visit_CNameDeclaratorNode(self, node):
if node.name in self.seen_vars_stack[-1]:
entry = self.env_stack[-1].lookup(node.name)
- if entry is None or not entry.extern:
+ if entry is None or entry.c_visibility != 'extern':
warning(node.pos, "cdef variable '%s' declared after it is used" % node.name, 2)
self.visitchildren(node)
return node
self.nested_funcdefs.append(node)
return node
- # node.entry.extern = 1
- # node.entry.c_visibility = 'public'
if node.py_func is None:
pf_cname = ''
else:
s.level = ctx.level
if ctx.api:
if ctx.cdef_flag:
- if ctx.extern:
+ if ctx.c_visibility == 'extern':
error(pos, "Cannot combine 'api' with 'extern'")
else:
s.error("'api' not allowed with this statement")
if ctx.level not in ('module', 'function', 'class', 'other'):
s.error("class definition not allowed here")
return p_class_statement(s, decorators)
- elif s.sy == 'from' and ctx.extern:
+ elif s.sy == 'from' and ctx.c_visibility == 'extern':
return p_cdef_extern_block(s, pos, ctx)
elif s.sy == 'import' and ctx.cdef_flag:
s.next()
return p_property_decl(s)
elif ctx.cdef_flag:
if s.sy == 'IDENT' and s.systring == 'cppclass':
- if not ctx.extern:
+ if ctx.c_visibility != 'extern':
error(pos, "C++ classes need to be declared extern")
return p_cpp_class_definition(s, pos, ctx)
elif s.sy == 'IDENT' and s.systring in ("struct", "union", "enum", "packed"):
error(s.position(), "Empty declarator")
name = ""
cname = None
+ if name == 'Rectangle':
+ pass
if cname is None and ctx.namespace is not None and nonempty:
cname = ctx.namespace + "::" + name
- if name == 'operator' and ctx.extern and nonempty:
+ if name == 'operator' and ctx.c_visibility == 'extern' and nonempty:
op = s.sy
if [1 for c in op if c in '+-*/<=>!%&|([^~,']:
s.next()
include_file = p_string_literal(s, 'u')[2]
ctx = ctx()
ctx.cdef_flag = 1
- ctx.extern = 1
+ ctx.c_visibility = 'extern'
if s.systring == "namespace":
s.next()
ctx.namespace = p_string_literal(s, 'u')[2]
items = []
# Work around overloading of the 'public' keyword.
item_ctx = ctx()
- if item_ctx.c_visibility == 'public':
- item_ctx.c_visibility = 'public'
+ if item_ctx.c_visibility in ('public', 'extern'):
item_ctx.visibility = 'public'
else:
item_ctx.c_visibility = 'public'
s.expect_dedent()
return Nodes.CEnumDefNode(
pos, name = name, cname = cname, items = items,
- typedef_flag = ctx.typedef_flag, extern = ctx.extern,
- c_visibility = ctx.c_visibility, visibility = ctx.visibility,
- in_pxd = ctx.level == 'module_pxd')
+ typedef_flag = ctx.typedef_flag, c_visibility = ctx.c_visibility,
+ visibility = ctx.visibility, in_pxd = ctx.level == 'module_pxd')
def p_c_enum_line(s, ctx, items):
_LOG.debug('p_c_enum_line(s=<s sy:%s systring:%s>)' % (s.sy, s.systring))
value = p_test(s)
items.append(Nodes.CEnumDefItemNode(pos,
name = name, cname = cname, value = value,
- extern = ctx.extern, visibility = ctx.visibility,
- c_visibility = ctx.c_visibility,
+ c_visibility = ctx.c_visibility, visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd'))
typedef_flag = ctx.typedef_flag,
cdef_flag = ctx.cdef_flag,
overridable = ctx.overridable,
- extern = ctx.extern,
c_visibility = ctx.c_visibility,
visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd',
#if prev_visibility != 'private' and visibility != prev_visibility:
# s.error("Conflicting visibility options '%s' and '%s'"
# % (prev_visibility, visibility))
- ctx.extern = 1
- ctx.c_visibility = 'public'
+ ctx.c_visibility = 'extern'
# Need to restore/set default value for Python visibility?
elif outer_scope and visibility not in ('readonly',):
ctx.c_visibility = visibility
result = Nodes.CFuncDefNode(pos,
cdef_flag = ctx.cdef_flag,
overridable = ctx.overridable,
- extern = ctx.extern,
c_visibility = ctx.c_visibility,
visibility = ctx.visibility,
base_type = base_type,
declarators.append(declarator)
s.expect_newline("Syntax error in C variable declaration")
result = Nodes.CVarDefNode(pos,
- extern = ctx.extern,
c_visibility = ctx.c_visibility,
visibility = ctx.visibility,
api = ctx.api,
s.expect_newline("Syntax error in ctypedef statement")
return Nodes.CTypeDefNode(
pos, base_type = base_type, declarator = declarator,
- extern = ctx.extern, visibility = ctx.visibility,
- c_visibility = ctx.c_visibility,
+ c_visibility = ctx.c_visibility, visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd')
def p_decorators(s):
s.next()
module_path.append(class_name)
class_name = p_ident(s)
- if module_path and not ctx.extern:
+ if module_path and ctx.c_visibility != 'extern':
error(pos, "Qualified class name only allowed for 'extern' C class")
if module_path and s.sy == 'IDENT' and s.systring == 'as':
s.next()
base_class_module = ".".join(base_class_path[:-1])
base_class_name = base_class_path[-1]
if s.sy == '[':
- if not (ctx.extern or ctx.c_visibility == 'public'):
+ if ctx.c_visibility not in ('extern', 'public'):
error(s.position(), "Name options only allowed for 'public' or 'extern' C class")
objstruct_name, typeobj_name = p_c_class_options(s)
if s.sy == ':':
s.expect_newline("Syntax error in C class definition")
doc = None
body = None
- if ctx.extern:
+ if ctx.c_visibility == 'extern':
if not module_path:
error(pos, "Module name required for 'extern' C class")
if typeobj_name:
else:
error(pos, "Invalid class visibility '%s'" % ctx.visibility_string())
return Nodes.CClassDefNode(pos,
- extern = ctx.extern,
c_visibility = ctx.c_visibility,
visibility = ctx.visibility,
typedef_flag = ctx.typedef_flag,
s.expect_indent()
attributes = []
body_ctx = Ctx()
- body_ctx.c_visibility = p_visibility(s, ctx)
+ #body_ctx = p_visibility(s, body_ctx)
+ body_ctx.c_visibility = ctx.c_visibility
body_ctx.visibility = ctx.visibility
- body_ctx.extern = ctx.extern
body_ctx.templates = templates
while s.sy != 'DEDENT':
if s.systring == 'cppclass':
name = class_name,
cname = cname,
base_classes = base_classes,
- extern = ctx.extern,
c_visibility = ctx.c_visibility,
visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd',
self.scope = scope = Symtab.CClassScope(
'',
None,
- extern=1)
+ c_visibility='extern')
scope.parent_type = self
scope.directives = {}
binding = Binding(name = 'conjugate', cname = ' ')
self.scope = scope = Symtab.CClassScope(
'',
None,
- extern=1)
+ c_visibility='extern')
scope.parent_type = self
scope.directives = {}
binding = Binding(name = 'real', cname = 'real')
self.to_py_function = None
self._convert_code = False
return False
- forward_decl = not self.entry.extern
+ forward_decl = self.entry.c_visibility != 'extern'
self._convert_code = StructUtilityCode(self, forward_decl)
env.use_utility_code(self._convert_code)
warning(pos, "'%s' is a reserved name in C." % binding.cname, -1)
entries = self.entries
if binding.name and binding.name in entries and not shadow:
- if binding.extern:
+ if binding.c_visibility == 'extern':
warning(pos, "'%s' redeclared " % binding.name, 0)
elif binding.c_visibility != 'ignore':
error(pos, "'%s' redeclared " % binding.name)
try:
type = PyrexTypes.create_typedef_type(
binding.name, base_type, binding.cname,
- binding.extern)
+ binding.c_visibility == 'extern')
except ValueError, e:
error(pos, e.args[0])
type = PyrexTypes.error_type
def declare_cpp_class(
self, binding,
pos, scope, base_classes = (), templates = None):
- if not binding.extern:
+ if binding.c_visibility != 'extern':
error(pos, "C++ classes may only be extern")
if binding.cname is None:
binding.cname = binding.name
# `visibility`. If there is a difference, return a string
# representing the conflicting `entry` visibility, otherwise
# return an empty string.
- if binding.extern != entry.extern:
- return 'extern'
if binding.c_visibility != entry.c_visibility:
return entry.c_visibility
if binding.visibility != entry.visibility:
else:
binding.cname = self.mangle(
Naming.var_prefix, binding.name)
- if type.is_cpp_class and not binding.extern:
+ if type.is_cpp_class and binding.c_visibility != 'extern':
constructor = type.scope.lookup(u'<init>')
if constructor is not None and PyrexTypes.best_match([], constructor.all_alternatives()) is None:
error(pos, "C++ class must have a default constructor to be stack allocated")
# Add an entry for a Python function.
entry = self.lookup_here(binding.name)
if not allow_redefine or Options.disable_function_redefinition:
- binding.extern = 1
- binding.c_visibility = binding.visibility = 'public'
+ binding.c_visibility = 'extern'
+ binding.visibility = 'public'
return self._declare_pyfunction(binding, entry = entry, pos = pos)
if entry:
if entry.type.is_unspecified:
entry.type = py_object_type
elif entry.type is not py_object_type:
- binding.extern = 1
- binding.c_visibility = binding.visibility = 'public'
+ binding.c_visibility = 'extern'
+ binding.visibility = 'public'
return self._declare_pyfunction(
binding, entry = entry, pos = pos)
else: # declare entry stub
warning(pos, "Function '%s' previously declared as '%s'" % (
binding.name, vis_diff), 1)
if not entry.type.same_as(type):
- if binding.extern and entry.extern:
+ if binding.c_visibility == 'extern' and entry.c_visibility == 'extern':
can_override = False
if self.is_cpp():
can_override = True
else:
entry = self.add_cfunction(binding, pos, type, modifiers)
entry.func_cname = binding.cname
- if in_pxd and not binding.extern:
+ if in_pxd and binding.c_visibility != 'extern':
entry.defined_in_pxd = 1
- if not defining and not in_pxd and not binding.extern:
+ if not defining and not in_pxd and binding.c_visibility != 'extern':
error(pos, "Non-extern C function '%s' declared but not defined" %
binding.name)
if defining:
binding.name, binding.cname, objstruct_cname)
# WTK: TODO: visibility checking
scope = CClassScope(
- binding.name, outer_scope = None, extern = 1)
+ binding.name, outer_scope = None, c_visibility = 'extern')
scope.directives = {}
if binding.name == 'bool':
scope.directives['final'] = True
# global variable.
entry = Scope.declare_var(
self, binding, type, is_cdef = is_cdef, pos = pos)
- if binding.c_visibility not in ('private', 'public'):
+ if binding.c_visibility not in ('private', 'public', 'extern'):
error(pos, "Module-level variable cannot be declared %s" %
binding.c_visibility)
if not is_cdef:
# If this is a non-extern typedef class, expose the typedef, but use
# the non-typedef struct internally to avoid needing forward
# declarations for anonymous structs.
- if typedef_flag and not binding.extern:
+ if typedef_flag and binding.c_visibility != 'extern':
if binding.c_visibility != 'public':
warning(pos, "ctypedef only valid for public and extern classes", 2)
objtypedef_cname = objstruct_cname
if not entry or shadow:
type = PyrexTypes.PyExtensionType(
binding.name, typedef_flag, base_type,
- is_external = binding.extern)
+ is_external = binding.c_visibility == 'extern')
type.pos = pos
type.buffer_defaults = buffer_defaults
if objtypedef_cname is not None:
type.objtypedef_cname = objtypedef_cname
- if binding.extern:
+ if binding.c_visibility == 'extern':
type.module_name = module_name
else:
type.module_name = self.qualified_name
entry.is_cclass = True
if objstruct_cname:
type.objstruct_cname = objstruct_cname
- elif binding.extern or binding.c_visibility != 'public':
+ elif binding.c_visibility != 'public':
binding.cname = self.mangle(
Naming.objstruct_prefix, binding.name)
type.objstruct_cname = binding.cname
scope = CClassScope(
name = binding.name,
outer_scope = self,
- extern = binding.extern)
+ c_visibility = binding.c_visibility)
if base_type and base_type.scope:
scope.declare_inherited_c_attributes(base_type.scope)
type.set_scope(scope)
if not type.scope:
error(entry.pos, "C class '%s' is declared but not defined" % name)
# Generate typeobj_cname
- if not entry.extern and not type.typeobj_cname:
+ if entry.c_visibility != 'extern' and not type.typeobj_cname:
type.typeobj_cname = self.mangle(Naming.typeobj_prefix, name)
## Generate typeptr_cname
#type.typeptr_cname = self.mangle(Naming.typeptr_prefix, name)
if debug_check_c_classes:
print("...entry %s %s" % (entry.name, entry))
print("......type = ", entry.type)
- print("......extern = ", entry.extern)
- print("......binding.c_visibility = ",
- entry.c_visibility)
+ print("......binding.c_visibility = ", entry.c_visibility)
print("......binding.visibility = ",
entry.python.binding.visibility)
self.check_c_class(entry)
if entry.is_cfunction:
if (entry.defined_in_pxd
and entry.scope is self
- and not entry.extern
+ and entry.c_visibility != 'extern'
and not entry.in_cinclude
and not entry.is_implemented):
error(entry.pos, "Non-extern C function '%s' declared but not defined" % name)
is_c_class_scope = 1
- def __init__(self, name, outer_scope, extern):
+ def __init__(self, name, outer_scope, c_visibility):
ClassScope.__init__(self, name, outer_scope)
- if not extern:
+ if c_visibility != 'extern':
self.method_table_cname = outer_scope.mangle(Naming.methtab_prefix, name)
self.getset_table_cname = outer_scope.mangle(Naming.gstab_prefix, name)
self.has_pyobject_attrs = 0
binding.cname = binding.name
if binding.c_visibility == 'private':
binding.cname = c_safe_identifier(binding.cname)
- if type.is_cpp_class and not binding.extern:
+ if type.is_cpp_class and binding.c_visibility != 'extern':
error(pos, "C++ classes not allowed as members of an extension type, use a pointer or reference instead")
entry = self.declare(binding, type, pos = pos)
entry.is_variable = 1
if binding.name == "__weakref__":
error(pos, "Special attribute __weakref__ cannot be exposed to Python")
if not type.is_pyobject:
- #print 'XXX', binding.name, binding.extern, binding.c_visibility, binding.visibility, type.create_to_py_utility_code(self), type.__class__ ####### XXXXX BUG! (cimportfrom_T248)
+ #print 'XXX', binding.name, binding.c_visibility == 'extern', binding.c_visibility, binding.visibility, type.create_to_py_utility_code(self), type.__class__ ####### XXXXX BUG! (cimportfrom_T248)
if not type.create_to_py_utility_code(self):
- #print 'XXX', binding.name, binding.extern, binding.c_visibility, binding.visibility ####### XXXXX BUG! (cimportfrom_T248)
+ #print 'XXX', binding.name, binding.c_visibility == 'extern', binding.c_visibility, binding.visibility ####### XXXXX BUG! (cimportfrom_T248)
error(pos,
"C attribute of type '%s' cannot be accessed from Python" % type)
return entry
if binding.name == "__new__":
error(pos, "__new__ method of extension type will change semantics "
"in a future version of Pyrex and Cython. Use __cinit__ instead.")
- if not binding.extern:
+ if binding.c_visibility != 'extern':
error(pos, "C class pyfunctions may only be extern")
entry = self.declare_var(binding, type = py_object_type, pos = pos)
special_sig = get_special_method_signature(binding.name)
if type.same_c_signature_as(entry.type, as_cmethod = 1) and type.nogil == entry.type.nogil:
pass
elif type.compatible_signature_with(entry.type, as_cmethod = 1) and type.nogil == entry.type.nogil:
- binding.extern = 0
binding.c_visibility = 'ignore'
binding.visibility = 'public'
entry = self.add_cfunction(binding, pos, type, modifiers)
# overridden methods of builtin types still have their Python
# equivalent that must be accessible to support bound methods
binding.name = EncodedString(binding.name)
- #entry = self.declare_cfunction(binding.name, type, None, binding.cname, visibility='extern',
- # utility_code = utility_code)
entry = self.declare_cfunction(
binding, type=type, utility_code = utility_code)
var_entry = Entry(
def declare_var(self, binding, type, is_cdef = 0, allow_pyobject = 0,
pos = None):
- if not binding.extern:
+ if binding.c_visibility != 'extern':
error(pos, "c++ variables must be 'extern'")
# Add an entry for an attribute.
if not binding.cname:
def declare_cfunction(self, binding, type, defining = 0, in_pxd = 0,
modifiers = (), utility_code = None, pos = None):
- if not binding.extern:
+ if binding.c_visibility != 'extern':
error(pos, "c++ cfunctions must be 'extern'")
if binding.name == self.name.split('::')[-1] and binding.cname is None:
self.check_base_default_constructor(pos)
binding = Binding(
name = base_entry.name,
cname = base_entry.cname,
- extern = True,
- c_visibility = 'public')
+ c_visibility = 'extern')
entry = self.declare(
binding, type = base_entry.type)
entry.is_variable = 1
parent_type_scope = scope.parent_type.base_type.scope
if scope.parent_scope is parent_type_scope.parent_scope:
entry = scope.parent_scope.lookup_here(scope.parent_type.base_type.name)
- if not entry.extern:
+ if entry.c_visibility != 'extern':
return self.slot_code(parent_type_scope)
return InternalMethodSlot.slot_code(self, scope)
parent_type_scope = scope.parent_type.base_type.scope
if scope.parent_scope is parent_type_scope.parent_scope:
entry = scope.parent_scope.lookup_here(scope.parent_type.base_type.name)
- if not entry.extern:
+ if entry.c_visibility != 'extern':
return self.slot_code(parent_type_scope)
return InternalMethodSlot.slot_code(self, scope)
parent_slot = slot.slot_code(base_type.scope)
if parent_slot != '0':
entry = scope.parent_scope.lookup_here(scope.parent_type.base_type.name)
- if not entry.extern:
+ if entry.c_visibility != 'extern':
return parent_slot
return None