Commit 4ce2f147 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

merge

parents bc80f4d2 ec09b000
0.9.4.1
-------
Bug fixes:
- Fixed indentation problem in Pyrex.Distutils.build_ext.
[Oliver Grisel <ogrisel@nuxeo.com>]
0.9.4
-----
Improvements:
- All use of lvalue casts has been eliminated, for
compatibility with gcc4.
- PyMODINIT_FUNC now used to declare the module init function.
- Generated code should be compilable as either C or C++.
When compiling as C++, "extern C" is used where appropriate
to preserve linkage semantics. C++ functions still cannot
be called yet.
- An extension type can be made weak-referenceable by
giving it a C attribute of type object called __weakref__.
- Source files opened in universal newlines mode.
- Support for public extension type C attributes of type
long long and unsigned long long added (but not tested).
[Sam Rushing <sam@rushing.nightmare.com>]
- Distutils include directories now passed to Pyrex compiler.
[Konrad Hinsen <khinsen@cea.fr>]
- Integer constants with an "L" suffix are now allowed
and are converted to Python long integers.
[Rainer Deyke <rainerd@eldwood.com>]
- A broken .c file is no longer left behind if there are
compilation errors.
- Using the result of a Python indexing or attribute access
operation as a char * is no longer considered an error in
most cases, as the former behaviour proved to be more
annoying than helpful.
Bug fixes:
- Fixed problems with conversion from Python integers to
C unsigned longs. Now use PyInt_AsUnsignedLongMask and
PyInt_AsUnsignedLongLongMask instead of the PyLong_*
functions (which only work on Python longs).
[Wim Vree <wim@vree.be>]
- C unsigned ints now converted to/from Python longs intead
of Python ints to avoid overflow problems.
[Heiko Wundram <me+pyrex@modelnine.org>]
- Correct PyArg_ParseTuple format characters now used for
unsigned types. [Jeff Bowden <jlb@houseofdistraction.com>]
- Nonzero return value from a base class tp_traverse call
is handled.
- Taking sizeof an incomplete type caused a crash while
producing an error message. [Drew Perttula <dperttula@pdi.com>]
- If a module cimported itself, definitions of global variables
were generated twice. [Parzival Herzog <parzp@shaw.ca>]
- Distutils extension updated to handle changed signature of
swig_sources(). [David M. Cooke <cookedm@physics.mcmaster.ca>]
- Incorrect C code generated for a raw string containing a double
quote preceded by a backslash. [Thomas Drake <bistroy@mac.com>]
- Declaration of public C function with an exception value written
to generated .pxi file without the except clause.
[Robby Dermody <robbyd@u20.org>]
- __delitem__ method of an extension type with no __setitem__
did not get called. [Richard Boulton <richard@tartarus.org>]
- A spurious Py_INCREF was generated when a return statement
required a type test. [Jonathan Doda <jdoda@sympatico.ca>]
- Casting a value to a function pointer and then immediately
calling it generated a cast to a function instead of a cast
to a function pointer. [Simon Burton <simon@arrowtheory.com>]
- Py_TPFLAGS_HAVE_GC was not being set on an extension type that
inherited from an external extension type that used GC but did
not itself have any PyObject* attributes.
[Michael Hordijk <hoffbrinkle@hotmail.com>]
- A return statement inside a for statement leaked a reference
to the loop's iterator.
[Jürgen Kartnaller <j.kartnaller@robotech.at>]
- Full module name now appears in __module__ attribute of classes
and extension types, provided a correct dotted name is used
for the .pyx file. [Giovanni Bajo <rasky@develer.com>]
- Public extension type with no C attributes produced an
invalid .pxi file. [Simon Burton <simon@arrowtheory.com>]
- Using a dict constructor as the second operand of a boolean
expression crashed the Pyrex compiler.
[Stefan Behnel <behnel_ml@gkec.informatik.tu-darmstadt.de>]
- A C declaration list ending with a comma resulted in invalid
C code being generated. [Alex Coventry <alex_c@mit.edu>]
- A raw string containing two consecutive backslashes produced
incorrect C code. [Helmut Jarausch <jarausch@igpm.rwth-aachen.de>]
- An error is reported if you attempt to declare a special
method of an extension type using 'cdef' instead of 'def'.
[Sam Rushing <srushing@ironport.com>]
0.9.3
-----
Enhancements:
- Types defined with a ctypedef in a 'cdef extern from' block
are now referred to by the typedef name in generated C code,
so it is no longer necessary to match the type in the C
header file exactly.
- Conversion to/from unsigned long now done with
PyLong_AsUnsignedLong and PyLong_FromUnsignedLong.
[Dug Song <dugsong@monkey.org>]
- A struct, union or enum definition in a 'cdef extern from'
block may now be left empty (using 'pass'). This can be useful
if you need to declare a variable of that type, but don't need
to refer to any of its members.
- More flexible about ordering of qualifiers such as 'long' and
'unsigned'.
["John (J5) Palmieri" <johnp@redhat.com>]
Bug fixes:
- Non-interned string literals used in a Python class
definition did not work.
[Atsuo Ishimoto <ishimoto@gembook.org>]
[Andreas Kostyrka <andreas@kostyrka.org>]
- Return types of the buffer interface functions for extension
types have been corrected.
[Dug Song <dugsong@monkey.org>]
- Added 'static' to declarations of string literals.
[Phil Frost <indigo@bitglue.com>]
- Float literals are now copied directly to the C code as written,
to avoid problems with loss of precision.
[Mario Pernici <Mario.Pernici@mi.infn.it>]
- Inheriting from an extension type with C methods defined in
another Pyrex module did not work.
[Itamar Shtull-Trauring <itamar@itamarst.org>]
0.9.2.1
-------
Bug fixes:
- Corrected an import statement setup.py, and made it
check for a unix platform in a more reliable way.
0.9.2
-----
Enhancements:
- Names of Python global variables and attributes are now
interned, and PyObject_GetAttr/SetAttr are used instead
of PyObject_GetAttrString/SetAttrString. String literals
which resemble Python identifiers are also interned.
- String literals are now converted to Python objects only
once instead of every time they are used.
- NUL characters are now allowed in Python string literals.
- Added some missing error checking code to the beginning
of module init functions. It's unlikely the operations
involved would ever fail, but you never know.
Bug fixes:
- Corrected some problems introduced by moving the Plex
package.
0.9.1.1
-------
Bug fixes:
- Corrected a problem in the setup.py (pyrexc script incorrectly
named).
- Updated the distutils extension to match changes in the
Pyrex compiler calling interface.
- Doing 'make clean' in Demos/callback was removing a little too
much (that's why cheesefinder.c kept disappearing).
0.9.1
-----
Enhancements:
- A C method can now call an inherited C method by the usual
Python technique.
[Jiba <jiba@tuxfamily.org>]
- The __modname__ of a Python class is now set correctly.
[Paul Prescod <paul@prescod.net>]
- A MANIFEST.in file has been added to the distribution to
facilitate building rpms.
[contributed by Konrad Hinsen <hinsen@cnrs-orleans.fr>]
Bug fixes:
- Conditional code now generated to allow for the renaming of LONG_LONG
to PY_LONG_LONG that occurred between Python 2.2 and 2.3.
- Header files referenced in cimported modules were not being included.
[Tom Popovich <tompopovich@aol.com>]
- References to C functions and variables in a cimported module were
not being recognised if made from within a local scope.
[Tom Popovich <tompopovich@aol.com>]
- Spurious declarations in code generated for a "finally" block.
[Brandon Long <blong@fiction.net>]
- Attempting to return a value from a __contains__ method didn't work.
[Andreas Kostyrka <andreas@mtg.co.at>]
- Incorrect code generated for an extension type with C methods
inheriting from a base type with no C methods.
[Robin Becker <robin@reportlab.com>]
- Failure to report an error if a C method was defined in the
implementation part of an extension type that was not declared
in the corresponding definition part. Documentation also updated
to explain that this is necessary.
[Jiba <jiba@tuxfamily.org>]
- Made it an error to forward-declare an extension type with
a different base class specification from its subsequent
definition.
[Jiba <jiba@tuxfamily.org>]
- C attributes of an extension type were not being propagated
through more than one level of inheritance.
[Jiba <jiba@tuxfamily.org>]
- If a garbage collection occurred early enough in the __new__
method of an extension type with Python-valued C attributes,
a crash could occur in its tp_traverse function.
[reported by Jiba <jiba@tuxfamily.org>]
[fix suggested by Paul Prescod <paul@prescod.net>]
- An empty vtable struct is no longer generated for extension
types with no C methods.
[Robin Becker <robin@reportlab.com>]
- Memory was leaked in the sq_item function of an extension
type with a __getitem__ method.
[Atsuo Ishimoto <ishimoto@gembook.org>]
- Code generated to work around a bug in some versions of Python
2.2 which fails to initialise the tp_free slot correctly in
some circumstances.
[Matthias Baas <baas@ira.uka.de>]
- Compiler crash when defining an extension type with a base
class specified by a dotted name.
[Alain Pointdexter <alainpoint@yahoo.fr>]
- Referencing an extension type defined in a cimported module
at run time did not work correctly.
[Alain Pointdexter <alainpoint@yahoo.fr>]
- Incorrect object struct code generated for an extension type
whose base class was defined in a .pxd file.
[Alain Pointdexter <alainpoint@yahoo.fr>]
- Redeclaring a type that wasn't previously an extension type
as an extension type caused a compiler crash.
[Scott Robinson <scott@tranzoa.com>]
- Incorrect code was generated for return statements in a
special method with no return value.
[Gary Bishop <gb@cs.unc.edu>]
- Single-line def statement did not work.
[Francois Pinard <pinard@iro.umontreal.ca>]
Modifications:
- Only the last pathname component of the .pyx file is reported in
backtraces now.
[Bryan Weingarten <bryan.weingarten@pobox.com>]
- Documentation corrected to remove the erroneous statement that
extension classes can have a __del__ method.
[Bryan Weingarten <bryan.weingarten@pobox.com>]
- Note added to documentation explaining that it is not possible
for an extension type's __new__ method to explicitly call the
inherited __new__ method.
- The version of Plex included with Pyrex is now installed
as a subpackage of the Pyrex package, rather than as a
top-level package, so as not to interfere with any other
version of Plex the user may have installed.
0.9
---
New features:
- Extension types can have properties. See the new "Properties"
section in the "Extension Types" page.
- An extension type can inherit from a builtin type or another
extension type. See "Subclassing" in the "Extension Types" page.
- Extension types can have C methods, which can be overridden
in derived extension types. See "C Methods" in the "Extension Types"
page.
Enhancements:
- Conversion is now performed between C long longs and Python
long integers without chopping to the size of a C long.
Also the Python PY_LONG_LONG type is now used for long longs
for greater portability.
Bug fixes:
- Names were sometimes being generated that were insufficiently
unique in the presence of cimported declarations.
- Changed the way the included filename table is declared from
char *[] to char **, to stop MSVC from complaining about it
having an unknown size.
[Alexander A Naanou <alex_nanou@pochta.ru>]
- Second argument of assert statement was not being coerced
to a Python value.
[Francois Pinard http://www.iro.umontreal.ca/~pinard]
- Return statement without value wasn't accepted in some
extension type special methods when it should have been.
[Francois Pinard http://www.iro.umontreal.ca/~pinard]
- Attempting to call a non-function C value crashed the
compiler.
[John J Lee <jjl@pobox.com>]
- Functions declared as "except *" were not returning exceptions.
[John J Lee <jjl@pobox.com>]
- A syntax warning from Plex about assignment to None has
been eliminated.
[Gordon Williams <g_will@cyberus.ca>]
- Public function declaration with empty argument list was
producing (void) in .pxi file.
[Michael P. Dubner <dubnerm@mindless.com>]
- Incorrect error signalling code was being generated in the
__hash__ special method of an extension type.
0.8.1
-----
Bug fixes:
- Names of structs, unions and enums in external header
files were getting mangled when they shouldn't have been.
[Norman Shelley <Norman.Shelley@motorola.com>]
- Modified distutils extension so that it will stop before
compiling the C file if the Pyrex compiler reports errors.
[John J Lee <jjl@pobox.com>]
0.8
---
New features:
- INCOMPATIBLE CHANGE: The type object of an external extension
type is now imported at run time using the Python import
mechanism. To make this possible, an 'extern' extension type
declaration must DECLARE THE MODULE from which the extension
type originates. See the new version of the "Extension Types"
documentation for details.
This change was made to eliminate the need for Pyrex to be
told the C name of the type object, or for the Pyrex module
to be linked against the object code providing the type object.
You will have to update any existing external extension type
declarations that you are using. I'm sorry about that, but it
was too hard to support both the old and new ways.
- Compile-time importing: A Pyrex module can now import declarations
from another Pyrex module using the new 'cimport' statement. See
the new section on "Sharing Declarations Between Pyrex Modules" in
the documentation.
Minor improvements:
- An error is reported if you declare a struct, union or
extension type using 'cdef' in one place and 'ctypedef'
in another.
- Struct, union and extension types can only be forward-
declared using 'cdef', not 'ctypedef' (otherwise invalid
C code would be generated).
- The 'global' statement can be used at the module level to
declare that a name is a module-level name rather than a
builtin. This can be used to access module attributes such
as __name__ that would otherwise be assumed to be builtins.
[Pat Maupin <pmaupin@speakeasy.net>]
- The 'assert' statement now accepts a second argument.
[Francois Pinard <pinard@iro.umontreal.ca>]
Bug fixes:
- When using Python 2.3, "True" or "False" could sometimes
turn up in generated code instead of "1" or "0".
[Adam Hixson <chixson@ou.edu>]
- Function return value not always converted to or from a
Python object when it should have been.
- Certain kinds of error in a function call expression
could crash the compiler.
["Edward C. Jones" <edcjones@erols.com>]
- Fixed memory leak in functions with * or ** args.
[Alexander A Naanou <alex_nanou@pochtamt.ru>]
0.7.1
-----
Bug fixes:
- Calling a function declared as returning an extension
type could crash the compiler.
- A function call with type errors in the argument list
could crash the compiler.
- An 'else' clause on a for-from statement could crash
the compiler.
- Incorrect casting code was generated when a generic
object argument of a special method was declared as
being of an extension type.
[Phillip J. Eby <pje@telecommunity.com>]
- A blank line that couldn't be interpreted wholly as
a valid indentation sequence caused a syntax error.
In particular, a formfeed character on an otherwise
blank line wasn't accepted.
[Francois Pinard <pinard@iro.umontreal.ca>]
- Parallel assignments were incorrectly optimised.
- A bare tuple constructor with an extra comma at the
end of a line caused a syntax error.
0.7
---
New features:
- Attributes of extension types can be exposed to Python
code, either read/write or read-only.
- Different internal and external names can be specified
for C entities.
- None is a compile-time constant, and more efficient code
is generated to reference it.
- Command line options for specifying directories to
search for include files.
Enhancements:
- More efficient code is generated for access to Python
valued C attributes of extension types.
- Cosmetic code improvement: Less casting back and forth
between extension types and PyObject * when referencing
C members of the object struct.
- C arguments and variables declared as an extension type
can take the value None.
- Form feed characters are accepted as whitespace.
- Function names in tracebacks are qualified with
module name and class name.
Bug fixes:
- A sufficiently complex expression in a boolean context
could cause code to be generated twice for the same
subexpression.
- Incorrect casting code was generated when passing an
extension type to a function expecting a generic Python
object.
- Executable statements are now disallowed inside a
cdef class block (previously they silently caused
crazy C code to be generated).
- Tracebacks should now report the correct filename for
functions defined in files included with the 'include'
statement.
- The documentation incorrectly claimed that an extension
type can't have a __del__ method. In fact, it can, and
it behaves as expected.
0.6.1
-----
Bug fixes:
- Fixed broken distutils extension.
0.6
---
New features:
- Command line options for reporting version number,
requesting a listing file and specifying the name of
the generated C file.
- An 'include' statement allows inclusion of declarations
from other Pyrex source files.
- If there are any public declarations, a Pyrex include
file is generated (as well as a .h file) containing
declarations for them.
- Extension types can be declared public, so their C
attributes are visible to other Pyrex and C code.
- Try-except statements can now have an 'else' clause.
[Francois Pinard <pinard@iro.umontreal.ca>]
- Multiple simple statements can be placed on one line
separated by semicolons.
- A suite consisting of a simple statement list can now
be placed on the same line after the colon in most
cases.
[Francois Pinard <pinard@iro.umontreal.ca>]
- The automatic coercion of a C string to a C char has
been removed (it proved to be too error-prone).
Instead, there is a new form of literal for C
character constants: c'X'
- The __get__ special method (used by descriptor objects)
now allows for the possibility of the 2nd or 3rd
arguments being NULL. Also the __set__ method has been
split into two methods, __set__ and __delete__.
[Phillip J. Eby <pje@telecommunity.com>]
Bug fixes:
- Values unpacked into a non-Python destination variable
were not being converted before assignment.
[Gareth Watts <gareth@omnipotent.net>]
- Hex constants greater than 0x7fffffff caused compiler
to crash. [Gareth Watts <gareth@omnipotent.net>]
- Type slots are no longer statically initialised with
extern function pointers, to avoid problems with
some compilers. The hack in the distutils extension
to work around this by compiling as C++ has been
disabled. [Phillip J. Eby <pje@telecommunity.com>]
- Fixed several more instances of the error-reporting
routine being called with arguments in the wrong
order. Hoping I've *finally* got all of them now...
- Nested for-from loops used the same control variable.
[Sebastien de Menten <sdementen@hotmail.com>]
- Fixed some other error message related bugs.
[Francois Pinard <pinard@iro.umontreal.ca>]
- Assigning to slice didn't work.
[Francois Pinard <pinard@iro.umontreal.ca>]
- Temp variables were being declared as extension
types and then being assigned PyObject *'s. All
Python temp vars are now declared as PyObject *.
[Francois Pinard <pinard@iro.umontreal.ca>]
0.5
---
Bug fixes:
- Algorithm for allocating temp variables redesigned
to fix various errors concerning temp
variable re-use.
[Mark Rowe <bdash@gmx.net>]
- Memory leak occured sometimes when an implicit
type test was applied to the result of an
expression.
[christoph.wiedemann@daimlerchrysler.com]
- __set__ method of extension types had wrong
signature.
[Josh Littlefield <joshl@cisco.com>]
0.4.6
-----
Bug fixes:
- Indexing multi-dimensional C arrays didn't
work.
[Gary Dietachmayer <gary.dietachmayer@dsto.defence.gov.au>]
0.4.5
-----
New features:
- There is now a 'public' declaration for
making Pyrex-defined variables and functions
available to external C code. A .h file is
also generated if there are any public
declarations.
Enhancements:
- Defining __len__/__getitem__ methods in an
extension class fills sq_length/sq_item slots
as well as mp_length/mp_subscript.
[Matthias Baas <baas@ira.uka.de>]
- The Distutils extension now allows .c files
to be incorporated along with .pyx files.
[Modification to Distutils extension contributed
by Darrell Gallion <dgallion1@yahoo.com>.]
Bug fixes:
- Float literals without a decimal point
work again now.
[Mike Rovner <mike@bindkey.com>]
[Peter Lepage <gpl@mail.lns.cornell.edu>]
- Compiler crashed if exception value didn't
match function return type.
[Michael JasonSmith <mpj17@smtphost.canterbury.ac.nz>]
- The setup.py file should now install the
Lexicon.pickle file in the right place.
[Patch supplied by David M. Cooke
<cookedm@arbutus.physics.mcmaster.ca>]
- Compiler crashed when compiling a C function that
returned an extension type.
[David M. Cooke
<cookedm@arbutus.physics.mcmaster.ca>]
- Anonymous enum types did not have C code
suppressed inside an extern-from block.
[Matthew Mueller <donut@azstarnet.com>]
0.4.4
-----
Enhancements:
- Tracebacks now extend into Pyrex function
calls and show line numbers in the Pyrex
source file.
- Syntax for float literals made more lenient
(no longer requires digits both before and
after the point).
[Peter Lepage <gpl@mail.lns.cornell.edu>]
- Method calls can be made on string literals
(e.g. ",".join(x)).
[pedro_rodriguez@club-internet.fr]
Bug fixes:
- Incorrect refcount code generated when a
Python function needing argument type tests
had local Python variables.
[Matthias Baas <baas@ira.uka.de>]
- 'self' parameter of __getitem__ method of
extension type had wrong implicit type.
[Peter Lepage <gpl@mail.lns.cornell.edu>]
- Repaired breakage introduced by trying to
allow an empty parameter list to be written
as (void). No longer attempting to allow
this (too hard to parse correctly).
[Peter Lepage <gpl@mail.lns.cornell.edu>]
- Found bug in Plex 1.1.2 which was the *real*
cause of the two-newlines-in-a-row problem.
Removed the Opt(Eol)+Str("\n") hacks in
the scanner which were working around this
before.
[pedro_rodriguez@club-internet.fr]
- __call__ special method of extension types
had wrong signature.
[Peter Lepage <gpl@mail.lns.cornell.edu>]
0.4.3
-----
New language features:
- For-from loop for iterating over integer
ranges, using pure C loop where possible.
Enhancements:
- sizeof() can now be applied to types as
well as variables.
- Improved handling of forward-declared
extension types.
Bug fixes:
- Two newlines in a row in a triple quoted
string caused a parse error on some
platforms.
[Matthias Baas <baas@ira.uka.de>]
- Fixed problem with break and continue in
the else-clause of a loop.
0.4.2
-----
New language features:
- C functions can be declared as having an
exception return value, which is checked
whenever the function is called. If an
exception is detected inside a C function
for which no exception value is declared,
a warning message is printed and the
exception is cleared.
- Cascaded assignments (i.e. a = b = c
are now supported.
- Anonymous enum declarations are allowed,
for when you just want to declare constants.
- The C types "long long" and "long double"
are now understood. Also, "int" is optional
after "short" or "long".
Enhancements:
- A * argument in a function call can now be
any sequence, not just a tuple.
- A C char* or char[] will be turned into
a char by taking its first character if
used in a context where a char is required,
thus allowing a string literal to be used as
a char literal.
- C string * C int or vice versa is now
interpreted as Python string replication.
- Function arguments are checked for void or
incomplete type.
Bug fixes:
- Non-external extension types show up in the
module dict once more (this got broken in
0.4.1).
- A spurious decref has been removed from the
runtime support code for the "import" statement.
Hopefully this will prevent the crashes some
people have been experiencing when importing
builtin modules.
[Mathew Yeates <mathew@comma.jpl.nasa.gov>]
0.4.1
-----
New language features:
- "ctypedef struct/union/enum/class" statements
added, for use in extern-from blocks when a
header file uses a ctypedef to declare a
tagless struct, union or enum type.
- "pass" allowed in an extern-from block.
- "cdef extern from *" for when you don't want
to specify an include file name.
- Argument names may be omitted in function
signatures when they're not needed.
- New reserved word NULL for the null C pointer.
Compiler enhancements:
- Lexicon is now picked in binary format, so
startup should be much faster on slower
machines.
- If Pyrex decides to rebuild the lexicon and
then finds that it can't write a pickle file,
it now prints a warning and carries on
instead of crashing.
- Chat about hash codes and lexicon pickling
now turned off by default except when creating
a new lexicon (which ought never happen now
unless you change the scanner).
Bug fixes:
- Modified the runtime support code for "import"
statements, hopefully fixing problem with using
a Pyrex module in conjunction with py2exe.
- DL_EXPORT now used in both the prototype and
definition of the module init function.
- Exception state is now saved and restored around
calls to an extension type __dealloc__ method,
to avoid screwing up if the object is deallocated
while an exception is being propagated.
- Making an attribute reference to a method of
an extension type caused a compiler crash.
- Doc string in new-style class definition
caused a run-time error.
- Insufficient parentheses were put around C type
casts.
- Constructors for extension types are now read-only
C global variables instead of entries in the
module dict. This change was needed to prevent
Numeric from blowing up due to touching its
typeobject before import_numeric() could be called.
0.4
---
New features:
- "cdef extern from" statement allows inclusion
of C header files to be specified, solving
a number of problems including:
- Clashes between Pyrex and C declarations,
due to "const" and other reasons
- Windows-specific features required in
function declarations
- Helping deal with types such as "size_t"
- Helping deal with functions defined as
macros
- Access to internals of pre-existing extension
types is now possible by placing an extension
type declaration inside a "cdef extern from"
block.
Bug fixes:
- Error not reported properly when passing
wrong number of args to certain special
methods of extension types.
[Mitch Chapman <mitchchapman@earthlink.net>]
- Compile-time crash when defining an extension
type with a __hash__ method.
Minor enhancements:
- Hashing of the scanner source file made more
platform-independent, making spurious regeneration
of the pickle less likely.
0.3.4
-----
Bug fixes:
- Runtime crash when using * or ** args in
a method of an extension type fixed.
[Matthew Mueller <donut@azstarnet.com>]
- Compiler crash when using default argument
values in a method of a Python class.
[Mike Rovner <mike@bindkey.com>]
Enhancements:
- Type slots filled with functions from outside
the extension module are now initialised dynamically,
which should eliminate at least some of the
"initialiser is not constant" problems experienced
on Windows.
[Marek Baczek <imbaczek@poczta.fm>]
- On Windows, __declspec(dllexport) is now used for
the module init func declaration (or should be --
I haven't tested this).
[Marek Baczek <imbaczek@poczta.fm>]
- The compiler shouldn't attempt to rewrite the
Lexicon.pickle file unless the source has been
changed (hashing is used now instead of comparing
timestamps). So there should be no problem any more
with installing Pyrex read-only.
[fawcett@uwindsor.ca]
0.3.3
-----
Bug fixes:
* A void * can be assigned from any other
pointer type.
[piers@cs.su.oz.au]
* File names in error messages no longer
quoted (this was apparently confusing some
editors).
[donut@azstarnet.com]
* Reference to a struct member which is an
array is coerced to a pointer.
[donut@azstarnet.com]
* Default argument values did not work
in methods of an extension type.
[donut@azstarnet.com]
* Single or double quote characters in a
triple-quoted string didn't work.
[donut@azstarnet.com]
* Using *args in a function definition
sometimes caused a crash at runtime.
[donut@azstarnet.com]
* A hack is included which tries to make
functions in Python.h which use 'const'
accessible from Pyrex. But it doesn't
work on all platforms. Thinking about a
better solution.
New features:
* Comment containing Pyrex version number
and date/time at top of generated C file.
[baas@ira.uka.de]
0.3.2
-----
Bug fixes:
* The & operator works again.
[matthias.oberlaender@daimlerchrysler.com]
[baas@ira.uka.de]
* The & operator had incorrect precedence.
* "SystemError: 'finally' pops bad exception"
under some circumstances when raising an
exception. [baas@ira.uka.de]
* Calling a Python function sometimes leaked
a reference.
* Crash under some circumstances when casting
a Python object reference to a C pointer type.
[mpj17@cosc.canterbury.ac.nz]
* Crash when redeclaring a function.
[baas@ira.uka.de]
* Crash when using a string constant inside
a Python class definition.
[mike@bindkey.com]
* 2-element slice indexing expressions.
[mike@bindkey.com]
* Crash when encountering mixed tabs and
spaces.
[mike@bindkey.com]
New features:
* A wider variety of constant expressions is
now accepted for enum values, array
dimensions, etc.
[mike@bindkey.com]
0.3.1
-----
New features:
* More special methods for extension types:
__delitem__, __delslice__, __getattr__,
__setattr__, __delattr__
* Module-level variable of a Python object type
declared with 'cdef' is private to the module, and
held in a C variable instead of the module dict.
* External C functions with variable argument lists
can be declared and called.
* Pyrex-defined Python functions can have default
argument values and * and ** arguments, and can be
called with keyword arguments.
* Pointer-to-function types can be declared.
* Pyrex now supports a declaration syntax that
C doesn't! Example:
cdef (int (*)()) foo() # function returning a function ptr
* There is now a ctypedef statement.
* Extension types can now be forward-declared.
* All permutations of (non-Unicode) string literals
and escape codes should work now.
* Hex and octal integer literals.
* Imaginary number literals.
* Docstrings are now supported.
Bug fixes:
* Type tests are performed when using a Python object
in a context requiring a particular extension type.
* Module-level variable holding the type object
of an extension type had incorrect type.
0.3
---
New features:
* Extension types! Yay!
0.2.2
-----
Bug fixes:
* Fixed error message generation again after a previous
bug was accidentally re-indroduced.
* Removed the declaration of isspace() from the code
generated for print statement support (it's not needed
and was conflicting with the system-supplied one on
some platforms).
0.2
---
New features:
* Executable statements are now allowed at the
top level of a module.
* Python class definitions are now supported, with
the following limitations:
- Class definitions are only allowed at the top
level of a module, not inside a control structure
or function or another class definition.
- Assigning a Pyrex-defined Python function to a
class attribute outside of the class definition
will not create a method (because it's not an
interpreted Python function and therefore
won't trigger the bound-method creation magic).
- The __metaclass__ mechanism and the creation of
new-style classes is not (yet) supported.
* Casting between Python and non-Python types is
better supported.
Bug fixes:
* Fixed bug preventing for-loops from working.
0.1.1
-----
* I've discovered a flaw in my algorithm for releasing
temp variables. Fixing this properly will require some
extensive reworking; I've put in a hack in the meantime
which should work at the cost of using more temp variables
than are strictly necessary.
* Fixed bug preventing access to builtin names from
working. This should also have fixed the import
statement, but I haven't tested it.
* Fixed some errors in __Pyx_GetExcValue.
* Fixed bug causing boolean expressions to malfunction
sometimes.
......@@ -6,6 +6,7 @@ from Symtab import BuiltinScope, StructOrUnionScope
from Cython.Utils import UtilityCode
from TypeSlots import Signature
import PyrexTypes
import Naming
builtin_function_table = [
# name, args, return, C API func, py equiv = "*"
......@@ -16,6 +17,7 @@ builtin_function_table = [
('delattr', "OO", "r", "PyObject_DelAttr"),
('dir', "O", "O", "PyObject_Dir"),
('divmod', "OO", "O", "PyNumber_Divmod"),
('exec', "OOO", "O", "__Pyx_PyRun"),
#('eval', "", "", ""),
#('execfile', "", "", ""),
#('filter', "", "", ""),
......@@ -154,6 +156,48 @@ bad:
}
""")
pyexec_utility_code = UtilityCode(
proto = """
static PyObject* __Pyx_PyRun(PyObject*, PyObject*, PyObject*);
""",
impl = """
static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
PyObject* result;
PyObject* s = 0;
if (!locals && !globals) {
globals = PyModule_GetDict(%s);""" % Naming.module_cname + """
if (!globals)
goto bad;
locals = globals;
} else if (!locals) {
locals = globals;
} else if (!globals) {
globals = locals;
}
if (PyUnicode_Check(o)) {
s = PyUnicode_AsUTF8String(o);
if (!s) goto bad;
o = s;
} else if (!PyString_Check(o)) {
/* FIXME: support file objects and code objects */
PyErr_SetString(PyExc_TypeError,
"exec currently requires a string as code input.");
goto bad;
}
result = PyRun_String(
PyString_AS_STRING(o), Py_file_input, globals, locals);
Py_XDECREF(s);
return result;
bad:
Py_XDECREF(s);
return 0;
}
""")
intern_utility_code = UtilityCode(
proto = """
#if PY_MAJOR_VERSION >= 3
......@@ -273,6 +317,7 @@ Py_XDECREF(__Pyx_PyFrozenSet_Type); __Pyx_PyFrozenSet_Type = NULL;
""")
builtin_utility_code = {
'exec' : pyexec_utility_code,
'getattr3' : getattr3_utility_code,
'intern' : intern_utility_code,
'set' : py23_set_utility_code,
......
......@@ -293,7 +293,7 @@ class GlobalState(object):
def add_interned_num_decl(self, entry):
if self.should_declare(entry.cname, entry):
if entry.init[-1] == "L":
self.initwriter.putln('%s = PyLong_FromString("%s", 0, 0); %s;' % (
self.initwriter.putln('%s = PyLong_FromString((char *)"%s", 0, 0); %s;' % (
entry.cname,
entry.init,
self.initwriter.error_goto_if_null(entry.cname, self.module_pos)))
......
......@@ -899,7 +899,7 @@ class LongNode(AtomicExprNode):
def generate_evaluation_code(self, code):
code.putln(
'%s = PyLong_FromString("%s", 0, 0); %s' % (
'%s = PyLong_FromString((char *)"%s", 0, 0); %s' % (
self.result(),
self.value,
code.error_goto_if_null(self.result(), self.pos)))
......@@ -1779,19 +1779,29 @@ class SliceIndexNode(ExprNode):
self.start.analyse_types(env)
if self.stop:
self.stop.analyse_types(env)
self.base = self.base.coerce_to_pyobject(env)
if self.base.type.is_array or self.base.type.is_ptr:
# we need a ptr type here instead of an array type, as
# array types can result in invalid type casts in the C
# code
self.type = PyrexTypes.CPtrType(self.base.type.base_type)
else:
self.base = self.base.coerce_to_pyobject(env)
self.type = py_object_type
c_int = PyrexTypes.c_py_ssize_t_type
if self.start:
self.start = self.start.coerce_to(c_int, env)
if self.stop:
self.stop = self.stop.coerce_to(c_int, env)
self.type = py_object_type
self.gil_check(env)
self.is_temp = 1
gil_message = "Slicing Python object"
def generate_result_code(self, code):
if not self.type.is_pyobject:
error(self.pos,
"Slicing is not currently supported for '%s'." % self.type)
return
code.putln(
"%s = PySequence_GetSlice(%s, %s, %s); %s" % (
self.result(),
......@@ -1802,16 +1812,39 @@ class SliceIndexNode(ExprNode):
def generate_assignment_code(self, rhs, code):
self.generate_subexpr_evaluation_code(code)
code.put_error_if_neg(self.pos,
"PySequence_SetSlice(%s, %s, %s, %s)" % (
self.base.py_result(),
self.start_code(),
self.stop_code(),
rhs.result()))
if self.type.is_pyobject:
code.put_error_if_neg(self.pos,
"PySequence_SetSlice(%s, %s, %s, %s)" % (
self.base.py_result(),
self.start_code(),
self.stop_code(),
rhs.result()))
else:
start_offset = ''
if self.start:
start_offset = self.start_code()
if start_offset == '0':
start_offset = ''
else:
start_offset += '+'
if rhs.type.is_array:
# FIXME: we should check both array sizes here
array_length = rhs.type.size
else:
# FIXME: fix the array size according to start/stop
array_length = self.base.type.size
for i in range(array_length):
code.putln("%s[%s%s] = %s[%d];" % (
self.base.result(), start_offset, i,
rhs.result(), i))
self.generate_subexpr_disposal_code(code)
rhs.generate_disposal_code(code)
def generate_deletion_code(self, code):
if not self.type.is_pyobject:
error(self.pos,
"Deleting slices is only supported for Python types, not '%s'." % self.type)
return
self.generate_subexpr_evaluation_code(code)
code.put_error_if_neg(self.pos,
"PySequence_DelSlice(%s, %s, %s)" % (
......@@ -1829,6 +1862,8 @@ class SliceIndexNode(ExprNode):
def stop_code(self):
if self.stop:
return self.stop.result()
elif self.base.type.is_array:
return self.base.type.size
else:
return "PY_SSIZE_T_MAX"
......@@ -4692,8 +4727,8 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
empty_dict = PyDict_New();
if (!empty_dict)
goto bad;
module = PyObject_CallFunction(__import__, "OOOO",
name, global_dict, empty_dict, list);
module = PyObject_CallFunctionObjArgs(__import__,
name, global_dict, empty_dict, list, NULL);
bad:
Py_XDECREF(empty_list);
Py_XDECREF(__import__);
......@@ -4810,11 +4845,11 @@ static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
create_class_utility_code = UtilityCode(
proto = """
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, const char *modname); /*proto*/
""",
impl = """
static PyObject *__Pyx_CreateClass(
PyObject *bases, PyObject *dict, PyObject *name, char *modname)
PyObject *bases, PyObject *dict, PyObject *name, const char *modname)
{
PyObject *py_modname;
PyObject *result = 0;
......@@ -4877,7 +4912,12 @@ static INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
return Py_None; // this is just to have an accurate signature
}
else {
return PyObject_CallMethod(L, "append", "(O)", x);
PyObject *r, *m;
m = PyObject_GetAttrString(L, "append");
if (!m) return NULL;
r = PyObject_CallFunctionObjArgs(m, x, NULL);
Py_DECREF(m);
return r;
}
}
""",
......@@ -4968,10 +5008,10 @@ impl = """
raise_noneattr_error_utility_code = UtilityCode(
proto = """
static INLINE void __Pyx_RaiseNoneAttributeError(char* attrname);
static INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname);
""",
impl = """
static INLINE void __Pyx_RaiseNoneAttributeError(char* attrname) {
static INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", attrname);
}
""")
......
......@@ -7,6 +7,7 @@
raw_prefixes = "rR"
string_prefixes = "cCuUbB"
IDENT = 'IDENT'
def make_lexicon():
from Cython.Plex import \
......@@ -82,7 +83,7 @@ def make_lexicon():
comment = Str("#") + Rep(AnyBut("\n"))
return Lexicon([
(name, 'IDENT'),
(name, IDENT),
(intliteral, 'INT'),
(fltconst, 'FLOAT'),
(imagconst, 'IMAG'),
......
......@@ -102,8 +102,8 @@ class Context:
NormalizeTree(self),
PostParse(self),
_specific_post_parse,
_align_function_definitions,
InterpretCompilerDirectives(self, self.pragma_overrides),
_align_function_definitions,
FlattenInListTransform(),
WithTransform(self),
DecoratorTransform(self),
......
......@@ -1448,7 +1448,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
flags = "READONLY"
else:
flags = "0"
code.putln('{"%s", %s, %s, %s, 0},' % (
code.putln('{(char *)"%s", %s, %s, %s, 0},' % (
entry.name,
type_code,
"offsetof(%s, %s)" % (objstruct, entry.cname),
......@@ -1466,7 +1466,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env.getset_table_cname)
for entry in env.property_entries:
code.putln(
'{"%s", %s, %s, %s, 0},' % (
'{(char *)"%s", %s, %s, %s, 0},' % (
entry.name,
entry.getter_cname or "0",
entry.setter_cname or "0",
......@@ -2050,10 +2050,10 @@ bad:
function_export_utility_code = UtilityCode(
proto = """
static int __Pyx_ExportFunction(char *name, void *f, char *sig); /*proto*/
static int __Pyx_ExportFunction(const char *name, void *f, const char *sig); /*proto*/
""",
impl = r"""
static int __Pyx_ExportFunction(char *name, void *f, char *sig) {
static int __Pyx_ExportFunction(const char *name, void *f, const char *sig) {
PyObject *d = 0;
PyObject *p = 0;
d = PyObject_GetAttrString(%(MODULE)s, "%(API)s");
......@@ -2066,7 +2066,7 @@ static int __Pyx_ExportFunction(char *name, void *f, char *sig) {
if (PyModule_AddObject(%(MODULE)s, "%(API)s", d) < 0)
goto bad;
}
p = PyCObject_FromVoidPtrAndDesc(f, sig, 0);
p = PyCObject_FromVoidPtrAndDesc(f, (void *)sig, 0);
if (!p)
goto bad;
if (PyDict_SetItemString(d, name, p) < 0)
......@@ -2085,16 +2085,16 @@ bad:
function_import_utility_code = UtilityCode(
proto = """
static int __Pyx_ImportFunction(PyObject *module, char *funcname, void **f, char *sig); /*proto*/
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, const char *sig); /*proto*/
""",
impl = """
#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, char *funcname, void **f, char *sig) {
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f, const char *sig) {
PyObject *d = 0;
PyObject *cobj = 0;
char *desc;
d = PyObject_GetAttrString(module, "%(API)s");
if (!d)
goto bad;
......
......@@ -5,6 +5,7 @@
import string, sys, os, time, copy
import Code
import Builtin
from Errors import error, warning, InternalError
import Naming
import PyrexTypes
......@@ -716,9 +717,11 @@ class CVarDefNode(StatNode):
# in_pxd boolean
# api boolean
# need_properties [entry]
# pxd_locals [CVarDefNode] (used for functions declared in pxd)
child_attrs = ["base_type", "declarators"]
need_properties = ()
pxd_locals = []
def analyse_declarations(self, env, dest_scope = None):
if not dest_scope:
......@@ -754,6 +757,8 @@ class CVarDefNode(StatNode):
entry = dest_scope.declare_cfunction(name, type, declarator.pos,
cname = cname, visibility = self.visibility, in_pxd = self.in_pxd,
api = self.api)
if entry is not None:
entry.pxd_locals = self.pxd_locals
else:
if self.in_pxd and self.visibility != 'extern':
error(self.pos,
......@@ -890,10 +895,12 @@ class FuncDefNode(StatNode, BlockNode):
# #filename string C name of filename string const
# entry Symtab.Entry
# needs_closure boolean Whether or not this function has inner functions/classes/yield
# pxd_locals [CVarDefNode] locals defined in the pxd
py_func = None
assmt = None
needs_closure = False
pxd_locals = []
def analyse_default_values(self, env):
genv = env.global_scope()
......@@ -1206,6 +1213,7 @@ class CFuncDefNode(FuncDefNode):
self.args = declarator.args
for formal_arg, type_arg in zip(self.args, type.args):
formal_arg.type = type_arg.type
formal_arg.name = type_arg.name
formal_arg.cname = type_arg.cname
name = name_declarator.name
cname = name_declarator.cname
......@@ -1460,44 +1468,64 @@ class DefNode(FuncDefNode):
self.num_required_kw_args = rk
self.num_required_args = r
def as_cfunction(self, cfunc):
def as_cfunction(self, cfunc=None, scope=None):
if self.star_arg:
error(self.star_arg.pos, "cdef function cannot have star argument")
if self.starstar_arg:
error(self.starstar_arg.pos, "cdef function cannot have starstar argument")
if len(self.args) != len(cfunc.type.args) or cfunc.type.has_varargs:
error(self.pos, "wrong number of arguments")
error(declarator.pos, "previous declaration here")
for formal_arg, type_arg in zip(self.args, cfunc.type.args):
name_declarator, type = formal_arg.analyse(cfunc.scope, nonempty=1)
if type is PyrexTypes.py_object_type or formal_arg.is_self:
formal_arg.type = type_arg.type
formal_arg.name_declarator = name_declarator
if cfunc is None:
cfunc_args = []
for formal_arg in self.args:
name_declarator, type = formal_arg.analyse(scope, nonempty=1)
cfunc_args.append(PyrexTypes.CFuncTypeArg(name = name_declarator.name,
cname = None,
type = py_object_type,
pos = formal_arg.pos))
cfunc_type = PyrexTypes.CFuncType(return_type = py_object_type,
args = cfunc_args,
has_varargs = False,
exception_value = None,
exception_check = False,
nogil = False,
with_gil = False,
is_overridable = True)
cfunc = CVarDefNode(self.pos, type=cfunc_type, pxd_locals=[])
else:
cfunc_type = cfunc.type
if len(self.args) != len(cfunc_type.args) or cfunc_type.has_varargs:
error(self.pos, "wrong number of arguments")
error(declarator.pos, "previous declaration here")
for formal_arg, type_arg in zip(self.args, cfunc_type.args):
name_declarator, type = formal_arg.analyse(cfunc.scope, nonempty=1)
if type is None or type is PyrexTypes.py_object_type or formal_arg.is_self:
formal_arg.type = type_arg.type
formal_arg.name_declarator = name_declarator
import ExprNodes
if cfunc.type.exception_value is None:
if cfunc_type.exception_value is None:
exception_value = None
else:
exception_value = ExprNodes.ConstNode(self.pos, value=cfunc.type.exception_value, type=cfunc.type.return_type)
exception_value = ExprNodes.ConstNode(self.pos, value=cfunc_type.exception_value, type=cfunc_type.return_type)
declarator = CFuncDeclaratorNode(self.pos,
base = CNameDeclaratorNode(self.pos, name=self.name, cname=None),
args = self.args,
has_varargs = False,
exception_check = cfunc.type.exception_check,
exception_check = cfunc_type.exception_check,
exception_value = exception_value,
with_gil = cfunc.type.with_gil,
nogil = cfunc.type.nogil)
with_gil = cfunc_type.with_gil,
nogil = cfunc_type.nogil)
return CFuncDefNode(self.pos,
modifiers = [],
base_type = CAnalysedBaseTypeNode(self.pos, type=cfunc.type.return_type),
base_type = CAnalysedBaseTypeNode(self.pos, type=cfunc_type.return_type),
declarator = declarator,
body = self.body,
doc = self.doc,
overridable = cfunc.type.is_overridable,
type = cfunc.type,
with_gil = cfunc.type.with_gil,
nogil = cfunc.type.nogil,
overridable = cfunc_type.is_overridable,
type = cfunc_type,
with_gil = cfunc_type.with_gil,
nogil = cfunc_type.nogil,
visibility = 'private',
api = False)
api = False,
pxd_locals = cfunc.pxd_locals)
def analyse_declarations(self, env):
if 'locals' in env.directives:
......@@ -1506,10 +1534,14 @@ class DefNode(FuncDefNode):
directive_locals = {}
self.directive_locals = directive_locals
for arg in self.args:
base_type = arg.base_type.analyse(env)
name_declarator, type = \
arg.declarator.analyse(base_type, env)
arg.name = name_declarator.name
if hasattr(arg, 'name'):
type = arg.type
name_declarator = None
else:
base_type = arg.base_type.analyse(env)
name_declarator, type = \
arg.declarator.analyse(base_type, env)
arg.name = name_declarator.name
if arg.name in directive_locals:
type_node = directive_locals[arg.name]
other_type = type_node.analyse_as_type(env)
......@@ -1521,7 +1553,7 @@ class DefNode(FuncDefNode):
error(type_node.pos, "Previous declaration here")
else:
type = other_type
if name_declarator.cname:
if name_declarator and name_declarator.cname:
error(self.pos,
"Python function argument cannot have C name specification")
arg.type = type.as_argument_type()
......@@ -2316,10 +2348,11 @@ class PyClassDefNode(ClassDefNode):
elif len(bases) == 1:
base = bases[0]
path = []
while isinstance(base, ExprNodes.AttributeNode):
from ExprNodes import AttributeNode, NameNode
while isinstance(base, AttributeNode):
path.insert(0, base.attribute)
base = base.obj
if isinstance(base, ExprNodes.NameNode):
if isinstance(base, NameNode):
path.insert(0, base.name)
base_class_name = path[-1]
if len(path) > 1:
......@@ -3056,6 +3089,45 @@ class PrintStatNode(StatNode):
self.arg_tuple.annotate(code)
class ExecStatNode(StatNode):
# exec statement
#
# args [ExprNode]
child_attrs = ["args"]
def analyse_expressions(self, env):
for i, arg in enumerate(self.args):
arg.analyse_expressions(env)
arg = arg.coerce_to_pyobject(env)
arg.release_temp(env)
self.args[i] = arg
self.temp_result = env.allocate_temp_pyobject()
env.release_temp(self.temp_result)
env.use_utility_code(Builtin.pyexec_utility_code)
self.gil_check(env)
gil_message = "Python exec statement"
def generate_execution_code(self, code):
args = []
for arg in self.args:
arg.generate_evaluation_code(code)
args.append( arg.py_result() )
args = tuple(args + ['0', '0'][:3-len(args)])
code.putln("%s = __Pyx_PyRun(%s, %s, %s);" % (
(self.temp_result,) + args))
for arg in self.args:
arg.generate_disposal_code(code)
code.putln(
code.error_goto_if_null(self.temp_result, self.pos))
code.put_decref_clear(self.temp_result, py_object_type)
def annotate(self, code):
for arg in self.args:
arg.annotate(code)
class DelStatNode(StatNode):
# del statement
#
......@@ -3469,6 +3541,7 @@ class SwitchStatNode(StatNode):
if self.else_clause is not None:
code.putln("default:")
self.else_clause.generate_execution_code(code)
code.putln("break;")
code.putln("}")
def annotate(self, code):
......@@ -4398,6 +4471,9 @@ class FromImportStatNode(StatNode):
env.use_utility_code(ExprNodes.type_test_utility_code)
break
else:
entry = env.lookup(target.name)
if entry.is_type and entry.type.name == name and entry.type.module_name == self.module.module_name.value:
continue # already cimported
self.interned_items.append(
(env.intern_identifier(name), target))
target.analyse_target_expression(env, None)
......@@ -4493,7 +4569,7 @@ static PyObject* %s = 0;
impl = r"""
#if PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
PyObject *f = PySys_GetObject("stdout");
PyObject *f = PySys_GetObject((char *)"stdout");
if (!f) {
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
}
......@@ -4504,7 +4580,7 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) {
PyObject *f;
PyObject* v;
int i;
if (!(f = __Pyx_GetStdout()))
return -1;
for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
......@@ -5117,8 +5193,8 @@ impl = r"""
static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) {
int result;
PyObject *pycobj;
pycobj = PyMapping_GetItemString(dict, "__pyx_vtable__");
pycobj = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
if (!pycobj)
goto bad;
*(void **)vtabptr = PyCObject_AsVoidPtr(pycobj);
......
......@@ -60,13 +60,15 @@ option_types = {
'nonecheck' : bool,
'embedsignature' : bool,
'locals' : dict,
'auto_cpdef': bool,
}
option_defaults = {
'boundscheck' : True,
'nonecheck' : False,
'embedsignature' : False,
'locals' : {}
'locals' : {},
'auto_cpdef': False,
}
def parse_option_value(name, value):
......
......@@ -234,6 +234,22 @@ class PxdPostParse(CythonTransform):
if (isinstance(node, DefNode) and self.scope_type == 'cclass'
and node.name in ('__getbuffer__', '__releasebuffer__')):
ok = True
if isinstance(node, CFuncDefNode):
ok = True
for stat in node.body.stats:
if not isinstance(stat, CVarDefNode):
self.context.error("C function definition not allowed here")
ok = False
break
node = CVarDefNode(node.pos,
visibility = node.visibility,
base_type = node.base_type,
declarators = [node.declarator],
in_pxd = True,
api = node.api,
overridable = node.overridable,
pxd_locals = node.body.stats)
if not ok:
self.context.nonfatal_error(PostParseError(node.pos,
......@@ -547,6 +563,8 @@ property NAME:
lenv.declare_var(var, type, type_node.pos)
else:
error(type_node.pos, "Not a type")
for stat in node.pxd_locals:
stat.analyse_declarations(lenv)
node.body.analyse_declarations(lenv)
self.env_stack.append(lenv)
self.visitchildren(node)
......@@ -601,6 +619,7 @@ class AlignFunctionDefinitions(CythonTransform):
def visit_ModuleNode(self, node):
self.scope = node.scope
self.directives = node.directives
self.visitchildren(node)
return node
......@@ -613,8 +632,8 @@ class AlignFunctionDefinitions(CythonTransform):
error(node.pos, "'%s' redeclared" % node.name)
error(pxd_def.pos, "previous declaration here")
return None
self.visitchildren(node)
return node
else:
return node
def visit_CClassDefNode(self, node, pxd_def=None):
if pxd_def is None:
......@@ -636,6 +655,8 @@ class AlignFunctionDefinitions(CythonTransform):
error(node.pos, "'%s' redeclared" % node.name)
error(pxd_def.pos, "previous declaration here")
return None
elif self.scope.is_module_scope and self.directives['auto_cpdef']:
node = node.as_cfunction(scope=self.scope)
# Enable this when internal def functions are allowed.
# self.visitchildren(node)
return node
......
# We declare all of these here to type the first argument.
from Cython.Compiler.Scanning cimport PyrexScanner
cpdef p_ident(PyrexScanner s, message =*)
cpdef p_ident_list(PyrexScanner s)
cpdef p_binop_expr(PyrexScanner s, ops, p_sub_expr)
cpdef p_simple_expr(PyrexScanner s)
cpdef p_test(PyrexScanner s)
cpdef p_or_test(PyrexScanner s)
cpdef p_rassoc_binop_expr(PyrexScanner s, ops, p_subexpr)
cpdef p_and_test(PyrexScanner s)
cpdef p_not_test(PyrexScanner s)
cpdef p_comparison(PyrexScanner s)
cpdef p_cascaded_cmp(PyrexScanner s)
cpdef p_cmp_op(PyrexScanner s)
cpdef p_bit_expr(PyrexScanner s)
cpdef p_xor_expr(PyrexScanner s)
cpdef p_and_expr(PyrexScanner s)
cpdef p_shift_expr(PyrexScanner s)
cpdef p_arith_expr(PyrexScanner s)
cpdef p_term(PyrexScanner s)
cpdef p_factor(PyrexScanner s)
cpdef p_typecast(PyrexScanner s)
cpdef p_sizeof(PyrexScanner s)
cpdef p_power(PyrexScanner s)
cpdef p_trailer(PyrexScanner s, node1)
cpdef p_call(PyrexScanner s, function)
cpdef p_index(PyrexScanner s, base)
cpdef p_subscript_list(PyrexScanner s)
cpdef p_subscript(PyrexScanner s)
cpdef p_slice_element(PyrexScanner s, follow_set)
cpdef expect_ellipsis(PyrexScanner s)
cpdef make_slice_nodes(pos, subscripts)
cpdef make_slice_node(pos, start, stop = *, step = *)
cpdef p_atom(PyrexScanner s)
cpdef p_name(PyrexScanner s, name)
cpdef p_cat_string_literal(PyrexScanner s)
cpdef p_opt_string_literal(PyrexScanner s)
cpdef p_string_literal(PyrexScanner s)
cpdef p_list_maker(PyrexScanner s)
cpdef p_list_iter(PyrexScanner s)
cpdef p_list_for(PyrexScanner s)
cpdef p_list_if(PyrexScanner s)
cpdef p_dict_maker(PyrexScanner s)
cpdef p_dict_item(PyrexScanner s)
cpdef p_backquote_expr(PyrexScanner s)
cpdef p_simple_expr_list(PyrexScanner s)
cpdef p_expr(PyrexScanner s)
cpdef p_testlist(PyrexScanner s)
#-------------------------------------------------------
#
# Statements
#
#-------------------------------------------------------
cpdef p_global_statement(PyrexScanner s)
cpdef p_expression_or_assignment(PyrexScanner s)
cpdef p_print_statement(PyrexScanner s)
cpdef p_del_statement(PyrexScanner s)
cpdef p_pass_statement(PyrexScanner s, bint with_newline = *)
cpdef p_break_statement(PyrexScanner s)
cpdef p_continue_statement(PyrexScanner s)
cpdef p_return_statement(PyrexScanner s)
cpdef p_raise_statement(PyrexScanner s)
cpdef p_import_statement(PyrexScanner s)
cpdef p_from_import_statement(PyrexScanner s, bint first_statement = *)
cpdef p_imported_name(PyrexScanner s, bint is_cimport)
cpdef p_dotted_name(PyrexScanner s, bint as_allowed)
cpdef p_as_name(PyrexScanner s)
cpdef p_assert_statement(PyrexScanner s)
cpdef p_if_statement(PyrexScanner s)
cpdef p_if_clause(PyrexScanner s)
cpdef p_else_clause(PyrexScanner s)
cpdef p_while_statement(PyrexScanner s)
cpdef p_for_statement(PyrexScanner s)
cpdef p_for_bounds(PyrexScanner s)
cpdef p_for_from_relation(PyrexScanner s)
cpdef p_for_from_step(PyrexScanner s)
cpdef p_target(PyrexScanner s, terminator)
cpdef p_for_target(PyrexScanner s)
cpdef p_for_iterator(PyrexScanner s)
cpdef p_try_statement(PyrexScanner s)
cpdef p_except_clause(PyrexScanner s)
cpdef p_include_statement(PyrexScanner s, ctx)
cpdef p_with_statement(PyrexScanner s)
cpdef p_simple_statement(PyrexScanner s, bint first_statement = *)
cpdef p_simple_statement_list(PyrexScanner s, ctx, bint first_statement = *)
cpdef p_compile_time_expr(PyrexScanner s)
cpdef p_DEF_statement(PyrexScanner s)
cpdef p_IF_statement(PyrexScanner s, ctx)
cpdef p_statement(PyrexScanner s, ctx, bint first_statement = *)
cpdef p_statement_list(PyrexScanner s, ctx, bint first_statement = *)
cpdef p_suite(PyrexScanner s, ctx = *, bint with_doc = *, bint with_pseudo_doc = *)
cpdef p_positional_and_keyword_args(PyrexScanner s, end_sy_set, type_positions= *, type_keywords= * )
cpdef p_c_base_type(PyrexScanner s, bint self_flag = *, bint nonempty = *)
cpdef p_calling_convention(PyrexScanner s)
cpdef p_c_complex_base_type(PyrexScanner s)
cpdef p_c_simple_base_type(PyrexScanner s, self_flag, nonempty)
cpdef p_buffer_access(PyrexScanner s, base_type_node)
cpdef bint looking_at_name(PyrexScanner s) except -2
cpdef bint looking_at_expr(PyrexScanner s) except -2
cpdef bint looking_at_base_type(PyrexScanner s) except -2
cpdef bint looking_at_dotted_name(PyrexScanner s) except -2
cpdef p_sign_and_longness(PyrexScanner s)
cpdef p_opt_cname(PyrexScanner s)
cpdef p_c_declarator(PyrexScanner s, ctx = *, bint empty = *, bint is_type = *, bint cmethod_flag = *,
bint assignable = *, bint nonempty = *,
bint calling_convention_allowed = *)
cpdef p_c_array_declarator(PyrexScanner s, base)
cpdef p_c_func_declarator(PyrexScanner s, pos, ctx, base, bint cmethod_flag)
cpdef p_c_simple_declarator(PyrexScanner s, ctx, bint empty, bint is_type, bint cmethod_flag,
bint assignable, bint nonempty)
cpdef p_nogil(PyrexScanner s)
cpdef p_with_gil(PyrexScanner s)
cpdef p_exception_value_clause(PyrexScanner s)
cpdef p_c_arg_list(PyrexScanner s, ctx = *, bint in_pyfunc = *, bint cmethod_flag = *,
bint nonempty_declarators = *, bint kw_only = *)
cpdef p_optional_ellipsis(PyrexScanner s)
cpdef p_c_arg_decl(PyrexScanner s, ctx, in_pyfunc, bint cmethod_flag = *, bint nonempty = *, bint kw_only = *)
cpdef p_api(PyrexScanner s)
cpdef p_cdef_statement(PyrexScanner s, ctx)
cpdef p_cdef_block(PyrexScanner s, ctx)
cpdef p_cdef_extern_block(PyrexScanner s, pos, ctx)
cpdef p_c_enum_definition(PyrexScanner s, pos, ctx)
cpdef p_c_enum_line(PyrexScanner s, items)
cpdef p_c_enum_item(PyrexScanner s, items)
cpdef p_c_struct_or_union_definition(PyrexScanner s, pos, ctx)
cpdef p_visibility(PyrexScanner s, prev_visibility)
cpdef p_c_modifiers(PyrexScanner s)
cpdef p_c_func_or_var_declaration(PyrexScanner s, pos, ctx)
cpdef p_ctypedef_statement(PyrexScanner s, ctx)
cpdef p_decorators(PyrexScanner s)
cpdef p_def_statement(PyrexScanner s, decorators = *)
cpdef p_py_arg_decl(PyrexScanner s)
cpdef p_class_statement(PyrexScanner s)
cpdef p_c_class_definition(PyrexScanner s, pos, ctx)
cpdef p_c_class_options(PyrexScanner s)
cpdef p_property_decl(PyrexScanner s)
cpdef p_doc_string(PyrexScanner s)
cpdef p_code(PyrexScanner s, level= *)
cpdef p_compiler_directive_comments(PyrexScanner s)
cpdef p_module(PyrexScanner s, pxd, full_module_name)
# cython: auto_cpdef=True
#
# Pyrex Parser
#
# This should be done automatically
import cython
cython.declare(Nodes=object, ExprNodes=object, EncodedString=object)
import os
import re
import sys
from types import ListType, TupleType
from Scanning import PyrexScanner, FileSourceDescriptor
from Cython.Compiler.Scanning import PyrexScanner, FileSourceDescriptor
import Nodes
import ExprNodes
import StringEncoding
......@@ -527,26 +532,22 @@ def p_atom(s):
def p_name(s, name):
pos = s.position()
if not s.compile_time_expr:
try:
value = s.compile_time_env.lookup_here(name)
except KeyError:
pass
if not s.compile_time_expr and name in s.compile_time_env:
value = s.compile_time_env.lookup_here(name)
rep = repr(value)
if isinstance(value, bool):
return ExprNodes.BoolNode(pos, value = value)
elif isinstance(value, int):
return ExprNodes.IntNode(pos, value = rep)
elif isinstance(value, long):
return ExprNodes.IntNode(pos, value = rep, longness = "L")
elif isinstance(value, float):
return ExprNodes.FloatNode(pos, value = rep)
elif isinstance(value, (str, unicode)):
return ExprNodes.StringNode(pos, value = value)
else:
rep = repr(value)
if isinstance(value, bool):
return ExprNodes.BoolNode(pos, value = value)
elif isinstance(value, int):
return ExprNodes.IntNode(pos, value = rep)
elif isinstance(value, long):
return ExprNodes.IntNode(pos, value = rep, longness = "L")
elif isinstance(value, float):
return ExprNodes.FloatNode(pos, value = rep)
elif isinstance(value, (str, unicode)):
return ExprNodes.StringNode(pos, value = value)
else:
error(pos, "Invalid type for compile-time constant: %s"
% value.__class__.__name__)
error(pos, "Invalid type for compile-time constant: %s"
% value.__class__.__name__)
return ExprNodes.NameNode(pos, name = name)
def p_cat_string_literal(s):
......@@ -902,6 +903,21 @@ def p_print_statement(s):
return Nodes.PrintStatNode(pos,
arg_tuple = arg_tuple, append_newline = not ends_with_comma)
def p_exec_statement(s):
# s.sy == 'exec'
pos = s.position()
s.next()
args = [ p_bit_expr(s) ]
if s.sy == 'in':
s.next()
args.append(p_simple_expr(s))
if s.sy == ',':
s.next()
args.append(p_simple_expr(s))
else:
error(pos, "'exec' currently requires a target mapping (globals/locals)")
return Nodes.ExecStatNode(pos, args = args)
def p_del_statement(s):
# s.sy == 'del'
pos = s.position()
......@@ -1307,7 +1323,7 @@ def p_with_statement(s):
if not allow_multi and isinstance(target, ExprNodes.TupleNode):
s.error("Multiple with statement target values not allowed without paranthesis")
body = p_suite(s)
return Nodes.WithStatNode(pos, manager = manager,
return Nodes.WithStatNode(pos, manager = manager,
target = target, body = body)
def p_simple_statement(s, first_statement = 0):
......@@ -1316,6 +1332,8 @@ def p_simple_statement(s, first_statement = 0):
node = p_global_statement(s)
elif s.sy == 'print':
node = p_print_statement(s)
elif s.sy == 'exec':
node = p_exec_statement(s)
elif s.sy == 'del':
node = p_del_statement(s)
elif s.sy == 'break':
......@@ -2128,7 +2146,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
assignable = 1, nonempty = 1)
declarator.overridable = ctx.overridable
if s.sy == ':':
if ctx.level not in ('module', 'c_class'):
if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd'):
s.error("C function definition not allowed here")
doc, suite = p_suite(s, Ctx(level = 'function'), with_doc = 1)
result = Nodes.CFuncDefNode(pos,
......@@ -2382,7 +2400,7 @@ def p_code(s, level=None):
repr(s.sy), repr(s.systring)))
return body
COMPILER_DIRECTIVE_COMMENT_RE = re.compile(r"^#\s*cython:\s*([a-z]+)\s*=(.*)$")
COMPILER_DIRECTIVE_COMMENT_RE = re.compile(r"^#\s*cython:\s*([a-z_]+)\s*=(.*)$")
def p_compiler_directive_comments(s):
result = {}
......
from Cython.Plex.Scanners cimport Scanner
cdef class CompileTimeScope:
cdef public entries
cdef public outer
cdef class PyrexScanner(Scanner):
cdef public context
cdef public list included_files
cdef public compile_time_env
cdef public bint compile_time_eval
cdef public bint compile_time_expr
cdef public bint parse_comments
cdef public source_encoding
cdef public list indentation_stack
cdef public indentation_char
cdef public int bracket_nesting_level
cdef public sy
cdef public systring
cdef long current_level(self)
cpdef begin(self, state)
cpdef next(self)
cpdef bint expect(self, what, message = *) except -2
cpdef indentation_action(self, text):
cdef:
long current_level
long new_level
......@@ -11,15 +11,21 @@ import stat
import sys
from time import time
import cython
cython.declare(EncodedString=object, string_prefixes=object, raw_prefixes=object, IDENT=object)
from Cython import Plex, Utils
from Cython.Plex import Scanner
from Cython.Plex.Scanners import Scanner
from Cython.Plex.Errors import UnrecognizedInput
from Errors import CompileError, error
from Lexicon import string_prefixes, raw_prefixes, make_lexicon
from Lexicon import string_prefixes, raw_prefixes, make_lexicon, IDENT
from StringEncoding import EncodedString
plex_version = getattr(Plex, '_version', None)
try:
plex_version = Plex._version
except AttributeError:
plex_version = None
#print "Plex version:", plex_version ###
debug_scanner = 0
......@@ -91,7 +97,7 @@ def try_to_unpickle_lexicon():
source_file = os.path.join(dir, "Lexicon.py")
lexicon_hash = hash_source_file(source_file)
lexicon_pickle = os.path.join(dir, "Lexicon.pickle")
f = open_pickled_lexicon(expected_hash = lexicon_hash)
f = open_pickled_lexicon(lexicon_hash)
if f:
if notify_lexicon_unpickling:
t0 = time()
......@@ -165,9 +171,12 @@ def build_resword_dict():
d[word] = 1
return d
cython.declare(resword_dict=object)
resword_dict = build_resword_dict()
#------------------------------------------------------------------
class CompileTimeScope(object):
class CompileTimeScope:
def __init__(self, outer = None):
self.entries = {}
......@@ -178,6 +187,9 @@ class CompileTimeScope(object):
def lookup_here(self, name):
return self.entries[name]
def __contains__(self, name):
return name in self.entries
def lookup(self, name):
try:
......@@ -286,7 +298,6 @@ class PyrexScanner(Scanner):
# compile_time_env dict Environment for conditional compilation
# compile_time_eval boolean In a true conditional compilation context
# compile_time_expr boolean In a compile-time expression context
resword_dict = build_resword_dict()
def __init__(self, file, filename, parent_scanner = None,
scope = None, context = None, source_encoding=None, parse_comments=True, initial_pos=None):
......@@ -403,15 +414,15 @@ class PyrexScanner(Scanner):
sy, systring = self.read()
except UnrecognizedInput:
self.error("Unrecognized character")
if sy == 'IDENT':
if systring in self.resword_dict:
if sy == IDENT:
if systring in resword_dict:
sy = systring
else:
systring = EncodedString(systring)
systring.encoding = self.source_encoding
self.sy = sy
self.systring = systring
if debug_scanner:
if False: # debug_scanner:
_, line, col = self.position()
if not self.systring or self.sy == self.systring:
t = self.sy
......@@ -443,7 +454,7 @@ class PyrexScanner(Scanner):
self.expected(what, message)
def expect_keyword(self, what, message = None):
if self.sy == 'IDENT' and self.systring == what:
if self.sy == IDENT and self.systring == what:
self.next()
else:
self.expected(what, message)
......
......@@ -821,6 +821,8 @@ class ModuleScope(Scope):
self.cached_builtins = []
self.undeclared_cached_builtins = []
self.namespace_cname = self.module_cname
for name in ['__builtins__', '__name__', '__file__', '__doc__']:
self.declare_var(EncodedString(name), py_object_type, None)
def qualifying_scope(self):
return self.parent_module
......
......@@ -14,26 +14,33 @@ class BasicVisitor(object):
# instance.
def __init__(self):
self.dispatch_table = {}
def visit(self, obj):
cls = obj.__class__
m = self.dispatch_table.get(cls.__name__)
if m is None:
cls = type(obj)
try:
handler_method = self.dispatch_table[cls]
except KeyError:
#print "Cache miss for class %s in visitor %s" % (
# cls.__name__, type(self).__name__)
# Must resolve, try entire hierarchy
pattern = "visit_%s"
mro = inspect.getmro(cls)
for cls in mro:
m = getattr(self, pattern % cls.__name__, None)
if m is not None:
for mro_cls in mro:
try:
handler_method = getattr(self, pattern % mro_cls.__name__)
break
except AttributeError:
pass
else:
print type(self), type(obj)
print self.access_path
print self.access_path[-1][0].pos
print self.access_path[-1][0].__dict__
if hasattr(self, 'access_path'):
print self.access_path
print self.access_path[-1][0].pos
print self.access_path[-1][0].__dict__
raise RuntimeError("Visitor does not accept object: %s" % obj)
self.dispatch_table[cls.__name__] = m
return m(obj)
#print "Caching " + cls.__name__
self.dispatch_table[cls] = handler_method
return handler_method(obj)
class TreeVisitor(BasicVisitor):
"""
......
import cython
cdef class Scanner:
cdef public lexicon
cdef public stream
cdef public name
cdef public buffer
cdef public long buf_start_pos
cdef public long next_pos
cdef public long cur_pos
cdef public long cur_line
cdef public long cur_line_start
cdef public long start_pos
cdef public long start_line
cdef public long start_col
cdef public text
cdef public initial_state # int?
cdef public state_name
cdef public list queue
cdef public bint trace
cdef public cur_char
cdef public input_state
cdef public level
cpdef next_char(self):
cdef:
long input_state
cpdef read(self)
cpdef position(self)
cpdef run_machine_inlined(self):
cdef:
long cur_pos
long cur_line
long cur_line_start
long input_state
long next_pos
long buf_start_pos
long buf_len
long buf_index
bint trace
long discard
cpdef begin(self, state)
cpdef produce(self, value, text = *)
......@@ -10,6 +10,8 @@
import Errors
from Regexps import BOL, EOL, EOF
import cython
class Scanner:
"""
A Scanner is used to read tokens from a stream of characters
......@@ -42,23 +44,23 @@ class Scanner:
"""
lexicon = None # Lexicon
stream = None # file-like object
name = ''
buffer = ''
buf_start_pos = 0 # position in input of start of buffer
next_pos = 0 # position in input of next char to read
cur_pos = 0 # position in input of current char
cur_line = 1 # line number of current char
cur_line_start = 0 # position in input of start of current line
start_pos = 0 # position in input of start of token
start_line = 0 # line number of start of token
start_col = 0 # position in line of start of token
text = None # text of last token read
initial_state = None # Node
state_name = '' # Name of initial state
queue = None # list of tokens to be returned
trace = 0
# lexicon = None # Lexicon
# stream = None # file-like object
# name = ''
# buffer = ''
# buf_start_pos = 0 # position in input of start of buffer
# next_pos = 0 # position in input of next char to read
# cur_pos = 0 # position in input of current char
# cur_line = 1 # line number of current char
# cur_line_start = 0 # position in input of start of current line
# start_pos = 0 # position in input of start of token
# start_line = 0 # line number of start of token
# start_col = 0 # position in line of start of token
# text = None # text of last token read
# initial_state = None # Node
# state_name = '' # Name of initial state
# queue = None # list of tokens to be returned
# trace = 0
def __init__(self, lexicon, stream, name = '', initial_pos = None):
"""
......@@ -73,6 +75,17 @@ class Scanner:
|name| is optional, and may be the name of the file being
scanned or any other identifying string.
"""
self.buffer = ''
self.buf_start_pos = 0
self.next_pos = 0
self.cur_pos = 0
self.cur_line = 1
self.start_pos = 0
self.start_line = 0
self.start_col = 0
self.text = None
self.state_name = None
self.lexicon = lexicon
self.stream = stream
self.name = name
......@@ -374,6 +387,3 @@ class Scanner:
Override this method if you want something to be done at
end of file.
"""
# For backward compatibility:
setattr(Scanner, "yield", Scanner.produce)
include MANIFEST.in README.txt INSTALL.txt CHANGES.txt ToDo.txt USAGE.txt
include CHANGES_pyrex.txt COPYING.txt LICENSE.txt Makefile
include MANIFEST.in README.txt INSTALL.txt ToDo.txt USAGE.txt
include COPYING.txt LICENSE.txt Makefile
recursive-include .hg *
include .hgignore .hgtags
include setup.py
include bin/cython bin/update_references
include bin/cython
include cython.py
include Cython/Compiler/Lexicon.pickle
include Cython/Includes/*.pxd
include Doc/*
include Demos/*.pyx
include Demos/*.pxd
include Demos/*.py
include Demos/callback/*
include Demos/embed/*
......
See http://trac.cython.org/cython_trac and http://wiki.cython.org/enhancements
-- The Original Pyrex Todo List --
DONE - Pointer-to-function types.
......
......@@ -20,12 +20,17 @@ the documentation.
This code was modeled on Quixote's ptl_import.
"""
import sys, os, shutil
import imp, ihooks, glob, md5
import imp, ihooks, glob
import __builtin__
import pyxbuild
from distutils.dep_util import newer
from distutils.extension import Extension
try:
import hashlib
except ImportError:
import md5 as hashlib
mod_name = "pyximport"
assert sys.hexversion >= 0x20000b1, "need Python 2.0b1 or later"
......@@ -54,7 +59,7 @@ def _load_pyrex(name, filename):
def get_distutils_extension(modname, pyxfilename):
extra = "_" + md5.md5(open(pyxfilename).read()).hexdigest()
extra = "_" + hashlib.md5(open(pyxfilename).read()).hexdigest()
# modname = modname + extra
extension_mod = handle_special_build(modname, pyxfilename)
......
......@@ -31,7 +31,10 @@ except ValueError:
try:
from Cython.Compiler.Main import compile
source_root = os.path.dirname(__file__)
compiled_modules = ["Cython.Plex.Scanners"]
compiled_modules = ["Cython.Plex.Scanners",
"Cython.Compiler.Scanning",
"Cython.Compiler.Parsing",
"Cython.Compiler.Visitor"]
extensions = []
for module in compiled_modules:
source_file = os.path.join(source_root, *module.split('.'))
......
__doc__ = u"""
>>> test_literal_list_slice_all()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_end()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_end()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_param(2)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_end_param(4)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_end_param(2,7)
(1, 2, 3, 4, 5)
>>> test_ptr_literal_list_slice_all()
(1, 2, 3, 4, 5)
>>> test_ptr_literal_list_slice_start()
(1, 2, 3, 4, 5)
>>> test_ptr_literal_list_slice_end()
(1, 2, 3, 4, 5)
"""
# this doesn't work - it would reassign the array address!
#
#def test_literal_list():
# cdef int a[5]
# a = [1,2,3,4,5]
# return (a[0], a[1], a[2], a[3], a[4])
def test_literal_list_slice_all():
cdef int a[5] # = [5,4,3,2,1]
a[:] = [1,2,3,4,5]
return (a[0], a[1], a[2], a[3], a[4])
def test_literal_list_slice_start():
cdef int a[7] # = [7,6,5,4,3,2,1]
a[2:] = [1,2,3,4,5]
return (a[2], a[3], a[4], a[5], a[6])
def test_literal_list_slice_end():
cdef int a[7] # = [7,6,5,4,3,2,1]
a[:5] = [1,2,3,4,5]
return (a[0], a[1], a[2], a[3], a[4])
def test_literal_list_slice_start_end():
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
a[2:7] = [1,2,3,4,5]
return (a[2], a[3], a[4], a[5], a[6])
def test_literal_list_slice_start_param(s):
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
a[s:] = [1,2,3,4,5]
return (a[2], a[3], a[4], a[5], a[6])
# return a[s:]
def test_literal_list_slice_end_param(e):
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
a[:e] = [1,2,3,4,5]
return (a[0], a[1], a[2], a[3], a[4])
# return a[:e]
def test_literal_list_slice_start_end_param(s,e):
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
a[s:e] = [1,2,3,4,5]
return (a[2], a[3], a[4], a[5], a[6])
# return a[s:e]
def test_ptr_literal_list_slice_all():
cdef int *a = [6,5,4,3,2]
a[:] = [1,2,3,4,5]
return (a[0], a[1], a[2], a[3], a[4])
def test_ptr_literal_list_slice_start():
cdef int *a = [6,5,4,3,2,1]
a[1:] = [1,2,3,4,5]
return (a[1], a[2], a[3], a[4], a[5])
def test_ptr_literal_list_slice_end():
cdef int *a = [6,5,4,3,2,1]
a[:5] = [1,2,3,4,5]
return (a[0], a[1], a[2], a[3], a[4])
# tuples aren't supported (yet)
#
#def test_literal_tuple():
# cdef int a[5]
# a = (1,2,3,4,5)
# return (a[0], a[1], a[2], a[3], a[4])
# this would be nice to have:
#
#def test_list(list l):
# cdef int a[5]
# a[:] = l
# return (a[0], a[1], a[2], a[3], a[4])
__doc__ = """# no unicode string, not tested in Python3!
#>>> a
#Traceback (most recent call last):
#NameError: name 'a' is not defined
#>>> test_module_scope()
#>>> a
>>> test_dict_scope1()
2
>>> d = {}
>>> test_dict_scope2(d)
>>> print d['b']
2
>>> d1 = {}
>>> test_dict_scope3(d1, d1)
>>> print d1['b']
2
>>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2)
>>> print d1.get('b'), d2.get('b')
None 2
>>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2)
>>> print d1.get('b'), d2.get('b')
None 2
>>> d1, d2 = dict(a=11), dict(c=5)
>>> test_dict_scope_ref(d1, d2)
>>> print d1.get('b'), d2.get('b')
None 16
>>> d = dict(a=11, c=5)
>>> test_dict_scope_ref(d, d)
>>> print d['b']
16
>>> d = dict(seq = [1,2,3,4])
>>> add_iter = test_def(d, 'seq')
>>> list(add_iter())
[2, 3, 4, 5]
>>> # errors
>>> d1, d2 = {}, {}
>>> test_dict_scope_ref(d1, d2)
Traceback (most recent call last):
NameError: name 'a' is not defined
"""
#def test_module_scope():
# exec "a=1+1"
# return __dict__['a']
def test_dict_scope1():
cdef dict d = {}
exec "b=1+1" in d
return d['b']
def test_dict_scope2(d):
exec "b=1+1" in d
def test_dict_scope3(d1, d2):
exec "b=1+1" in d1, d2
def test_dict_scope_ref(d1, d2):
exec "b=a+c" in d1, d2
def test_def(d, varref):
exec """
def test():
for x in %s:
yield x+1
""" % varref in d
return d['test']
__doc__ = u"""
>>> import sys as sous
>>> import distutils.core as corey
>>> from copy import deepcopy as copey
>>> sous is _sous
True
>>> corey is _corey
True
>>> copey is _copey
True
>>> _sous is not None
True
>>> _corey is not None
True
>>> _copey is not None
True
>>> print(_sous.__name__)
sys
>>> print(sous.__name__)
sys
>>> print(_corey.__name__)
distutils.core
>>> print(corey.__name__)
distutils.core
>>> print(_copey.__name__)
deepcopy
>>> print(copey.__name__)
deepcopy
"""
import sys as _sous
import distutils.core as _corey
from copy import deepcopy as _copey
......@@ -89,6 +89,9 @@ __doc__ = u"""
1
>>> switch_off(2)
0
>>> switch_pass(1)
1
"""
def switch_simple_py(x):
......@@ -173,3 +176,12 @@ def switch_off(int x):
else:
return 0
return -1
def switch_pass(int x):
if x == 1:
pass
elif x == 2:
pass
else:
pass
return x
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