Robert Bradshaw | 2 Dec 10:39
Favicon

Fwd: [Pyrex] ANN: Pyrex 0.9.6.4

Looking at the changelog, this should be a pretty easy merge :-)

Begin forwarded message:

> From: Greg Ewing <greg.ewing@...>
> Date: December 1, 2007 7:30:49 PM PST
> To: Pyrex List <pyrex@...>
> Subject: [Pyrex] ANN: Pyrex 0.9.6.4
>
> Pyrex 0.9.6.4 is now available:
>
>    http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
>
> Mostly just bug fixes in this release; see CHANGES.txt on
> the web site for details.
>
>
> What is Pyrex?
> --------------
>
> Pyrex is a language for writing Python extension modules.
> It lets you freely mix operations on Python and C data, with
> all Python reference counting and error checking handled
> automatically.
>
> _______________________________________________
> Pyrex mailing list
> Pyrex@...
> http://lists.copyleft.no/mailman/listinfo/pyrex

(Continue reading)

Stefan Behnel | 2 Dec 12:31
Picon
Favicon
Gravatar

Small fix for "with gil" compiler error

Hi,

here's a small fix for the error report the compiler generates when running
into a "with UNKNOWN". Both Cython and Pyrex currently crash here.

BTW, Greg, what's the status of the "with gil" block implementation?
Currently, it also generates the error below.

Stefan

# HG changeset patch
# User Stefan Behnel <scoder@...>
# Date 1196593655 -3600
# Node ID f82502b66b0d6cab80698040f270c10262e746a8
# Parent  b2c3a4522f29fe8103303477bee496b6790bfd5b
fixed broken call to compiler error function

diff -r b2c3a4522f29 -r f82502b66b0d Compiler/Parsing.py
--- a/Compiler/Parsing.py       Sat Nov 24 10:54:22 2007 +0100
+++ b/Compiler/Parsing.py       Sun Dec 02 12:07:35 2007 +0100
@@ -1202,7 +1202,8 @@ def p_with_statement(s):
         body = p_suite(s)
         return Nodes.GILStatNode(pos, state = state, body = body)
     else:
-        s.error(pos, "Only 'with gil' and 'with nogil' implemented")
+        s.error("Only 'with gil' and 'with nogil' implemented",
+                pos = pos)

 def p_simple_statement(s):
     #print "p_simple_statement:", s.sy, s.systring ###
(Continue reading)

David McNab | 5 Dec 19:58
Picon
Favicon

req - block-local variables

Hi Cython folks,

I'd love it if Cython could support the declaration of block-local
variables, eg:

        def somefunc(int arg1):
            cdef int var1       # conventional function-local var

            if arg1 == 0:
                cdef int var2   # block-local var 
                ...

Given that C already supports this, would it be very hard to support in
Cython as well?

Thoughts?

Cheers
David

Robert Bradshaw | 5 Dec 20:14
Favicon

Re: req - block-local variables

On Dec 5, 2007, at 10:58 AM, David McNab wrote:

> Hi Cython folks,
>
> I'd love it if Cython could support the declaration of block-local
> variables, eg:
>
>         def somefunc(int arg1):
>             cdef int var1       # conventional function-local var
>
>             if arg1 == 0:
>                 cdef int var2   # block-local var
>                 ...

There are times I've wished I could do this too.

> Given that C already supports this, would it be very hard to  
> support in
> Cython as well?

It would be possible to allow such declarations, but forcing them  
local to the block would require a significant change to the code- 
generating mechanism (which would contradict Python semantics as  
well, e.g.

def somefunc(arg1):
     if arg1 == 0:
         x = 3 # this is a declaration
     [...]
     if arg1 == 0:
(Continue reading)

David McNab | 5 Dec 21:10
Picon
Favicon

Re: req - block-local variables

On Wed, 2007-12-05 at 11:14 -0800, Robert Bradshaw wrote:
> There are times I've wished I could do this too.
> 
> > Given that C already supports this, would it be very hard to  
> > support in
> > Cython as well?
> 
> It would be possible to allow such declarations, but forcing them  
> local to the block would require a significant change to the code- 
> generating mechanism (which would contradict Python semantics as  
> well, e.g.
> 
> def somefunc(arg1):
>      if arg1 == 0:
>          x = 3 # this is a declaration
>      [...]
>      if arg1 == 0:
>          return x # x is still valid in this block
> 
> is perfectly valid Python).

Yes, for python vars.
But my intention for block-local cdef vars is that their scope be
limited to the block, like in C

> Having definitions that "leak out" to the function-level scope would  
> probably not be to hard.

That's not what I'm looking for. I'm wishing for the ability to declare
cdef vars within blocks whose scope is confined to the block, just like
(Continue reading)

Stefan Behnel | 8 Dec 10:03
Picon
Favicon
Gravatar

Re: req - block-local variables


David McNab wrote:
> I'm wishing for the ability to declare
> cdef vars within blocks whose scope is confined to the block, just like
> in C - no 'leaking out'.

That would be mainly of syntactical interest. While I understand that it would
be nice for readability to declare a name only in the scope where it is
supposed to be used, you would likely not gain much performance-wise, as C
compilers are pretty good in figuring out the 'real' scope of a variable.

Stefan
David McNab | 8 Dec 11:27
Picon
Favicon

Re: req - block-local variables

On Sat, 2007-12-08 at 10:03 +0100, Stefan Behnel wrote:
> David McNab wrote:
> > I'm wishing for the ability to declare
> > cdef vars within blocks whose scope is confined to the block, just like
> > in C - no 'leaking out'.
> 
> That would be mainly of syntactical interest. While I understand that it would
> be nice for readability to declare a name only in the scope where it is
> supposed to be used, you would likely not gain much performance-wise, as C
> compilers are pretty good in figuring out the 'real' scope of a variable.

Agreed - the idea was only for readability, with no performance goal in
mind.

I find that with large functions, it's distracting to keep flipping
between lines of code in the function and the cdef vars at the top of
the function.

Cheers
David

Mattias Holm | 8 Dec 18:30
Picon

C99 types

Hi, 

I am working on a project that is written in C99, with embedded Python. For boolean values in C, the standard _Bool type  is used which is unsupported by Pyrex. I saw that Cython was supporting boolean ints, though not exactly same, is there any  support for C99 types (_Bool, _Complex and so on) in Cython?


Regards,

Mattias

Robert Bradshaw | 8 Dec 20:58
Favicon

Re: _Bool support

I hadn't even thought of this, but it's totally doable. I don't  
imagine we'd want to be exporting these symbols by default (we don't  
want to require C99 compliance) but it could certainly be an option  
if someone wants to implement it.

- Robert

On Dec 8, 2007, at 7:54 AM, Mattias Holm wrote:

> Hi,
>
> I am working on a project that I am writing in C99, with embedded
> Python. For boolean values in C, I am using the standard _Bool type
> which is unsupported by Pyrex. I saw that Cython was supporting
> boolean ints, though not exactly same, are you planning on supporting
> C99 types (_Bool, _Complex and so on) in Cython?
>
>
> Regards
> Mattias
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google  
> Groups "cython" group.
> To post to this group, send email to cython@...
> To unsubscribe from this group, send email to cython- 
> unsubscribe@...
> For more options, visit this group at http://groups.google.com/ 
> group/cython?hl=en
> -~----------~----~----~----~------~----~------~--~---

Re: req - block-local variables

> On Sat, 2007-12-08 at 10:03 +0100, Stefan Behnel wrote:
> > David McNab wrote:
> > > I'm wishing for the ability to declare cdef vars within blocks
> > > whose scope is confined to the block, just like in C - no
> > > 'leaking out'.
> > 
> > That would be mainly of syntactical interest. While I understand
> > that it would be nice for readability to declare a name only in
> > the scope where it is supposed to be used, you would likely not
> > gain much performance-wise, as C compilers are pretty good in
> > figuring out the 'real' scope of a variable.

Something that is allowed in all versions of C is declaring new
variables at the top of a block, which can then be used only in that
block. One could say: move the variable to the top of the function or
method, as we've stated in the rest of this e-mail thread.

But, there is a situation that can be (ab)used in C in which this
cannot be done without some thought: it's possible to declare
variables with the same name in different blocks that do not have the
same type. For example (in C):

if (something == 0)
{
	unsigned int i;

	for (i = 0; i < something_that_is_unsigned; i++)
		do_something1();
}
else
{
	int i;

	for (i = 0; i < something_that_is_signed; i++)
		do_something2();
}

This is a bad example, but you get the picture.

I can imagine a situation in Pyrex/Cython in which you would want to
use the same variable name (for clarity or readability) in different
blocks, but with different types. For example:

if isinstance(an_object, some_specific_list_type):
	cdef item_in_the_list_type item

	for item in an_object:
		item.something_specific()
else:
	cdef object item

	for item in an_object:
		something_generic(item)

> Agreed - the idea was only for readability, with no performance goal
> in mind.

But in the above example, it is possible that the code in the first
block is compiled to something faster because of the knowledge that
the items in the list are of some specific type (or perhaps, the
'something_specific' method is a C method that can only be called if
the 'item' is known to be of type 'item_in_the_list_type').

Of course, the programmer could simply declare two cdefs at the top of
the function called 'item1' and 'item2' or something similar.

I realize that in Python, it does not work this way (and in fact, the
type difference is not a issue in pure Python anyway), which would
make Pyrex/Cython less compatible with pure Python. Therefore, it
might not be a good idea to implement such a possibility.

> I find that with large functions, it's distracting to keep flipping
> between lines of code in the function and the cdef vars at the top
> of the function.

Certainly true.

> Cheers
> David

--

-- 
With kind regards,
Sven

Gmane