Commit 72f8a46e authored by Vitja Makarov's avatar Vitja Makarov

Merge remote branch 'upstream/master'

parents 62567a26 0a56c99d
This diff is collapsed.
......@@ -867,9 +867,8 @@ class IntNode(ConstNode):
return self
elif dst_type.is_float:
if self.constant_result is not not_a_constant:
float_value = float(self.constant_result)
return FloatNode(self.pos, value=repr(float_value), type=dst_type,
constant_result=float_value)
return FloatNode(self.pos, value='%d.0' % int(self.constant_result), type=dst_type,
constant_result=float(self.constant_result))
else:
return FloatNode(self.pos, value=self.value, type=dst_type,
constant_result=not_a_constant)
......@@ -3061,7 +3060,11 @@ class SimpleCallNode(CallNode):
# nogil anyway)
pass
else:
self.args[i] = arg.coerce_to_temp(env)
#self.args[i] = arg.coerce_to_temp(env)
# instead: issue a warning
if i > 0 or i == 1 and self.self is not None: # skip first arg
warning(arg.pos, "Argument evaluation order in C function call is undefined and may not be as expected", 0)
break
# Calc result type and code fragment
if isinstance(self.function, NewExprNode):
self.type = PyrexTypes.CPtrType(self.function.class_type)
......
This diff is collapsed.
......@@ -970,7 +970,7 @@ class CVarDefNode(StatNode):
error(self.pos,
"Only 'extern' C variable declaration allowed in .pxd file")
entry = dest_scope.declare_var(name, type, declarator.pos,
cname = cname, visibility = visibility, is_cdef = 1)
cname=cname, visibility=visibility, api=self.api, is_cdef=1)
entry.needs_property = need_property
......@@ -980,6 +980,7 @@ class CStructOrUnionDefNode(StatNode):
# kind "struct" or "union"
# typedef_flag boolean
# visibility "public" or "private"
# api boolean
# in_pxd boolean
# attributes [CVarDefNode] or None
# entry Entry
......@@ -995,7 +996,8 @@ class CStructOrUnionDefNode(StatNode):
scope = StructOrUnionScope(self.name)
self.entry = env.declare_struct_or_union(
self.name, self.kind, scope, self.typedef_flag, self.pos,
self.cname, visibility = self.visibility, packed = self.packed)
self.cname, visibility = self.visibility, api = self.api,
packed = self.packed)
if self.attributes is not None:
if self.in_pxd and not env.in_cinclude:
self.entry.defined_in_pxd = 1
......@@ -1078,6 +1080,7 @@ class CEnumDefNode(StatNode):
# items [CEnumDefItemNode]
# typedef_flag boolean
# visibility "public" or "private"
# api boolean
# in_pxd boolean
# entry Entry
......@@ -1086,7 +1089,7 @@ class CEnumDefNode(StatNode):
def analyse_declarations(self, env):
self.entry = env.declare_enum(self.name, self.pos,
cname = self.cname, typedef_flag = self.typedef_flag,
visibility = self.visibility)
visibility = self.visibility, api = self.api)
if self.items is not None:
if self.in_pxd and not env.in_cinclude:
self.entry.defined_in_pxd = 1
......@@ -1097,7 +1100,7 @@ class CEnumDefNode(StatNode):
pass
def generate_execution_code(self, code):
if self.visibility == 'public':
if self.visibility == 'public' or self.api:
temp = code.funcstate.allocate_temp(PyrexTypes.py_object_type, manage_ref=True)
for item in self.entry.enum_values:
code.putln("%s = PyInt_FromLong(%s); %s" % (
......@@ -1129,7 +1132,7 @@ class CEnumDefItemNode(StatNode):
self.value.analyse_const_expression(env)
entry = env.declare_const(self.name, enum_entry.type,
self.value, self.pos, cname = self.cname,
visibility = enum_entry.visibility)
visibility = enum_entry.visibility, api = enum_entry.api)
enum_entry.enum_values.append(entry)
......@@ -1137,6 +1140,7 @@ class CTypeDefNode(StatNode):
# base_type CBaseTypeNode
# declarator CDeclaratorNode
# visibility "public" or "private"
# api boolean
# in_pxd boolean
child_attrs = ["base_type", "declarator"]
......@@ -1147,7 +1151,7 @@ class CTypeDefNode(StatNode):
name = name_declarator.name
cname = name_declarator.cname
entry = env.declare_typedef(name, type, self.pos,
cname = cname, visibility = self.visibility)
cname = cname, visibility = self.visibility, api = self.api)
if self.in_pxd and not env.in_cinclude:
entry.defined_in_pxd = 1
......@@ -1742,7 +1746,6 @@ class CFuncDefNode(FuncDefNode):
def generate_function_header(self, code, with_pymethdef, with_opt_args = 1, with_dispatch = 1, cname = None):
arg_decls = []
type = self.type
visibility = self.entry.visibility
for arg in type.args[:len(type.args)-type.optional_arg_count]:
arg_decls.append(arg.declaration_code())
if with_dispatch and self.overridable:
......@@ -1756,24 +1759,20 @@ class CFuncDefNode(FuncDefNode):
if cname is None:
cname = self.entry.func_cname
entity = type.function_header_code(cname, ', '.join(arg_decls))
if visibility == 'public':
dll_linkage = "DL_EXPORT"
if self.entry.visibility == 'private':
storage_class = "static "
else:
dll_linkage = None
header = self.return_type.declaration_code(entity,
dll_linkage = dll_linkage)
if visibility == 'extern':
storage_class = "%s " % Naming.extern_c_macro
elif visibility == 'public':
storage_class = ""
else:
storage_class = "static "
dll_linkage = None
modifiers = ""
if 'inline' in self.modifiers:
self.modifiers[self.modifiers.index('inline')] = 'cython_inline'
code.putln("%s%s %s {" % (
storage_class,
' '.join(self.modifiers).upper(), # macro forms
header))
if self.modifiers:
modifiers = "%s " % ' '.join(self.modifiers).upper()
header = self.return_type.declaration_code(entity, dll_linkage=dll_linkage)
#print (storage_class, modifiers, header)
code.putln("%s%s%s {" % (storage_class, modifiers, header))
def generate_argument_declarations(self, env, code):
for arg in self.args:
......
......@@ -64,7 +64,6 @@ class SkipDeclarations(object):
def visit_CStructOrUnionDefNode(self, node):
return node
class NormalizeTree(CythonTransform):
"""
This transform fixes up a few things after parsing
......
......@@ -2428,7 +2428,7 @@ def p_c_enum_definition(s, pos, ctx):
return Nodes.CEnumDefNode(
pos, name = name, cname = cname, items = items,
typedef_flag = ctx.typedef_flag, visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd')
api = ctx.api, in_pxd = ctx.level == 'module_pxd')
def p_c_enum_line(s, ctx, items):
if s.sy != 'pass':
......@@ -2489,7 +2489,7 @@ def p_c_struct_or_union_definition(s, pos, ctx):
return Nodes.CStructOrUnionDefNode(pos,
name = name, cname = cname, kind = kind, attributes = attributes,
typedef_flag = ctx.typedef_flag, visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd', packed = packed)
api = ctx.api, in_pxd = ctx.level == 'module_pxd', packed = packed)
def p_visibility(s, prev_visibility):
pos = s.position()
......@@ -2574,7 +2574,8 @@ def p_ctypedef_statement(s, ctx):
s.expect_newline("Syntax error in ctypedef statement")
return Nodes.CTypeDefNode(
pos, base_type = base_type,
declarator = declarator, visibility = visibility,
declarator = declarator,
visibility = visibility, api = api,
in_pxd = ctx.level == 'module_pxd')
def p_decorators(s):
......@@ -2701,8 +2702,8 @@ def p_c_class_definition(s, pos, ctx):
base_class_module = ".".join(base_class_path[:-1])
base_class_name = base_class_path[-1]
if s.sy == '[':
if ctx.visibility not in ('public', 'extern'):
error(s.position(), "Name options only allowed for 'public' or 'extern' C class")
if ctx.visibility not in ('public', 'extern') and not ctx.api:
error(s.position(), "Name options only allowed for 'public', 'api', or 'extern' C class")
objstruct_name, typeobj_name = p_c_class_options(s)
if s.sy == ':':
if ctx.level == 'module_pxd':
......@@ -2726,7 +2727,10 @@ def p_c_class_definition(s, pos, ctx):
error(pos, "Type object name specification required for 'public' C class")
elif ctx.visibility == 'private':
if ctx.api:
error(pos, "Only 'public' C class can be declared 'api'")
if not objstruct_name:
error(pos, "Object struct name specification required for 'api' C class")
if not typeobj_name:
error(pos, "Type object name specification required for 'api' C class")
else:
error(pos, "Invalid class visibility '%s'" % ctx.visibility)
return Nodes.CClassDefNode(pos,
......
......@@ -1190,8 +1190,8 @@ class CComplexType(CNumericType):
visibility="extern")
scope.parent_type = self
scope.directives = {}
scope.declare_var("real", self.real_type, None, "real", is_cdef=True)
scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True)
scope.declare_var("real", self.real_type, None, cname="real", is_cdef=True)
scope.declare_var("imag", self.real_type, None, cname="imag", is_cdef=True)
entry = scope.declare_cfunction(
"conjugate",
CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True),
......
This diff is collapsed.
......@@ -378,6 +378,32 @@ class TestExec(DebugTestCase):
gdb.execute('cy exec some_random_var = 14')
self.assertEqual('14', self.eval_command('some_random_var'))
class CySet(DebugTestCase):
def test_cyset(self):
self.break_and_run('os.path.join("foo", "bar")')
gdb.execute('cy set a = $cy_eval("{None: []}")')
stringvalue = self.read_var("a", cast_to=str)
self.assertEqual(stringvalue, "{None: []}")
class TestCyEval(DebugTestCase):
"Test the $cy_eval() gdb function."
def test_cy_eval(self):
# This function leaks a few objects in the GDB python process. This
# is no biggie
self.break_and_run('os.path.join("foo", "bar")')
result = gdb.execute('print $cy_eval("None")', to_string=True)
assert re.match(r'\$\d+ = None\n', result), result
result = gdb.execute('print $cy_eval("[a]")', to_string=True)
assert re.match(r'\$\d+ = \[0\]', result), result
class TestClosure(DebugTestCase):
def break_and_run_func(self, funcname):
......
......@@ -113,5 +113,3 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase):
frame = self.pyobject_fromcode('PyEval_GetFrame()')
self.assertEqual(type(frame), libpython.PyFrameObjectPtr)
\ No newline at end of file
......@@ -592,6 +592,7 @@ class CyCy(CythonCommand):
cy bt / cy backtrace
cy list
cy print
cy set
cy locals
cy globals
cy exec
......@@ -607,6 +608,7 @@ class CyCy(CythonCommand):
completer_class, prefix=True)
commands = dict(
# GDB commands
import_ = CyImport.register(),
break_ = CyBreak.register(),
step = CyStep.register(),
......@@ -624,9 +626,13 @@ class CyCy(CythonCommand):
globals = CyGlobals.register(),
exec_ = libpython.FixGdbCommand('cy exec', '-cy-exec'),
_exec = CyExec.register(),
set = CySet.register(),
# GDB functions
cy_cname = CyCName('cy_cname'),
cy_cvalue = CyCValue('cy_cvalue'),
cy_lineno = CyLine('cy_lineno'),
cy_eval = CyEval('cy_eval'),
)
for command_name, command in commands.iteritems():
......@@ -1169,15 +1175,14 @@ class CyGlobals(CyLocals):
max_name_length, ' ')
class CyExec(CythonCommand, libpython.PyExec):
class EvaluateOrExecuteCodeMixin(object):
"""
Execute Python code in the nearest Python or Cython frame.
Evaluate or execute Python code in a Cython or Python frame. The 'evalcode'
method evaluations Python code, prints a traceback if an exception went
uncaught, and returns any return value as a gdb.Value (NULL on exception).
"""
name = '-cy-exec'
command_class = gdb.COMMAND_STACK
completer_class = gdb.COMPLETE_NONE
def _fill_locals_dict(self, executor, local_dict_pointer):
"Fill a remotely allocated dict with values from the Cython C stack"
cython_func = self.get_cython_function()
......@@ -1208,28 +1213,22 @@ class CyExec(CythonCommand, libpython.PyExec):
raise gdb.GdbError("Unable to execute Python code.")
finally:
# PyDict_SetItem doesn't steal our reference
executor.decref(pystringp)
executor.xdecref(pystringp)
def _find_first_cython_or_python_frame(self):
frame = gdb.selected_frame()
while frame:
if (self.is_cython_function(frame) or
self.is_python_function(frame)):
frame.select()
return frame
frame = frame.older()
raise gdb.GdbError("There is no Cython or Python frame on the stack.")
def invoke(self, expr, from_tty):
frame = self._find_first_cython_or_python_frame()
if self.is_python_function(frame):
libpython.py_exec.invoke(expr, from_tty)
return
expr, input_type = self.readcode(expr)
executor = libpython.PythonCodeExecutor()
def _evalcode_cython(self, executor, code, input_type):
with libpython.FetchAndRestoreError():
# get the dict of Cython globals and construct a dict in the
# inferior with Cython locals
......@@ -1240,9 +1239,65 @@ class CyExec(CythonCommand, libpython.PyExec):
try:
self._fill_locals_dict(executor,
libpython.pointervalue(local_dict))
executor.evalcode(expr, input_type, global_dict, local_dict)
result = executor.evalcode(code, input_type, global_dict,
local_dict)
finally:
executor.decref(libpython.pointervalue(local_dict))
executor.xdecref(libpython.pointervalue(local_dict))
return result
def evalcode(self, code, input_type):
"""
Evaluate `code` in a Python or Cython stack frame using the given
`input_type`.
"""
frame = self._find_first_cython_or_python_frame()
executor = libpython.PythonCodeExecutor()
if self.is_python_function(frame):
return libpython._evalcode_python(executor, code, input_type)
return self._evalcode_cython(executor, code, input_type)
class CyExec(CythonCommand, libpython.PyExec, EvaluateOrExecuteCodeMixin):
"""
Execute Python code in the nearest Python or Cython frame.
"""
name = '-cy-exec'
command_class = gdb.COMMAND_STACK
completer_class = gdb.COMPLETE_NONE
def invoke(self, expr, from_tty):
expr, input_type = self.readcode(expr)
executor = libpython.PythonCodeExecutor()
executor.xdecref(self.evalcode(expr, executor.Py_single_input))
class CySet(CythonCommand):
"""
Set a Cython variable to a certain value
cy set my_cython_c_variable = 10
cy set my_cython_py_variable = $cy_eval("{'doner': 'kebab'}")
This is equivalent to
set $cy_value("my_cython_variable") = 10
"""
name = 'cy set'
command_class = gdb.COMMAND_DATA
completer_class = gdb.COMPLETE_NONE
@require_cython_frame
def invoke(self, expr, from_tty):
name_and_expr = expr.split('=', 1)
if len(name_and_expr) != 2:
raise gdb.GdbError("Invalid expression. Use 'cy set var = expr'.")
varname, expr = name_and_expr
cname = self.cy.cy_cname.invoke(varname.strip())
gdb.execute("set %s = %s" % (cname, expr))
# Functions
......@@ -1312,6 +1367,18 @@ class CyLine(gdb.Function, CythonBase):
def invoke(self):
return self.get_cython_lineno()
class CyEval(gdb.Function, CythonBase, EvaluateOrExecuteCodeMixin):
"""
Evaluate Python code in the nearest Python or Cython frame and return
"""
@gdb_function_value_to_unicode
def invoke(self, python_expression):
input_type = libpython.PythonCodeExecutor.Py_eval_input
return self.evalcode(python_expression, input_type)
cython_info = CythonInfo()
cy = CyCy.register()
cython_info.cy = cy
......
......@@ -1949,27 +1949,41 @@ class ExecutionControlCommandBase(gdb.Command):
gdb.execute("delete %s" % bp)
def filter_output(self, result):
output = []
match_finish = re.search(r'^Value returned is \$\d+ = (.*)', result,
re.MULTILINE)
if match_finish:
output.append('Value returned: %s' % match_finish.group(1))
reflags = re.MULTILINE
regexes = [
output_on_halt = [
(r'^Program received signal .*', reflags|re.DOTALL),
(r'.*[Ww]arning.*', 0),
(r'^Program exited .*', reflags),
]
output_always = [
# output when halting on a watchpoint
(r'^(Old|New) value = .*', reflags),
# output from the 'display' command
(r'^\d+: \w+ = .*', reflags),
]
def filter_output(regexes):
output = []
for regex, flags in regexes:
match = re.search(regex, result, flags)
if match:
for match in re.finditer(regex, result, flags):
output.append(match.group(0))
return '\n'.join(output)
# Filter the return value output of the 'finish' command
match_finish = re.search(r'^Value returned is \$\d+ = (.*)', result,
re.MULTILINE)
if match_finish:
finish_output = 'Value returned: %s\n' % match_finish.group(1)
else:
finish_output = ''
return (filter_output(output_on_halt),
finish_output + filter_output(output_always))
def stopped(self):
return get_selected_inferior().pid == 0
......@@ -1979,17 +1993,23 @@ class ExecutionControlCommandBase(gdb.Command):
of source code or the result of the last executed gdb command (passed
in as the `result` argument).
"""
result = self.filter_output(result)
output_on_halt, output_always = self.filter_output(result)
if self.stopped():
print result.strip()
print output_always
print output_on_halt
else:
frame = gdb.selected_frame()
source_line = self.lang_info.get_source_line(frame)
if self.lang_info.is_relevant_function(frame):
raised_exception = self.lang_info.exc_info(frame)
if raised_exception:
print raised_exception
print self.lang_info.get_source_line(frame) or result
if source_line:
if output_always.rstrip():
print output_always.rstrip()
print source_line
else:
print result
......@@ -2190,12 +2210,12 @@ class PythonInfo(LanguageInfo):
try:
tstate = frame.read_var('tstate').dereference()
if gdb.parse_and_eval('tstate->frame == f'):
# tstate local variable initialized
# tstate local variable initialized, check for an exception
inf_type = tstate['curexc_type']
inf_value = tstate['curexc_value']
if inf_type:
return 'An exception was raised: %s(%s)' % (inf_type,
inf_value)
return 'An exception was raised: %s' % (inf_value,)
except (ValueError, RuntimeError), e:
# Could not read the variable tstate or it's memory, it's ok
pass
......@@ -2342,7 +2362,7 @@ class PythonCodeExecutor(object):
"Increment the reference count of a Python object in the inferior."
gdb.parse_and_eval('Py_IncRef((PyObject *) %d)' % pointer)
def decref(self, pointer):
def xdecref(self, pointer):
"Decrement the reference count of a Python object in the inferior."
# Py_DecRef is like Py_XDECREF, but a function. So we don't have
# to check for NULL. This should also decref all our allocated
......@@ -2382,10 +2402,11 @@ class PythonCodeExecutor(object):
with FetchAndRestoreError():
try:
self.decref(gdb.parse_and_eval(code))
pyobject_return_value = gdb.parse_and_eval(code)
finally:
self.free(pointer)
return pyobject_return_value
class FetchAndRestoreError(PythonCodeExecutor):
"""
......@@ -2462,6 +2483,20 @@ class FixGdbCommand(gdb.Command):
self.fix_gdb()
def _evalcode_python(executor, code, input_type):
"""
Execute Python code in the most recent stack frame.
"""
global_dict = gdb.parse_and_eval('PyEval_GetGlobals()')
local_dict = gdb.parse_and_eval('PyEval_GetLocals()')
if (pointervalue(global_dict) == 0 or pointervalue(local_dict) == 0):
raise gdb.GdbError("Unable to find the locals or globals of the "
"most recent Python function (relative to the "
"selected frame).")
return executor.evalcode(code, input_type, global_dict, local_dict)
class PyExec(gdb.Command):
def readcode(self, expr):
......@@ -2484,17 +2519,9 @@ class PyExec(gdb.Command):
def invoke(self, expr, from_tty):
expr, input_type = self.readcode(expr)
executor = PythonCodeExecutor()
global_dict = gdb.parse_and_eval('PyEval_GetGlobals()')
local_dict = gdb.parse_and_eval('PyEval_GetLocals()')
if pointervalue(global_dict) == 0 or pointervalue(local_dict) == 0:
raise gdb.GdbError("Unable to find the locals or globals of the "
"most recent Python function (relative to the "
"selected frame).")
executor.evalcode(expr, input_type, global_dict, local_dict)
executor.xdecref(_evalcode_python(executor, input_type, global_dict,
local_dict))
gdb.execute('set breakpoint pending on')
......
......@@ -17,6 +17,7 @@ pure_mode_cmethod_inheritance_T583
genexpr_iterable_lookup_T600
for_from_pyvar_loop_T601
decorators_T593
temp_sideeffects_T654
# CPython regression tests that don't current work:
pyregr.test_threadsignals
......
......@@ -11,6 +11,12 @@ cdef public class C[type C_Type, object C_Obj]:
cdef public Zax *blarg
cdef public C c_pub = C()
cdef api C c_api = C()
cdef public dict o_pub = C()
cdef api list o_api = C()
cdef api float f(Foo *x):
pass
......@@ -19,3 +25,6 @@ cdef public void g(Blarg *x):
cdef public api void h(Zax *x):
pass
cdef extern from "a_capi.h":
pass
# --
ctypedef int Int0
ctypedef api int Int1
ctypedef enum EnumA0: EA0
ctypedef api enum EnumA1: EA1
cdef enum EnumB0: EB0=0
cdef api enum EnumB1: EB1=1
cdef Int0 i0 = 0
cdef EnumA0 ea0 = EA0
cdef EnumB0 eb0 = EB0
cdef api Int1 i1 = 0
cdef api EnumA1 ea1 = EA1
cdef api EnumB1 eb1 = EB1
# --
ctypedef struct StructA0:
int SA0
ctypedef api struct StructA1:
int SA1
cdef struct StructB0:
int SB0
cdef api struct StructB1:
int SB1
cdef StructA0 sa0 = {'SA0':0}
cdef StructB0 sb0 = {'SB0':2}
cdef api StructA1 sa1 = {'SA1':1}
cdef api StructB1 sb1 = {'SB1':3}
# --
ctypedef class Foo0: pass
ctypedef api class Foo1 [type PyFoo1_Type, object PyFoo1_Object]: pass
cdef class Bar0: pass
cdef api class Bar1 [type PyBar1_Type, object PyBar1_Object]: pass
cdef Foo0 f0 = None
cdef Bar0 b0 = None
cdef api Foo1 f1 = None
cdef api Bar1 b1 = None
# --
cdef void bar0(): pass
cdef api void bar1(): pass
cdef void* spam0(object o) except NULL: return NULL
cdef api void* spam1(object o) except NULL: return NULL
bar0()
bar1()
spam0(None)
spam1(None)
# --
# --
ctypedef int Int0
ctypedef public int Int1
ctypedef api int Int2
ctypedef public api int Int3
ctypedef enum EnumA0: EA0
ctypedef public enum EnumA1: EA1
ctypedef api enum EnumA2: EA2
ctypedef public api enum EnumA3: EA3
cdef enum EnumB0: EB0=0
cdef public enum EnumB1: EB1=1
cdef api enum EnumB2: EB2=2
cdef public api enum EnumB3: EB3=3
# --
ctypedef struct StructA0:
int SA0
ctypedef public struct StructA1:
int SA1
ctypedef api struct StructA2:
int SA2
ctypedef public api struct StructA3:
int SA3
cdef struct StructB0:
int SB0
cdef public struct StructB1:
int SB1
cdef api struct StructB2:
int SB2
cdef public api struct StructB3:
int SB3
# --
ctypedef class Foo0: pass
ctypedef public class Foo1 [type PyFoo1_Type, object PyFoo1_Object]: pass
ctypedef api class Foo2 [type PyFoo2_Type, object PyFoo2_Object]: pass
ctypedef public api class Foo3 [type PyFoo3_Type, object PyFoo3_Object]: pass
cdef class Bar0: pass
cdef public class Bar1 [type PyBar1_Type, object PyBar1_Object]: pass
cdef api class Bar2 [type PyBar2_Type, object PyBar2_Object]: pass
cdef public api class Bar3 [type PyBar3_Type, object PyBar3_Object]: pass
# --
cdef void bar0(): pass
cdef public void bar1(): pass
cdef api void bar2(): pass
cdef public api void bar3(): pass
cdef void* spam0(object o) except NULL: return NULL
cdef public void* spam1(object o) except NULL: return NULL
cdef api void* spam2(object o) except NULL: return NULL
cdef public api void* spam3(object o) except NULL: return NULL
bar0()
spam0(None)
# --
cdef double d0 = 0
cdef public double d1 = 1
cdef api double d2 = 2
cdef public api double d3 = 3
cdef object o0 = None
cdef public object o1 = None
cdef api object o2 = None
cdef public api object o3 = None
# --
# --
ctypedef int Int0
ctypedef public int Int1
ctypedef enum EnumA0: EA0
ctypedef public enum EnumA1: EA1
cdef enum EnumB0: EB0=0
cdef public enum EnumB1: EB1=1
cdef Int0 i0 = 0
cdef EnumA0 ea0 = EA0
cdef EnumB0 eb0 = EB0
cdef public Int1 i1 = 0
cdef public EnumA1 ea1 = EA1
cdef public EnumB1 eb1 = EB1
# --
ctypedef struct StructA0:
int SA0
ctypedef public struct StructA1:
int SA1
cdef struct StructB0:
int SB0
cdef public struct StructB1:
int SB1
cdef StructA0 sa0 = {'SA0':0}
cdef StructB0 sb0 = {'SB0':2}
cdef public StructA1 sa1 = {'SA1':1}
cdef public StructB1 sb1 = {'SB1':3}
# --
ctypedef class Foo0: pass
ctypedef public class Foo1 [type PyFoo1_Type, object PyFoo1_Object]: pass
cdef class Bar0: pass
cdef public class Bar1 [type PyBar1_Type, object PyBar1_Object]: pass
cdef Foo0 f0 = None
cdef Bar0 b0 = None
cdef public Foo1 f1 = None
cdef public Bar1 b1 = None
# --
cdef void bar0(): pass
cdef public void bar1(): pass
cdef void* spam0(object o) except NULL: return NULL
cdef public void* spam1(object o) except NULL: return NULL
bar0()
bar1()
spam0(None)
spam1(None)
# --
# --
ctypedef int Int0
ctypedef public int Int1
ctypedef api int Int2
ctypedef public api int Int3
ctypedef enum EnumA0: EA0
ctypedef public enum EnumA1: EA1
ctypedef api enum EnumA2: EA2
ctypedef public api enum EnumA3: EA3
cdef enum EnumB0: EB0=0
cdef public enum EnumB1: EB1=1
cdef api enum EnumB2: EB2=2
cdef public api enum EnumB3: EB3=3
# --
ctypedef struct StructA0:
int SA0
ctypedef public struct StructA1:
int SA1
ctypedef api struct StructA2:
int SA2
ctypedef public api struct StructA3:
int SA3
cdef struct StructB0:
int SB0
cdef public struct StructB1:
int SB1
cdef api struct StructB2:
int SB2
cdef public api struct StructB3:
int SB3
# --
ctypedef class Foo0: pass
ctypedef public class Foo1 [type PyFoo1_Type, object PyFoo1_Object]: pass
ctypedef api class Foo2 [type PyFoo2_Type, object PyFoo2_Object]: pass
ctypedef public api class Foo3 [type PyFoo3_Type, object PyFoo3_Object]: pass
cdef class Bar0: pass
cdef public class Bar1 [type PyBar1_Type, object PyBar1_Object]: pass
cdef api class Bar2 [type PyBar2_Type, object PyBar2_Object]: pass
cdef public api class Bar3 [type PyBar3_Type, object PyBar3_Object]: pass
# --
cdef inline void bar0(): pass
cdef public void bar1()
cdef api void bar2()
cdef public api void bar3()
cdef inline void* spam0(object o) except NULL: return NULL
cdef public void* spam1(object o) except NULL
cdef api void* spam2(object o) nogil except NULL
cdef public api void* spam3(object o) except NULL with gil
# --
#cdef public int i1
#cdef api int i2
#cdef public api int i3
# --
cdef class Foo1: pass
cdef class Foo2: pass
cdef class Foo3: pass
cdef class Bar1: pass
cdef class Bar2: pass
cdef class Bar3: pass
cdef public void bar1(): pass
cdef api void bar2(): pass
cdef public api void bar3(): pass
cdef public void* spam1(object o) except NULL: return NULL
cdef api void* spam2(object o) nogil except NULL: return NULL
cdef public api void* spam3(object o) except NULL with gil: return NULL
......@@ -2,8 +2,20 @@ __doc__ = u"""
>>> import sys
>>> sys.getrefcount(Foo.__pyx_vtable__)
2
>>> sys.getrefcount(__pyx_capi__['spam'])
>>> sys.getrefcount(__pyx_capi__['ten'])
2
>>> sys.getrefcount(__pyx_capi__['pi'])
2
>>> sys.getrefcount(__pyx_capi__['obj'])
2
>>> sys.getrefcount(__pyx_capi__['dct'])
2
>>> sys.getrefcount(__pyx_capi__['one'])
2
>>> sys.getrefcount(__pyx_capi__['two'])
Traceback (most recent call last):
...
KeyError: 'two'
"""
cdef public api class Foo [type FooType, object FooObject]:
......@@ -12,3 +24,12 @@ cdef public api class Foo [type FooType, object FooObject]:
cdef api void spam():
pass
cdef api int ten = 10
cdef api double pi = 3.14
cdef api object obj = object()
cdef api dict dct = {}
cdef public api int one = 1
cdef public int two = 2
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment