Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e0f843d
Update Parsing.py
rinarakaki Nov 3, 2023
5f39773
Update Parsing.pxd
rinarakaki Nov 3, 2023
50ac989
Update ExprNodes.py
rinarakaki Nov 3, 2023
4954d6d
Update ExprNodes.py
rinarakaki Nov 3, 2023
a976b1e
Update ExprNodes.py
rinarakaki Nov 3, 2023
342fe84
Update refnanny.pyx
rinarakaki Nov 3, 2023
43a61f9
Update Parsing.py
rinarakaki Nov 3, 2023
9a8aea7
Update Parsing.pxd
rinarakaki Nov 3, 2023
b6eb959
Update Parsing.pxd
rinarakaki Nov 3, 2023
3217734
Update Parsing.py
rinarakaki Nov 3, 2023
55fbed4
Update Nodes.py
rinarakaki Nov 3, 2023
e787608
Update Nodes.py
rinarakaki Nov 3, 2023
fdf4f22
Update refnanny.pyx
rinarakaki Nov 3, 2023
29ab77d
Update ExprNodes.py
rinarakaki Nov 3, 2023
ecc7bd5
Update ExprNodes.py
rinarakaki Nov 3, 2023
7881512
Update refnanny.pyx
rinarakaki Nov 3, 2023
dd40731
Update ExprNodes.py
rinarakaki Nov 3, 2023
baba8c1
Update refnanny.pyx
rinarakaki Nov 3, 2023
bbe6319
Update Parsing.py
rinarakaki Nov 3, 2023
7fababd
Update Parsing.pxd
rinarakaki Nov 3, 2023
24ba4c9
Update refnanny.pyx
rinarakaki Nov 3, 2023
f305f1b
Merge branch 'main' into variable-declarations
rinarakaki Nov 5, 2023
cba9d7b
Update
rinarakaki Nov 5, 2023
5bce336
Merge branch 'main' into variable-declarations
rinarakaki Nov 5, 2023
185174e
Update cimport_package_module_T4.pyx
rinarakaki Nov 5, 2023
855c9e0
Update cimport_package_module_T4.pyx
rinarakaki Nov 5, 2023
df6a249
Update
rinarakaki Nov 7, 2023
24b1671
Update
rinarakaki Nov 12, 2023
a2809eb
Update
rinarakaki Nov 13, 2023
99fcc3a
Merge branch 'main' into variable-declarations
rinarakaki Nov 14, 2023
dd342d3
Update
rinarakaki Nov 16, 2023
1886711
Merge branch 'main' into variable-declarations
rinarakaki Nov 19, 2023
ba75b97
Merge branch 'main' into variable-declarations
rinarakaki Nov 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cython/Compiler/ExprNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,9 @@ def _analyse_target_declaration(self, env, is_assignment_expression):
type = py_object_type
if is_assignment_expression:
self.entry = env.declare_assignment_expression_target(self.name, type, self.pos)
# TODO https://github.com/rnarkk/cython/pull/39 https://github.com/rnarkk/cython/pull/42
elif self.is_cython_module and not env.is_module_scope:
error(self.pos, "Undeclared variable")
else:
self.entry = env.declare_var(self.name, type, self.pos)
if self.entry.is_declared_generic:
Expand Down
8 changes: 4 additions & 4 deletions Cython/Compiler/Parsing.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ fn p_imported_name(PyrexScanner s)
fn p_dotted_name(PyrexScanner s, u2 as_allowed)
fn p_as_name(PyrexScanner s)
fn p_assert_statement(PyrexScanner s)
fn p_if_statement(PyrexScanner s)
fn p_if_clause(PyrexScanner s)
fn p_if_statement(PyrexScanner s, ctx)
fn p_if_clause(PyrexScanner s, ctx)
fn p_else_clause(PyrexScanner s)
fn p_loop_statement(PyrexScanner s)
fn p_while_statement(PyrexScanner s)
fn p_for_statement(PyrexScanner s, u2 is_async=*)
fn p_for_statement(PyrexScanner s, ctx, u2 is_async=*)
fn dict p_for_bounds(PyrexScanner s, u2 allow_testlist=*, u2 is_async=*)
fn p_for_from_relation(PyrexScanner s)
fn p_for_from_step(PyrexScanner s)
fn p_target(PyrexScanner s, terminator)
fn p_for_target(PyrexScanner s)
fn p_for_iterator(PyrexScanner s, u2 allow_testlist=*, u2 is_async=*)
fn p_try_statement(PyrexScanner s)
fn p_try_statement(PyrexScanner s, ctx)
fn p_except_clause(PyrexScanner s)
fn p_include_statement(PyrexScanner s, ctx)
fn p_with_statement(PyrexScanner s)
Expand Down
31 changes: 16 additions & 15 deletions Cython/Compiler/Parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def p_async_statement(s, ctx, decorators):
elif decorators:
s.error("Decorators can only be followed by functions or classes")
elif s.sy == 'for':
return p_for_statement(s, is_async=True)
return p_for_statement(s, ctx, is_async=True)
elif s.sy == 'with':
s.next()
return p_with_items(s, is_async=True)
Expand Down Expand Up @@ -2029,22 +2029,22 @@ def p_assert_statement(s):
statement_terminators = cython.declare(frozenset, frozenset((
';', 'NEWLINE', 'EOF')))

def p_if_statement(s):
def p_if_statement(s, ctx):
# s.sy == 'if'
pos = s.position()
s.next()
if_clauses = [p_if_clause(s)]
if_clauses = [p_if_clause(s, ctx)]
while s.sy == 'elif':
s.next()
if_clauses.append(p_if_clause(s))
if_clauses.append(p_if_clause(s, ctx))
else_clause = p_else_clause(s)
return Nodes.IfStatNode(pos,
if_clauses = if_clauses, else_clause = else_clause)

def p_if_clause(s):
def p_if_clause(s, ctx):
pos = s.position()
test = p_namedexpr_test(s)
body = p_suite(s)
body = p_suite(s, ctx)
return Nodes.IfClauseNode(pos,
condition = test, body = body)

Expand Down Expand Up @@ -2073,12 +2073,13 @@ def p_while_statement(s):
condition = test, body = body,
else_clause = else_clause)

def p_for_statement(s, is_async=False):

def p_for_statement(s, ctx, is_async=False):
# s.sy == 'for'
pos = s.position()
s.next()
kw = p_for_bounds(s, allow_testlist=True, is_async=is_async)
body = p_suite(s)
body = p_suite(s, ctx)
else_clause = p_else_clause(s)
kw.update(body=body, else_clause=else_clause, is_async=is_async)
return Nodes.ForStatNode(pos, **kw)
Expand Down Expand Up @@ -2174,19 +2175,19 @@ def p_for_iterator(s, allow_testlist=True, is_async=False):
return (ExprNodes.AsyncIteratorNode if is_async else ExprNodes.IteratorNode)(pos, sequence=expr)


def p_try_statement(s):
def p_try_statement(s, ctx):
# s.sy == 'try'
pos = s.position()
s.next()
body = p_suite(s)
body = p_suite(s, ctx)
except_clauses = []
else_clause = None
if s.sy in ('except', 'else'):
while s.sy == 'except':
except_clauses.append(p_except_clause(s))
if s.sy == 'else':
s.next()
else_clause = p_suite(s)
else_clause = p_suite(s, ctx)
body = Nodes.TryExceptStatNode(pos,
body = body, except_clauses = except_clauses,
else_clause = else_clause)
Expand All @@ -2195,7 +2196,7 @@ def p_try_statement(s):
# try-except-finally is equivalent to nested try-except/try-finally
if s.sy == 'finally':
s.next()
finally_clause = p_suite(s)
finally_clause = p_suite(s, ctx)
return Nodes.TryFinallyStatNode(pos,
body = body, finally_clause = finally_clause)
else:
Expand Down Expand Up @@ -2642,15 +2643,15 @@ def p_statement(s, ctx, first_statement = 0):
return node
s.error("Executable statement not allowed here")
if s.sy == 'if':
return p_if_statement(s)
return p_if_statement(s, ctx)
elif s.sy == "loop":
return p_loop_statement(s)
elif s.sy == 'while':
return p_while_statement(s)
elif s.sy == 'for':
return p_for_statement(s)
return p_for_statement(s, ctx)
elif s.sy == 'try':
return p_try_statement(s)
return p_try_statement(s, ctx)
elif s.sy == 'with':
return p_with_statement(s)
elif s.sy == 'async':
Expand Down
14 changes: 8 additions & 6 deletions Cython/Runtime/refnanny.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cdef class Context(object):
if is_null:
self.errors.append(f"NULL argument on line {lineno}")
return
id_ = id(obj)
count, linenumbers = self.refs.get(id_, (0, []))
let auto id_ = id(obj)
let auto (count, linenumbers) = self.refs.get(id_, (0, []))
self.refs[id_] = (count + 1, linenumbers)
linenumbers.append(lineno)

Expand All @@ -48,8 +48,8 @@ cdef class Context(object):
if is_null:
self.errors.append(f"NULL argument on line {lineno}")
return false
id_ = id(obj)
count, linenumbers = self.refs.get(id_, (0, []))
let auto id_ = id(obj)
let auto (count, linenumbers) = self.refs.get(id_, (0, []))
if count == 0:
self.errors.append(f"Too many decrefs on line {lineno}, reference acquired on lines {linenumbers!r}")
return false
Expand All @@ -61,7 +61,9 @@ cdef class Context(object):

fn end(self):
if self.refs:
msg = u"References leaked:"
let msg = u"References leaked:"
let i32 count
let list linenos
for count, linenos in self.refs.itervalues():
msg += f"\n ({count}) acquired on lines: {u', '.join([f'{x}' for x in linenos])}"
self.errors.append(msg)
Expand Down Expand Up @@ -90,7 +92,7 @@ fn PyObject* SetupContext(r&i8 funcname, isize lineno, r&i8 filename) except NUL
PyThreadState_Get() # Check that we hold the GIL
PyErr_Fetch(&type, &value, &tb)
try:
ctx = Context(funcname, lineno, filename)
let ctx = Context(funcname, lineno, filename)
Py_INCREF(ctx)
result = <PyObject*>ctx
except Exception, e:
Expand Down