class CBinding(_BindingAttributes):
"""Configure the presence and behaviour of an object's C bindings.
- * c_name (string): Generated symbol name (or source name, is the
+ * cname (string): Generated symbol name (or source name, is the
symbol is external.
- * c_namespace (string): C++ namespace (`None` for C objects)
+ * cnamespace (string): C++ namespace (`None` for C objects)
* api (boolean): Add to generated header file
* visibility ('private'|'public'):
* const (boolean): Symbol data is readonly.
"""
- c_name = None
+ cname = None
namespace = None
api = 0
c_visibility = 'private'
def put_unpack_buffer_aux_into_scope(buffer_aux, mode, code):
# Generate code to copy the needed struct info into local
# variables.
- bufstruct = buffer_aux.buffer_info_var.c_name
+ bufstruct = buffer_aux.buffer_info_var.cname
varspec = [("strides", buffer_aux.stridevars),
("shape", buffer_aux.shapevars)]
for field, vars in varspec:
code.putln(" ".join(["%s = %s.%s[%d];" %
- (s.c_name, bufstruct, field, idx)
+ (s.cname, bufstruct, field, idx)
for idx, s in enumerate(vars)]))
def put_acquire_arg_buffer(entry, code, pos):
code.globalstate.use_utility_code(acquire_utility_code)
buffer_aux = entry.buffer_aux
getbuffer = get_getbuffer_call(
- code, entry.c_name, buffer_aux, entry.type)
+ code, entry.cname, buffer_aux, entry.type)
# Acquire any new buffer
code.putln("{")
def put_release_buffer_code(code, entry):
code.globalstate.use_utility_code(acquire_utility_code)
code.putln("__Pyx_SafeReleaseBuffer(&%s);" %
- entry.buffer_aux.buffer_info_var.c_name)
+ entry.buffer_aux.buffer_info_var.cname)
def get_getbuffer_call(code, obj_cname, buffer_aux, buffer_type):
ndim = buffer_type.ndim
cast = int(buffer_type.cast)
flags = get_flags(buffer_aux, buffer_type)
- bufstruct = buffer_aux.buffer_info_var.c_name
+ bufstruct = buffer_aux.buffer_info_var.cname
dtype_typeinfo = get_type_information_cname(code, buffer_type.dtype)
"""
code.globalstate.use_utility_code(acquire_utility_code)
- bufstruct = buffer_aux.buffer_info_var.c_name
+ bufstruct = buffer_aux.buffer_info_var.cname
flags = get_flags(buffer_aux, buffer_type)
code.putln("{") # Set up necesarry stack for getbuffer
"""
bufaux = entry.buffer_aux
- bufstruct = bufaux.buffer_info_var.c_name
+ bufstruct = bufaux.buffer_info_var.cname
negative_indices = directives['wraparound'] and entry.type.negative_indices
if directives['boundscheck']:
# not unsigned, deal with negative index
code.putln("if (%s < 0) {" % cname)
if negative_indices:
- code.putln("%s += %s;" % (cname, shape.c_name))
+ code.putln("%s += %s;" % (cname, shape.cname))
code.putln("if (%s) %s = %d;" % (
code.unlikely("%s < 0" % cname), tmp_cname, dim))
else:
cast = "(size_t)"
code.putln("if (%s) %s = %d;" % (
code.unlikely("%s >= %s%s" % (
- cname, cast, shape.c_name)),
+ cname, cast, shape.cname)),
tmp_cname, dim))
code.globalstate.use_utility_code(raise_indexerror_code)
code.putln("if (%s) {" % code.unlikely("%s != -1" % tmp_cname))
bufaux.shapevars):
if signed != 0:
code.putln("if (%s < 0) %s += %s;" % (
- cname, cname, shape.c_name))
+ cname, cname, shape.cname))
# Create buffer lookup and return it
# This is done via utility macros/inline functions, which vary
if mode == 'full':
for i, s, o in zip(index_cnames, bufaux.stridevars, bufaux.suboffsetvars):
params.append(i)
- params.append(s.c_name)
- params.append(o.c_name)
+ params.append(s.cname)
+ params.append(o.cname)
funcname = "__Pyx_BufPtrFull%dd" % nd
funcgen = buf_lookup_full_code
else:
assert False
for i, s in zip(index_cnames, bufaux.stridevars):
params.append(i)
- params.append(s.c_name)
+ params.append(s.cname)
# Make sure the utility code is available
if funcname not in code.globalstate.utility_codes:
for f, typeinfo in zip(fields, types):
typecode.putln(' {&%s, "%s", offsetof(%s, %s)},' %
(typeinfo, f.name,
- dtype.declaration_code(""), f.c_name),
+ dtype.declaration_code(""), f.cname),
safe=True)
typecode.putln(' {NULL, NULL, 0}', safe=True)
typecode.putln("};", safe=True)
w.exit_cfunc_scope()
def put_pyobject_decl(self, entry):
- self['global_var'].putln("static PyObject *%s;" % entry.c_name)
+ self['global_var'].putln("static PyObject *%s;" % entry.cname)
# constant handling at code generation time
def add_cached_builtin_decl(self, entry):
if Options.cache_builtins:
- if self.should_declare(entry.c_name, entry):
+ if self.should_declare(entry.cname, entry):
self.put_pyobject_decl(entry)
w = self.parts['cached_builtins']
if entry.name == 'xrange':
w.putln('#if PY_MAJOR_VERSION >= 3')
self.put_cached_builtin_init(
entry.pos, StringEncoding.EncodedString('range'),
- entry.c_name)
+ entry.cname)
w.putln('#else')
self.put_cached_builtin_init(
entry.pos,
StringEncoding.EncodedString(entry.name),
- entry.c_name)
+ entry.cname)
if entry.name == 'xrange':
w.putln('#endif')
#print "...private and not definition, skipping" ###
return
if entry.c_visibility == 'private' and not entry.used:
- #print "not used and private, skipping", entry.c_name ###
+ #print "not used and private, skipping", entry.cname ###
return
storage_class = ""
if entry.extern:
if (entry.extern or
entry.c_visibility != 'public'):
dll_linkage = None
- self.put(entry.type.declaration_code(entry.c_name,
+ self.put(entry.type.declaration_code(entry.cname,
dll_linkage = dll_linkage))
if entry.init is not None:
self.put_safe(" = %s" % entry.type.literal_code(entry.init))
type = entry.type
if (not entry.is_self_arg and not entry.type.is_complete()
or entry.type.is_extension_type):
- return "(PyObject *)" + entry.c_name
+ return "(PyObject *)" + entry.cname
else:
- return entry.c_name
+ return entry.cname
def as_pyobject(self, cname, type):
from PyrexTypes import py_object_type, typecast
def put_var_decref_clear(self, entry):
if entry.type.is_pyobject:
self.putln("__Pyx_DECREF(%s); %s = 0;" % (
- self.entry_as_pyobject(entry), entry.c_name))
+ self.entry_as_pyobject(entry), entry.cname))
def put_var_xdecref(self, entry):
if entry.type.is_pyobject:
def put_var_xdecref_clear(self, entry):
if entry.type.is_pyobject:
self.putln("__Pyx_XDECREF(%s); %s = 0;" % (
- self.entry_as_pyobject(entry), entry.c_name))
+ self.entry_as_pyobject(entry), entry.cname))
def put_var_decrefs(self, entries, used_only = 0):
for entry in entries:
self.putln("%s = %s; Py_INCREF(Py_None);" % (cname, py_none))
def put_init_var_to_py_none(self, entry, template = "%s", nanny=True):
- code = template % entry.c_name
+ code = template % entry.cname
#if entry.type.is_extension_type:
# code = "((PyObject*)%s)" % code
self.put_init_to_py_none(code, entry.type, nanny)
def get_constant_c_result_code(self):
if not self.entry or self.entry.type.is_pyobject:
return None
- return self.entry.c_name
+ return self.entry.cname
def coerce_to(self, dst_type, env):
# If coercing to a generic pyobject and this is a builtin
entry = self.entry
if not entry:
return "<error>" # There was an error earlier
- return entry.c_name
+ return entry.cname
def generate_result_code(self, code):
assert hasattr(self, 'entry')
elif not Options.init_local_none and assigned is None:
code.putln(
'if (%s == 0) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }' %
- (entry.c_name, entry.name,
+ (entry.cname, entry.name,
code.error_goto(self.pos)))
entry.scope.control_flow.set_state(
self.pos, (entry.name, 'initialized'), True)
code.putln('%s = %s;' % (rhstmp, rhs.result_as(self.ctype())))
buffer_aux = self.entry.buffer_aux
- bufstruct = buffer_aux.buffer_info_var.c_name
+ bufstruct = buffer_aux.buffer_info_var.cname
import Buffer
Buffer.put_assign_to_buffer(self.result(), rhstmp, buffer_aux, self.entry.type,
is_initialized=not self.lhs_of_first_assignment,
raise_py_exception = "__Pyx_CppExn2PyErr()"
elif func_type.exception_value.type.is_pyobject:
raise_py_exception = ' try { throw; } catch(const std::exception& exn) { PyErr_SetString(%s, exn.what()); } catch(...) { PyErr_SetNone(%s); }' % (
- func_type.exception_value.entry.c_name,
- func_type.exception_value.entry.c_name)
+ func_type.exception_value.entry.cname,
+ func_type.exception_value.entry.cname)
else:
raise_py_exception = '%s(); if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError , "Error converting c++ exception.")' % (
- func_type.exception_value.entry.c_name)
+ func_type.exception_value.entry.cname)
if self.nogil:
raise_py_exception = 'Py_BLOCK_THREADS; %s; Py_UNBLOCK_THREADS' % raise_py_exception
code.putln(
# Create a temporary entry describing the C method
# as an ordinary function.
ubcm_entry = Symtab.Entry(entry.name,
- "%s->%s" % (type.vtabptr_cname, entry.c_name),
+ "%s->%s" % (type.vtabptr_cname, entry.cname),
entry.type)
ubcm_entry.is_cfunction = 1
ubcm_entry.func_cname = entry.func_cname
# because they do not have struct entries
if entry.is_variable or entry.is_cmethod:
self.type = entry.type
- self.member = entry.c_name
+ self.member = entry.cname
return
else:
# If it's not a variable or C method, it must be a Python
for arg, member in zip(self.args, self.type.scope.var_entries):
code.putln("%s.%s = %s;" % (
self.result(),
- member.c_name,
+ member.cname,
arg.result()))
else:
raise InternalError("List type never specified")
h_code.putln("%s %s;" % (
Naming.extern_c_macro,
entry.type.declaration_code(
- entry.c_name, dll_linkage = "DL_IMPORT")))
+ entry.cname, dll_linkage = "DL_IMPORT")))
if i_code:
i_code.putln("cdef extern %s" %
- entry.type.declaration_code(entry.c_name, pyrex = 1))
+ entry.type.declaration_code(entry.cname, pyrex = 1))
def api_name(self, env):
return env.qualified_name.replace(".", "__")
for entry in api_funcs:
type = CPtrType(entry.type)
h_code.putln("static %s;" % type.declaration_code(
- entry.c_name))
+ entry.cname))
h_code.putln("")
h_code.put_h_guard(Naming.api_func_guard + "import_module")
h_code.put(import_module_utility_code.impl)
h_code.putln(
'if (__Pyx_ImportFunction(module, "%s", (void (**)(void))&%s, "%s") < 0) goto bad;' % (
entry.name,
- entry.c_name,
+ entry.cname,
sig))
h_code.putln("Py_DECREF(module); module = 0;")
for entry in public_extension_types:
if var_entries:
for entry in var_entries:
i_code.putln("cdef %s" % entry.type.declaration_code(
- entry.c_name, pyrex = 1))
+ entry.cname, pyrex = 1))
else:
i_code.putln("pass")
i_code.dedent()
writer = code
writer.putln("")
writer.putln("typedef %s;" % base_type.declaration_code(
- entry.c_name))
+ entry.cname))
def sue_header_footer(self, type, kind, name):
if type.typedef_flag:
for attr in var_entries:
code.putln(
"%s;" %
- attr.type.declaration_code(attr.c_name))
+ attr.type.declaration_code(attr.cname))
code.putln(footer)
if packed:
code.putln("#if defined(__SUNPRO_C)")
def generate_enum_definition(self, entry, code):
code.mark_pos(entry.pos)
type = entry.type
- name = entry.c_name or entry.name or ""
+ name = entry.cname or entry.name or ""
header, footer = \
self.sue_header_footer(type, "enum", name)
code.putln("")
for value_entry in enum_values:
if value_entry.value_node is None:
- value_code = value_entry.c_name
+ value_code = value_entry.cname
else:
value_code = ("%s = %s" % (
- value_entry.c_name,
+ value_entry.cname,
value_entry.value_node.result()))
if value_entry is not last_entry:
value_code += ","
for attr in type.scope.var_entries:
code.putln(
"%s;" %
- attr.type.declaration_code(attr.c_name))
+ attr.type.declaration_code(attr.cname))
code.putln(footer)
if type.objtypedef_cname is not None:
# Only for exposing public typedef name.
type = entry.type
if not definition and entry.defined_in_pxd:
type = CPtrType(type)
- header = type.declaration_code(entry.c_name,
+ header = type.declaration_code(entry.cname,
dll_linkage = dll_linkage)
if entry.c_visibility == 'private':
storage_class = "static "
for entry in py_attrs:
if scope.is_internal or entry.name == "__weakref__":
# internal classes do not need None inits
- code.putln("p->%s = 0;" % entry.c_name)
+ code.putln("p->%s = 0;" % entry.cname)
else:
code.put_init_var_to_py_none(entry, "p->%s", nanny=False)
entry = scope.lookup_here("__new__")
code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);")
for entry in py_attrs:
code.put_xdecref(
- "p->%s" % entry.c_name, entry.type, nanny=False)
+ "p->%s" % entry.cname, entry.type, nanny=False)
if base_type:
tp_dealloc = TypeSlots.get_base_slot_function(scope, tp_slot)
if tp_dealloc is None:
base_type.typeptr_cname)
code.putln("}")
for entry in py_attrs:
- var_code = "p->%s" % entry.c_name
+ var_code = "p->%s" % entry.cname
code.putln(
"if (%s) {"
% var_code)
code.putln("%s->tp_clear(o);" % base_type.typeptr_cname)
code.putln("}")
for entry in py_attrs:
- name = "p->%s" % entry.c_name
+ name = "p->%s" % entry.cname
code.putln("tmp = ((PyObject*)%s);" % name)
code.put_init_to_py_none(name, entry.type, nanny=False)
code.putln("Py_XDECREF(tmp);")
code.error_goto(entry.pos)))
code.putln("Py_INCREF(o);")
code.put_decref(
- entry.c_name, entry.type, nanny=False)
+ entry.cname, entry.type, nanny=False)
code.putln("%s = %s;" % (
- entry.c_name,
+ entry.cname,
PyrexTypes.typecast(entry.type, py_object_type, "o")))
elif entry.type.from_py_function:
rhs = "%s(o)" % entry.type.from_py_function
if entry.type.is_enum:
rhs = PyrexTypes.typecast(entry.type, PyrexTypes.c_long_type, rhs)
code.putln("%s = %s; if (%s) %s;" % (
- entry.c_name,
+ entry.cname,
rhs,
- entry.type.error_condition(entry.c_name),
+ entry.type.error_condition(entry.cname),
code.error_goto(entry.pos)))
else:
code.putln('PyErr_Format(PyExc_TypeError, "Cannot convert Python object %s to %s");' % (name, entry.type))
if entry.type.is_pyobject and entry.used:
code.putln("Py_DECREF(%s); %s = 0;" % (
code.entry_as_pyobject(entry),
- entry.c_name))
+ entry.cname))
code.putln("__Pyx_CleanupGlobals();")
if Options.generate_cleanup_code >= 3:
code.putln("/*--- Type import cleanup code ---*/")
if Options.cache_builtins:
code.putln("/*--- Builtin cleanup code ---*/")
for entry in env.cached_builtins:
- code.put_decref_clear(entry.c_name,
+ code.put_decref_clear(entry.cname,
PyrexTypes.py_object_type,
nanny=False)
code.putln("/*--- Intern cleanup code ---*/")
PyrexTypes.py_object_type,
nanny=False)
# for entry in env.pynum_entries:
-# code.put_decref_clear(entry.c_name,
+# code.put_decref_clear(entry.cname,
# PyrexTypes.py_object_type,
# nanny=False)
# for entry in env.all_pystring_entries:
# for entry in env.default_entries:
# if entry.type.is_pyobject and entry.used:
# code.putln("Py_DECREF(%s); %s = 0;" % (
-# code.entry_as_pyobject(entry), entry.c_name))
+# code.entry_as_pyobject(entry), entry.cname))
code.putln("Py_INCREF(Py_None); return Py_None;")
def generate_main_method(self, env, code):
signature = entry.type.signature_string()
code.putln('if (__Pyx_ExportFunction("%s", (void (*)(void))%s, "%s") < 0) %s' % (
entry.name,
- entry.c_name,
+ entry.cname,
signature,
code.error_goto(self.pos)))
'if (__Pyx_ImportFunction(%s, "%s", (void (**)(void))&%s, "%s") < 0) %s' % (
temp,
entry.name,
- entry.c_name,
+ entry.cname,
entry.type.signature_string(),
code.error_goto(self.pos)))
code.putln("Py_DECREF(%s); %s = 0;" % (temp, temp))
tp_weaklistoffset,
tp_weaklistoffset,
objstruct,
- weakref_entry.c_name))
+ weakref_entry.cname))
else:
error(weakref_entry.pos, "__weakref__ slot must be of type 'object'")
code.putln(
"%s.%s = %s%s;" % (
type.vtable_cname,
- meth_entry.c_name,
+ meth_entry.cname,
cast,
meth_entry.func_cname))
cname = self.cname, visibility='ignore')
struct_entry.type.typedef_flag = False
# FIXME: this might be considered a hack ;-)
- struct_entry.c_name = struct_entry.type.cname = (
+ struct_entry.cname = struct_entry.type.cname = (
'_' + self.entry.type.typedef_cname)
def analyse_expressions(self, env):
for item in self.entry.enum_values:
code.putln("%s = PyInt_FromLong(%s); %s" % (
temp,
- item.c_name,
+ item.cname,
code.error_goto_if_null(temp, item.pos)))
code.put_gotref(temp)
code.putln('if (__Pyx_SetAttrString(%s, "%s", %s) < 0) %s' % (
if self.needs_closure:
lenv = ClosureScope(name=self.entry.name,
outer_scope = genv,
- scope_name=self.entry.c_name)
+ scope_name=self.entry.cname)
else:
lenv = LocalScope(name=self.entry.name,
outer_scope=genv,
for entry in lenv.var_entries + lenv.arg_entries:
if entry.type.is_buffer and entry.buffer_aux.buffer_info_var.used:
code.putln("%s.buf = NULL;" %
- entry.buffer_aux.buffer_info_var.c_name)
+ entry.buffer_aux.buffer_info_var.cname)
# ----- Check and convert arguments
self.generate_argument_type_tests(code)
# ----- Acquire buffer arguments
code.putln("__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);")
for entry in lenv.buffer_entries:
Buffer.put_release_buffer_code(code, entry)
- #code.putln("%s = 0;" % entry.c_name)
+ #code.putln("%s = 0;" % entry.cname)
code.putln("__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}")
err_val = self.error_value()
if entry.used and not entry.in_closure:
code.put_var_decref(entry)
elif entry.in_closure and self.needs_closure:
- code.put_giveref(entry.c_name)
+ code.put_giveref(entry.cname)
# Decref any increfed args
for entry in lenv.arg_entries:
if entry.type.is_pyobject:
if arg.type.typeobj_is_available():
code.globalstate.use_utility_code(arg_type_test_utility_code)
typeptr_cname = arg.type.typeptr_cname
- arg_code = "((PyObject *)%s)" % arg.entry.c_name
+ arg_code = "((PyObject *)%s)" % arg.entry.cname
code.putln(
'if (unlikely(!__Pyx_ArgTypeTest(%s, %s, %d, "%s", %s))) %s' % (
arg_code,
def generate_arg_none_check(self, arg, code):
# Generate None check for one argument.
code.putln('if (unlikely(((PyObject *)%s) == Py_None)) {' %
- arg.entry.c_name)
+ arg.entry.cname)
code.putln('''PyErr_Format(PyExc_TypeError, "Argument '%s' must not be None"); %s''' % (
arg.name,
code.error_goto(arg.pos)))
# Special code for the __getbuffer__ function
#
def getbuffer_init(self, code):
- info = self.local_scope.arg_entries[1].c_name
+ info = self.local_scope.arg_entries[1].cname
# Python 3.0 betas have a bug in memoryview which makes it call
# getbuffer with a NULL parameter. For now we work around this;
# the following line should be removed when this bug is fixed.
code.put_giveref("%s->obj" % info) # Do not refnanny object within structs
def getbuffer_error_cleanup(self, code):
- info = self.local_scope.arg_entries[1].c_name
+ info = self.local_scope.arg_entries[1].cname
code.put_gotref("%s->obj" % info)
code.putln("__Pyx_DECREF(%s->obj); %s->obj = NULL;" %
(info, info))
def getbuffer_normal_cleanup(self, code):
- info = self.local_scope.arg_entries[1].c_name
+ info = self.local_scope.arg_entries[1].cname
code.putln("if (%s->obj == Py_None) {" % info)
code.put_gotref("Py_None")
code.putln("__Pyx_DECREF(Py_None); %s->obj = NULL;" % info)
if arg.is_generic:
item = PyrexTypes.typecast(arg.type, PyrexTypes.py_object_type, item)
entry = arg.entry
- code.putln("%s = %s;" % (entry.c_name, item))
+ code.putln("%s = %s;" % (entry.cname, item))
if entry.in_closure:
code.put_var_incref(entry)
else:
func = arg.type.from_py_function
if func:
code.putln("%s = %s(%s); %s" % (
- arg.entry.c_name,
+ arg.entry.cname,
func,
item,
code.error_goto_if(
arg.type.error_condition(
- arg.entry.c_name),
+ arg.entry.cname),
arg.pos)))
else:
error(arg.pos, "Cannot convert Python object argument to type '%s'" % arg.type)
if self.starstar_arg:
code.putln("%s = (%s) ? PyDict_Copy(%s) : PyDict_New();" % (
- self.starstar_arg.entry.c_name,
+ self.starstar_arg.entry.cname,
Naming.kwds_cname,
Naming.kwds_cname))
code.putln("if (unlikely(!%s)) return %s;" % (
- self.starstar_arg.entry.c_name,
+ self.starstar_arg.entry.cname,
self.error_value()))
self.starstar_arg.entry.xdecref_cleanup = 0
- code.put_gotref(self.starstar_arg.entry.c_name)
+ code.put_gotref(self.starstar_arg.entry.cname)
if self.self_in_stararg:
# need to create a new tuple with 'self' inserted as first item
code.put("%s = PyTuple_New(PyTuple_GET_SIZE(%s)+1); if (unlikely(!%s)) " % (
- self.star_arg.entry.c_name,
+ self.star_arg.entry.cname,
Naming.args_cname,
- self.star_arg.entry.c_name))
+ self.star_arg.entry.cname))
if self.starstar_arg:
code.putln("{")
code.put_decref_clear(
- self.starstar_arg.entry.c_name, py_object_type)
+ self.starstar_arg.entry.cname, py_object_type)
code.putln("return %s;" % self.error_value())
code.putln("}")
else:
code.putln("return %s;" % self.error_value())
- code.put_gotref(self.star_arg.entry.c_name)
+ code.put_gotref(self.star_arg.entry.cname)
code.put_incref(Naming.self_cname, py_object_type)
code.put_giveref(Naming.self_cname)
code.putln("PyTuple_SET_ITEM(%s, 0, %s);" % (
- self.star_arg.entry.c_name, Naming.self_cname))
+ self.star_arg.entry.cname, Naming.self_cname))
temp = code.funcstate.allocate_temp(PyrexTypes.c_py_ssize_t_type, manage_ref=False)
code.putln("for (%s=0; %s < PyTuple_GET_SIZE(%s); %s++) {" % (
temp, temp, Naming.args_cname, temp))
code.put_incref("item", py_object_type)
code.put_giveref("item")
code.putln("PyTuple_SET_ITEM(%s, %s+1, item);" % (
- self.star_arg.entry.c_name, temp))
+ self.star_arg.entry.cname, temp))
code.putln("}")
code.funcstate.release_temp(temp)
self.star_arg.entry.xdecref_cleanup = 0
elif self.star_arg:
code.put_incref(Naming.args_cname, py_object_type)
code.putln("%s = %s;" % (
- self.star_arg.entry.c_name,
+ self.star_arg.entry.cname,
Naming.args_cname))
self.star_arg.entry.xdecref_cleanup = 0
if arg.is_generic and arg.default:
code.putln(
"%s = %s;" % (
- arg.entry.c_name,
+ arg.entry.cname,
arg.calculate_default_value_code(code)))
def generate_stararg_init_code(self, max_positional_args, code):
if self.starstar_arg:
self.starstar_arg.entry.xdecref_cleanup = 0
code.putln('%s = PyDict_New(); if (unlikely(!%s)) return %s;' % (
- self.starstar_arg.entry.c_name,
- self.starstar_arg.entry.c_name,
+ self.starstar_arg.entry.cname,
+ self.starstar_arg.entry.cname,
self.error_value()))
- code.put_gotref(self.starstar_arg.entry.c_name)
+ code.put_gotref(self.starstar_arg.entry.cname)
if self.star_arg:
self.star_arg.entry.xdecref_cleanup = 0
code.putln('if (PyTuple_GET_SIZE(%s) > %d) {' % (
Naming.args_cname,
max_positional_args))
code.put('%s = PyTuple_GetSlice(%s, %d, PyTuple_GET_SIZE(%s)); ' % (
- self.star_arg.entry.c_name, Naming.args_cname,
+ self.star_arg.entry.cname, Naming.args_cname,
max_positional_args, Naming.args_cname))
- code.put_gotref(self.star_arg.entry.c_name)
+ code.put_gotref(self.star_arg.entry.cname)
if self.starstar_arg:
code.putln("")
code.putln("if (unlikely(!%s)) {" %
- self.star_arg.entry.c_name)
+ self.star_arg.entry.cname)
code.put_decref_clear(
- self.starstar_arg.entry.c_name, py_object_type)
+ self.starstar_arg.entry.cname, py_object_type)
code.putln('return %s;' % self.error_value())
code.putln('}')
else:
code.putln("if (unlikely(!%s)) return %s;" % (
- self.star_arg.entry.c_name,
+ self.star_arg.entry.cname,
self.error_value()))
code.putln('} else {')
code.put("%s = %s; " % (
- self.star_arg.entry.c_name, Naming.empty_tuple))
+ self.star_arg.entry.cname, Naming.empty_tuple))
code.put_incref(Naming.empty_tuple, py_object_type)
code.putln('}')
Naming.kwds_cname,
Naming.pykwdlist_cname,
(self.starstar_arg and
- self.starstar_arg.entry.c_name or
+ self.starstar_arg.entry.cname or
'0'),
pos_arg_count,
self.name))
code.putln('} else {')
code.putln(
"%s = %s;" % (
- arg.entry.c_name,
+ arg.entry.cname,
arg.calculate_default_value_code(code)))
code.putln('}')
self.generate_arg_conversion(arg, code)
elif arg.entry.in_closure:
code.putln('%s = %s;' % (
- arg.entry.c_name, arg.hdr_cname))
+ arg.entry.cname, arg.hdr_cname))
if arg.type.is_pyobject:
code.put_var_incref(arg.entry)
else:
if new_type.assignable_from(old_type):
code.putln(
- "%s = %s;" % (arg.entry.c_name, arg.hdr_cname))
+ "%s = %s;" % (arg.entry.cname, arg.hdr_cname))
else:
error(arg.pos,
"Cannot convert 1 argument from '%s' to '%s'" %
func = new_type.from_py_function
# copied from CoerceFromPyTypeNode
if func:
- lhs = arg.entry.c_name
+ lhs = arg.entry.cname
rhs = "%s(%s)" % (func, arg.hdr_cname)
if new_type.is_enum:
rhs = PyrexTypes.typecast(new_type, PyrexTypes.c_long_type, rhs)
lhs,
rhs,
code.error_goto_if(
- new_type.error_condition(arg.entry.c_name),
+ new_type.error_condition(arg.entry.cname),
arg.pos)))
else:
error(arg.pos,
func = old_type.to_py_function
if func:
code.putln("%s = %s(%s); %s" % (
- arg.entry.c_name,
+ arg.entry.cname,
func,
arg.hdr_cname,
- code.error_goto_if_null(arg.entry.c_name, arg.pos)))
+ code.error_goto_if_null(arg.entry.cname, arg.pos)))
code.put_var_gotref(arg.entry)
else:
error(arg.pos,
if self.py_func.is_module_scope:
self_arg = "((PyObject *)%s)" % Naming.module_cname
else:
- self_arg = "((PyObject *)%s)" % self.args[0].c_name
+ self_arg = "((PyObject *)%s)" % self.args[0].cname
code.putln("/* Check if called by wrapper */")
code.putln("if (unlikely(%s)) ;" % Naming.skip_dispatch_cname)
code.putln("/* Check if overriden in Python */")
self.target.analyse_target_declaration(env)
cenv = self.create_scope(env)
cenv.directives = env.directives
- cenv.class_obj_cname = self.target.entry.c_name
+ cenv.class_obj_cname = self.target.entry.cname
self.body.analyse_declarations(cenv)
def analyse_expressions(self, env):
as_name = '%s_%s' % (
target_module_scope.next_id(Naming.closure_class_prefix),
- node.entry.c_name)
+ node.entry.cname)
entry = target_module_scope.declare_c_class(name = as_name,
pos = node.pos, defining = True, implementing = True)
for name, entry in in_closure:
class_scope.declare_var(pos=entry.pos,
name=entry.name,
- cname=entry.c_name,
+ cname=entry.cname,
type=entry.type,
is_cdef=True)
node.needs_closure = True
# We're dealing with a closure where a variable from an outer
# scope is accessed, get it from the scope object.
cname = '%s->%s' % (Naming.cur_scope_cname,
- entry.outer_entry.c_name)
+ entry.outer_entry.cname)
qname = '%s.%s.%s' % (entry.scope.outer_scope.qualified_name,
entry.scope.name,
entry.name)
elif entry.in_closure:
cname = '%s->%s' % (Naming.cur_scope_cname,
- entry.c_name)
+ entry.cname)
qname = entry.qualified_name
else:
- cname = entry.c_name
+ cname = entry.cname
qname = entry.qualified_name
if not entry.pos:
def opt_arg_cname(self, arg_name):
return self.op_arg_struct.base_type.scope.lookup(
- arg_name).c_name
+ arg_name).cname
class CFuncTypeArg(object):
nameconst_cname = code.get_py_string_const(
member.name, identifier=True)
code.putln("member = %s(s.%s); if (member == NULL) goto bad;" % (
- member.type.to_py_function, member.c_name))
+ member.type.to_py_function, member.cname))
code.putln("if (PyDict_SetItem(res, %s, member) < 0) goto bad;" % nameconst_cname)
code.putln("Py_DECREF(member);")
code.putln("return res;")
def __init__(self, name, cname, type, pos = None, init = None):
self.name = name
- self.c_name = cname
+ self.cname = cname
self.type = type
self.pos = pos
self.init = init
# Binding attributes
def __init__(self, binding, type, pos = None, init = None):
Entry.__init__(
- self, name=binding.name, cname=binding.c_name,
+ self, name=binding.name, cname=binding.cname,
type=type, pos = pos, init=init)
binding.push(self)
if type.is_buffer and not isinstance(self, LocalScope):
error(pos, ERR_BUF_LOCALONLY)
if (not self.in_cinclude and
- binding.c_name and re.match("^_[_A-Z]+$", binding.c_name)):
+ binding.cname and re.match("^_[_A-Z]+$", binding.cname)):
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
- warning(pos, "'%s' is a reserved name in C." % binding.c_name, -1)
+ warning(pos, "'%s' is a reserved name in C." % binding.cname, -1)
entries = self.entries
if binding.name and binding.name in entries:
if binding.extern:
return entry
def _WTK_setup(self, name, cname, visibility):
- binding = Binding(name=name, c_name=cname)
+ binding = Binding(name=name, cname=cname)
if visibility == 'extern':
binding.extern = 1
binding.c_visibility = 'public'
def WTK_declare_const(self, binding,
type, value, pos):
# Add an entry for a named constant.
- if not binding.c_name:
+ if not binding.cname:
if self.in_cinclude or binding.c_visibility == 'public':
- binding.c_name = binding.name
+ binding.cname = binding.name
else:
- binding.c_name = self.mangle(
+ binding.cname = self.mangle(
Naming.enum_prefix, binding.name)
entry = self.WTK_declare(binding, type, pos)
entry.is_const = 1
def WTK_declare_type(self, binding,
type, defining = 1, pos = None):
# Add an entry for a type definition.
- if not binding.c_name:
- binding.c_name = binding.name
+ if not binding.cname:
+ binding.cname = binding.name
entry = self.WTK_declare(binding, type, pos)
entry.is_type = 1
if defining:
def WTK_declare_typedef(self, binding,
base_type, pos):
- if not binding.c_name:
+ if not binding.cname:
if self.in_cinclude or binding.c_visibility == 'public':
- binding.c_name = binding.name
+ binding.cname = binding.name
else:
- binding.c_name = self.mangle(
+ binding.cname = self.mangle(
Naming.type_prefix, binding.name)
try:
type = PyrexTypes.create_typedef_type(
- binding.name, base_type, binding.c_name,
+ binding.name, base_type, binding.cname,
binding.extern)
except ValueError, e:
error(pos, e.args[0])
self, binding,
pos, kind, scope, typedef_flag, packed=False):
# Add an entry for a struct or union definition.
- if not binding.c_name:
+ if not binding.cname:
if self.in_cinclude or binding.c_visibility == 'public':
- binding.c_name = binding.name
+ binding.cname = binding.name
else:
- binding.c_name = self.mangle(
+ binding.cname = self.mangle(
Naming.type_prefix, binding.name)
entry = self.lookup_here(binding.name)
if not entry:
type = PyrexTypes.CStructOrUnionType(
- binding.name, kind, scope, typedef_flag, binding.c_name,
+ binding.name, kind, scope, typedef_flag, binding.cname,
packed)
entry = self.WTK_declare_type(
binding, type,
pos, scope, base_classes = (), templates = None):
if not binding.extern:
error(pos, "C++ classes may only be extern")
- if binding.c_name is None:
- binding.c_name = binding.name
+ if binding.cname is None:
+ binding.cname = binding.name
entry = self.lookup_here(binding.name)
if not entry:
type = PyrexTypes.CppClassType(
- binding.name, scope, binding.c_name, base_classes,
+ binding.name, scope, binding.cname, base_classes,
templates = templates)
entry = self.WTK_declare_type(
binding, type,
def WTK_declare_enum(self, binding, pos,
typedef_flag):
if binding.name:
- if not binding.c_name:
+ if not binding.cname:
if self.in_cinclude or binding.c_visibility == 'public':
- binding.c_name = binding.name
+ binding.cname = binding.name
else:
- binding.c_name = self.mangle(
+ binding.cname = self.mangle(
Naming.type_prefix, binding.name)
type = PyrexTypes.CEnumType(
- binding.name, binding.c_name, typedef_flag)
+ binding.name, binding.cname, typedef_flag)
else:
type = PyrexTypes.c_anon_enum_type
entry = self.WTK_declare_type(binding, type, pos = pos)
def WTK_declare_var(self, binding, type,
is_cdef = 0, pos = None):
# Add an entry for a variable.
- if not binding.c_name:
+ if not binding.cname:
if binding.c_visibility != 'private':
- binding.c_name = binding.name
+ binding.cname = binding.name
else:
- binding.c_name = self.mangle(
+ binding.cname = self.mangle(
Naming.var_prefix, binding.name)
if type.is_cpp_class and not binding.extern:
constructor = type.scope.lookup(u'<init>')
else: # declare entry stub
self.WTK_declare_var(
binding, py_object_type, pos = pos)
- entry = self.WTK_declare_var(Binding(name=None, c_name=binding.name),
+ entry = self.WTK_declare_var(Binding(name=None, cname=binding.name),
py_object_type, pos = pos)
entry.name = EncodedString(binding.name)
entry.qualified_name = self.qualify_name(binding.name)
pos = None):
# Add an entry for an anonymous Python function.
entry = self.WTK_declare_var(binding, py_object_type, pos = pos)
- entry.name = EncodedString(binding.c_name)
- entry.func_cname = binding.c_name
+ entry.name = EncodedString(binding.cname)
+ entry.func_cname = binding.cname
entry.signature = pyfunction_signature
entry.is_anonymous = True
return entry
in_pxd = 0, modifiers = (), utility_code = None):
# Add an entry for a C function.
- if not binding.c_name:
+ if not binding.cname:
if binding.api or binding.c_visibility != 'private':
- binding.c_name = binding.name
+ binding.cname = binding.name
else:
- binding.c_name = self.mangle(
+ binding.cname = self.mangle(
Naming.func_prefix, binding.name)
entry = self.lookup_here(binding.name)
if entry:
can_override = False
if self.is_cpp():
can_override = True
- elif binding.c_name:
+ elif binding.cname:
# if all alternatives have different cnames,
# it's safe to allow signature overrides
for alt_entry in entry.all_alternatives():
- if (not alt_entry.c_name or
- binding.c_name == alt_entry.c_name):
+ if (not alt_entry.cname or
+ binding.cname == alt_entry.cname):
break # cname not unique!
else:
can_override = True
error(pos, "Function signature does not match previous declaration")
else:
entry = self.WTK_add_cfunction(binding, pos, type, modifiers)
- entry.func_cname = binding.c_name
+ entry.func_cname = binding.cname
if in_pxd and not binding.extern:
entry.defined_in_pxd = 1
if not defining and not in_pxd and not binding.extern:
else:
python_equiv = EncodedString(python_equiv)
var_entry = WTK_Entry(
- Binding(name=python_equiv, c_name=python_equiv), py_object_type)
+ Binding(name=python_equiv, cname=python_equiv), py_object_type)
var_entry.is_variable = 1
var_entry.is_builtin = 1
var_entry.utility_code = utility_code
def WTK_declare_builtin_type(self, binding, objstruct_cname = None, utility_code = None):
binding.name = EncodedString(binding.name)
- type = PyrexTypes.BuiltinObjectType(binding.name, binding.c_name, objstruct_cname)
+ type = PyrexTypes.BuiltinObjectType(binding.name, binding.cname, objstruct_cname)
# WTK: TODO: visibility checking. CClassCcope visibility splitting
scope = CClassScope(binding.name, outer_scope=None, visibility='extern')
scope.directives = {}
entry.utility_code = utility_code
var_entry = WTK_Entry(
- binding.deepcopy(c_name="((PyObject*)%s)" % entry.type.typeptr_cname),
+ binding.deepcopy(cname="((PyObject*)%s)" % entry.type.typeptr_cname),
type = self.lookup('type').type, # make sure "type" is the first type declared...
pos = entry.pos)
var_entry.is_variable = 1
entry.is_builtin = 1
entry.is_const = 1
entry.name = binding.name
- entry.c_name = Naming.builtin_prefix + binding.name
+ entry.cname = Naming.builtin_prefix + binding.name
self.cached_builtins.append(entry)
self.undeclared_cached_builtins.append(entry)
else:
if objstruct_cname:
type.objstruct_cname = objstruct_cname
elif binding.extern or binding.c_visibility != 'public':
- binding.c_name = self.mangle(
+ binding.cname = self.mangle(
Naming.objstruct_prefix, binding.name)
- type.objstruct_cname = binding.c_name
+ type.objstruct_cname = binding.cname
else:
error(entry.pos,
"Object name required for 'public' or 'extern' C class")
def declare_arg(self, name, type, pos):
binding = self._WTK_setup(name, None, 'private')
- binding.c_name = self.mangle(Naming.var_prefix, binding.name)
+ binding.cname = self.mangle(Naming.var_prefix, binding.name)
return self.WTK_declare_arg(
binding, type, pos = pos)
entry.in_closure = True
# Would it be better to declare_var here?
inner_entry = Entry(
- entry.name, entry.c_name,
+ entry.name, entry.cname,
entry.type, entry.pos)
inner_entry.scope = self
inner_entry.is_variable = True
def mangle_closure_cnames(self, outer_scope_cname):
for entry in self.entries.values():
if entry.from_closure:
- cname = entry.outer_entry.c_name
+ cname = entry.outer_entry.cname
if self.is_passthrough:
- entry.c_name = cname
+ entry.cname = cname
else:
if cname.startswith(Naming.cur_scope_cname):
cname = cname[len(Naming.cur_scope_cname)+2:]
- entry.c_name = "%s->%s" % (
+ entry.cname = "%s->%s" % (
outer_scope_cname, cname)
elif entry.in_closure:
- entry.original_cname = entry.c_name
- entry.c_name = "%s->%s" % (
- Naming.cur_scope_cname, entry.c_name)
+ entry.original_cname = entry.cname
+ entry.cname = "%s->%s" % (
+ Naming.cur_scope_cname, entry.cname)
class GeneratorExpressionScope(Scope):
"""Scope for generator expressions and comprehensions. As opposed
type = outer_entry.type # may still be 'unspecified_type' !
# the parent scope needs to generate code for the variable, but
# this scope must hold its name exclusively
- binding.c_name = '%s%s' % (self.genexp_prefix, self.parent_scope.mangle(
+ binding.cname = '%s%s' % (self.genexp_prefix, self.parent_scope.mangle(
Naming.var_prefix, binding.name))
entry = self.WTK_declare(
binding, type, pos = pos)
def WTK_declare_var(self, binding, type,
is_cdef = 0, allow_pyobject = 0, pos = None):
# Add an entry for an attribute.
- if not binding.c_name:
- binding.c_name = binding.name
+ if not binding.cname:
+ binding.cname = binding.name
if binding.c_visibility == 'private':
- binding.c_name = c_safe_identifier(binding.c_name)
+ binding.cname = c_safe_identifier(binding.cname)
if type.is_cfunction:
type = PyrexTypes.CPtrType(type)
entry = self.WTK_declare(binding, type, pos)
error(pos,
"The name '%s' is reserved for a special method."
% binding.name)
- if not binding.c_name:
- binding.c_name = binding.name
+ if not binding.cname:
+ binding.cname = binding.name
if binding.c_visibility == 'private':
- binding.c_name = c_safe_identifier(binding.c_name)
+ binding.cname = c_safe_identifier(binding.cname)
if type.is_cpp_class and not binding.extern:
error(pos, "C++ classes not allowed as members of an extension type, use a pointer or reference instead")
entry = self.WTK_declare(binding, type, pos)
error(pos,
"C method '%s' not previously declared in definition part of"
" extension type" % binding.name)
- if not binding.c_name:
- binding.c_name = binding.name
+ if not binding.cname:
+ binding.cname = binding.name
entry = self.WTK_add_cfunction(binding, pos, type, modifiers)
if defining:
entry.func_cname = self.mangle(Naming.func_prefix, binding.name)
# 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.c_name, visibility='extern',
+ #entry = self.declare_cfunction(binding.name, type, None, binding.cname, visibility='extern',
# utility_code = utility_code)
entry = self.WTK_declare_cfunction(
binding, pos=None, type=type,
utility_code = utility_code) # WTK: need all declare_cfunction-s wrapped
var_entry = WTK_Entry(
- Binding(name=binding.name, c_name=binding.name), py_object_type)
+ Binding(name=binding.name, cname=binding.name), py_object_type)
var_entry.is_variable = 1
var_entry.is_builtin = 1
var_entry.utility_code = utility_code
# inherited type, with cnames modified appropriately
# to work with this type.
def adapt(cname):
- return "%s.%s" % (Naming.obj_base_cname, base_entry.c_name)
+ return "%s.%s" % (Naming.obj_base_cname, base_entry.cname)
for base_entry in \
base_scope.inherited_var_entries + base_scope.var_entries:
entry = self.declare(
base_entry.name,
- adapt(base_entry.c_name),
+ adapt(base_entry.cname),
base_entry.type, None, 'private')
entry.is_variable = 1
self.inherited_var_entries.append(entry)
visibility = base_entry.c_visibility
entry = self.add_cfunction(
base_entry.name, base_entry.type,
- base_entry.pos, adapt(base_entry.c_name),
+ base_entry.pos, adapt(base_entry.cname),
visibility, base_entry.func_modifiers)
entry.is_inherited = 1
def WTK_declare_var(self, binding, type,
is_cdef = 0, allow_pyobject = 0, pos = None):
# Add an entry for an attribute.
- if not binding.c_name:
- binding.c_name = binding.name
+ if not binding.cname:
+ binding.cname = binding.name
if type.is_cfunction:
type = PyrexTypes.CPtrType(type)
entry = self.WTK_declare(binding, type, pos)
def WTK_declare_cfunction(
self, binding, pos, type, defining = 0,
in_pxd = 0, modifiers = (), utility_code = None):
- if binding.name == self.name.split('::')[-1] and binding.c_name is None:
+ if binding.name == self.name.split('::')[-1] and binding.cname is None:
self.check_base_default_constructor(pos)
binding.name = '<init>'
type.return_type = self.lookup(self.name).type
if base_entry.name in self.entries:
base_entry.name
entry = self.declare(
- base_entry.name, base_entry.c_name,
+ base_entry.name, base_entry.cname,
base_entry.type, None, 'extern')
entry.is_variable = 1
self.inherited_var_entries.append(entry)
visibility = base_entry.c_visibility
entry = self.declare_cfunction(
base_entry.name, base_entry.type,
- base_entry.pos, base_entry.c_name,
+ base_entry.pos, base_entry.cname,
visibility, base_entry.func_modifiers,
utility_code = base_entry.utility_code)
entry.is_inherited = 1