├── Tools └── BUILD.bazel ├── tests ├── compile │ ├── cheese.h │ ├── a │ │ ├── __init__.py │ │ └── b.pxd │ ├── dotted_cimport_submodule │ │ ├── a.pxd │ │ └── __init__.pyx │ ├── ewing9.pxd │ ├── altet1.h │ ├── belchenko2.h │ ├── hinsen1.h │ ├── watts2.pyx │ ├── builtin.pyx │ ├── drake1.pyx │ ├── ewing8.pyx │ ├── ewing9.pyx │ ├── jiba4.pyx │ ├── assert2.pyx │ ├── carrdecl.pyx │ ├── coventry1.pyx │ ├── globalonly.pyx │ ├── omittedargnames.pyx │ ├── cdefexternfromstar.pyx │ ├── ewing3.pyx │ ├── ewing5.pyx │ ├── ishimoto4.pyx │ ├── lepage_2.pyx │ ├── none.pyx │ ├── cdefexternempty.pyx │ ├── pyclass.pyx │ ├── globalstmt.pyx │ ├── ewing4.pyx │ ├── excvalreturn.pyx │ ├── food.h │ ├── formfeed.pyx │ ├── longunsigned.pyx │ ├── burton1.pyx.BROKEN │ ├── exthash.pyx │ ├── extindex.pyx │ ├── ishimoto1.pyx │ ├── pxd_override_T230.pxd │ ├── slicex.pyx │ ├── ctypedefclass.pyx │ ├── declandimpl.pxd │ ├── extdelattr.pyx │ ├── extdelitem.pyx │ ├── extdescrdel.pyx │ ├── extdescrget.pyx │ ├── extdescrset.pyx │ ├── extgetattr.pyx │ ├── extpropertydoc.pyx │ ├── extsetattr.pyx │ ├── extsetitem.pyx │ ├── johnson2.pyx │ ├── nonctypedefclass.pyx │ ├── dotted_cimport.pyx │ ├── extgetitem.pyx │ ├── cimport_package_module_T4.pyx │ ├── extern_packed_struct.pyx │ ├── jiba5.pyx │ ├── argdefault.pyx │ ├── cpdef.pyx │ ├── extimported.pyx │ ├── kleckner1.pyx │ ├── coercetovoidptr.pyx │ ├── fromimport_star.pyx │ ├── getattr3ref.pyx.BROKEN │ ├── emptytry.pyx │ ├── extdelslice.pyx │ ├── behnel4.pyx │ ├── builtinbuffer.py │ ├── extpropertydel.pyx │ ├── extsetslice.pyx │ ├── ctypedef.pyx │ ├── extpropertyset.pyx │ ├── cverylongtypes.pyx │ ├── import.pyx │ ├── pinard4.pyx │ ├── ellipsis_T488.pyx │ ├── extforward.pyx │ ├── extpropertyget.pyx │ ├── arraytoptrarg.pyx │ ├── complexbasetype.pyx │ ├── cunsignedlong.pyx │ ├── nullptr.pyx │ ├── withgil.pyx │ ├── cpp_templated_ctypedef.pyx │ ├── del.pyx │ ├── constexpr.pyx │ ├── ctypedefenum.pyx │ ├── ctypedefunion.pyx │ ├── hinsen2.pyx │ ├── pxd_override_T230.py │ ├── specmethextarg.pyx │ ├── globvardef.pyx │ ├── johnson1.pyx │ ├── parallel_compile_float_rank.pyx │ ├── cpp_nogil.h │ ├── libc_errno.pyx │ ├── utf8bom.pyx │ ├── extargdefault.pyx │ ├── extimportedsubtype.pyx │ ├── khavkine1.pyx │ ├── constcast.pyx │ ├── declandimpl.pyx │ ├── notnonearg.pyx │ ├── traceback.pyx │ ├── types_and_names.pxd │ ├── specmethargdefault.pyx │ ├── ewing1.pyx │ ├── cstructreturn.pyx │ ├── min_async.pyx │ ├── point.h │ ├── typecast.pyx │ ├── belchenko1.pyx │ ├── extern.pyx │ ├── magcmp.pyx │ ├── ewing8.pxd │ ├── ass2longlong.pyx │ ├── gencall.pyx │ ├── cast_ctypedef_array_T518_helper.h │ ├── ctypedef_public_class_T355.pxd │ ├── funcptr.pyx │ ├── ctypedefstruct.pyx │ ├── cenum.pyx │ ├── doda1.pyx │ ├── jiba6.pyx │ ├── specialfloatvals.pyx │ ├── publicapi_cimport.pyx │ ├── casttoexttype.pyx │ ├── ewing7.pyx │ ├── belchenko2.pyx.BROKEN │ ├── gustafsson2.pyx │ ├── crunchytype.pxd │ ├── indices.pyx │ ├── cdef_syntax.pyx │ ├── extinheritdel.pyx │ ├── huss2.pyx │ ├── cpp_class_redefinition.pyx │ ├── extinheritset.pyx │ ├── forfromelse.pyx │ ├── future_imports.pyx │ ├── extpropertyall.pyx │ ├── cargdef.pyx │ ├── weakref_T276.pyx │ ├── altet1.pyx.BROKEN │ ├── cimportfrom_T248.pyx │ ├── cassign.pyx │ ├── excvalcheck.h │ ├── inplace_ops.pyx │ ├── ctypedefpubapi.pyx │ ├── arrayptrcompat.pyx │ ├── excvalcheck.pyx │ └── extexttype.pyx ├── run │ ├── includes │ │ ├── a.h │ │ ├── b.h │ │ ├── c.h │ │ ├── d.h │ │ ├── e.h │ │ ├── indirect_d.pxd │ │ ├── b.pxd │ │ ├── d.pxd │ │ └── includefile.pxi │ ├── filenames.pxi │ ├── autotestdict.pxd │ ├── cpdef_optargs_pure.pxd │ ├── complex_numbers_c89_T398.h │ ├── testinclude.pxi │ ├── extmember.pxd │ ├── crashT245.h │ ├── cdef_opt.pxd │ ├── dynamic_attributes.pxd │ ├── pass.pyx │ ├── cimport_alias_subclass_helper.pxd │ ├── inlinepxd.pxd │ ├── check_fused_types_pxd.pxd │ ├── pinard6.pyx │ ├── static_methods.pxd │ ├── cpdef_extern_func_in_py.pxd │ ├── inlinepxd_support.pxd │ ├── str_encoding_latin1.pyx │ ├── ass2local.pyx │ ├── crashT245_pxd.pxd │ ├── r_jiba1.pxd │ ├── unicodeliteralslatin1.pyx │ ├── cpp_exceptions_nogil_helper.h │ ├── struct_conversion_extern_header.h │ ├── verbatiminclude.h │ ├── ref2local.pyx │ ├── fmod.pyx │ ├── overflow_check_int.pyx │ ├── strconstinclass.pyx │ ├── wundram1.pyx │ ├── cmethod_inline_T474.pxd │ ├── complex_numbers_cxx_T398.h │ ├── kostyrka2.pyx │ ├── extclasspass.pyx │ ├── overflow_check_longlong.pyx │ ├── overflow_check_uint.pyx │ ├── complex_numbers_c89_T398.pyx │ ├── complex_numbers_c99_T398.pyx │ ├── complex_numbers_cxx_T398.pyx │ ├── file_encoding_T740.py │ ├── behnel3.pyx │ ├── cpp_class_redef.pxd │ ├── filenames.pyx │ ├── overflow_check_ulonglong.pyx │ ├── pure_cdef_class_property_decorator_T264.pxd │ ├── behnel2.pyx │ ├── define_macro_helper.h │ ├── dietachmayer1.pyx │ ├── extlen.pyx │ ├── complex_numbers_c89_T398_long_double.pyx │ ├── cpdef_extern_func.pxd │ ├── cstringmeth.pyx │ ├── include.pyx │ ├── ticket_124.pyx │ ├── types.h │ ├── nononetypecheck.pyx │ ├── anonymousenum.pyx │ ├── numpy_ValueError_T172.pyx │ ├── numpy_cimport.pyx │ ├── kostyrka.pyx │ ├── r_jeff_epler_1.pyx │ ├── inline.pyx │ ├── r_print.pyx │ ├── varargdecl.pyx │ ├── addressof.pyx │ ├── empty_declarators.pyx │ ├── extinstantiate.pyx │ ├── watts1.pyx │ ├── typeofexttype.pyx │ ├── bishop2.pyx │ ├── crashT245.pyx │ ├── menten1.pyx │ ├── lambda_T723.pyx │ ├── ctypedef_delegation.pyx │ ├── unreachable.pyx │ ├── charcomparisonT412.pyx │ ├── function_as_method_py_T494.py │ ├── baas3.pyx │ ├── tandemstats.pyx │ ├── behnel1.pyx │ ├── r_mitch_chapman_2.pyx │ ├── arg_incref.pyx │ ├── classpass.pyx │ ├── directive_locals_in_pxd.pxd │ ├── ishimoto2.pyx │ ├── r_starargcall.pyx │ ├── varargcall.pyx │ ├── concatcstrings.pyx │ ├── define_macro.pyx │ ├── function_as_method_T494.pyx │ ├── r_starargsonly.pyx │ ├── cdef_class_order.pyx │ ├── class_scope.py │ ├── cython2_bytes.pyx │ ├── ptr_warning_T714.pyx │ ├── altet2.pyx │ ├── numpy_common.pxi │ ├── r_toofewargs.pyx │ ├── closure_leak_1.pyx │ ├── r_lepage_3.pyx │ ├── reimport.pyx │ ├── backquote.pyx │ ├── import_error_T734.py │ ├── cpp_vector_in_generator.pyx │ ├── r_typecast.pyx │ ├── cpp_iterators_simple.h │ ├── r_pyclass.pyx │ ├── builtin_globals.py │ ├── ext_instance_type_T232.pyx │ ├── mod__name__.pyx │ ├── modbody.pyx │ ├── non_const_as_const_arg.pyx │ ├── attribute_and_lambda.pyx │ ├── complex_numbers_T305_long_double.pyx │ ├── generator_expressions_and_locals.pyx │ ├── if_else_expr_cpp_helper.h │ ├── temp_alloc_T409.pyx │ ├── boolean_context.pyx │ ├── cimport_alias_subclass.pyx │ ├── relativeimport_star_T542.pyx │ ├── cpdef_enums.pxd │ ├── mangle_c_keywords.pyx │ ├── packedstruct_T290.pyx │ ├── ishimoto3.pyx │ ├── r_mcintyre1.pyx │ ├── slice2b.pyx │ ├── cimport_cython_T505.pyx │ ├── classbody_exec.pyx │ ├── ass2cglobal.pyx │ ├── extclassbody.pyx │ ├── cdef_class_field.pyx │ ├── pynumop.pyx │ ├── r_bowden1.pyx │ ├── tupleunpack_T712.pyx │ ├── yield_inside_lambda.py │ ├── array_address.pyx │ ├── float_floor_division_T260.pyx │ ├── str_ascii_auto_encoding.pyx │ ├── class_scope_del_T684.py │ ├── memview_vector.pyx │ ├── r_uintindex.pyx │ ├── rodriguez_1.pyx │ └── switch_transform.pyx ├── broken │ ├── invalid-module-name.pyx │ ├── cimportfunc.pyx │ ├── includepublic.pyx │ ├── naanou_1.pyx │ ├── r_classmodname.pyx │ ├── r_tbfilename.pyx │ ├── getattr3ref.pyx │ ├── r_simpcall.pyx │ ├── externfunc.pyx │ ├── l_capi.pyx │ ├── r_classdoc.pyx │ ├── tslots.pyx │ ├── cimportfrompkgdir.pyx │ ├── r_getattr3.pyx │ ├── cexportfunc.pyx │ ├── r_extweakref.pyx │ ├── l_cfuncexport.pyx │ ├── retconvert.pyx │ ├── big_t.pyx │ ├── pkg.cimport.pyx │ ├── r_cfuncimport.pyx │ ├── r_import.pyx │ ├── getattr.pyx │ ├── pkg.cimportfrom.pyx │ ├── cimportfrom.pyx │ ├── r_newstyleclass.pyx │ ├── fwddeclcclass.pyx │ ├── plex2.pyx │ ├── test_include_options.pyx │ ├── r_capi.pyx │ ├── raise.pyx │ ├── b_extimpinherit.pyx │ ├── r_traceback.pyx │ ├── cascadedass.pyx │ ├── cimport.pyx │ ├── i_public.pyx │ ├── r_unpack.pyx │ ├── ctypedefextern.pyx │ ├── intindex.pyx │ ├── builtindict.pyx │ └── r_extinherit.pyx ├── errors │ ├── pxd_cdef_class_declaration_T286.pxd │ ├── e_nogilcmeth.pxd │ ├── empty.pyx │ ├── nogilcmeth.pxd │ ├── e_bufaccess_pxd.pxd │ ├── pure_cclass_without_body.pxd │ ├── encoding.pyx │ ├── invalid_hex_escape0.pyx │ ├── invalid_hex_escape1.pyx │ ├── invalid_uescape.pyx │ ├── invalid_uescape0.pyx │ ├── invalid_uescape2.pyx │ ├── futurebraces.pyx │ ├── e_assnone.pyx │ ├── invalid_cast.pyx │ ├── invalid_uescapeN.pyx │ ├── e_func_in_pxd_support.pxd │ ├── fused_syntax.pyx │ ├── se_mixtabspace.pyx │ ├── se_badindent.pyx │ ├── e_cdef_missing_declarator.pyx │ ├── pure_cclass_without_body.py │ ├── callingnonexisting_T307.pyx │ ├── e2_packedstruct_T290.pyx │ ├── pep448_syntax_1.pyx │ ├── cdef_in_pyclass.pyx │ ├── e_badpyparam.pyx │ ├── e_cdef_in_py.py │ ├── e_sizeofincomplete.pyx │ ├── pep448_syntax_2.pyx │ ├── pep492_badsyntax_async9.pyx │ ├── pep492_badsyntax_async5.pyx │ ├── pep492_badsyntax_async7.pyx │ ├── pxd_cdef_class_declaration_T286.pyx │ ├── se_badindent2.pyx │ ├── e_cdef_closure.pyx │ ├── e_decorators.pyx │ ├── pep448_syntax_3.pyx │ ├── pep492_badsyntax_async8.pyx │ ├── void_as_arg.pyx │ ├── mod_errors.pyx │ ├── e_bitop.pyx │ ├── e_numop.pyx │ ├── missing_self_in_cpdef_method_T156.pyx │ ├── notcimportedT418.pyx │ ├── typoT304.pyx │ ├── e_notnone.pyx │ ├── pep492_badsyntax_async1.pyx │ ├── e_undefexttype.pyx │ ├── pep492_badsyntax_async4.pyx │ ├── e_cenum.pyx │ ├── cdefoptargs.pyx │ ├── e_addop.pyx │ ├── e_badexcvaltype.pyx │ ├── e_cdef_yield.pyx │ ├── e_notnone2.pyx │ ├── fused_syntax_ctypedef.pyx │ ├── e_nogilcmeth.pyx │ ├── nogilcmeth.pyx │ ├── se_multass.pyx │ ├── w_cdef_override.pyx │ ├── cfunc_directive_in_pyclass.pyx │ ├── e_autotestdict.pyx │ ├── buffertypedef_T117.pyx │ ├── cdef_syntax.pyx │ ├── cmethbasematch.pxd │ ├── compile_time_unraisable_T370.pyx │ ├── e_multass.pyx │ ├── e_pyobinstruct.pyx │ ├── missing_self_in_cpdef_method_T165.pyx │ ├── pep492_badsyntax_async2.pyx │ ├── bufaccess_noassignT444.pyx │ ├── cpdef_syntax.pyx │ ├── cython3_bytes.pyx │ ├── e_switch.pyx │ ├── e_tuple_args_T692.py │ ├── nonconst_def.pyx │ ├── e_unop.pyx │ ├── e_while.pyx │ ├── pyobjcastdisallow_T313.pyx │ ├── cpp_no_constructor.pyx │ ├── literal_lists.pyx │ ├── subtyping_final_class.pyx │ ├── e_switch_transform.pyx │ ├── nogil_buffer_acquisition.pyx │ ├── duplicate_const.pyx │ ├── extended_unpacking_parser2.pyx │ ├── syntax_warnings.pyx │ ├── e_subop.pyx │ ├── e_func_in_pxd.pyx │ ├── e_exceptclause.pyx │ ├── e_powop.pyx │ ├── e_pxdimpl.pyx │ ├── nogilfunctype.pyx │ ├── cdefspecial.pyx │ ├── missing_baseclass_in_predecl_T262.pyx │ ├── w_uninitialized_generators.pyx │ ├── undefinedname.pyx │ ├── extended_unpacking_notuple.pyx │ ├── nonconst_def_tuple.pyx │ ├── w_uninitialized_del.pyx │ ├── cdefkwargs.pyx │ ├── e_tempcast.pyx │ ├── e_ctypedefornot.pyx │ └── e_cdefassign.pyx ├── memoryview │ ├── memoryview.pxd │ ├── bufaccess.h │ └── memview_assignments.pyx ├── cygwin_bugs.txt ├── wrappers │ └── cpp_references_helper.h ├── buffers │ └── bufaccess.h ├── travis_macos_cpp_bugs.txt └── build │ └── basic_cythonize.srctree ├── Cython ├── Parser │ └── __init__.py ├── Runtime │ └── __init__.py ├── Tests │ └── __init__.py ├── Build │ ├── Tests │ │ └── __init__.py │ ├── Distutils.py │ └── __init__.py ├── Compiler │ ├── __init__.py │ ├── Tests │ │ └── __init__.py │ └── Version.py ├── Debugger │ ├── __init__.py │ └── Tests │ │ ├── __init__.py │ │ ├── cfuncs.h │ │ └── cfuncs.c ├── Includes │ ├── libc │ │ ├── __init__.pxd │ │ ├── stddef.pxd │ │ └── setjmp.pxd │ ├── posix │ │ ├── __init__.pxd │ │ └── ioctl.pxd │ ├── libcpp │ │ ├── pair.pxd │ │ ├── __init__.pxd │ │ ├── stack.pxd │ │ └── typeinfo.pxd │ └── cpython │ │ ├── pyport.pxd │ │ └── ceval.pxd ├── Distutils │ └── __init__.py ├── Tempita │ └── __init__.py └── Utility │ ├── TestCyUtilityLoader.pyx │ └── TestUtilityLoader.c ├── Demos ├── libraries │ ├── mymath.h │ ├── mymath.c │ └── call_mymath.pyx ├── embed │ ├── embedded.output │ ├── embedded.pyx │ ├── README.rst │ └── assert_equal.py ├── callback │ ├── cheesefinder.h │ ├── run_cheese.py │ ├── Makefile │ └── Setup.py ├── run_numeric_demo.py ├── integrate0.py ├── run_spam.py ├── integrate1.pyx ├── numpy_demo.pyx ├── run_primes.py ├── integrate2.pyx ├── pyprimes.py └── benchmarks │ └── meteor_contest.pxd ├── docs ├── src │ ├── changes.rst │ ├── quickstart │ │ ├── sage.png │ │ ├── jupyter.png │ │ ├── htmlreport.png │ │ └── index.rst │ ├── tutorial │ │ ├── htmlreport.png │ │ └── python_division.png │ ├── userguide │ │ └── compute_typed_html.jpg │ └── reference │ │ ├── limitations.rst │ │ ├── directives.rst │ │ ├── special_mention.rst │ │ └── interfacing_with_other_code.rst ├── examples │ ├── tutorial │ │ ├── string │ │ │ ├── to_unicode.pxd │ │ │ ├── api_func.pyx │ │ │ ├── c_func.pxd │ │ │ ├── someheader.h │ │ │ ├── arg_memview.pyx │ │ │ ├── for_char.pyx │ │ │ ├── naive_decode.pyx │ │ │ ├── for_bytes.pyx │ │ │ ├── auto_conversion_3.pyx │ │ │ ├── for_unicode.pyx │ │ │ ├── const.pyx │ │ │ ├── if_char_in.pyx │ │ │ ├── decode.pyx │ │ │ ├── try_finally.pyx │ │ │ ├── auto_conversion_1.pyx │ │ │ ├── decode_cpp_string.pyx │ │ │ ├── cpp_string.pyx │ │ │ ├── to_char.pyx │ │ │ └── return_memview.pyx │ │ ├── external │ │ │ ├── libc_sin.pyx │ │ │ ├── keyword_args.pyx │ │ │ ├── cpdef_sin.pyx │ │ │ ├── py_version_hex.pyx │ │ │ ├── atoi.pyx │ │ │ └── keyword_args_call.pyx │ │ ├── pure │ │ │ ├── dostuff.py │ │ │ ├── dostuff.pxd │ │ │ ├── cython_declare2.py │ │ │ ├── annotations.py │ │ │ ├── locals.py │ │ │ ├── compiled_switch.py │ │ │ ├── A.pxd │ │ │ ├── cython_declare.py │ │ │ ├── mymodule.pxd │ │ │ ├── exceptval.py │ │ │ ├── mymodule.py │ │ │ └── A.py │ │ ├── cdef_classes │ │ │ ├── math_function_2.pyx │ │ │ ├── sin_of_square.pxd │ │ │ ├── math_function.py │ │ │ └── sin_of_square.pyx │ │ ├── profiling_tutorial │ │ │ ├── often_called.pyx │ │ │ ├── calc_pi.py │ │ │ ├── profile.py │ │ │ ├── calc_pi_2.pyx │ │ │ ├── profile_2.py │ │ │ └── calc_pi_3.pyx │ │ ├── cython_tutorial │ │ │ ├── setup.py │ │ │ └── fib.pyx │ │ ├── array │ │ │ ├── safe_usage.pyx │ │ │ ├── clone.pyx │ │ │ ├── unsafe_usage.pyx │ │ │ └── resize.pyx │ │ └── clibraries │ │ │ ├── queue.pyx │ │ │ └── queue2.pyx │ ├── userguide │ │ ├── sharing_declarations │ │ │ ├── volume.pxd │ │ │ ├── lunch.h │ │ │ ├── volume.pyx │ │ │ ├── c_lunch.pxd │ │ │ ├── shrubbing.pxd │ │ │ ├── lunch.pyx │ │ │ ├── dishes.pxd │ │ │ ├── setup.py │ │ │ ├── shrubbing.pyx │ │ │ ├── landscaping.pyx │ │ │ └── spammery.pyx │ │ ├── extension_types │ │ │ ├── my_module.pxd │ │ │ ├── python_access.pyx │ │ │ ├── widen_shrubbery.pyx │ │ │ ├── shrubbery_2.pyx │ │ │ ├── dict_animal.pyx │ │ │ └── my_module.pyx │ │ ├── wrapping_CPlusPlus │ │ │ ├── setup.py │ │ │ ├── function_templates.pyx │ │ │ ├── iterate.pyx │ │ │ └── vector_demo.pyx │ │ ├── memoryviews │ │ │ ├── C_func_file.h │ │ │ ├── transpose.pyx │ │ │ ├── memory_layout_2.pyx │ │ │ ├── np_flag_const.pyx │ │ │ ├── C_func_file.c │ │ │ ├── slicing.pyx │ │ │ ├── view_string.pyx │ │ │ └── copy.pyx │ │ ├── language_basics │ │ │ ├── kwargs_2.pyx │ │ │ ├── kwargs_1.pyx │ │ │ ├── optional_subclassing.pxd │ │ │ ├── cdef_block.pyx │ │ │ ├── compile_time.pyx │ │ │ ├── override.pyx │ │ │ ├── struct_union_enum.pyx │ │ │ └── optional_subclassing.pyx │ │ ├── parallelism │ │ │ └── simple_sum.pyx │ │ └── external_C_code │ │ │ ├── delorean.pyx │ │ │ ├── marty.c │ │ │ └── c_code_docstring.pyx │ ├── quickstart │ │ ├── build │ │ │ ├── hello.pyx │ │ │ └── setup.py │ │ └── cythonize │ │ │ ├── cdef_keyword.pyx │ │ │ ├── integrate.py │ │ │ └── integrate_cy.pyx │ ├── README.rst │ └── not_in_docs │ │ └── great_circle │ │ ├── c1.pyx │ │ └── p1.py ├── _static │ ├── favicon.ico │ ├── cythonlogo.png │ └── cython-logo-light.png ├── .hgignore └── index.rst ├── test-requirements.txt ├── Doc └── s5 │ ├── ui │ └── default │ │ ├── blank.gif │ │ ├── bodybg.gif │ │ ├── cython-logo64.png │ │ ├── opera.css │ │ └── slides.css │ └── ep2008 │ ├── worker.py │ └── stupidlowercase.py ├── pyximport ├── __init__.py └── PKG-INFO ├── test-requirements-cpython.txt ├── .coveragerc ├── bin ├── cythonize ├── cygdb ├── cython └── cython.bat ├── cygdb.py ├── setupegg.py ├── cythonize.py └── .hgignore /Tools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/compile/cheese.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Cython/Parser/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/run/includes/a.h: -------------------------------------------------------------------------------- 1 | int a = 1; -------------------------------------------------------------------------------- /tests/broken/invalid-module-name.pyx: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/run/includes/b.h: -------------------------------------------------------------------------------- 1 | int b = a+1; -------------------------------------------------------------------------------- /tests/run/includes/c.h: -------------------------------------------------------------------------------- 1 | int c = b+1; -------------------------------------------------------------------------------- /tests/run/includes/d.h: -------------------------------------------------------------------------------- 1 | int d = c+1; -------------------------------------------------------------------------------- /tests/run/includes/e.h: -------------------------------------------------------------------------------- 1 | int e = d+1; -------------------------------------------------------------------------------- /Cython/Runtime/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /Cython/Tests/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /tests/run/filenames.pxi: -------------------------------------------------------------------------------- 1 | spam = u"ftang" 2 | -------------------------------------------------------------------------------- /Cython/Build/Tests/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /Cython/Compiler/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /Cython/Debugger/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /tests/compile/a/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /tests/compile/a/b.pxd: -------------------------------------------------------------------------------- 1 | cdef int **foo(void*) 2 | -------------------------------------------------------------------------------- /tests/compile/dotted_cimport_submodule/a.pxd: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/compile/ewing9.pxd: -------------------------------------------------------------------------------- 1 | cdef struct xmlDoc 2 | -------------------------------------------------------------------------------- /tests/run/autotestdict.pxd: -------------------------------------------------------------------------------- 1 | # I just exist 2 | -------------------------------------------------------------------------------- /Cython/Compiler/Tests/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /Cython/Debugger/Tests/__init__.py: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /Cython/Includes/libc/__init__.pxd: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /Cython/Includes/posix/__init__.pxd: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /Demos/libraries/mymath.h: -------------------------------------------------------------------------------- 1 | double sinc(double); 2 | -------------------------------------------------------------------------------- /tests/compile/altet1.h: -------------------------------------------------------------------------------- 1 | typedef int blarg; 2 | 3 | -------------------------------------------------------------------------------- /docs/src/changes.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../CHANGES.rst 2 | -------------------------------------------------------------------------------- /tests/run/includes/indirect_d.pxd: -------------------------------------------------------------------------------- 1 | from d cimport d 2 | -------------------------------------------------------------------------------- /Cython/Debugger/Tests/cfuncs.h: -------------------------------------------------------------------------------- 1 | void some_c_function(void); 2 | -------------------------------------------------------------------------------- /Cython/Includes/libcpp/pair.pxd: -------------------------------------------------------------------------------- 1 | from .utility cimport pair 2 | -------------------------------------------------------------------------------- /Demos/embed/embedded.output: -------------------------------------------------------------------------------- 1 | __main__ 2 | Hi, I'm embedded. 3 | -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | coverage 3 | pycodestyle 4 | -------------------------------------------------------------------------------- /tests/broken/cimportfunc.pyx: -------------------------------------------------------------------------------- 1 | from cexportfunc cimport f, g 2 | -------------------------------------------------------------------------------- /tests/broken/includepublic.pyx: -------------------------------------------------------------------------------- 1 | include "i_public.pxi" 2 | 3 | -------------------------------------------------------------------------------- /tests/broken/naanou_1.pyx: -------------------------------------------------------------------------------- 1 | def f(a, *p, **n): 2 | pass 3 | -------------------------------------------------------------------------------- /tests/broken/r_classmodname.pyx: -------------------------------------------------------------------------------- 1 | class Spam: 2 | pass 3 | -------------------------------------------------------------------------------- /tests/run/cpdef_optargs_pure.pxd: -------------------------------------------------------------------------------- 1 | cpdef func(x, y=*, z=*) 2 | -------------------------------------------------------------------------------- /tests/broken/r_tbfilename.pyx: -------------------------------------------------------------------------------- 1 | def foo(): 2 | raise Exception 3 | -------------------------------------------------------------------------------- /tests/compile/belchenko2.h: -------------------------------------------------------------------------------- 1 | void c_func(unsigned char pixel); 2 | -------------------------------------------------------------------------------- /tests/compile/dotted_cimport_submodule/__init__.pyx: -------------------------------------------------------------------------------- 1 | # empty file 2 | -------------------------------------------------------------------------------- /tests/errors/pxd_cdef_class_declaration_T286.pxd: -------------------------------------------------------------------------------- 1 | cdef class A 2 | -------------------------------------------------------------------------------- /tests/run/complex_numbers_c89_T398.h: -------------------------------------------------------------------------------- 1 | #define CYTHON_CCOMPLEX 0 2 | -------------------------------------------------------------------------------- /tests/run/testinclude.pxi: -------------------------------------------------------------------------------- 1 | # this will be included 2 | 3 | D = 2 4 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/to_unicode.pxd: -------------------------------------------------------------------------------- 1 | cdef unicode _text(s) 2 | -------------------------------------------------------------------------------- /tests/errors/e_nogilcmeth.pxd: -------------------------------------------------------------------------------- 1 | cdef class C: 2 | cdef void f(self) 3 | -------------------------------------------------------------------------------- /tests/errors/empty.pyx: -------------------------------------------------------------------------------- 1 | # cython: autotestdict=False 2 | # mode: error 3 | -------------------------------------------------------------------------------- /tests/run/extmember.pxd: -------------------------------------------------------------------------------- 1 | cdef class Spam: 2 | cdef public Spam e 3 | -------------------------------------------------------------------------------- /tests/run/includes/b.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "b.h": 2 | cdef int b 3 | -------------------------------------------------------------------------------- /tests/run/includes/d.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "d.h": 2 | cdef int d 3 | -------------------------------------------------------------------------------- /Cython/Build/Distutils.py: -------------------------------------------------------------------------------- 1 | from Cython.Distutils.build_ext import build_ext 2 | -------------------------------------------------------------------------------- /tests/broken/getattr3ref.pyx: -------------------------------------------------------------------------------- 1 | cdef int f() except -1: 2 | g = getattr3 3 | -------------------------------------------------------------------------------- /tests/broken/r_simpcall.pyx: -------------------------------------------------------------------------------- 1 | def f(): 2 | print "Spam!" 3 | 4 | f() 5 | -------------------------------------------------------------------------------- /tests/errors/nogilcmeth.pxd: -------------------------------------------------------------------------------- 1 | cdef class C: 2 | cdef void f(self) nogil 3 | -------------------------------------------------------------------------------- /tests/run/crashT245.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int x; 3 | } MyStruct; 4 | 5 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/volume.pxd: -------------------------------------------------------------------------------- 1 | cdef float cube(float) 2 | -------------------------------------------------------------------------------- /tests/broken/externfunc.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "foo.h": 2 | 3 | int fred() 4 | -------------------------------------------------------------------------------- /tests/broken/l_capi.pyx: -------------------------------------------------------------------------------- 1 | cdef api float f(float x): 2 | return 0.5 * x * x 3 | -------------------------------------------------------------------------------- /tests/broken/r_classdoc.pyx: -------------------------------------------------------------------------------- 1 | class Spam: 2 | """Spam, glorious spam!""" 3 | 4 | -------------------------------------------------------------------------------- /tests/compile/hinsen1.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | PyObject_HEAD 3 | } PySpamObject; 4 | -------------------------------------------------------------------------------- /tests/compile/watts2.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef int x 4 | x = 0xFFFFFFFF 5 | -------------------------------------------------------------------------------- /tests/run/cdef_opt.pxd: -------------------------------------------------------------------------------- 1 | cdef class A: 2 | cpdef foo(self, bint a=*, b=*) 3 | -------------------------------------------------------------------------------- /tests/compile/builtin.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(): 4 | x = open("foo") 5 | -------------------------------------------------------------------------------- /tests/compile/drake1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef char *s 4 | s = r'\"HT\"' 5 | -------------------------------------------------------------------------------- /tests/compile/ewing8.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Blarg: 4 | pass 5 | -------------------------------------------------------------------------------- /tests/compile/ewing9.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef struct xmlDoc: 4 | int i 5 | -------------------------------------------------------------------------------- /tests/compile/jiba4.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class A: 4 | cdef object x 5 | -------------------------------------------------------------------------------- /tests/errors/e_bufaccess_pxd.pxd: -------------------------------------------------------------------------------- 1 | # See e_bufaccess2.pyx 2 | 3 | ctypedef nothing T 4 | -------------------------------------------------------------------------------- /tests/errors/pure_cclass_without_body.pxd: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef class Test 4 | -------------------------------------------------------------------------------- /tests/run/dynamic_attributes.pxd: -------------------------------------------------------------------------------- 1 | cdef class MegaSpam: 2 | cdef dict __dict__ 3 | -------------------------------------------------------------------------------- /tests/run/includes/includefile.pxi: -------------------------------------------------------------------------------- 1 | # this file will be included 2 | 3 | XYZ = 5 4 | -------------------------------------------------------------------------------- /tests/run/pass.pyx: -------------------------------------------------------------------------------- 1 | def f(): 2 | """ 3 | >>> f() 4 | """ 5 | pass 6 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/lunch.h: -------------------------------------------------------------------------------- 1 | void eject_tomato(float speed); 2 | -------------------------------------------------------------------------------- /tests/broken/tslots.pyx: -------------------------------------------------------------------------------- 1 | cdef class Spam: 2 | pass 3 | 4 | def probe(): 5 | pass 6 | -------------------------------------------------------------------------------- /tests/compile/assert2.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(a, b): 4 | assert a, a+b 5 | -------------------------------------------------------------------------------- /tests/compile/carrdecl.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern: 4 | cdef func(int[]) 5 | -------------------------------------------------------------------------------- /tests/compile/coventry1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Tst: 4 | cdef foo, 5 | -------------------------------------------------------------------------------- /tests/run/cimport_alias_subclass_helper.pxd: -------------------------------------------------------------------------------- 1 | cdef class Base: 2 | cdef bint foo(self) 3 | -------------------------------------------------------------------------------- /tests/run/inlinepxd.pxd: -------------------------------------------------------------------------------- 1 | 2 | cdef inline int my_add(int a, int b): 3 | return a + b 4 | -------------------------------------------------------------------------------- /tests/broken/cimportfrompkgdir.pyx: -------------------------------------------------------------------------------- 1 | from package.inpackage cimport Spam 2 | 3 | cdef Spam s2 4 | -------------------------------------------------------------------------------- /tests/compile/globalonly.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | global __name__ 4 | print __name__ 5 | 6 | -------------------------------------------------------------------------------- /Cython/Build/__init__.py: -------------------------------------------------------------------------------- 1 | from .Dependencies import cythonize 2 | from .Distutils import build_ext 3 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/examples/quickstart/build/hello.pyx: -------------------------------------------------------------------------------- 1 | def say_hello_to(name): 2 | print("Hello %s!" % name) 3 | -------------------------------------------------------------------------------- /tests/broken/r_getattr3.pyx: -------------------------------------------------------------------------------- 1 | def test(obj, attr, dflt): 2 | return getattr3(obj, attr, dflt) 3 | -------------------------------------------------------------------------------- /tests/compile/omittedargnames.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern void spam(int, char *) 4 | 5 | -------------------------------------------------------------------------------- /tests/errors/encoding.pyx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/tests/errors/encoding.pyx -------------------------------------------------------------------------------- /Doc/s5/ui/default/blank.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/Doc/s5/ui/default/blank.gif -------------------------------------------------------------------------------- /Doc/s5/ui/default/bodybg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/Doc/s5/ui/default/bodybg.gif -------------------------------------------------------------------------------- /docs/_static/cythonlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/_static/cythonlogo.png -------------------------------------------------------------------------------- /docs/src/quickstart/sage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/src/quickstart/sage.png -------------------------------------------------------------------------------- /tests/compile/cdefexternfromstar.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern from *: 4 | int spam 5 | 6 | -------------------------------------------------------------------------------- /tests/compile/ewing3.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class C: 4 | cdef f(self): 5 | pass 6 | -------------------------------------------------------------------------------- /tests/compile/ewing5.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef char *f(): 4 | raise Exception 5 | 6 | f() 7 | -------------------------------------------------------------------------------- /tests/compile/ishimoto4.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void __stdcall f(): 4 | pass 5 | 6 | f() 7 | -------------------------------------------------------------------------------- /tests/compile/lepage_2.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef struct BB: 4 | void (*f) (void* state) 5 | -------------------------------------------------------------------------------- /tests/compile/none.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void spam(): 4 | eggs = None 5 | 6 | spam() 7 | -------------------------------------------------------------------------------- /tests/run/check_fused_types_pxd.pxd: -------------------------------------------------------------------------------- 1 | cimport cython 2 | 3 | unresolved_t = cython.fused_type(int, float) 4 | -------------------------------------------------------------------------------- /tests/run/pinard6.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> x 3 | (1, 2) 4 | """ 5 | 6 | x = 1, 7 | x = 1, 2, 8 | -------------------------------------------------------------------------------- /tests/run/static_methods.pxd: -------------------------------------------------------------------------------- 1 | cdef class FromPxd: 2 | @staticmethod 3 | cdef static_cdef(int* x) 4 | -------------------------------------------------------------------------------- /docs/examples/userguide/extension_types/my_module.pxd: -------------------------------------------------------------------------------- 1 | cdef class Shrubbery: 2 | cdef int width, height 3 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/volume.pyx: -------------------------------------------------------------------------------- 1 | cdef float cube(float x): 2 | return x * x * x 3 | -------------------------------------------------------------------------------- /tests/broken/cexportfunc.pyx: -------------------------------------------------------------------------------- 1 | cdef int f(): 2 | pass 3 | 4 | cdef char *g(int k, float z): 5 | pass 6 | -------------------------------------------------------------------------------- /tests/compile/cdefexternempty.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern from "cheese.h": 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /tests/compile/pyclass.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | class Spam: 4 | 5 | def eggs(self): 6 | pass 7 | -------------------------------------------------------------------------------- /docs/examples/quickstart/cythonize/cdef_keyword.pyx: -------------------------------------------------------------------------------- 1 | cdef double f(double x) except? -2: 2 | return x ** 2 - x 3 | -------------------------------------------------------------------------------- /docs/src/quickstart/jupyter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/src/quickstart/jupyter.png -------------------------------------------------------------------------------- /docs/src/tutorial/htmlreport.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/src/tutorial/htmlreport.png -------------------------------------------------------------------------------- /pyximport/__init__.py: -------------------------------------------------------------------------------- 1 | from .pyximport import * 2 | 3 | # replicate docstring 4 | from .pyximport import __doc__ 5 | -------------------------------------------------------------------------------- /tests/broken/r_extweakref.pyx: -------------------------------------------------------------------------------- 1 | cdef class Animal: 2 | cdef object __weakref__ 3 | cdef public object name 4 | -------------------------------------------------------------------------------- /tests/compile/globalstmt.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(): 4 | global a,b,c,d 5 | a = b 6 | c = d 7 | -------------------------------------------------------------------------------- /tests/run/cpdef_extern_func_in_py.pxd: -------------------------------------------------------------------------------- 1 | 2 | cdef extern from "math.h": 3 | cpdef double pxd_sqrt "sqrt"(double) 4 | -------------------------------------------------------------------------------- /tests/run/inlinepxd_support.pxd: -------------------------------------------------------------------------------- 1 | 2 | cdef inline int my_add(int a, int b=1, int c=0): 3 | return a + b + c 4 | -------------------------------------------------------------------------------- /tests/run/str_encoding_latin1.pyx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/tests/run/str_encoding_latin1.pyx -------------------------------------------------------------------------------- /Demos/libraries/mymath.c: -------------------------------------------------------------------------------- 1 | #include "math.h" 2 | 3 | double sinc(double x) { 4 | return x == 0 ? 1 : sin(x)/x; 5 | } 6 | -------------------------------------------------------------------------------- /Doc/s5/ui/default/cython-logo64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/Doc/s5/ui/default/cython-logo64.png -------------------------------------------------------------------------------- /docs/.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | 3 | *.pyc 4 | *~ 5 | .*.swp 6 | 7 | syntax: regexp 8 | ^build/ 9 | ^_build/ 10 | -------------------------------------------------------------------------------- /docs/_static/cython-logo-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/_static/cython-logo-light.png -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/c_lunch.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "lunch.h": 2 | void eject_tomato(float) 3 | -------------------------------------------------------------------------------- /docs/src/quickstart/htmlreport.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/src/quickstart/htmlreport.png -------------------------------------------------------------------------------- /tests/broken/l_cfuncexport.pyx: -------------------------------------------------------------------------------- 1 | cdef int f(int x): 2 | return x * x 3 | 4 | cdef int g(int x): 5 | return 5 * x 6 | -------------------------------------------------------------------------------- /tests/broken/retconvert.pyx: -------------------------------------------------------------------------------- 1 | def f(): 2 | return 42 3 | 4 | cdef int g(): 5 | cdef object x 6 | return x 7 | -------------------------------------------------------------------------------- /tests/compile/ewing4.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void f(): 4 | "This is a pseudo doc string." 5 | 6 | f() 7 | -------------------------------------------------------------------------------- /tests/compile/excvalreturn.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef int spam() except -1: 4 | eggs = 42 5 | 6 | spam() 7 | -------------------------------------------------------------------------------- /tests/compile/food.h: -------------------------------------------------------------------------------- 1 | struct Tomato { 2 | PyObject_HEAD 3 | }; 4 | 5 | struct Bicycle{ 6 | PyObject_HEAD 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /tests/compile/formfeed.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef int x 4 | 5 | x = 42 6 | 7 | 8 | y = 88 9 | 10 | -------------------------------------------------------------------------------- /tests/compile/longunsigned.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern unsigned long x 4 | cdef extern long unsigned y 5 | -------------------------------------------------------------------------------- /tests/run/ass2local.pyx: -------------------------------------------------------------------------------- 1 | def f(): 2 | """ 3 | >>> f() 4 | 42 5 | """ 6 | a = 42 7 | return a 8 | -------------------------------------------------------------------------------- /tests/run/crashT245_pxd.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "crashT245.h": 2 | ctypedef struct MyStruct: 3 | int x 4 | 5 | -------------------------------------------------------------------------------- /tests/run/r_jiba1.pxd: -------------------------------------------------------------------------------- 1 | cdef class Parrot: 2 | cdef void describe(self) 3 | 4 | cdef class Norwegian(Parrot): 5 | pass 6 | -------------------------------------------------------------------------------- /tests/run/unicodeliteralslatin1.pyx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/tests/run/unicodeliteralslatin1.pyx -------------------------------------------------------------------------------- /docs/src/tutorial/python_division.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/src/tutorial/python_division.png -------------------------------------------------------------------------------- /tests/compile/burton1.pyx.BROKEN: -------------------------------------------------------------------------------- 1 | cdef void f(): 2 | cdef void (*p)() 3 | p = 0 4 | (p)() 5 | -------------------------------------------------------------------------------- /tests/compile/exthash.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __hash__(self): 6 | pass 7 | 8 | -------------------------------------------------------------------------------- /tests/compile/extindex.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __index__(self): 6 | return 42 7 | -------------------------------------------------------------------------------- /tests/compile/ishimoto1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class A: 4 | 5 | def __getitem__(self, x): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/pxd_override_T230.pxd: -------------------------------------------------------------------------------- 1 | cdef class A: 2 | cpdef foo(self) 3 | 4 | cdef class B(A): 5 | cpdef foo(self) 6 | -------------------------------------------------------------------------------- /tests/compile/slicex.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(a, b, c, d, e, f, g, h, i): 4 | a = b[c:d, e:f:g, ..., h, :i:] 5 | -------------------------------------------------------------------------------- /tests/run/cpp_exceptions_nogil_helper.h: -------------------------------------------------------------------------------- 1 | void foo(int i) { 2 | if (i==0) 3 | return; 4 | else 5 | throw i; 6 | } 7 | -------------------------------------------------------------------------------- /tests/run/struct_conversion_extern_header.h: -------------------------------------------------------------------------------- 1 | struct my_date_t { 2 | int year; 3 | int month; 4 | int day; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/run/verbatiminclude.h: -------------------------------------------------------------------------------- 1 | static long cube(long x) 2 | { 3 | return x * x * x; 4 | } 5 | 6 | #define long broken_long 7 | -------------------------------------------------------------------------------- /Cython/Debugger/Tests/cfuncs.c: -------------------------------------------------------------------------------- 1 | void 2 | some_c_function(void) 3 | { 4 | int a, b, c; 5 | 6 | a = 1; 7 | b = 2; 8 | } 9 | -------------------------------------------------------------------------------- /tests/compile/ctypedefclass.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef class spam: 4 | pass 5 | 6 | cdef spam s 7 | 8 | s = None 9 | -------------------------------------------------------------------------------- /tests/compile/declandimpl.pxd: -------------------------------------------------------------------------------- 1 | cdef struct Sandwich: 2 | int i 3 | char *s 4 | 5 | cdef class Tomato: 6 | cdef float danger 7 | -------------------------------------------------------------------------------- /tests/compile/extdelattr.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __delattr__(self, n): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/extdelitem.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __delitem__(self, i): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/extdescrdel.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Foo: 4 | 5 | def __delete__(self, i): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/extdescrget.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Foo: 4 | 5 | def __get__(self, i, c): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/extdescrset.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Foo: 4 | 5 | def __set__(self, i, v): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/extgetattr.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __getattr__(self, x): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/extpropertydoc.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | property eggs: 6 | 7 | "Ova" 8 | -------------------------------------------------------------------------------- /tests/compile/extsetattr.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __setattr__(self, n, x): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/extsetitem.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __setitem__(self, i, x): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/compile/johnson2.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class C: 4 | 5 | cdef object foo 6 | cdef object __weakref__ 7 | -------------------------------------------------------------------------------- /tests/compile/nonctypedefclass.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class spam: 4 | pass 5 | 6 | cdef spam s 7 | 8 | s = None 9 | -------------------------------------------------------------------------------- /tests/errors/invalid_hex_escape0.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | '\x' 4 | 5 | _ERRORS = ''' 6 | 3:1: Invalid hex escape '\x' 7 | ''' 8 | -------------------------------------------------------------------------------- /tests/errors/invalid_hex_escape1.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | '\x1' 4 | 5 | _ERRORS = ''' 6 | 3:1: Invalid hex escape '\x' 7 | ''' 8 | -------------------------------------------------------------------------------- /tests/run/ref2local.pyx: -------------------------------------------------------------------------------- 1 | def f(): 2 | """ 3 | >>> f() 4 | 42 5 | """ 6 | a = 42 7 | b = a 8 | return b 9 | -------------------------------------------------------------------------------- /Cython/Distutils/__init__.py: -------------------------------------------------------------------------------- 1 | from Cython.Distutils.build_ext import build_ext 2 | from Cython.Distutils.extension import Extension 3 | -------------------------------------------------------------------------------- /docs/examples/tutorial/external/libc_sin.pyx: -------------------------------------------------------------------------------- 1 | from libc.math cimport sin 2 | 3 | cdef double f(double x): 4 | return sin(x * x) 5 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/dostuff.py: -------------------------------------------------------------------------------- 1 | def dostuff(n): 2 | t = 0 3 | for i in range(n): 4 | t += i 5 | return t 6 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/shrubbing.pxd: -------------------------------------------------------------------------------- 1 | cdef class Shrubbery: 2 | cdef int width 3 | cdef int length 4 | -------------------------------------------------------------------------------- /docs/src/userguide/compute_typed_html.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/cython/master/docs/src/userguide/compute_typed_html.jpg -------------------------------------------------------------------------------- /tests/broken/big_t.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "foo.h": 2 | ctypedef long long big_t 3 | cdef void spam(big_t b) 4 | 5 | spam(grail) 6 | -------------------------------------------------------------------------------- /tests/broken/pkg.cimport.pyx: -------------------------------------------------------------------------------- 1 | cimport spam, eggs 2 | 3 | cdef extern spam.Spam yummy 4 | cdef eggs.Eggs fried 5 | 6 | fried = None 7 | -------------------------------------------------------------------------------- /tests/compile/dotted_cimport.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cimport dotted_cimport_submodule.a 4 | import dotted_cimport_submodule.b 5 | -------------------------------------------------------------------------------- /tests/compile/extgetitem.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __getitem__(self, x): 6 | pass 7 | 8 | -------------------------------------------------------------------------------- /tests/errors/invalid_uescape.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | u'\uXYZ' 4 | 5 | _ERRORS = ''' 6 | 3:2: Invalid unicode escape '\u' 7 | ''' 8 | -------------------------------------------------------------------------------- /tests/errors/invalid_uescape0.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | u'\u' 4 | 5 | _ERRORS = ''' 6 | 3:2: Invalid unicode escape '\u' 7 | ''' 8 | -------------------------------------------------------------------------------- /tests/errors/invalid_uescape2.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | u'\u12' 4 | 5 | _ERRORS = ''' 6 | 3:2: Invalid unicode escape '\u' 7 | ''' 8 | -------------------------------------------------------------------------------- /tests/memoryview/memoryview.pxd: -------------------------------------------------------------------------------- 1 | ctypedef float ext_dtype 2 | 3 | cdef extern from "bufaccess.h": 4 | ctypedef float td_h_double 5 | -------------------------------------------------------------------------------- /tests/run/fmod.pyx: -------------------------------------------------------------------------------- 1 | def fmod(double a, double b): 2 | """ 3 | >>> fmod(7, 1.25) 4 | 0.75 5 | """ 6 | return a % b 7 | -------------------------------------------------------------------------------- /Demos/libraries/call_mymath.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "mymath.h": 2 | double sinc(double) 3 | 4 | def call_sinc(x): 5 | return sinc(x) 6 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/dostuff.pxd: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | @cython.locals(t=cython.int, i=cython.int) 4 | cpdef int dostuff(int n) 5 | -------------------------------------------------------------------------------- /test-requirements-cpython.txt: -------------------------------------------------------------------------------- 1 | jupyter 2 | line_profiler 3 | # transitive dependency of jupyter (17.0+ lacks wheels for Py3.4) 4 | pyzmq<17 5 | -------------------------------------------------------------------------------- /tests/broken/r_cfuncimport.pyx: -------------------------------------------------------------------------------- 1 | cimport l_cfuncexport 2 | from l_cfuncexport cimport g 3 | 4 | print l_cfuncexport.f(42) 5 | print g(42) 6 | -------------------------------------------------------------------------------- /tests/compile/cimport_package_module_T4.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 4 2 | # mode: compile 3 | 4 | from a cimport b 5 | 6 | cdef int **t = b.foo(NULL) 7 | -------------------------------------------------------------------------------- /tests/compile/extern_packed_struct.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern from *: 4 | cdef packed struct MyStruct: 5 | char a 6 | -------------------------------------------------------------------------------- /tests/compile/jiba5.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(): 4 | cdef int i=0 5 | global mylist 6 | del mylist[i] 7 | return 8 | -------------------------------------------------------------------------------- /tests/errors/futurebraces.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | from __future__ import braces 4 | 5 | _ERRORS = u""" 6 | 3:23: not a chance 7 | """ 8 | -------------------------------------------------------------------------------- /tests/run/overflow_check_int.pyx: -------------------------------------------------------------------------------- 1 | # cython: overflowcheck.fold = True 2 | 3 | 4 | ctypedef int INT 5 | 6 | include "overflow_check.pxi" 7 | -------------------------------------------------------------------------------- /tests/run/strconstinclass.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> c = C() 3 | >>> c.x 4 | 'foo' 5 | """ 6 | 7 | class C: 8 | x = "foo" 9 | -------------------------------------------------------------------------------- /tests/run/wundram1.pyx: -------------------------------------------------------------------------------- 1 | """ 2 | >>> x == 5 or repr(x) 3 | True 4 | """ 5 | 6 | 7 | cdef unsigned int ui 8 | ui = 5 9 | x = ui 10 | -------------------------------------------------------------------------------- /Cython/Includes/libcpp/__init__.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from *: 2 | ctypedef bint bool 3 | ctypedef void* nullptr_t 4 | nullptr_t nullptr 5 | -------------------------------------------------------------------------------- /Cython/Includes/posix/ioctl.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "" nogil: 2 | enum: FIONBIO 3 | 4 | int ioctl(int fd, int request, ...) 5 | -------------------------------------------------------------------------------- /docs/examples/tutorial/external/keyword_args.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "string.h": 2 | char* strstr(const char *haystack, const char *needle) 3 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/cython_declare2.py: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | cython.declare(x=cython.int, y=cython.double) # cdef int x; cdef double y 4 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/api_func.pyx: -------------------------------------------------------------------------------- 1 | from to_unicode cimport _text 2 | 3 | def api_func(s): 4 | text_input = _text(s) 5 | # ... 6 | -------------------------------------------------------------------------------- /docs/src/reference/limitations.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: cython 2 | 3 | .. _limitations: 4 | 5 | *********** 6 | Limitations 7 | *********** 8 | 9 | -------------------------------------------------------------------------------- /tests/compile/argdefault.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef swallow 4 | 5 | def spam(w, int x = 42, y = "grail", z = swallow): 6 | pass 7 | 8 | -------------------------------------------------------------------------------- /tests/compile/cpdef.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class A: 4 | cpdef a(self): 5 | ma(self) 6 | 7 | cpdef ma(x): 8 | print x 9 | -------------------------------------------------------------------------------- /tests/compile/extimported.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern class Spam.Eggs.Ham: 4 | pass 5 | 6 | cdef Ham ham 7 | 8 | ham = None 9 | -------------------------------------------------------------------------------- /tests/compile/kleckner1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(x,): 4 | pass 5 | 6 | cdef void g(int x,): 7 | pass 8 | 9 | g(0) 10 | -------------------------------------------------------------------------------- /tests/cygwin_bugs.txt: -------------------------------------------------------------------------------- 1 | complex_numbers_c89_T398_long_double 2 | complex_numbers_T305_long_double 3 | int_float_builtins_as_casts_T400_long_double 4 | -------------------------------------------------------------------------------- /tests/run/cmethod_inline_T474.pxd: -------------------------------------------------------------------------------- 1 | cdef class TestInlineMethod(object): 2 | cdef inline int cdef_inline_method(self): 3 | return 0 4 | -------------------------------------------------------------------------------- /tests/run/complex_numbers_cxx_T398.h: -------------------------------------------------------------------------------- 1 | #if defined(__cplusplus) 2 | #define CYTHON_CCOMPLEX 1 3 | #else 4 | #define CYTHON_CCOMPLEX 0 5 | #endif 6 | -------------------------------------------------------------------------------- /tests/run/kostyrka2.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> x = X() 3 | >>> x.slots 4 | [''] 5 | """ 6 | 7 | class X: 8 | slots = ["", ] 9 | -------------------------------------------------------------------------------- /Demos/callback/cheesefinder.h: -------------------------------------------------------------------------------- 1 | typedef void (*cheesefunc)(char *name, void *user_data); 2 | void find_cheeses(cheesefunc user_func, void *user_data); 3 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/c_func.pxd: -------------------------------------------------------------------------------- 1 | cdef char* c_call_returning_a_c_string() 2 | cdef void get_a_c_string(char** c_string, Py_ssize_t *length) 3 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/lunch.pyx: -------------------------------------------------------------------------------- 1 | cimport c_lunch 2 | 3 | def eject_tomato(float speed): 4 | c_lunch.eject_tomato(speed) 5 | -------------------------------------------------------------------------------- /docs/src/reference/directives.rst: -------------------------------------------------------------------------------- 1 | Compiler Directives 2 | =================== 3 | 4 | See `Compilation `_. 5 | -------------------------------------------------------------------------------- /tests/broken/r_import.pyx: -------------------------------------------------------------------------------- 1 | import spam 2 | print "Imported spam" 3 | print dir(spam) 4 | 5 | import sys 6 | print "Imported sys" 7 | print sys 8 | 9 | -------------------------------------------------------------------------------- /tests/compile/coercetovoidptr.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void f(): 4 | cdef void *p 5 | cdef char *q=NULL 6 | p = q 7 | 8 | f() 9 | -------------------------------------------------------------------------------- /tests/compile/fromimport_star.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | from spam import * 4 | from ...spam.foo import * 5 | from . import * 6 | from ... import * 7 | -------------------------------------------------------------------------------- /tests/compile/getattr3ref.pyx.BROKEN: -------------------------------------------------------------------------------- 1 | __doc__ = """ 2 | >>> print f() 3 | """ 4 | 5 | def f(): 6 | g = getattr3 7 | return g.__name__ 8 | -------------------------------------------------------------------------------- /tests/run/extclasspass.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> e = Eggs() 3 | >>> type(e).__name__ 4 | 'Eggs' 5 | """ 6 | 7 | cdef class Eggs: pass 8 | -------------------------------------------------------------------------------- /tests/run/overflow_check_longlong.pyx: -------------------------------------------------------------------------------- 1 | # cython: overflowcheck.fold = False 2 | 3 | 4 | ctypedef long long INT 5 | 6 | include "overflow_check.pxi" 7 | -------------------------------------------------------------------------------- /tests/run/overflow_check_uint.pyx: -------------------------------------------------------------------------------- 1 | # cython: overflowcheck.fold = False 2 | 3 | 4 | ctypedef unsigned int INT 5 | 6 | include "overflow_check.pxi" 7 | -------------------------------------------------------------------------------- /tests/wrappers/cpp_references_helper.h: -------------------------------------------------------------------------------- 1 | 2 | int ref_var_value = 10; 3 | int& ref_var = ref_var_value; 4 | 5 | int& ref_func(int& x) { return x; } 6 | -------------------------------------------------------------------------------- /docs/examples/tutorial/cdef_classes/math_function_2.pyx: -------------------------------------------------------------------------------- 1 | cdef class Function: 2 | cpdef double evaluate(self, double x) except *: 3 | return 0 4 | -------------------------------------------------------------------------------- /docs/examples/tutorial/external/cpdef_sin.pyx: -------------------------------------------------------------------------------- 1 | """ 2 | >>> sin(0) 3 | 0.0 4 | """ 5 | 6 | cdef extern from "math.h": 7 | cpdef double sin(double x) 8 | -------------------------------------------------------------------------------- /docs/examples/tutorial/profiling_tutorial/often_called.pyx: -------------------------------------------------------------------------------- 1 | cimport cython 2 | 3 | @cython.profile(False) 4 | def my_often_called_function(): 5 | pass 6 | -------------------------------------------------------------------------------- /docs/examples/userguide/extension_types/python_access.pyx: -------------------------------------------------------------------------------- 1 | cdef class Shrubbery: 2 | cdef public int width, height 3 | cdef readonly float depth 4 | -------------------------------------------------------------------------------- /tests/compile/emptytry.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void f(): 4 | try: 5 | pass 6 | finally: 7 | pass 8 | 9 | f() 10 | -------------------------------------------------------------------------------- /tests/compile/extdelslice.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __delslice__(self, Py_ssize_t i, Py_ssize_t j): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/errors/e_assnone.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef void spam(): 4 | None = 42 5 | _ERRORS = u""" 6 | 4:1: Cannot assign to or delete this 7 | """ 8 | -------------------------------------------------------------------------------- /tests/run/complex_numbers_c89_T398.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 398 2 | 3 | cdef extern from "complex_numbers_c89_T398.h": pass 4 | include "complex_numbers_T305.pyx" 5 | -------------------------------------------------------------------------------- /tests/run/complex_numbers_c99_T398.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 398 2 | 3 | cdef extern from "complex_numbers_c99_T398.h": pass 4 | include "complex_numbers_T305.pyx" 5 | -------------------------------------------------------------------------------- /tests/run/complex_numbers_cxx_T398.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 398 2 | 3 | cdef extern from "complex_numbers_cxx_T398.h": pass 4 | include "complex_numbers_T305.pyx" 5 | -------------------------------------------------------------------------------- /tests/run/file_encoding_T740.py: -------------------------------------------------------------------------------- 1 | # encoding: koi8-r 2 | # mode: run 3 | # ticket: 740 4 | """ 5 | >>> wtf 6 | 'wtf' 7 | """ 8 | 9 | wtf = 'wtf' 10 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = True 3 | parallel = True 4 | concurrency = multiprocessing,thread 5 | include = Cython/* 6 | source = Cython 7 | omit = Test* 8 | -------------------------------------------------------------------------------- /Demos/run_numeric_demo.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import numpy_demo 3 | 4 | a = numpy.array([1.0, 3.5, 8.4, 2.3, 6.6, 4.1], "d") 5 | numpy_demo.sum_of_squares(a) 6 | -------------------------------------------------------------------------------- /bin/cythonize: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # command line frontend for cythonize() 5 | # 6 | 7 | from Cython.Build.Cythonize import main 8 | main() 9 | -------------------------------------------------------------------------------- /cygdb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | from Cython.Debugger import Cygdb as cygdb 6 | 7 | if __name__ == '__main__': 8 | cygdb.main() 9 | -------------------------------------------------------------------------------- /tests/broken/getattr.pyx: -------------------------------------------------------------------------------- 1 | cdef class Spam: 2 | cdef public object eggs 3 | 4 | def __getattr__(self, name): 5 | print "Spam getattr:", name 6 | -------------------------------------------------------------------------------- /tests/broken/pkg.cimportfrom.pyx: -------------------------------------------------------------------------------- 1 | from spam cimport Spam 2 | from eggs cimport Eggs 3 | 4 | cdef extern Spam yummy 5 | cdef Eggs fried 6 | 7 | fried = None 8 | -------------------------------------------------------------------------------- /tests/buffers/bufaccess.h: -------------------------------------------------------------------------------- 1 | /* See bufaccess.pyx */ 2 | 3 | typedef short td_h_short; 4 | typedef double td_h_double; 5 | typedef unsigned short td_h_ushort; 6 | -------------------------------------------------------------------------------- /tests/compile/behnel4.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef enum E: 4 | spam, eggs 5 | 6 | cdef E f() except spam: 7 | return eggs 8 | 9 | f() 10 | -------------------------------------------------------------------------------- /tests/compile/builtinbuffer.py: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | import cython 3 | 4 | @cython.cclass 5 | class BuiltinRef: 6 | cython.declare(pybuf = 'Py_buffer') 7 | 8 | -------------------------------------------------------------------------------- /tests/compile/extpropertydel.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | property eggs: 6 | 7 | def __del__(self): 8 | pass 9 | -------------------------------------------------------------------------------- /tests/compile/extsetslice.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | def __setslice__(self, Py_ssize_t i, Py_ssize_t j, x): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/errors/invalid_cast.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | a = True 5 | 6 | _ERRORS = u""" 7 | 4:9: 'foao' is not a type identifier 8 | """ 9 | -------------------------------------------------------------------------------- /tests/memoryview/bufaccess.h: -------------------------------------------------------------------------------- 1 | /* See bufaccess.pyx */ 2 | 3 | typedef short td_h_short; 4 | typedef double td_h_double; 5 | typedef unsigned short td_h_ushort; 6 | -------------------------------------------------------------------------------- /tests/run/behnel3.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> y 3 | >>> y or {} 4 | {} 5 | >>> x 6 | {} 7 | """ 8 | 9 | y = None 10 | x = y or {} 11 | -------------------------------------------------------------------------------- /tests/run/cpp_class_redef.pxd: -------------------------------------------------------------------------------- 1 | # tag: cpp 2 | 3 | cdef extern cppclass Foo: 4 | int _foo 5 | void set_foo(int foo) nogil 6 | int get_foo() nogil 7 | -------------------------------------------------------------------------------- /tests/run/filenames.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> print(spam) 3 | ftang 4 | >>> foo 5 | 42 6 | """ 7 | 8 | include "filenames.pxi" 9 | 10 | foo = 42 11 | -------------------------------------------------------------------------------- /tests/run/overflow_check_ulonglong.pyx: -------------------------------------------------------------------------------- 1 | # cython: overflowcheck.fold = True 2 | 3 | 4 | ctypedef unsigned long long INT 5 | 6 | include "overflow_check.pxi" 7 | -------------------------------------------------------------------------------- /Demos/callback/run_cheese.py: -------------------------------------------------------------------------------- 1 | import cheese 2 | 3 | def report_cheese(name): 4 | print("Found cheese: " + name) 5 | 6 | cheese.find(report_cheese) 7 | 8 | 9 | -------------------------------------------------------------------------------- /bin/cygdb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | from Cython.Debugger import Cygdb as cygdb 6 | 7 | if __name__ == '__main__': 8 | cygdb.main() 9 | -------------------------------------------------------------------------------- /bin/cython: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Cython -- Main Program, Unix 5 | # 6 | 7 | from Cython.Compiler.Main import main 8 | main(command_line = 1) 9 | -------------------------------------------------------------------------------- /docs/src/reference/special_mention.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: cython 2 | 3 | .. _special_mention: 4 | 5 | 6 | *************** 7 | Special Mention 8 | *************** 9 | -------------------------------------------------------------------------------- /tests/broken/cimportfrom.pyx: -------------------------------------------------------------------------------- 1 | from spam cimport Spam 2 | from pkg.eggs cimport Eggs as ova 3 | 4 | cdef extern Spam yummy 5 | cdef ova fried 6 | 7 | fried = None 8 | -------------------------------------------------------------------------------- /tests/compile/ctypedef.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef int *IntPtr 4 | ctypedef unsigned long ULong 5 | cdef extern IntPtr spam 6 | cdef extern ULong grail 7 | -------------------------------------------------------------------------------- /tests/compile/extpropertyset.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | property eggs: 6 | 7 | def __set__(self, x): 8 | pass 9 | -------------------------------------------------------------------------------- /tests/errors/invalid_uescapeN.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | u'\N{GIBBET NICH}' 4 | 5 | _ERRORS = ''' 6 | 3:2: Unknown Unicode character name 'GIBBET NICH' 7 | ''' 8 | -------------------------------------------------------------------------------- /tests/run/pure_cdef_class_property_decorator_T264.pxd: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # ticket: 264 3 | # tag: property, decorator 4 | 5 | cdef class Prop: 6 | cdef _value 7 | -------------------------------------------------------------------------------- /tests/broken/r_newstyleclass.pyx: -------------------------------------------------------------------------------- 1 | class Inquisition(object): 2 | """Something that nobody expects.""" 3 | 4 | def __repr__(self): 5 | return "Surprise!" 6 | -------------------------------------------------------------------------------- /tests/compile/cverylongtypes.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern short int s 4 | cdef extern long int l 5 | cdef extern long long ll 6 | cdef extern long double ld 7 | -------------------------------------------------------------------------------- /tests/compile/import.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(): 4 | import spam 5 | import spam.eggs 6 | import spam, eggs, ham 7 | import spam as tasty 8 | 9 | -------------------------------------------------------------------------------- /tests/compile/pinard4.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | __doc__ = u""" 4 | >>> fiches_CP 5 | [] 6 | """ 7 | 8 | fiches_CP = [1,2,3] 9 | fiches_CP[:] = [] 10 | -------------------------------------------------------------------------------- /tests/run/behnel2.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> y 3 | 1 4 | >>> y and {} 5 | {} 6 | >>> x 7 | {} 8 | """ 9 | 10 | y = 1 11 | x = y and {} 12 | -------------------------------------------------------------------------------- /tests/run/define_macro_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef DEFINE_NO_VALUE 3 | #define VAL (DEFINE_WITH_VALUE + 1) 4 | #else 5 | #define VAL DEFINE_WITH_VALUE 6 | #endif 7 | -------------------------------------------------------------------------------- /tests/run/dietachmayer1.pyx: -------------------------------------------------------------------------------- 1 | def test(): 2 | """ 3 | >>> test() 4 | 1.0 5 | """ 6 | cdef float[10][10] v 7 | v[1][2] = 1.0 8 | return v[1][2] 9 | -------------------------------------------------------------------------------- /tests/run/extlen.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> len(Spam()) 3 | 0 4 | """ 5 | 6 | cdef class Spam: 7 | 8 | def __len__(self): 9 | return 0 10 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/annotations.py: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | def func(foo: dict, bar: cython.int) -> tuple: 4 | foo["hello world"] = 3 + bar 5 | return foo, 5 6 | -------------------------------------------------------------------------------- /tests/compile/ellipsis_T488.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 488 2 | # mode: compile 3 | #from ... import foo 4 | 5 | print ... 6 | def test(): 7 | x = ... 8 | assert x is Ellipsis 9 | -------------------------------------------------------------------------------- /tests/compile/extforward.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam 4 | 5 | cdef class Grail: 6 | cdef Spam spam 7 | 8 | cdef class Spam: 9 | pass 10 | 11 | -------------------------------------------------------------------------------- /tests/compile/extpropertyget.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | property eggs: 6 | 7 | def __get__(self): 8 | pass 9 | 10 | -------------------------------------------------------------------------------- /tests/errors/e_func_in_pxd_support.pxd: -------------------------------------------------------------------------------- 1 | cdef foo(): 2 | return 1 3 | 4 | cdef public inline foo2(): 5 | return 1 6 | 7 | cdef api inline foo3(): 8 | return 1 9 | -------------------------------------------------------------------------------- /tests/errors/fused_syntax.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef fused my_fused_type: int a; char b 4 | 5 | _ERRORS = u""" 6 | fused_syntax.pyx:3:26: Expected a newline 7 | """ 8 | -------------------------------------------------------------------------------- /tests/errors/se_mixtabspace.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | a = b # space space 5 | c = d # tab 6 | _ERRORS = u""" 7 | 5:0: Mixed use of tabs and spaces 8 | """ 9 | -------------------------------------------------------------------------------- /docs/examples/tutorial/external/py_version_hex.pyx: -------------------------------------------------------------------------------- 1 | from cpython.version cimport PY_VERSION_HEX 2 | 3 | # Python version >= 3.2 final ? 4 | print(PY_VERSION_HEX >= 0x030200F0) 5 | -------------------------------------------------------------------------------- /docs/examples/userguide/wrapping_CPlusPlus/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | from Cython.Build import cythonize 4 | 5 | setup(ext_modules=cythonize("rect.pyx")) 6 | -------------------------------------------------------------------------------- /tests/broken/fwddeclcclass.pyx: -------------------------------------------------------------------------------- 1 | cdef class Widget: 2 | pass 3 | 4 | cdef class Container: 5 | pass 6 | 7 | cdef Widget w 8 | cdef Container c 9 | w.parent = c 10 | -------------------------------------------------------------------------------- /tests/compile/arraytoptrarg.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void f1(char *argv[]): 4 | f2(argv) 5 | 6 | cdef void f2(char *argv[]): 7 | pass 8 | 9 | f1(NULL) 10 | -------------------------------------------------------------------------------- /tests/compile/complexbasetype.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern (int *[42]) spam, grail, swallow 4 | 5 | cdef (int (*)()) brian(): 6 | return NULL 7 | 8 | brian() 9 | -------------------------------------------------------------------------------- /tests/compile/cunsignedlong.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void f(): 4 | cdef unsigned long x 5 | cdef object y=0 6 | x = y 7 | y = x 8 | 9 | f() 10 | -------------------------------------------------------------------------------- /tests/compile/nullptr.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef char *p1 4 | cdef int *p2 5 | cdef int x 6 | 7 | p1 = NULL 8 | p2 = NULL 9 | x = p1 == NULL 10 | x = NULL == p2 11 | -------------------------------------------------------------------------------- /tests/compile/withgil.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void f() with gil: 4 | x = 42 5 | 6 | cdef int g(void* x) with gil: 7 | pass 8 | 9 | f() 10 | g("test") 11 | -------------------------------------------------------------------------------- /tests/errors/se_badindent.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | a = b # space space 5 | c = d # space tab 6 | _ERRORS = u""" 7 | 5:0: Mixed use of tabs and spaces 8 | """ 9 | -------------------------------------------------------------------------------- /tests/run/complex_numbers_c89_T398_long_double.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 398 2 | 3 | cdef extern from "complex_numbers_c89_T398.h": pass 4 | include "complex_numbers_T305_long_double.pyx" 5 | -------------------------------------------------------------------------------- /tests/run/cpdef_extern_func.pxd: -------------------------------------------------------------------------------- 1 | # cython: c_string_type=str 2 | # cython: c_string_encoding=ascii 3 | 4 | cdef extern from "math.h": 5 | cpdef double pxd_sqrt "sqrt"(double) 6 | -------------------------------------------------------------------------------- /tests/run/cstringmeth.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> y 3 | ('1', '2', '3') 4 | >>> x 5 | '1foo2foo3' 6 | """ 7 | 8 | 9 | y = ('1','2','3') 10 | 11 | x = 'foo'.join(y) 12 | -------------------------------------------------------------------------------- /tests/run/include.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> D 3 | 2 4 | >>> XYZ 5 | 5 6 | """ 7 | 8 | D = 1 9 | 10 | include "testinclude.pxi" 11 | include "includes/includefile.pxi" 12 | -------------------------------------------------------------------------------- /tests/run/ticket_124.pyx: -------------------------------------------------------------------------------- 1 | def spam(dict d): 2 | """ 3 | >>> spam(dict(test=2)) 4 | False 5 | """ 6 | for elm in d: 7 | return False 8 | return True 9 | -------------------------------------------------------------------------------- /tests/run/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | This header is present to test effects of misdeclaring 3 | types Cython-side. 4 | */ 5 | typedef long actually_long_t; 6 | typedef short actually_short_t; 7 | -------------------------------------------------------------------------------- /docs/examples/tutorial/cython_tutorial/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from Cython.Build import cythonize 3 | 4 | setup( 5 | ext_modules=cythonize("fib.pyx"), 6 | ) 7 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/locals.py: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | @cython.locals(a=cython.long, b=cython.long, n=cython.longlong) 4 | def foo(a, b, x, y): 5 | n = a * b 6 | # ... 7 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/C_func_file.h: -------------------------------------------------------------------------------- 1 | #ifndef C_FUNC_FILE_H 2 | #define C_FUNC_FILE_H 3 | 4 | void multiply_by_10_in_C(double arr[], unsigned int n); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /docs/src/quickstart/index.rst: -------------------------------------------------------------------------------- 1 | Getting Started 2 | =============== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | overview 8 | install 9 | build 10 | cythonize 11 | -------------------------------------------------------------------------------- /tests/broken/plex2.pyx: -------------------------------------------------------------------------------- 1 | cdef class Spam: 2 | pass 3 | 4 | cdef void foo(object blarg): 5 | pass 6 | 7 | cdef void xyzzy(): 8 | cdef Spam spam 9 | foo(spam) 10 | -------------------------------------------------------------------------------- /tests/broken/test_include_options.pyx: -------------------------------------------------------------------------------- 1 | import sys 2 | from Pyrex.Compiler.Main import main 3 | 4 | sys.argv[1:] = "-I spam -Ieggs --include-dir ham".split() 5 | main(command_line = 1) 6 | -------------------------------------------------------------------------------- /tests/compile/cpp_templated_ctypedef.pyx: -------------------------------------------------------------------------------- 1 | # tag: cpp 2 | # mode: compile 3 | 4 | cdef extern from *: 5 | cdef cppclass Foo[T]: 6 | pass 7 | ctypedef Foo[int] IntFoo 8 | -------------------------------------------------------------------------------- /tests/compile/del.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(a, b): 4 | global g 5 | del g 6 | del a[b] 7 | del a[b][42] 8 | del a.spam 9 | del a.spam.eggs 10 | -------------------------------------------------------------------------------- /tests/errors/e_cdef_missing_declarator.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef int 4 | 5 | cdef extern from *: 6 | void f(int) 7 | _ERRORS = u""" 8 | 3:8: Empty declarator 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/pure_cclass_without_body.py: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | class Test(object): 4 | pass 5 | 6 | _ERRORS = u""" 7 | 3:5: C class 'Test' is declared but not defined 8 | """ 9 | -------------------------------------------------------------------------------- /tests/run/nononetypecheck.pyx: -------------------------------------------------------------------------------- 1 | cdef class Spam: 2 | pass 3 | 4 | cdef f(Spam s): 5 | pass 6 | 7 | def g(): 8 | """ 9 | >>> g() 10 | """ 11 | f(None) 12 | -------------------------------------------------------------------------------- /docs/examples/tutorial/array/safe_usage.pyx: -------------------------------------------------------------------------------- 1 | from cpython cimport array 2 | import array 3 | cdef array.array a = array.array('i', [1, 2, 3]) 4 | cdef int[:] ca = a 5 | 6 | print(ca[0]) 7 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/compiled_switch.py: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | if cython.compiled: 4 | print("Yep, I'm compiled.") 5 | else: 6 | print("Just a lowly interpreted script.") 7 | -------------------------------------------------------------------------------- /tests/broken/r_capi.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "l_capi_api.h": 2 | float f(float) 3 | int import_l_capi() except -1 4 | 5 | def test(): 6 | print f(3.1415) 7 | 8 | import_l_capi() 9 | -------------------------------------------------------------------------------- /tests/broken/raise.pyx: -------------------------------------------------------------------------------- 1 | def f(a, b, c): 2 | #raise 3 | raise a 4 | raise "spam" 5 | raise a, b 6 | raise "spam", 42 7 | raise a, b, c 8 | raise "spam", 42, c() 9 | -------------------------------------------------------------------------------- /tests/compile/constexpr.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef enum Grail: 4 | k = 42 5 | 6 | cdef enum Spam: 7 | a = -1 8 | b = 2 + 3 9 | c = 42 > 17 10 | d = k 11 | -------------------------------------------------------------------------------- /tests/compile/ctypedefenum.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef enum parrot_state: 4 | alive = 1 5 | dead = 2 6 | 7 | cdef parrot_state polly 8 | 9 | polly = dead 10 | 11 | -------------------------------------------------------------------------------- /tests/compile/ctypedefunion.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef union pet: 4 | int cat 5 | float dog 6 | 7 | cdef pet sam 8 | 9 | sam.cat = 1 10 | sam.dog = 2.7 11 | 12 | -------------------------------------------------------------------------------- /tests/compile/hinsen2.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class vector: 4 | def __div__(vector self, double factor): 5 | cdef object result = vector() 6 | return result 7 | -------------------------------------------------------------------------------- /tests/run/anonymousenum.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> p 3 | 42 4 | """ 5 | 6 | cdef enum: 7 | spam = 42 8 | grail = 17 9 | 10 | cdef int i 11 | i = spam 12 | 13 | p = i 14 | -------------------------------------------------------------------------------- /tests/run/numpy_ValueError_T172.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 172 2 | # tag: numpy 3 | 4 | __doc__ = u""" 5 | >>> 1 6 | 1 7 | """ 8 | cimport numpy 9 | class ValueError(object): pass 10 | -------------------------------------------------------------------------------- /tests/run/numpy_cimport.pyx: -------------------------------------------------------------------------------- 1 | # tag: numpy 2 | 3 | """ 4 | >>> import sys 5 | >>> 'numpy' in sys.modules 6 | True 7 | """ 8 | cimport numpy as np 9 | include "numpy_common.pxi" 10 | -------------------------------------------------------------------------------- /Cython/Tempita/__init__.py: -------------------------------------------------------------------------------- 1 | # The original Tempita implements all of its templating code here. 2 | # Moved it to _tempita.py to make the compilation portable. 3 | 4 | from ._tempita import * 5 | -------------------------------------------------------------------------------- /Demos/embed/embedded.pyx: -------------------------------------------------------------------------------- 1 | # cython: language_level=3 2 | 3 | print(__name__) 4 | 5 | if __name__ == "__main__": 6 | print("Hi, I'm embedded.") 7 | else: 8 | print("I'm being imported.") 9 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/someheader.h: -------------------------------------------------------------------------------- 1 | typedef const char specialChar; 2 | int process_string(const char* s); 3 | const unsigned char* look_up_cached_string(const unsigned char* key); 4 | -------------------------------------------------------------------------------- /docs/examples/userguide/extension_types/widen_shrubbery.pyx: -------------------------------------------------------------------------------- 1 | from my_module cimport Shrubbery 2 | 3 | cdef widen_shrubbery(Shrubbery sh, extra_width): 4 | sh.width = sh.width + extra_width 5 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/kwargs_2.pyx: -------------------------------------------------------------------------------- 1 | def g(a, b, *, c, d): 2 | ... 3 | 4 | # We cannot call g with less verbosity than this. 5 | foo = g(4.0, "something", c=68, d="other") 6 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/dishes.pxd: -------------------------------------------------------------------------------- 1 | cdef enum otherstuff: 2 | sausage, eggs, lettuce 3 | 4 | cdef struct spamdish: 5 | int oz_of_spam 6 | otherstuff filler 7 | -------------------------------------------------------------------------------- /setupegg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Wrapper to run setup.py using setuptools.""" 3 | import setuptools 4 | with open('setup.py') as f: 5 | exec(compile(f.read(), 'setup.py', 'exec')) 6 | -------------------------------------------------------------------------------- /tests/compile/pxd_override_T230.py: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | class A: 4 | def foo(self): 5 | return "A" 6 | 7 | class B(A): 8 | def foo(self): 9 | return "B" 10 | -------------------------------------------------------------------------------- /tests/compile/specmethextarg.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | cdef int eggs 5 | 6 | def __iadd__(self, Spam other): 7 | self.eggs = self.eggs + other.eggs 8 | 9 | -------------------------------------------------------------------------------- /tests/errors/callingnonexisting_T307.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 307 2 | # mode: error 3 | 4 | nonexisting(3, with_kw_arg=4) 5 | 6 | _ERRORS = u""" 7 | 4:0: undeclared name not builtin: nonexisting 8 | """ 9 | -------------------------------------------------------------------------------- /tests/errors/e2_packedstruct_T290.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 290 2 | # mode: error 3 | 4 | cdef packed foo: 5 | pass 6 | 7 | _ERRORS = u""" 8 | 4:12: Expected 'struct', found 'foo' 9 | """ 10 | -------------------------------------------------------------------------------- /tests/run/kostyrka.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> t = TEST() 3 | >>> 1 in t 4 | True 5 | """ 6 | 7 | cdef class TEST: 8 | def __contains__(self, x): 9 | return 42 10 | -------------------------------------------------------------------------------- /tests/run/r_jeff_epler_1.pyx: -------------------------------------------------------------------------------- 1 | def blowup(p): 2 | """ 3 | >>> blowup([2, 3, 5]) 4 | 1 5 | """ 6 | cdef int n, i 7 | n = 10 8 | i = 1 9 | return n % p[i] 10 | -------------------------------------------------------------------------------- /docs/examples/quickstart/build/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from Cython.Build import cythonize 3 | 4 | setup(name='Hello world app', 5 | ext_modules=cythonize("hello.pyx")) 6 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/A.pxd: -------------------------------------------------------------------------------- 1 | cpdef int myfunction(int x, int y=*) 2 | cdef double _helper(double a) 3 | 4 | cdef class A: 5 | cdef public int a, b 6 | cpdef foo(self, double x) 7 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/cython_declare.py: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | x = cython.declare(cython.int) # cdef int x 4 | y = cython.declare(cython.double, 0.57721) # cdef double y = 0.57721 5 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/mymodule.pxd: -------------------------------------------------------------------------------- 1 | # mymodule.pxd 2 | 3 | # declare a C function as "cpdef" to export it to the module 4 | cdef extern from "math.h": 5 | cpdef double sin(double x) 6 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/arg_memview.pyx: -------------------------------------------------------------------------------- 1 | def process_byte_data(unsigned char[:] data): 2 | length = data.shape[0] 3 | first_byte = data[0] 4 | slice_view = data[1:-1] 5 | # ... 6 | -------------------------------------------------------------------------------- /tests/broken/b_extimpinherit.pyx: -------------------------------------------------------------------------------- 1 | cdef class Parrot: 2 | 3 | cdef describe(self): 4 | print "This is a parrot." 5 | 6 | cdef action(self): 7 | print "Polly wants a cracker!" 8 | -------------------------------------------------------------------------------- /tests/broken/r_traceback.pyx: -------------------------------------------------------------------------------- 1 | cdef int spam() except -1: 2 | raise Exception("Spam error") 3 | 4 | cdef int grail() except -1: 5 | spam() 6 | 7 | def tomato(): 8 | grail() 9 | 10 | -------------------------------------------------------------------------------- /tests/compile/globvardef.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef int a_global_int 4 | cdef a_global_pyobject 5 | 6 | a_global_int = 0 7 | a_global_pyobject = None 8 | 9 | cdef object unused 10 | -------------------------------------------------------------------------------- /tests/compile/johnson1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef enum foo: 4 | FOO 5 | 6 | cdef void func(): 7 | cdef foo x 8 | map = [FOO] 9 | x = map[0] 10 | 11 | func() 12 | -------------------------------------------------------------------------------- /tests/compile/parallel_compile_float_rank.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | from cython.parallel import * 4 | cdef ssize_t i 5 | with nogil, parallel(): 6 | for i in range(10): 7 | pass 8 | 9 | -------------------------------------------------------------------------------- /tests/errors/pep448_syntax_1.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep448 3 | 4 | def unpack_mix(): 5 | [*1, **1] 6 | 7 | 8 | _ERRORS = """ 9 | 5:9: Expected an identifier or literal 10 | """ 11 | -------------------------------------------------------------------------------- /tests/run/inline.pyx: -------------------------------------------------------------------------------- 1 | def test(x): 2 | """ 3 | >>> test(3) 4 | 3 5 | """ 6 | return retinput(x) 7 | 8 | cdef inline int retinput(int x): 9 | o = x 10 | return o 11 | -------------------------------------------------------------------------------- /tests/run/r_print.pyx: -------------------------------------------------------------------------------- 1 | def frighten(): 2 | """ 3 | >>> frighten() 4 | NOBODY expects the Spanish Inquisition! 5 | """ 6 | print u"NOBODY", u"expects", u"the Spanish Inquisition!" 7 | -------------------------------------------------------------------------------- /tests/run/varargdecl.pyx: -------------------------------------------------------------------------------- 1 | cdef grail(char *blarg, ...): 2 | pass 3 | 4 | def test(): 5 | """ 6 | >>> test() 7 | """ 8 | grail(b"test") 9 | grail(b"test", b"toast") 10 | -------------------------------------------------------------------------------- /cythonize.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Cython -- enhanced main program 5 | # 6 | 7 | if __name__ == '__main__': 8 | from Cython.Build.Cythonize import main 9 | main() 10 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/for_char.pyx: -------------------------------------------------------------------------------- 1 | cdef char* c_string = "Hello to A C-string's world" 2 | 3 | cdef char c 4 | for c in c_string[:11]: 5 | if c == 'A': 6 | print("Found the letter A") 7 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/naive_decode.pyx: -------------------------------------------------------------------------------- 1 | from c_func cimport c_call_returning_a_c_string 2 | 3 | cdef char* some_c_string = c_call_returning_a_c_string() 4 | ustring = some_c_string.decode('UTF-8') 5 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from Cython.Build import cythonize 3 | 4 | setup(ext_modules=cythonize(["landscaping.pyx", "shrubbing.pyx"])) 5 | -------------------------------------------------------------------------------- /tests/compile/cpp_nogil.h: -------------------------------------------------------------------------------- 1 | struct NoGilTest1 { 2 | NoGilTest1() { } 3 | void doSomething() { } 4 | }; 5 | 6 | struct NoGilTest2 { 7 | NoGilTest2() { } 8 | void doSomething() { } 9 | }; 10 | -------------------------------------------------------------------------------- /tests/compile/libc_errno.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | from libc.errno cimport * 4 | 5 | if errno == EDOM : pass 6 | if errno == EILSEQ : pass 7 | if errno == ERANGE : pass 8 | 9 | errno = 0 10 | -------------------------------------------------------------------------------- /tests/errors/cdef_in_pyclass.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | class Pyclass(object): 4 | cdef bad(self): 5 | pass 6 | 7 | _ERRORS = """ 8 | 4:9: cdef statement not allowed here 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/e_badpyparam.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef struct Foo 4 | 5 | def f(Foo *p): 6 | pass 7 | _ERRORS = u""" 8 | 5:6: Cannot convert Python object argument to type 'Foo *' 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/e_cdef_in_py.py: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def func(): 4 | cdef int i 5 | 6 | 7 | _ERRORS = """ 8 | 4:4: The 'cdef' keyword is only allowed in Cython files (pyx/pxi/pxd) 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/e_sizeofincomplete.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef struct unbekannt 4 | cdef int n 5 | n = sizeof(unbekannt) 6 | _ERRORS = u""" 7 | 5:4: Cannot take sizeof incomplete type 'unbekannt' 8 | """ 9 | -------------------------------------------------------------------------------- /tests/errors/pep448_syntax_2.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep448 3 | 4 | def unpack_wrong_stars(): 5 | [**1] 6 | 7 | 8 | _ERRORS = """ 9 | 5:5: Expected an identifier or literal 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/pep492_badsyntax_async9.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep492, async 3 | 4 | async def foo(): 5 | await 6 | 7 | _ERRORS = """ 8 | 5:9: Expected an identifier or literal 9 | """ 10 | -------------------------------------------------------------------------------- /tests/memoryview/memview_assignments.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | # tag: memoryview 3 | 4 | cdef double[::1] contig 5 | # see if we can assign a strided value to a contiguous one 6 | contig[:] = contig[::2] 7 | -------------------------------------------------------------------------------- /tests/run/addressof.pyx: -------------------------------------------------------------------------------- 1 | def f(int a): 2 | """ 3 | >>> f(5) 4 | 5 5 | """ 6 | cdef int i,j 7 | cdef int *p 8 | i = a 9 | p = &i 10 | j = p[0] 11 | return j 12 | -------------------------------------------------------------------------------- /tests/run/empty_declarators.pyx: -------------------------------------------------------------------------------- 1 | cpdef zed(short, long, complex, x): 2 | """ 3 | >>> zed(short=1, long=2, complex=3, x=4) 4 | (1, 2, 3, 4) 5 | """ 6 | return short, long, complex, x 7 | -------------------------------------------------------------------------------- /tests/run/extinstantiate.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> type(f()).__name__ 3 | 'Spam' 4 | """ 5 | 6 | cdef class Spam: 7 | pass 8 | 9 | def f(): 10 | s = Spam() 11 | return s 12 | -------------------------------------------------------------------------------- /tests/run/watts1.pyx: -------------------------------------------------------------------------------- 1 | def test(): 2 | """ 3 | >>> test() == 55 + 66 4 | True 5 | """ 6 | cdef int a,b 7 | cdef object foo = (55,66) 8 | a,b = foo 9 | return a + b 10 | -------------------------------------------------------------------------------- /Demos/integrate0.py: -------------------------------------------------------------------------------- 1 | def f(x): 2 | return x**2-x 3 | 4 | def integrate_f(a, b, N): 5 | s = 0.0 6 | dx = (b-a)/N 7 | for i in range(N): 8 | s += f(a+i*dx) 9 | return s * dx 10 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/for_bytes.pyx: -------------------------------------------------------------------------------- 1 | cdef bytes bytes_string = b"hello to A bytes' world" 2 | 3 | cdef char c 4 | for c in bytes_string: 5 | if c == 'A': 6 | print("Found the letter A") 7 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/kwargs_1.pyx: -------------------------------------------------------------------------------- 1 | def f(a, b, *args, c, d = 42, e, **kwds): 2 | ... 3 | 4 | 5 | # We cannot call f with less verbosity than this. 6 | foo = f(4, "bar", c=68, e=1.0) 7 | -------------------------------------------------------------------------------- /tests/broken/cascadedass.pyx: -------------------------------------------------------------------------------- 1 | cdef void foo(): 2 | cdef int i, j, k 3 | i = j = k 4 | a = b = c 5 | i = j = c 6 | a = b = k 7 | (a, b), c = (d, e), f = (x, y), z 8 | # a, b = p, q = x, y 9 | -------------------------------------------------------------------------------- /tests/compile/utf8bom.pyx: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # mode: compile 3 | 4 | # this file starts with a UTF-8 encoded BOM 5 | # the only thing we test is that it properly compiles 6 | 7 | def test(): 8 | pass 9 | -------------------------------------------------------------------------------- /tests/errors/pep492_badsyntax_async5.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep492, async 3 | 4 | def foo(): 5 | await list() 6 | 7 | _ERRORS = """ 8 | 5:10: Syntax error in simple statement list 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/pep492_badsyntax_async7.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep492, async 3 | 4 | async def foo(): 5 | yield from [] 6 | 7 | _ERRORS = """ 8 | 5:4: 'yield from' not supported here 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/pxd_cdef_class_declaration_T286.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 286 2 | # mode: error 3 | 4 | cdef class A: 5 | pass 6 | 7 | _ERRORS = u""" 8 | 1:5: C class 'A' is declared but not defined 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/se_badindent2.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | a = b 5 | c = d 6 | _ERRORS = u""" 7 | 5:0: Possible inconsistent indentation 8 | 5:0: Expected an identifier or literal 9 | """ 10 | -------------------------------------------------------------------------------- /tests/compile/extargdefault.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern class somewhere.Swallow: 4 | pass 5 | 6 | cdef Swallow swallow 7 | 8 | def spam(x = swallow, Swallow y = swallow): 9 | pass 10 | -------------------------------------------------------------------------------- /tests/compile/extimportedsubtype.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | from crunchytype cimport Crunchy 4 | 5 | cdef class Sub2(Crunchy): 6 | cdef char character 7 | 8 | cdef class Sub1(Sub2): 9 | pass 10 | -------------------------------------------------------------------------------- /tests/compile/khavkine1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class T: 4 | cdef int[1] a 5 | 6 | cdef object b 7 | 8 | cdef void f(void *obj): 9 | ( obj).a[0] = 1 10 | 11 | b = None 12 | f(NULL) 13 | -------------------------------------------------------------------------------- /tests/errors/e_cdef_closure.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cpdef cpdef_yield(): 4 | def inner(): 5 | pass 6 | 7 | _ERRORS = u""" 8 | 3:6: closures inside cpdef functions not yet supported 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/e_decorators.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | _ERRORS = u""" 4 | 4:4 Expected a newline after decorator 5 | """ 6 | 7 | 8 | class A: 9 | pass 10 | 11 | @A().a 12 | def f(): 13 | pass 14 | -------------------------------------------------------------------------------- /tests/errors/pep448_syntax_3.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep448 3 | 4 | def unpack_mix_in_set(): 5 | {*1, **2} 6 | 7 | 8 | _ERRORS = """ 9 | 5:9: unexpected **item found in set literal 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/pep492_badsyntax_async8.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep492, async 3 | 4 | async def foo(): 5 | await await fut 6 | 7 | _ERRORS = """ 8 | 5:10: Expected an identifier or literal 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/void_as_arg.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef extern from *: 4 | void foo(void) 5 | 6 | _ERRORS = u""" 7 | 4:13:Use spam() rather than spam(void) to declare a function with no arguments. 8 | """ 9 | -------------------------------------------------------------------------------- /Cython/Utility/TestCyUtilityLoader.pyx: -------------------------------------------------------------------------------- 1 | ########## TestCyUtilityLoader ########## 2 | #@requires: OtherUtility 3 | 4 | test {{cy_loader}} impl 5 | 6 | 7 | ########## OtherUtility ########## 8 | req {{cy_loader}} impl 9 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/exceptval.py: -------------------------------------------------------------------------------- 1 | import cython 2 | 3 | @cython.exceptval(-1) 4 | def func(x: cython.int) -> cython.int: 5 | if x < 0: 6 | raise ValueError("need integer >= 0") 7 | return x + 1 8 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/transpose.pyx: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | array = np.arange(20, dtype=np.intc).reshape((2, 10)) 4 | 5 | cdef int[:, ::1] c_contig = array 6 | cdef int[::1, :] f_contig = c_contig.T 7 | -------------------------------------------------------------------------------- /tests/compile/constcast.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | from libc.stdlib cimport malloc, free 3 | 4 | cdef void f(): 5 | cdef const int **allocated = malloc(sizeof(int *)) 6 | free(allocated) 7 | 8 | f() 9 | -------------------------------------------------------------------------------- /tests/compile/declandimpl.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Tomato: 4 | 5 | def eject(self): 6 | pass 7 | 8 | cdef extern Sandwich butty 9 | cdef Tomato supertom 10 | 11 | supertom = None 12 | -------------------------------------------------------------------------------- /tests/compile/notnonearg.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern class external.Spam [object Spam]: pass 4 | cdef extern class external.Eggs [object Eggs]: pass 5 | 6 | def ham(Spam s, Eggs e not None): 7 | pass 8 | -------------------------------------------------------------------------------- /tests/compile/traceback.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def spam(): 4 | raise Exception 5 | 6 | cdef int grail() except -1: 7 | raise Exception 8 | 9 | def tomato(): 10 | spam() 11 | grail() 12 | -------------------------------------------------------------------------------- /tests/compile/types_and_names.pxd: -------------------------------------------------------------------------------- 1 | cdef struct point: 2 | double x 3 | double y 4 | double z 5 | 6 | cdef foo(int, int i, 7 | list, list L, 8 | point, point p, point* ps) 9 | 10 | -------------------------------------------------------------------------------- /tests/errors/mod_errors.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def mod_complex(): 4 | x = (1.1+2.0j) % 4 5 | return x 6 | 7 | _ERRORS = """ 8 | 4:19: mod operator not supported for type 'double complex' 9 | """ 10 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/auto_conversion_3.pyx: -------------------------------------------------------------------------------- 1 | # cython: c_string_type=unicode, c_string_encoding=ascii 2 | 3 | def func(): 4 | ustring = u'abc' 5 | cdef char* s = ustring 6 | return s[0] # returns u'a' 7 | -------------------------------------------------------------------------------- /tests/broken/cimport.pyx: -------------------------------------------------------------------------------- 1 | cimport spam 2 | cimport pkg.eggs 3 | 4 | cdef spam.Spam yummy 5 | cdef pkg.eggs.Eggs fried 6 | 7 | spam.eat(yummy) 8 | spam.tons = 3.14 9 | ova = pkg.eggs 10 | fried = pkg.eggs.Eggs() 11 | -------------------------------------------------------------------------------- /tests/compile/specmethargdefault.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Grail: 4 | 5 | def __cinit__(self, spam = None): 6 | pass 7 | 8 | def __init__(self, parrot = 42): 9 | pass 10 | 11 | -------------------------------------------------------------------------------- /tests/errors/e_bitop.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | cdef int int1, int2 5 | cdef char *ptr 6 | int1 = int2 | ptr # error 7 | _ERRORS = u""" 8 | 6:13: Invalid operand types for '|' (int; char *) 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/e_numop.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | cdef int int1, int2 5 | cdef int *ptr 6 | int1 = int2 * ptr # error 7 | _ERRORS = u""" 8 | 6:13: Invalid operand types for '*' (int; int *) 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/missing_self_in_cpdef_method_T156.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 156 2 | # mode: error 3 | 4 | cdef class B: 5 | cpdef b(): 6 | pass 7 | 8 | _ERRORS = u""" 9 | 5:10: C method has no self argument 10 | """ 11 | -------------------------------------------------------------------------------- /tests/run/typeofexttype.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: exttype 3 | 4 | 5 | cdef class Spam: 6 | pass 7 | 8 | 9 | def test(): 10 | """ 11 | >>> test() 12 | """ 13 | cdef type t 14 | t = Spam 15 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/for_unicode.pyx: -------------------------------------------------------------------------------- 1 | cdef unicode ustring = u'Hello world' 2 | 3 | # NOTE: no typing required for 'uchar' ! 4 | for uchar in ustring: 5 | if uchar == u'A': 6 | print("Found the letter A") 7 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/optional_subclassing.pxd: -------------------------------------------------------------------------------- 1 | cdef class A: 2 | cdef foo(self) 3 | 4 | cdef class B(A): 5 | cdef foo(self, x=*) 6 | 7 | cdef class C(B): 8 | cpdef foo(self, x=*, int k=*) 9 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/memory_layout_2.pyx: -------------------------------------------------------------------------------- 1 | from cython cimport view 2 | 3 | # VALID 4 | cdef int[::view.indirect, ::1, :] a 5 | cdef int[::view.indirect, :, ::1] b 6 | cdef int[::view.indirect_contiguous, ::1, :] c 7 | -------------------------------------------------------------------------------- /tests/broken/i_public.pyx: -------------------------------------------------------------------------------- 1 | cdef public int grail 2 | 3 | cdef public spam(int servings): 4 | pass 5 | 6 | cdef public class sandwich [object sandwich, type sandwich_Type]: 7 | cdef int tomato 8 | cdef float lettuce 9 | -------------------------------------------------------------------------------- /tests/compile/ewing1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef int blarg(int i): 4 | pass 5 | 6 | cdef void foo(): 7 | cdef float f=0 8 | cdef int i 9 | if blarg( f): 10 | pass 11 | 12 | foo() 13 | -------------------------------------------------------------------------------- /tests/errors/notcimportedT418.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 418 2 | # mode: error 3 | 4 | import somemod.child 5 | 6 | cdef somemod.child.something x 7 | 8 | _ERRORS = u""" 9 | 6:5: 'somemod.child' is not a cimported module 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/typoT304.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 304 2 | # mode: error 3 | 4 | def f(): 5 | print assert sizeof(int) == sizof(short) == sizeof(long) 6 | 7 | _ERRORS = u""" 8 | 5:10: Expected an identifier or literal 9 | """ 10 | -------------------------------------------------------------------------------- /tests/run/bishop2.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> f = foo() 3 | >>> 'a' in f 4 | True 5 | >>> 1 in f 6 | True 7 | """ 8 | 9 | cdef class foo: 10 | 11 | def __contains__(self, key): 12 | return 1 13 | -------------------------------------------------------------------------------- /tests/run/crashT245.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 245 2 | 3 | cimport crashT245_pxd 4 | 5 | def f(): 6 | """ 7 | >>> f() 8 | {'x': 1} 9 | """ 10 | cdef crashT245_pxd.MyStruct s 11 | s.x = 1 12 | print s 13 | -------------------------------------------------------------------------------- /tests/run/menten1.pyx: -------------------------------------------------------------------------------- 1 | def loops(): 2 | """ 3 | >>> loops() 4 | 5 5 | """ 6 | cdef int k 7 | for i from 0 <= i < 5: 8 | for j from 0 <= j < 2: 9 | k = i + j 10 | return k 11 | -------------------------------------------------------------------------------- /Demos/callback/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | python Setup.py build_ext --inplace 3 | 4 | test: all 5 | python run_cheese.py 6 | 7 | clean: 8 | @echo Cleaning Demos/callback 9 | @rm -f cheese.c *.o *.so *~ core 10 | @rm -rf build 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/clibraries/queue.pyx: -------------------------------------------------------------------------------- 1 | # queue.pyx 2 | 3 | cimport cqueue 4 | 5 | cdef class Queue: 6 | cdef cqueue.Queue* _c_queue 7 | 8 | def __cinit__(self): 9 | self._c_queue = cqueue.queue_new() 10 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/const.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "someheader.h": 2 | ctypedef const char specialChar 3 | int process_string(const char* s) 4 | const unsigned char* look_up_cached_string(const unsigned char* key) 5 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/np_flag_const.pyx: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | cdef const double[:] myslice # const item type => read-only view 4 | 5 | a = np.linspace(0, 10, num=50) 6 | a.setflags(write=False) 7 | myslice = a 8 | -------------------------------------------------------------------------------- /tests/broken/r_unpack.pyx: -------------------------------------------------------------------------------- 1 | seq = [1, [2, 3]] 2 | 3 | def f(): 4 | a, (b, c) = [1, [2, 3]] 5 | print a 6 | print b 7 | print c 8 | 9 | def g(): 10 | a, b, c = seq 11 | 12 | def h(): 13 | a, = seq 14 | -------------------------------------------------------------------------------- /tests/compile/cstructreturn.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef struct Foo: 4 | int blarg 5 | 6 | cdef Foo f(): 7 | blarg = 1 + 2 8 | cdef Foo foo 9 | foo.blarg = blarg 10 | return foo 11 | 12 | f() 13 | -------------------------------------------------------------------------------- /tests/errors/e_notnone.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef extern class Grail.Shrubbery 4 | 5 | cdef void spam(Shrubbery sh not None): 6 | pass 7 | _ERRORS = u""" 8 | 5:15: 'not None' only allowed in Python functions 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/pep492_badsyntax_async1.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep492, async 3 | 4 | async def foo(): 5 | def foo(a=await list()): 6 | pass 7 | 8 | _ERRORS = """ 9 | 5:14: 'await' not supported here 10 | """ 11 | -------------------------------------------------------------------------------- /tests/run/lambda_T723.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # ticket: 723 3 | # tag: lambda 4 | 5 | def t723(a): 6 | """ 7 | >>> t723(2)() 8 | 4 9 | >>> t723(2)(3) 10 | 9 11 | """ 12 | return lambda x=a: x * x 13 | -------------------------------------------------------------------------------- /Cython/Includes/libc/stddef.pxd: -------------------------------------------------------------------------------- 1 | # 7.17 Common definitions 2 | 3 | cdef extern from "": 4 | 5 | ctypedef signed int ptrdiff_t 6 | 7 | ctypedef unsigned int size_t 8 | 9 | ctypedef int wchar_t 10 | -------------------------------------------------------------------------------- /docs/examples/README.rst: -------------------------------------------------------------------------------- 1 | This example directory is organized like the ``Cython/docs/src/`` directory, 2 | with one directory per ``.rst`` file. All files in this directory are tested 3 | in the :file:`runtests.py` with the mode `compile`. 4 | -------------------------------------------------------------------------------- /docs/examples/tutorial/external/atoi.pyx: -------------------------------------------------------------------------------- 1 | from libc.stdlib cimport atoi 2 | 3 | cdef parse_charptr_to_py_int(char* s): 4 | assert s is not NULL, "byte string value is NULL" 5 | return atoi(s) # note: atoi() has no error detection! 6 | -------------------------------------------------------------------------------- /docs/examples/userguide/parallelism/simple_sum.pyx: -------------------------------------------------------------------------------- 1 | from cython.parallel import prange 2 | 3 | cdef int i 4 | cdef int n = 30 5 | cdef int sum = 0 6 | 7 | for i in prange(n, nogil=True): 8 | sum += i 9 | 10 | print(sum) 11 | -------------------------------------------------------------------------------- /tests/compile/min_async.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | # tag: pep492, await 3 | 4 | # Need to include all utility code ! 5 | 6 | async def sleep(x): 7 | pass 8 | 9 | 10 | async def call(): 11 | await sleep(1) 12 | yield 13 | -------------------------------------------------------------------------------- /tests/compile/point.h: -------------------------------------------------------------------------------- 1 | #ifndef POINT_H 2 | #define POINT_H 3 | 4 | namespace geometry { 5 | 6 | struct Point 7 | { 8 | double x; 9 | double y; 10 | int color; 11 | }; 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /tests/compile/typecast.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void f(obj): 4 | cdef size_t i=0 5 | cdef char *p 6 | p = i 7 | p = &i 8 | obj = p 9 | p = obj 10 | 11 | f(None) 12 | -------------------------------------------------------------------------------- /tests/errors/e_undefexttype.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef class Spam 4 | cdef extern class external.Eggs 5 | _ERRORS = u""" 6 | 3:5: C class 'Spam' is declared but not defined 7 | 4:5: C class 'Eggs' is declared but not defined 8 | """ 9 | -------------------------------------------------------------------------------- /tests/errors/pep492_badsyntax_async4.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep492, async 3 | 4 | async def foo(): 5 | async def foo(): await list() 6 | 7 | _ERRORS = """ 8 | # ??? - this fails in CPython, not sure why ... 9 | """ 10 | -------------------------------------------------------------------------------- /tests/run/ctypedef_delegation.pyx: -------------------------------------------------------------------------------- 1 | 2 | ctypedef char* LPSTR 3 | 4 | def typedef_delegation(): 5 | """ 6 | >>> typedef_delegation() 7 | """ 8 | cdef LPSTR c_str = b"ascii" 9 | assert c_str == b"ascii" 10 | -------------------------------------------------------------------------------- /tests/run/unreachable.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: generators unreachable 3 | 4 | def with_yield_removed(): 5 | """ 6 | >>> o = with_yield_removed() 7 | >>> list(o) 8 | [] 9 | """ 10 | return 11 | yield 12 | -------------------------------------------------------------------------------- /Demos/embed/README.rst: -------------------------------------------------------------------------------- 1 | This example demonstrates how Cython-generated code 2 | can be called directly from a main program written in C. 3 | 4 | The Windows makefiles were contributed by 5 | Duncan Booth: Duncan.Booth@SuttonCourtenay.org.uk. 6 | -------------------------------------------------------------------------------- /docs/examples/tutorial/cdef_classes/sin_of_square.pxd: -------------------------------------------------------------------------------- 1 | cdef class Function: 2 | cpdef double evaluate(self, double x) except * 3 | 4 | cdef class SinOfSquareFunction(Function): 5 | cpdef double evaluate(self, double x) except * 6 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/if_char_in.pyx: -------------------------------------------------------------------------------- 1 | cpdef void is_in(Py_UCS4 uchar_val): 2 | if uchar_val in u'abcABCxY': 3 | print("The character is in the string.") 4 | else: 5 | print("The character is not in the string") 6 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/shrubbing.pyx: -------------------------------------------------------------------------------- 1 | cdef class Shrubbery: 2 | def __cinit__(self, int w, int l): 3 | self.width = w 4 | self.length = l 5 | 6 | def standard_shrubbery(): 7 | return Shrubbery(3, 7) 8 | -------------------------------------------------------------------------------- /tests/broken/ctypedefextern.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "ctypedefextern.h": 2 | 3 | ctypedef int some_int 4 | ctypedef some_int *some_ptr 5 | 6 | cdef void spam(): 7 | cdef some_int i 8 | cdef some_ptr p 9 | p[0] = i 10 | -------------------------------------------------------------------------------- /tests/broken/intindex.pyx: -------------------------------------------------------------------------------- 1 | cdef int f() except -1: 2 | cdef object x, y, z 3 | cdef int i 4 | cdef unsigned int ui 5 | z = x[y] 6 | z = x[i] 7 | x[y] = z 8 | x[i] = z 9 | z = x[ui] 10 | x[ui] = z 11 | -------------------------------------------------------------------------------- /tests/compile/belchenko1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern from *: 4 | ctypedef int intptr_t 5 | 6 | cdef int _is_aligned(void *ptr): 7 | return ((ptr) & ((sizeof(int))-1)) == 0 8 | 9 | _is_aligned(NULL) 10 | -------------------------------------------------------------------------------- /tests/compile/extern.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern int i 4 | cdef extern char *s[] 5 | cdef extern void spam(char c) 6 | 7 | cdef extern int eggs(): 8 | pass 9 | 10 | cdef int grail(): 11 | pass 12 | 13 | grail() 14 | -------------------------------------------------------------------------------- /tests/compile/magcmp.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void foo(): 4 | cdef int bool, int1=0, int2=0 5 | bool = int1 < int2 6 | bool = int1 > int2 7 | bool = int1 <= int2 8 | bool = int1 >= int2 9 | 10 | foo() 11 | -------------------------------------------------------------------------------- /tests/errors/e_cenum.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef enum Spam: 4 | a, b, c 5 | 6 | cdef void f(): 7 | global a 8 | a = 42 # assignment to non-lvalue 9 | 10 | _ERRORS = u""" 11 | 8:1: Assignment to non-lvalue 'a' 12 | """ 13 | -------------------------------------------------------------------------------- /tests/run/charcomparisonT412.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 412 2 | 3 | def f(): 4 | """ 5 | >>> f() 6 | True 7 | True 8 | """ 9 | 10 | cdef char a 11 | a = 62 12 | print (a == '>') 13 | print (a == '>') 14 | -------------------------------------------------------------------------------- /tests/run/function_as_method_py_T494.py: -------------------------------------------------------------------------------- 1 | # ticket: 494 2 | 3 | __doc__ = """ 4 | >>> A.foo = foo 5 | >>> A().foo() 6 | True 7 | """ 8 | 9 | class A: 10 | pass 11 | 12 | def foo(self): 13 | return self is not None 14 | -------------------------------------------------------------------------------- /Cython/Compiler/Version.py: -------------------------------------------------------------------------------- 1 | # for backwards compatibility 2 | 3 | from __future__ import absolute_import 4 | 5 | from .. import __version__ as version 6 | 7 | # For 'generated by' header line in C files. 8 | 9 | watermark = str(version) 10 | -------------------------------------------------------------------------------- /Demos/run_spam.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | 3 | from spam import Spam 4 | 5 | s = Spam() 6 | print("Created:", s) 7 | s.set_amount(42) 8 | print("Amount =", s.get_amount()) 9 | s.describe() 10 | s = None 11 | -------------------------------------------------------------------------------- /Doc/s5/ep2008/worker.py: -------------------------------------------------------------------------------- 1 | 2 | class HardWorker(object): 3 | u"Almost Sisyphus" 4 | def __init__(self, task): 5 | self.task = task 6 | 7 | def work_hard(self): 8 | for i in range(100): 9 | self.task() 10 | -------------------------------------------------------------------------------- /tests/compile/ewing8.pxd: -------------------------------------------------------------------------------- 1 | cdef struct Foo 2 | cdef class Blarg 3 | 4 | ctypedef Foo FooType 5 | ctypedef Blarg BlargType 6 | 7 | cdef struct Foo: 8 | FooType *f 9 | 10 | cdef class Blarg: 11 | cdef FooType *f 12 | cdef BlargType b 13 | -------------------------------------------------------------------------------- /tests/errors/cdefoptargs.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def call5(): 4 | b(1,2,3,4,5) 5 | 6 | cdef b(a, b, c=1, d=2): 7 | pass 8 | 9 | _ERRORS = u""" 10 | 4:5:Call with wrong number of arguments (expected at most 4, got 5) 11 | """ 12 | -------------------------------------------------------------------------------- /tests/errors/e_addop.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | cdef int int1, int3 5 | cdef int *ptr1, *ptr2, *ptr3 6 | ptr1 = ptr2 + ptr3 # error 7 | 8 | _ERRORS = u""" 9 | 6:13: Invalid operand types for '+' (int *; int *) 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/e_badexcvaltype.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef char *spam() except -1: 4 | pass 5 | 6 | _ERRORS = u""" 7 | 3:26: Cannot assign type 'long' to 'char *' 8 | 3:26: Exception value incompatible with function return type 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/e_cdef_yield.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef cdef_yield(): 4 | yield 5 | 6 | cpdef cpdef_yield(): 7 | yield 8 | 9 | _ERRORS = u""" 10 | 4:4: 'yield' not supported here 11 | 7:4: 'yield' not supported here 12 | """ 13 | -------------------------------------------------------------------------------- /tests/errors/e_notnone2.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def eggs(int x not None, char* y not None): 4 | pass 5 | _ERRORS = u""" 6 | 3: 9: Only Python type arguments can have 'not None' 7 | 3:25: Only Python type arguments can have 'not None' 8 | """ 9 | -------------------------------------------------------------------------------- /tests/errors/fused_syntax_ctypedef.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cimport cython 4 | 5 | ctypedef cython.fused_type(int, float) fused_t 6 | 7 | _ERRORS = u""" 8 | fused_syntax_ctypedef.pyx:5:39: Syntax error in ctypedef statement 9 | """ 10 | -------------------------------------------------------------------------------- /tests/travis_macos_cpp_bugs.txt: -------------------------------------------------------------------------------- 1 | complex_numbers_T305 2 | complex_numbers_c99_T398 3 | complex_numbers_cpp 4 | complex_numbers_cxx_T398 5 | cpdef_extern_func 6 | cpp_classes_def 7 | cpp_smart_ptr 8 | cpp_stl_conversion 9 | cpp_stl_function 10 | -------------------------------------------------------------------------------- /Demos/integrate1.pyx: -------------------------------------------------------------------------------- 1 | # cython: language_level=3 2 | 3 | def f(x): 4 | return x**2-x 5 | 6 | 7 | def integrate_f(a, b, N): 8 | s = 0.0 9 | dx = (b-a)/N 10 | for i in range(N): 11 | s += f(a+i*dx) 12 | return s * dx 13 | -------------------------------------------------------------------------------- /Demos/numpy_demo.pyx: -------------------------------------------------------------------------------- 1 | cimport numpy as cnp 2 | 3 | 4 | def sum_of_squares(cnp.ndarray[double, ndim=1] arr): 5 | cdef long N = arr.shape[0] 6 | cdef double ss = 0 7 | for i in range(N): 8 | ss += arr[i]**2 9 | return ss 10 | -------------------------------------------------------------------------------- /Demos/run_primes.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | 3 | import sys 4 | from primes import primes 5 | 6 | if len(sys.argv) >= 2: 7 | n = int(sys.argv[1]) 8 | else: 9 | n = 1000 10 | 11 | print(primes(n)) 12 | -------------------------------------------------------------------------------- /docs/examples/quickstart/cythonize/integrate.py: -------------------------------------------------------------------------------- 1 | def f(x): 2 | return x ** 2 - x 3 | 4 | 5 | def integrate_f(a, b, N): 6 | s = 0 7 | dx = (b - a) / N 8 | for i in range(N): 9 | s += f(a + i * dx) 10 | return s * dx 11 | -------------------------------------------------------------------------------- /tests/compile/ass2longlong.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void spam(): 4 | cdef long long L 5 | cdef unsigned long long U 6 | cdef object x = object() 7 | L = x 8 | x = L 9 | U = x 10 | x = U 11 | 12 | spam() 13 | -------------------------------------------------------------------------------- /tests/compile/gencall.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(x, y): 4 | x = y 5 | 6 | def z(a, b, c): 7 | f(x = 42, y = "spam") 8 | f(*a) 9 | f(**b) 10 | f(x = 42, **b) 11 | f(a, *b) 12 | f(a, x = 42, *b, **c) 13 | 14 | -------------------------------------------------------------------------------- /tests/errors/e_nogilcmeth.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef class C: 4 | cdef void f(self) nogil: 5 | pass 6 | 7 | _ERRORS = u""" 8 | 2:12: Previous declaration is here 9 | 4: 6: Signature not compatible with previous declaration 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/nogilcmeth.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef class C: 4 | cdef void f(self): 5 | pass 6 | 7 | _ERRORS = u""" 8 | 2:15: Previous declaration is here 9 | 4:9: Signature not compatible with previous declaration 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/se_multass.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(obj1a, obj2a, obj3a, obj1b, obj2b, obj3b, obj4b): 4 | obj1a, (obj2a, obj3a) = obj1b, (obj2b, obj3b, obj4b) 5 | 6 | _ERRORS = u""" 7 | 4:9: too many values to unpack (expected 2, got 3) 8 | """ 9 | -------------------------------------------------------------------------------- /tests/errors/w_cdef_override.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: werror 3 | 4 | cdef foo(): 5 | pass 6 | 7 | def foo(): 8 | pass 9 | 10 | _ERRORS = u""" 11 | 7:0: 'foo' redeclared 12 | 7:0: Overriding cdef method with def method. 13 | """ 14 | -------------------------------------------------------------------------------- /tests/run/baas3.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> m = MyClass() 3 | >>> m is foo(m) 4 | True 5 | """ 6 | 7 | cdef class MyClass: 8 | pass 9 | 10 | def foo(MyClass c): 11 | cdef MyClass res 12 | res = c 13 | return res 14 | -------------------------------------------------------------------------------- /Doc/s5/ui/default/opera.css: -------------------------------------------------------------------------------- 1 | /* DO NOT CHANGE THESE unless you really want to break Opera Show */ 2 | .slide { 3 | visibility: visible !important; 4 | position: static !important; 5 | page-break-before: always; 6 | } 7 | #slide0 {page-break-before: avoid;} 8 | -------------------------------------------------------------------------------- /tests/compile/cast_ctypedef_array_T518_helper.h: -------------------------------------------------------------------------------- 1 | struct __foo_struct { int i, j; }; 2 | typedef struct __foo_struct foo_t[1]; 3 | 4 | static void foo_init (foo_t v) { v[0].i = 0; v[0].j = 0; } 5 | static void foo_clear (foo_t v) { v[0].i = 0; v[0].j = 0; } 6 | -------------------------------------------------------------------------------- /tests/compile/ctypedef_public_class_T355.pxd: -------------------------------------------------------------------------------- 1 | ctypedef public class Time [type MyTime_Type, object MyTimeObject]: 2 | cdef public double seconds 3 | 4 | ctypedef public class Event [type MyEvent_Type, object MyEventObject]: 5 | cdef public Time time 6 | -------------------------------------------------------------------------------- /tests/errors/cfunc_directive_in_pyclass.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | import cython 3 | 4 | class Pyclass(object): 5 | @cython.cfunc 6 | def bad(self): 7 | pass 8 | 9 | _ERRORS = """ 10 | 5:4: cfunc directive is not allowed here 11 | """ 12 | -------------------------------------------------------------------------------- /tests/errors/e_autotestdict.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cimport cython 4 | 5 | @cython.autotestdict(False) 6 | def foo(): 7 | pass 8 | 9 | _ERRORS = u""" 10 | 5:0: The autotestdict compiler directive is not allowed in function scope 11 | """ 12 | -------------------------------------------------------------------------------- /tests/run/tandemstats.pyx: -------------------------------------------------------------------------------- 1 | cdef int i, j, k 2 | i = 17; j = 42; k = i * j 3 | if j > k: i = 88 4 | else: i = 99; j = k 5 | 6 | def result(): 7 | """ 8 | >>> result() == (99, 17*42, 17*42) 9 | True 10 | """ 11 | return (i,j,k) 12 | -------------------------------------------------------------------------------- /Doc/s5/ep2008/stupidlowercase.py: -------------------------------------------------------------------------------- 1 | 2 | def stupid_lower_case(char* s): 3 | cdef Py_ssize_t size, i 4 | 5 | size = len(s) 6 | for i in range(size): 7 | if s[i] >= 'A' and s[i] <= 'Z': 8 | s[i] += 'a' - 'A' 9 | return s 10 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/C_func_file.c: -------------------------------------------------------------------------------- 1 | #include "C_func_file.h" 2 | 3 | void multiply_by_10_in_C(double arr[], unsigned int n) 4 | { 5 | unsigned int i; 6 | for (i = 0; i < n; i++) { 7 | arr[i] *= 10; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/landscaping.pyx: -------------------------------------------------------------------------------- 1 | cimport shrubbing 2 | import shrubbing 3 | 4 | def main(): 5 | cdef shrubbing.Shrubbery sh 6 | sh = shrubbing.standard_shrubbery() 7 | print("Shrubbery size is", sh.width, 'x', sh.length) 8 | -------------------------------------------------------------------------------- /tests/compile/funcptr.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef int grail(): 4 | cdef int (*spam)() 5 | spam = &grail 6 | spam = grail 7 | spam() 8 | 9 | ctypedef int funcptr_t() 10 | 11 | cdef inline funcptr_t* dummy(): 12 | return &grail 13 | -------------------------------------------------------------------------------- /tests/errors/buffertypedef_T117.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 117 2 | # mode: error 3 | 4 | ctypedef object[float] mybuffer 5 | 6 | _ERRORS = u""" 7 | 1:0: Buffer vars not allowed in module scope 8 | 4:0: Buffer types only allowed as function local variables 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/cdef_syntax.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef pass 4 | cdef void 5 | cdef nogil class test: pass 6 | 7 | _ERRORS = u""" 8 | 3: 5: Expected an identifier, found 'pass' 9 | 4: 9: Empty declarator 10 | 5:11: Expected ':', found 'class' 11 | """ 12 | -------------------------------------------------------------------------------- /tests/errors/cmethbasematch.pxd: -------------------------------------------------------------------------------- 1 | cdef class Base(object): 2 | cdef f(self) 3 | 4 | cdef class MissingRedeclaration(Base): 5 | pass 6 | 7 | cdef class BadRedeclaration(Base): 8 | cdef f(self) 9 | 10 | cdef class NarrowerReturn(Base): 11 | pass 12 | -------------------------------------------------------------------------------- /tests/errors/compile_time_unraisable_T370.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 370 2 | # mode: error 3 | 4 | cdef int raiseit(): 5 | raise IndexError 6 | 7 | try: raiseit() 8 | except: pass 9 | 10 | _ERRORS = u""" 11 | FIXME: provide a good error message here. 12 | """ 13 | -------------------------------------------------------------------------------- /tests/run/behnel1.pyx: -------------------------------------------------------------------------------- 1 | cdef class Spam: 2 | cdef eggs(self, a): 3 | return a 4 | 5 | cdef Spam spam(): 6 | return Spam() 7 | 8 | def viking(a): 9 | """ 10 | >>> viking(5) 11 | 5 12 | """ 13 | return spam().eggs(a) 14 | -------------------------------------------------------------------------------- /tests/run/r_mitch_chapman_2.pyx: -------------------------------------------------------------------------------- 1 | def boolExpressionsFail(): 2 | """ 3 | >>> boolExpressionsFail() 4 | 'Not 2b' 5 | """ 6 | dict = {1: 1} 7 | if not "2b" in dict: 8 | return "Not 2b" 9 | else: 10 | return "2b?" 11 | -------------------------------------------------------------------------------- /tests/compile/ctypedefstruct.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef struct order: 4 | int spam 5 | int eggs 6 | 7 | cdef order order1 8 | 9 | order1.spam = 7 10 | order1.eggs = 2 11 | 12 | ctypedef struct linked: 13 | int a 14 | linked *next 15 | -------------------------------------------------------------------------------- /tests/errors/e_multass.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(obj1a, obj1b): 4 | cdef int int1, int2, int3 5 | cdef int *ptr2 6 | int1, int3, obj1a = int2, ptr2, obj1b # error 7 | 8 | 9 | _ERRORS = u""" 10 | 6:27: Cannot assign type 'int *' to 'int' 11 | """ 12 | -------------------------------------------------------------------------------- /tests/errors/e_pyobinstruct.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef object x 4 | 5 | cdef struct spam: 6 | object parrot 7 | 8 | def f(): 9 | cdef spam s 10 | s.parrot = x 11 | _ERRORS = u""" 12 | 6:8: C struct/union member cannot be a Python object 13 | """ 14 | -------------------------------------------------------------------------------- /tests/run/arg_incref.pyx: -------------------------------------------------------------------------------- 1 | def f(dict d, x=4): 2 | """ 3 | >>> f({1:1, 2:2}) 4 | [1, 2] 5 | """ 6 | cdef dict d_new = {} 7 | l = [] 8 | for k in d: 9 | d = d_new 10 | l.append(k) 11 | l.sort() 12 | return l 13 | -------------------------------------------------------------------------------- /tests/run/classpass.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> s = Spam() 3 | >>> s.__class__.__name__ 4 | 'Spam' 5 | 6 | >>> s = SpamT() 7 | >>> type(s).__name__ 8 | 'SpamT' 9 | """ 10 | 11 | class Spam: pass 12 | 13 | class SpamT(object): pass 14 | -------------------------------------------------------------------------------- /tests/run/directive_locals_in_pxd.pxd: -------------------------------------------------------------------------------- 1 | cimport cython 2 | 3 | @cython.locals(egg=double) 4 | cdef foo(egg) 5 | 6 | @cython.locals(egg=cython.double) 7 | cdef foo_defval(egg=*) 8 | 9 | @cython.locals(egg=cython.bint, v=cython.int) 10 | cpdef cpfoo(egg=*) 11 | -------------------------------------------------------------------------------- /tests/run/ishimoto2.pyx: -------------------------------------------------------------------------------- 1 | 2 | class C: 3 | """ 4 | >>> C().xxx(5) 5 | 5 6 | >>> C().xxx() 7 | 'a b' 8 | >>> C().xxx(42) 9 | 42 10 | >>> C().xxx() 11 | 'a b' 12 | """ 13 | def xxx(self, p="a b"): 14 | return p 15 | -------------------------------------------------------------------------------- /tests/run/r_starargcall.pyx: -------------------------------------------------------------------------------- 1 | def spam(a, b, c): 2 | print u"Args:", a, b, c 3 | 4 | def eggs(): 5 | """ 6 | >>> eggs() 7 | Args: 1 2 3 8 | Args: buckle my shoe 9 | """ 10 | spam(*(1,2,3)) 11 | spam(*[u"buckle",u"my",u"shoe"]) 12 | -------------------------------------------------------------------------------- /tests/run/varargcall.pyx: -------------------------------------------------------------------------------- 1 | cdef grail(const char *blarg, ...): 2 | pass 3 | 4 | 5 | def swallow(): 6 | """ 7 | >>> swallow() 8 | """ 9 | grail("spam") 10 | grail("spam", 42) 11 | grail("spam", b"abc") 12 | grail("spam", "abc") 13 | -------------------------------------------------------------------------------- /Doc/s5/ui/default/slides.css: -------------------------------------------------------------------------------- 1 | @import url(s5-core.css); /* required to make the slide show run at all */ 2 | @import url(framing.css); /* sets basic placement and size of slide components */ 3 | @import url(pretty.css); /* stuff that makes the slides look better than blah */ -------------------------------------------------------------------------------- /docs/examples/userguide/external_C_code/delorean.pyx: -------------------------------------------------------------------------------- 1 | # delorean.pyx 2 | 3 | cdef public struct Vehicle: 4 | int speed 5 | float power 6 | 7 | cdef api void activate(Vehicle *v): 8 | if v.speed >= 88 and v.power >= 1.21: 9 | print("Time travel achieved") -------------------------------------------------------------------------------- /docs/examples/userguide/wrapping_CPlusPlus/function_templates.pyx: -------------------------------------------------------------------------------- 1 | # distutils: language = c++ 2 | 3 | cdef extern from "" namespace "std": 4 | T max[T](T a, T b) 5 | 6 | print(max[long](3, 4)) 7 | print(max(1.5, 2.5)) # simple template argument deduction 8 | -------------------------------------------------------------------------------- /tests/compile/cenum.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef enum Spam: 4 | a 5 | b, c, 6 | d, e, f 7 | g = 42 8 | 9 | cdef void eggs(): 10 | cdef Spam s1, s2=a 11 | cdef int i 12 | s1 = s2 13 | s1 = c 14 | i = s1 15 | 16 | eggs() 17 | -------------------------------------------------------------------------------- /tests/compile/doda1.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | pass 5 | 6 | cdef Spam foo(): 7 | return blarg() 8 | #cdef Spam grail 9 | #grail = blarg() 10 | #return grail 11 | 12 | cdef object blarg(): 13 | pass 14 | 15 | foo() 16 | -------------------------------------------------------------------------------- /tests/compile/jiba6.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern from "string.h": 4 | void memcpy(void* des, void* src, int size) 5 | 6 | cdef void f(): 7 | cdef float[3] f1 8 | cdef float* f2 9 | f2 = f1 + 1 10 | memcpy(f1, f2, 1) 11 | 12 | f() 13 | -------------------------------------------------------------------------------- /tests/compile/specialfloatvals.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | DEF nan = float('nan') 4 | DEF inf = float('inf') 5 | DEF minf = -float('inf') 6 | 7 | cdef int f() except -1: 8 | cdef float x, y, z 9 | x = nan 10 | y = inf 11 | z = minf 12 | 13 | f() 14 | -------------------------------------------------------------------------------- /tests/errors/missing_self_in_cpdef_method_T165.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 165 2 | # mode: error 3 | 4 | cdef class A: 5 | cpdef a(int not_self): 6 | pass 7 | 8 | _ERRORS = u""" 9 | 5:10: Self argument (int) of C method 'a' does not match parent type (A) 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/pep492_badsyntax_async2.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: pep492, async 3 | 4 | async def foo(): 5 | def foo(a:await list()): 6 | pass 7 | 8 | _ERRORS = """ 9 | 5:14: 'await' not supported here 10 | 5:14: 'await' not supported here 11 | """ 12 | -------------------------------------------------------------------------------- /tests/run/concatcstrings.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> spam == u'C string 1' + u'C string 2' 3 | True 4 | """ 5 | 6 | import sys 7 | if sys.version_info[0] >= 3: 8 | __doc__ = __doc__.replace(u" u'", u" '") 9 | 10 | spam = u"C string 1" + u"C string 2" 11 | -------------------------------------------------------------------------------- /tests/run/define_macro.pyx: -------------------------------------------------------------------------------- 1 | #distutils: define_macros = DEFINE_NO_VALUE DEFINE_WITH_VALUE=0 2 | 3 | cdef extern from "define_macro_helper.h" nogil: 4 | int VAL; 5 | 6 | def test(): 7 | """ 8 | >>> test() 9 | 1 10 | """ 11 | return VAL 12 | -------------------------------------------------------------------------------- /tests/run/function_as_method_T494.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 494 2 | # cython: binding=True 3 | 4 | __doc__ = """ 5 | >>> A.foo = foo 6 | >>> A().foo() 7 | True 8 | """ 9 | 10 | class A: 11 | pass 12 | 13 | def foo(self): 14 | return self is not None 15 | -------------------------------------------------------------------------------- /tests/run/r_starargsonly.pyx: -------------------------------------------------------------------------------- 1 | def spam(*args): 2 | """ 3 | >>> spam() 4 | Args: () 5 | >>> spam(42) 6 | Args: (42,) 7 | >>> spam("one", 2, "buckle my shoe") 8 | Args: ('one', 2, 'buckle my shoe') 9 | """ 10 | print u"Args:", args 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/cdef_classes/math_function.py: -------------------------------------------------------------------------------- 1 | class MathFunction(object): 2 | def __init__(self, name, operator): 3 | self.name = name 4 | self.operator = operator 5 | 6 | def __call__(self, *operands): 7 | return self.operator(*operands) 8 | -------------------------------------------------------------------------------- /tests/compile/publicapi_cimport.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | from publicapi_pxd_mix cimport * 3 | 4 | bar0() 5 | bar1() 6 | bar2() 7 | bar3() 8 | 9 | spam0(None) 10 | spam1(None) 11 | spam2(None) 12 | spam3(None) 13 | 14 | i0 = 0 15 | i1 = 1 16 | i2 = 2 17 | i3 = 3 18 | 19 | -------------------------------------------------------------------------------- /tests/errors/bufaccess_noassignT444.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 444 2 | # mode: error 3 | 4 | def test(): 5 | cdef object[int] not_assigned_to 6 | not_assigned_to[2] = 3 7 | 8 | _ERRORS = """ 9 | 6:5: local variable 'not_assigned_to' referenced before assignment 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/cpdef_syntax.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cpdef nogil: pass 4 | cpdef nogil class test: pass 5 | 6 | _ERRORS = u""" 7 | 3: 6: cdef blocks cannot be declared cpdef 8 | 4: 6: cdef blocks cannot be declared cpdef 9 | 4:12: Expected ':', found 'class' 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/cython3_bytes.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # -*- coding: utf-8 -*- 3 | # cython: language_level=3 4 | 5 | escaped = b'abc\xc3\xbc\xc3\xb6\xc3\xa4' 6 | invalid = b'abcüöä' 7 | 8 | _ERRORS = """ 9 | 6:10: bytes can only contain ASCII literal characters. 10 | """ 11 | -------------------------------------------------------------------------------- /tests/errors/e_switch.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef int x = 3 4 | 5 | if x == NONEXISTING: 6 | print 2 7 | elif x == 2: 8 | print 2342 9 | elif x == 4: 10 | print 34 11 | 12 | _ERRORS = u""" 13 | 5:8: undeclared name not builtin: NONEXISTING 14 | """ 15 | -------------------------------------------------------------------------------- /tests/errors/e_tuple_args_T692.py: -------------------------------------------------------------------------------- 1 | # ticket: 692 2 | # mode: error 3 | 4 | def func((a, b)): 5 | return a + b 6 | 7 | _ERRORS = u""" 8 | 4:9: Missing argument name 9 | 5:11: undeclared name not builtin: a 10 | 5:15: undeclared name not builtin: b 11 | """ 12 | 13 | -------------------------------------------------------------------------------- /tests/errors/nonconst_def.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | import os 4 | DEF ospath = os.path 5 | 6 | _ERRORS = u""" 7 | 4:13: Compile-time name 'os' not defined 8 | 4:15: Error in compile-time expression: AttributeError: 'NoneType' object has no attribute 'path' 9 | """ 10 | -------------------------------------------------------------------------------- /tests/run/cdef_class_order.pyx: -------------------------------------------------------------------------------- 1 | cimport cython 2 | 3 | cdef class B 4 | 5 | cdef class A(object): 6 | cdef list dealloc1 7 | 8 | cdef class B(A): 9 | cdef list dealloc2 10 | 11 | def test(): 12 | """ 13 | >>> test() 14 | """ 15 | A(), B() 16 | -------------------------------------------------------------------------------- /tests/run/class_scope.py: -------------------------------------------------------------------------------- 1 | # mode:run 2 | # tag: class, scope 3 | 4 | class MethodRedef(object): 5 | """ 6 | >>> MethodRedef().a(5) 7 | 7 8 | """ 9 | 10 | def a(self, i): 11 | return i+1 12 | 13 | def a(self, i): 14 | return i+2 15 | -------------------------------------------------------------------------------- /tests/run/cython2_bytes.pyx: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # cython: language_level=2 3 | 4 | b = b'abcüöä \x12' 5 | 6 | cdef char* cs = 'abcüöä \x12' 7 | 8 | def compare_cs(): 9 | """ 10 | >>> b == compare_cs() 11 | True 12 | """ 13 | return cs 14 | -------------------------------------------------------------------------------- /tests/run/ptr_warning_T714.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: werror 3 | # ticket: 714 4 | 5 | def test_ptr(): 6 | """ 7 | >>> test_ptr() 8 | 123 9 | """ 10 | cdef int a 11 | cdef int *ptr 12 | 13 | ptr = &a 14 | ptr[0] = 123 15 | return a 16 | -------------------------------------------------------------------------------- /Cython/Includes/cpython/pyport.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "Python.h": 2 | ctypedef int int32_t 3 | ctypedef int int64_t 4 | ctypedef unsigned int uint32_t 5 | ctypedef unsigned int uint64_t 6 | 7 | const Py_ssize_t PY_SSIZE_T_MIN 8 | const Py_ssize_t PY_SSIZE_T_MAX 9 | -------------------------------------------------------------------------------- /docs/examples/userguide/extension_types/shrubbery_2.pyx: -------------------------------------------------------------------------------- 1 | from my_module cimport Shrubbery 2 | 3 | cdef Shrubbery another_shrubbery(Shrubbery sh1): 4 | cdef Shrubbery sh2 5 | sh2 = Shrubbery() 6 | sh2.width = sh1.width 7 | sh2.height = sh1.height 8 | return sh2 9 | -------------------------------------------------------------------------------- /tests/compile/casttoexttype.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern class external.Spam: 4 | pass 5 | 6 | cdef void foo(object x): 7 | pass 8 | 9 | cdef void blarg(void *y, object z): 10 | foo(y) 11 | foo(z) 12 | 13 | blarg(None, None) 14 | -------------------------------------------------------------------------------- /tests/compile/ewing7.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class A: 4 | cdef void f(self, x): 5 | pass 6 | 7 | cdef class B(A): 8 | cdef void f(self, object x): 9 | pass 10 | 11 | cdef extern void g(A a, b) 12 | 13 | cdef extern void g(A a, b) 14 | 15 | -------------------------------------------------------------------------------- /tests/errors/e_unop.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | cdef int int1 5 | cdef char *str2 6 | int1 = -str2 # error 7 | int1 = ~str2 # error 8 | _ERRORS = u""" 9 | 6:8: Invalid operand type for '-' (char *) 10 | 7:8: Invalid operand type for '~' (char *) 11 | """ 12 | -------------------------------------------------------------------------------- /tests/errors/e_while.pyx: -------------------------------------------------------------------------------- 1 | # cython: remove_unreachable=False 2 | # mode: error 3 | 4 | def f(a, b): 5 | cdef int i 6 | break # error 7 | continue # error 8 | _ERRORS = u""" 9 | 6:1: break statement not inside loop 10 | 7:1: continue statement not inside loop 11 | """ 12 | -------------------------------------------------------------------------------- /tests/errors/pyobjcastdisallow_T313.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 313 2 | # mode: error 3 | 4 | a = 3 5 | 6 | cdef void* allowed = a 7 | cdef double* disallowed = a 8 | 9 | _ERRORS = u""" 10 | 7:26: Python objects cannot be cast to pointers of primitive types 11 | """ 12 | -------------------------------------------------------------------------------- /tests/run/altet2.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> iter(C()) # doctest: +ELLIPSIS 3 | Traceback (most recent call last): 4 | TypeError: iter() returned non-iterator... 5 | """ 6 | 7 | cdef class C: 8 | 9 | def __iter__(self): 10 | "This is a doc string." 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/cython_tutorial/fib.pyx: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | def fib(n): 4 | """Print the Fibonacci series up to n.""" 5 | a, b = 0, 1 6 | while b < n: 7 | print(b, end=' ') 8 | a, b = b, a + b 9 | 10 | print() 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/profiling_tutorial/calc_pi.py: -------------------------------------------------------------------------------- 1 | # calc_pi.py 2 | 3 | def recip_square(i): 4 | return 1. / i ** 2 5 | 6 | def approx_pi(n=10000000): 7 | val = 0. 8 | for k in range(1, n + 1): 9 | val += recip_square(k) 10 | return (6 * val) ** .5 11 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/cdef_block.pyx: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | cdef: 4 | struct Spam: 5 | int tons 6 | 7 | int i 8 | float a 9 | Spam *p 10 | 11 | void f(Spam *s): 12 | print(s.tons, "Tons of spam") 13 | -------------------------------------------------------------------------------- /bin/cython.bat: -------------------------------------------------------------------------------- 1 | @REM Start cython from windows commandline as "cython", not "cython.py". 2 | @REM This is especially useful for windows power shell, as no extra window 3 | @REM is used. 4 | 5 | @echo OFF 6 | python -c "from Cython.Compiler.Main import main; main(command_line = 1)" %* 7 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/compile_time.pyx: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | DEF FavouriteFood = u"spam" 4 | DEF ArraySize = 42 5 | DEF OtherArraySize = 2 * ArraySize + 17 6 | 7 | cdef int a1[ArraySize] 8 | cdef int a2[OtherArraySize] 9 | print("I like", FavouriteFood) -------------------------------------------------------------------------------- /tests/compile/belchenko2.pyx.BROKEN: -------------------------------------------------------------------------------- 1 | cdef extern from "belchenko2.h": 2 | void c_func(unsigned char pixel) 3 | 4 | def f(unsigned char pixel): 5 | c_func(pixel) 6 | 7 | def g(signed char pixel): 8 | c_func(pixel) 9 | 10 | def h(char pixel): 11 | c_func(pixel) 12 | 13 | -------------------------------------------------------------------------------- /tests/compile/gustafsson2.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef enum someenum_t: 4 | ENUMVALUE_1 5 | ENUMVALUE_2 6 | 7 | cdef somefunction(someenum_t val): 8 | if val == ENUMVALUE_1: 9 | pass 10 | 11 | somefunction(ENUMVALUE_1) 12 | somefunction(ENUMVALUE_2) 13 | -------------------------------------------------------------------------------- /tests/errors/cpp_no_constructor.pyx: -------------------------------------------------------------------------------- 1 | # tag: cpp 2 | # mode: error 3 | 4 | cdef extern from *: 5 | cdef cppclass Foo: 6 | Foo() 7 | Foo(int) 8 | 9 | new Foo(1, 2) 10 | 11 | _ERRORS = u""" 12 | 9:7: Call with wrong number of arguments (expected 1, got 2) 13 | """ 14 | -------------------------------------------------------------------------------- /tests/errors/literal_lists.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | cdef int* p 5 | if false(): 6 | p = [1, 2, 3] 7 | 8 | def false(): 9 | return False 10 | 11 | _ERRORS = u""" 12 | 6:8: Literal list must be assigned to pointer at time of declaration 13 | """ 14 | -------------------------------------------------------------------------------- /tests/run/numpy_common.pxi: -------------------------------------------------------------------------------- 1 | # hack to avoid C compiler warnings about unused functions in the NumPy header files 2 | 3 | cdef extern from *: 4 | bint FALSE "0" 5 | void import_array() 6 | # void import_umath() 7 | 8 | if FALSE: 9 | import_array() 10 | # import_umath() 11 | -------------------------------------------------------------------------------- /tests/run/r_toofewargs.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> s = Spam() 3 | Traceback (most recent call last): 4 | TypeError: __init__() takes exactly 3 positional arguments (0 given) 5 | """ 6 | 7 | cdef class Spam: 8 | 9 | def __init__(self, a, b, int c): 10 | pass 11 | -------------------------------------------------------------------------------- /Cython/Includes/cpython/ceval.pxd: -------------------------------------------------------------------------------- 1 | 2 | cdef extern from "Python.h": 3 | 4 | void PyEval_InitThreads() 5 | # Initialize and acquire the global interpreter lock. 6 | 7 | int PyEval_ThreadsInitialized() 8 | # Returns a non-zero value if PyEval_InitThreads() has been called. 9 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/decode.pyx: -------------------------------------------------------------------------------- 1 | from c_func cimport get_a_c_string 2 | 3 | cdef char* c_string = NULL 4 | cdef Py_ssize_t length = 0 5 | 6 | # get pointer and length from a C function 7 | get_a_c_string(&c_string, &length) 8 | 9 | ustring = c_string[:length].decode('UTF-8') 10 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/try_finally.pyx: -------------------------------------------------------------------------------- 1 | from libc.stdlib cimport free 2 | from c_func cimport c_call_returning_a_c_string 3 | 4 | cdef bytes py_string 5 | cdef char* c_string = c_call_returning_a_c_string() 6 | try: 7 | py_string = c_string 8 | finally: 9 | free(c_string) 10 | -------------------------------------------------------------------------------- /tests/run/closure_leak_1.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: closure 3 | 4 | def reassign_args(x, *args): 5 | """ 6 | >>> reassign_args(1, [1,2,3,4]) 7 | """ 8 | a,args = args[0], args[1:] 9 | b = False 10 | if b: 11 | c = x.map_coefficients(lambda c: c(*args)) 12 | -------------------------------------------------------------------------------- /tests/run/r_lepage_3.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> g = Grail() 3 | >>> g("spam", 42, ["tomato", "sandwich"]) 4 | Grail called with: spam 42 ['tomato', 'sandwich'] 5 | """ 6 | 7 | cdef class Grail: 8 | 9 | def __call__(self, x, y, z): 10 | print u"Grail called with:", x, y, z 11 | -------------------------------------------------------------------------------- /tests/run/reimport.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: import 3 | 4 | # reimports at module init time used to be a problem in Py3 5 | import reimport 6 | 7 | def test(): 8 | """ 9 | >>> test() 10 | True 11 | """ 12 | import sys 13 | return reimport in sys.modules.values() 14 | -------------------------------------------------------------------------------- /Demos/callback/Setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from distutils.extension import Extension 3 | from Cython.Build import cythonize 4 | 5 | setup( 6 | name = 'callback', 7 | ext_modules=cythonize([ 8 | Extension("cheese", ["cheese.pyx", "cheesefinder.c"]), 9 | ]), 10 | ) 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/external/keyword_args_call.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from "string.h": 2 | char* strstr(const char *haystack, const char *needle) 3 | 4 | cdef char* data = "hfvcakdfagbcffvschvxcdfgccbcfhvgcsnfxjh" 5 | 6 | cdef char* pos = strstr(needle='akd', haystack=data) 7 | print(pos is not NULL) 8 | -------------------------------------------------------------------------------- /tests/compile/crunchytype.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from *: 2 | """ 3 | struct CrunchyType { 4 | int number; 5 | PyObject* string; 6 | }; 7 | """ 8 | cdef class crunchytype.Crunchy [ object CrunchyType ]: 9 | cdef int number 10 | cdef object string 11 | -------------------------------------------------------------------------------- /tests/compile/indices.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef int* a 4 | cdef object x 5 | 6 | cdef int f(int i): 7 | print i 8 | return i 9 | 10 | x[f(1)] = 3 11 | a[f(1)] = 3 12 | 13 | x[f(2)] += 4 14 | a[f(2)] += 4 15 | 16 | print x[1] 17 | print a[1] 18 | 19 | x[f(1)] = 15 20 | -------------------------------------------------------------------------------- /tests/errors/subtyping_final_class.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cimport cython 4 | 5 | @cython.final 6 | cdef class FinalClass: 7 | pass 8 | 9 | cdef class SubType(FinalClass): 10 | pass 11 | 12 | _ERRORS = """ 13 | 9:19: Base class 'FinalClass' of type 'SubType' is final 14 | """ 15 | -------------------------------------------------------------------------------- /tests/run/backquote.pyx: -------------------------------------------------------------------------------- 1 | def f(obj2): 2 | """ 3 | >>> f(20) 4 | '20' 5 | >>> f('test') 6 | "'test'" 7 | """ 8 | obj1 = `obj2` 9 | return obj1 10 | 11 | def g(): 12 | """ 13 | >>> g() 14 | '42' 15 | """ 16 | obj1 = `42` 17 | return obj1 18 | -------------------------------------------------------------------------------- /docs/examples/userguide/extension_types/dict_animal.pyx: -------------------------------------------------------------------------------- 1 | cdef class Animal: 2 | 3 | cdef int number_of_legs 4 | cdef dict __dict__ 5 | 6 | def __cinit__(self, int number_of_legs): 7 | self.number_of_legs = number_of_legs 8 | 9 | 10 | dog = Animal(4) 11 | dog.has_tail = True 12 | -------------------------------------------------------------------------------- /tests/errors/e_switch_transform.pyx: -------------------------------------------------------------------------------- 1 | # cython: optimize.use_switch=True 2 | # mode: error 3 | # tag: cerror 4 | 5 | import cython 6 | 7 | cdef extern from *: 8 | enum: 9 | ONE "1" 10 | ONE_AGAIN "1+0" 11 | 12 | def is_not_one(int i): 13 | return i != ONE and i != ONE_AGAIN 14 | -------------------------------------------------------------------------------- /tests/errors/nogil_buffer_acquisition.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cimport numpy as np 4 | 5 | cdef void func(np.ndarray[np.double_t, ndim=1] myarray) nogil: 6 | pass 7 | 8 | _ERRORS = u""" 9 | 5:15: Buffer may not be acquired without the GIL. Consider using memoryview slices instead. 10 | """ 11 | -------------------------------------------------------------------------------- /tests/run/import_error_T734.py: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # ticket: 734 3 | 4 | def test_import_error(): 5 | """ 6 | >>> test_import_error() # doctest: +ELLIPSIS 7 | Traceback (most recent call last): 8 | ImportError: cannot import name ...xxx... 9 | """ 10 | from sys import xxx 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/array/clone.pyx: -------------------------------------------------------------------------------- 1 | from cpython cimport array 2 | import array 3 | 4 | cdef array.array int_array_template = array.array('i', []) 5 | cdef array.array newarray 6 | 7 | # create an array with 3 elements with same type as template 8 | newarray = array.clone(int_array_template, 3, zero=False) 9 | -------------------------------------------------------------------------------- /docs/examples/tutorial/clibraries/queue2.pyx: -------------------------------------------------------------------------------- 1 | # queue.pyx 2 | 3 | cimport cqueue 4 | 5 | cdef class Queue: 6 | cdef cqueue.Queue* _c_queue 7 | 8 | def __cinit__(self): 9 | self._c_queue = cqueue.queue_new() 10 | if self._c_queue is NULL: 11 | raise MemoryError() 12 | -------------------------------------------------------------------------------- /docs/examples/tutorial/profiling_tutorial/profile.py: -------------------------------------------------------------------------------- 1 | # profile.py 2 | 3 | import pstats, cProfile 4 | 5 | import calc_pi 6 | 7 | cProfile.runctx("calc_pi.approx_pi()", globals(), locals(), "Profile.prof") 8 | 9 | s = pstats.Stats("Profile.prof") 10 | s.strip_dirs().sort_stats("time").print_stats() 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/mymodule.py: -------------------------------------------------------------------------------- 1 | # mymodule.py 2 | 3 | import cython 4 | 5 | # override with Python import if not in compiled code 6 | if not cython.compiled: 7 | from math import sin 8 | 9 | # calls sin() from math.h when compiled with Cython and math.sin() in Python 10 | print(sin(0)) 11 | -------------------------------------------------------------------------------- /tests/compile/cdef_syntax.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | # the following are valid syntax constructs and should not produce errors 4 | 5 | ctypedef int x; 6 | 7 | cdef no_semi(): 8 | cdef int i 9 | 10 | cdef with_semi(): 11 | cdef int i; 12 | 13 | def use_cdef(): 14 | &no_semi, &with_semi 15 | -------------------------------------------------------------------------------- /tests/compile/extinheritdel.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Parrot: 4 | pass 5 | 6 | cdef class Norwegian(Parrot): 7 | 8 | def __delitem__(self, i): 9 | pass 10 | 11 | def __delattr__(self, n): 12 | pass 13 | 14 | def __delete__(self, i): 15 | pass 16 | -------------------------------------------------------------------------------- /tests/compile/huss2.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef enum Color: 4 | red 5 | white 6 | blue 7 | 8 | cdef void f(): 9 | cdef Color e 10 | cdef int i 11 | 12 | i = red 13 | i = red + 1 14 | i = red | 1 15 | e = white 16 | i = e 17 | i = e + 1 18 | 19 | f() 20 | -------------------------------------------------------------------------------- /tests/run/cpp_vector_in_generator.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: cpp 3 | 4 | from libcpp.vector cimport vector 5 | 6 | def stack_vector_in_generator(vector[int] vint): 7 | """ 8 | >>> tuple( stack_vector_in_generator([1,2]) ) 9 | (1, 2) 10 | """ 11 | for i in vint: 12 | yield i 13 | -------------------------------------------------------------------------------- /Demos/integrate2.pyx: -------------------------------------------------------------------------------- 1 | # cython: language_level=3 2 | 3 | cdef double f(double x) except? -2: 4 | return x**2-x 5 | 6 | 7 | def integrate_f(double a, double b, int N): 8 | cdef int i 9 | s = 0.0 10 | dx = (b-a)/N 11 | for i in range(N): 12 | s += f(a+i*dx) 13 | return s * dx 14 | -------------------------------------------------------------------------------- /Demos/pyprimes.py: -------------------------------------------------------------------------------- 1 | def primes(kmax): 2 | p = [] 3 | k = 0 4 | n = 2 5 | while k < kmax: 6 | i = 0 7 | while i < k and n % p[i] != 0: 8 | i = i + 1 9 | if i == k: 10 | p.append(n) 11 | k = k + 1 12 | n = n + 1 13 | return p 14 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/auto_conversion_1.pyx: -------------------------------------------------------------------------------- 1 | # cython: c_string_type=unicode, c_string_encoding=utf8 2 | 3 | cdef char* c_string = 'abcdefg' 4 | 5 | # implicit decoding: 6 | cdef object py_unicode_object = c_string 7 | 8 | # explicit conversion to Python bytes: 9 | py_bytes_object = c_string 10 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/slicing.pyx: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | exporting_object = np.arange(0, 15 * 10 * 20, dtype=np.intc).reshape((15, 10, 20)) 4 | 5 | cdef int[:, :, :] my_view = exporting_object 6 | 7 | # These are all equivalent 8 | my_view[10] 9 | my_view[10, :, :] 10 | my_view[10, ...] 11 | -------------------------------------------------------------------------------- /tests/compile/cpp_class_redefinition.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | # tag: cpp, warnings 3 | 4 | cdef extern from "templates.h": 5 | cdef cppclass TemplateTest1[T]: 6 | TemplateTest1() 7 | T value 8 | int t 9 | T getValue() 10 | 11 | cdef cppclass TemplateTest1[T] 12 | 13 | -------------------------------------------------------------------------------- /tests/compile/extinheritset.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Parrot: 4 | pass 5 | 6 | cdef class Norwegian(Parrot): 7 | 8 | def __setitem__(self, i, x): 9 | pass 10 | 11 | def __setattr__(self, n, x): 12 | pass 13 | 14 | def __set__(self, i, v): 15 | pass 16 | -------------------------------------------------------------------------------- /tests/compile/forfromelse.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void spam(): 4 | cdef int i, j=0, k=0 5 | for i from 0 <= i < 10: 6 | j = k 7 | else: 8 | k = j 9 | 10 | # new syntax 11 | for 0 <= i < 10: 12 | j = i 13 | else: 14 | j = k 15 | 16 | spam() 17 | -------------------------------------------------------------------------------- /tests/compile/future_imports.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | from __future__ import nested_scopes 4 | 5 | from __future__ import with_statement 6 | 7 | pass 8 | 9 | from __future__ import nested_scopes ; from __future__ import nested_scopes 10 | 11 | from __future__ import print_function 12 | print(end='') 13 | -------------------------------------------------------------------------------- /tests/errors/duplicate_const.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef extern from *: 4 | cdef const const int a 5 | cdef const volatile int b 6 | cdef volatile const int c 7 | cdef volatile volatile int d 8 | 9 | 10 | _ERRORS = """ 11 | 4:9: Duplicate 'const' 12 | 7:9: Duplicate 'volatile' 13 | """ 14 | -------------------------------------------------------------------------------- /tests/errors/extended_unpacking_parser2.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | # invalid syntax (as handled by the parser) 4 | 5 | def syntax(): 6 | *a, *b = 1,2,3,4,5 7 | 8 | 9 | _ERRORS = u""" 10 | 6:4: more than 1 starred expression in assignment 11 | 6:8: more than 1 starred expression in assignment 12 | """ 13 | -------------------------------------------------------------------------------- /tests/errors/syntax_warnings.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | # tag: werror 3 | 4 | cdef useless_semicolon(): 5 | cdef int i; 6 | pass; 7 | 8 | ctypedef int x; 9 | 10 | 11 | _ERRORS=""" 12 | 5:14: useless trailing semicolon 13 | 6:8: useless trailing semicolon 14 | 8:14: useless trailing semicolon 15 | """ 16 | -------------------------------------------------------------------------------- /tests/run/r_typecast.pyx: -------------------------------------------------------------------------------- 1 | cdef class ExtType: 2 | cdef c_method(self): 3 | return self 4 | 5 | def method(self): 6 | return 1 7 | 8 | def call_method(ExtType et): 9 | """ 10 | >>> call_method( ExtType() ).method() 11 | 1 12 | """ 13 | return et.c_method() 14 | -------------------------------------------------------------------------------- /docs/examples/tutorial/pure/A.py: -------------------------------------------------------------------------------- 1 | def myfunction(x, y=2): 2 | a = x - y 3 | return a + x * y 4 | 5 | def _helper(a): 6 | return a + 1 7 | 8 | class A: 9 | def __init__(self, b=0): 10 | self.a = 3 11 | self.b = b 12 | 13 | def foo(self, x): 14 | print(x + _helper(1.0)) 15 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/decode_cpp_string.pyx: -------------------------------------------------------------------------------- 1 | # distutils: language = c++ 2 | 3 | from libcpp.string cimport string 4 | 5 | def get_ustrings(): 6 | cdef string s = string(b'abcdefg') 7 | 8 | ustring1 = s.decode('UTF-8') 9 | ustring2 = s[2:-2].decode('UTF-8') 10 | return ustring1, ustring2 11 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Welcome to Cython's Documentation 3 | ================================= 4 | 5 | Also see the `Cython project homepage `_. 6 | 7 | .. toctree:: 8 | :maxdepth: 2 9 | 10 | src/quickstart/index 11 | src/tutorial/index 12 | src/userguide/index 13 | src/changes 14 | -------------------------------------------------------------------------------- /tests/compile/extpropertyall.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef class Spam: 4 | 5 | property eggs: 6 | 7 | "Ova" 8 | 9 | def __get__(self): 10 | pass 11 | 12 | def __set__(self, x): 13 | pass 14 | 15 | def __del__(self): 16 | pass 17 | 18 | -------------------------------------------------------------------------------- /tests/errors/e_subop.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | cdef int int2 5 | cdef char *ptr1, *ptr2, *ptr3 6 | ptr1 = int2 - ptr3 # error 7 | ptr1 = ptr2 - ptr3 # error 8 | _ERRORS = u""" 9 | 6:13: Invalid operand types for '-' (int; char *) 10 | 7:13: Cannot assign type 'ptrdiff_t' to 'char *' 11 | """ 12 | -------------------------------------------------------------------------------- /tests/run/cpp_iterators_simple.h: -------------------------------------------------------------------------------- 1 | class DoublePointerIter { 2 | public: 3 | DoublePointerIter(double* start, int len) : start_(start), len_(len) { } 4 | double* begin() { return start_; } 5 | double* end() { return start_ + len_; } 6 | private: 7 | double* start_; 8 | int len_; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /tests/run/r_pyclass.pyx: -------------------------------------------------------------------------------- 1 | class Spam: 2 | 3 | def __init__(self, w): 4 | self.weight = w 5 | 6 | def serve(self): 7 | print self.weight, u"tons of spam!" 8 | 9 | def order(): 10 | """ 11 | >>> order() 12 | 42 tons of spam! 13 | """ 14 | s = Spam(42) 15 | s.serve() 16 | -------------------------------------------------------------------------------- /docs/examples/quickstart/cythonize/integrate_cy.pyx: -------------------------------------------------------------------------------- 1 | def f(double x): 2 | return x ** 2 - x 3 | 4 | 5 | def integrate_f(double a, double b, int N): 6 | cdef int i 7 | cdef double s, dx 8 | s = 0 9 | dx = (b - a) / N 10 | for i in range(N): 11 | s += f(a + i * dx) 12 | return s * dx 13 | -------------------------------------------------------------------------------- /docs/examples/tutorial/array/unsafe_usage.pyx: -------------------------------------------------------------------------------- 1 | from cpython cimport array 2 | import array 3 | 4 | cdef array.array a = array.array('i', [1, 2, 3]) 5 | 6 | # access underlying pointer: 7 | print(a.data.as_ints[0]) 8 | 9 | from libc.string cimport memset 10 | 11 | memset(a.data.as_voidptr, 0, len(a) * sizeof(int)) 12 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/cpp_string.pyx: -------------------------------------------------------------------------------- 1 | # distutils: language = c++ 2 | 3 | from libcpp.string cimport string 4 | 5 | def get_bytes(): 6 | py_bytes_object = b'hello world' 7 | cdef string s = py_bytes_object 8 | 9 | s.append('abc') 10 | py_bytes_object = s 11 | return py_bytes_object 12 | 13 | -------------------------------------------------------------------------------- /tests/errors/e_func_in_pxd.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cimport e_func_in_pxd_support 4 | 5 | _ERRORS = u""" 6 | 1:5: function definition in pxd file must be declared 'cdef inline' 7 | 4:5: inline function definition in pxd file cannot be 'public' 8 | 7:5: inline function definition in pxd file cannot be 'api' 9 | """ 10 | -------------------------------------------------------------------------------- /tests/run/builtin_globals.py: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: allow_unknown_names 3 | 4 | assert "NEW" not in globals() 5 | 6 | globals().update(NEW=True) 7 | 8 | assert "NEW" in globals() 9 | 10 | 11 | def default_args(value=NEW): 12 | """ 13 | >>> default_args() 14 | True 15 | """ 16 | return value 17 | -------------------------------------------------------------------------------- /tests/run/ext_instance_type_T232.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 232 2 | 3 | cdef class MyExt: 4 | cdef object attr 5 | 6 | def set_attr(value): 7 | """ 8 | >>> set_attr(5) 9 | """ 10 | MyExt().attr = value 11 | 12 | def get_attr(): 13 | """ 14 | >>> get_attr() 15 | """ 16 | return MyExt().attr 17 | -------------------------------------------------------------------------------- /tests/run/mod__name__.pyx: -------------------------------------------------------------------------------- 1 | 2 | module_name = __name__ 3 | 4 | def in_module(): 5 | """ 6 | >>> print(in_module()) 7 | mod__name__ 8 | """ 9 | return module_name 10 | 11 | def in_function(): 12 | """ 13 | >>> print(in_function()) 14 | mod__name__ 15 | """ 16 | return __name__ 17 | -------------------------------------------------------------------------------- /tests/run/modbody.pyx: -------------------------------------------------------------------------------- 1 | 2 | def f(): 3 | """ 4 | >>> f() 5 | >>> g 6 | 42 7 | >>> x == 'spam' 8 | True 9 | >>> y == 'eggs' 10 | True 11 | >>> z == 'spameggs' 12 | True 13 | """ 14 | pass 15 | 16 | g = 42 17 | x = u"spam" 18 | y = u"eggs" 19 | if g: 20 | z = x + y 21 | -------------------------------------------------------------------------------- /tests/run/non_const_as_const_arg.pyx: -------------------------------------------------------------------------------- 1 | cdef double f(const double a, const double b, const double c): 2 | return a + b - c 3 | 4 | def test_non_const_as_const_arg(): 5 | """ 6 | >>> test_non_const_as_const_arg() 7 | 1.0 8 | """ 9 | cdef double a = 1., b = 1., c = 1. 10 | return f(a, b, c) 11 | -------------------------------------------------------------------------------- /docs/examples/userguide/wrapping_CPlusPlus/iterate.pyx: -------------------------------------------------------------------------------- 1 | # distutils: language = c++ 2 | 3 | from libcpp.vector cimport vector 4 | 5 | def main(): 6 | cdef vector[int] v = [4, 6, 5, 10, 3] 7 | 8 | cdef int value 9 | for value in v: 10 | print(value) 11 | 12 | return [x*x for x in v if x % 2 == 0] 13 | -------------------------------------------------------------------------------- /tests/compile/cargdef.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def f(obj, int i, double f, char *s1, char s2[]): 4 | pass 5 | 6 | cdef g(obj, int i, double f, char *s1, char s2[]): 7 | pass 8 | 9 | cdef do_g(object (*func)(object, int, double, char*, char*)): 10 | return func(1, 2, 3.14159, "a", "b") 11 | 12 | do_g(&g) 13 | -------------------------------------------------------------------------------- /tests/run/attribute_and_lambda.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: lambda, attribute, regression 3 | 4 | class TestClass(object): 5 | bar = 123 6 | 7 | 8 | def test_attribute_and_lambda(f): 9 | """ 10 | >>> test_attribute_and_lambda(lambda _: TestClass()) 11 | 123 12 | """ 13 | return f(lambda x: x).bar 14 | -------------------------------------------------------------------------------- /tests/run/complex_numbers_T305_long_double.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 305 2 | 3 | cimport cython 4 | 5 | def test_object_conversion(o): 6 | """ 7 | >>> test_object_conversion(2) 8 | (2+0j) 9 | >>> test_object_conversion(2j - 0.5) 10 | (-0.5+2j) 11 | """ 12 | cdef long double complex a = o 13 | return a 14 | -------------------------------------------------------------------------------- /tests/run/generator_expressions_and_locals.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: genexpr, locals 3 | # ticket: 715 4 | 5 | def genexpr_not_in_locals(): 6 | """ 7 | >>> genexpr_not_in_locals() 8 | {'t': (0, 1, 4, 9, 16, 25, 36, 49, 64, 81)} 9 | """ 10 | t = tuple(x*x for x in range(10)) 11 | return locals() 12 | -------------------------------------------------------------------------------- /tests/run/if_else_expr_cpp_helper.h: -------------------------------------------------------------------------------- 1 | class Holder { 2 | public: 3 | int value; 4 | Holder() : value(-1) { } 5 | Holder(int value) : value(value) { } 6 | }; 7 | 8 | Holder v1(1); 9 | Holder v2(2); 10 | 11 | Holder& get_v1() { 12 | return v1; 13 | } 14 | 15 | Holder& get_v2() { 16 | return v2; 17 | } 18 | -------------------------------------------------------------------------------- /tests/run/temp_alloc_T409.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 409 2 | # Extracted from sage/plot/plot3d/index_face_set.pyx:502 3 | # Turns out to be a bug in implementation of PEP 3132 (Extended Iterable Unpacking) 4 | 5 | def foo(): 6 | """ 7 | >>> foo() 8 | ([0, 0], [0, 0]) 9 | """ 10 | a = b = [0,0] 11 | return a, b 12 | -------------------------------------------------------------------------------- /docs/examples/tutorial/cdef_classes/sin_of_square.pyx: -------------------------------------------------------------------------------- 1 | from libc.math cimport sin 2 | 3 | cdef class Function: 4 | cpdef double evaluate(self, double x) except *: 5 | return 0 6 | 7 | cdef class SinOfSquareFunction(Function): 8 | cpdef double evaluate(self, double x) except *: 9 | return sin(x ** 2) 10 | -------------------------------------------------------------------------------- /docs/examples/userguide/external_C_code/marty.c: -------------------------------------------------------------------------------- 1 | # marty.c 2 | #include "delorean_api.h" 3 | 4 | Vehicle car; 5 | 6 | int main(int argc, char *argv[]) { 7 | Py_Initialize(); 8 | import_delorean(); 9 | car.speed = atoi(argv[1]); 10 | car.power = atof(argv[2]); 11 | activate(&car); 12 | Py_Finalize(); 13 | } 14 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/override.pyx: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | cdef class A: 4 | cdef foo(self): 5 | print("A") 6 | 7 | cdef class B(A): 8 | cpdef foo(self): 9 | print("B") 10 | 11 | class C(B): # NOTE: not cdef class 12 | def foo(self): 13 | print("C") 14 | -------------------------------------------------------------------------------- /docs/examples/userguide/sharing_declarations/spammery.pyx: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | from volume cimport cube 4 | 5 | def menu(description, size): 6 | print(description, ":", cube(size), 7 | "cubic metres of spam") 8 | 9 | menu("Entree", 1) 10 | menu("Main course", 3) 11 | menu("Dessert", 2) 12 | -------------------------------------------------------------------------------- /tests/compile/weakref_T276.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 276 2 | # mode: compile 3 | 4 | __doc__ = u""" 5 | """ 6 | 7 | cdef class A: 8 | cdef __weakref__ 9 | 10 | ctypedef public class B [type B_Type, object BObject]: 11 | cdef __weakref__ 12 | 13 | cdef public class C [type C_Type, object CObject]: 14 | cdef __weakref__ 15 | 16 | -------------------------------------------------------------------------------- /tests/errors/e_exceptclause.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | try: 4 | raise KeyError 5 | except KeyError: 6 | pass 7 | except: 8 | pass 9 | except: 10 | pass 11 | except AttributeError: 12 | pass 13 | 14 | _ERRORS = u""" 15 | 9:0: default 'except:' must be last 16 | 11:0: default 'except:' must be last 17 | """ 18 | -------------------------------------------------------------------------------- /tests/errors/e_powop.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | def f(): 4 | cdef char *str1 5 | cdef float flt1, flt2, flt3 6 | flt1 = str1 ** flt3 # error 7 | flt1 = flt2 ** str1 # error 8 | 9 | _ERRORS = u""" 10 | 6:13: Invalid operand types for '**' (char *; float) 11 | 7:13: Invalid operand types for '**' (float; char *) 12 | """ 13 | -------------------------------------------------------------------------------- /tests/errors/e_pxdimpl.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cimport e_pxdimpl_imported 4 | 5 | _ERRORS = u""" 6 | 6:4: function definition in pxd file must be declared 'cdef inline' 7 | 18:4: function definition in pxd file must be declared 'cdef inline' 8 | 23:8: function definition in pxd file must be declared 'cdef inline' 9 | """ 10 | -------------------------------------------------------------------------------- /tests/errors/nogilfunctype.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef extern from *: 4 | cdef void f() 5 | cdef void (*fp)() nogil 6 | 7 | cdef void g() nogil 8 | cdef void (*gp)() 9 | 10 | gp = g 11 | 12 | fp = f 13 | 14 | _ERRORS = u""" 15 | 12:5: Cannot assign type 'void (void)' to 'void (*)(void) nogil' 16 | """ 17 | -------------------------------------------------------------------------------- /tests/run/boolean_context.pyx: -------------------------------------------------------------------------------- 1 | 2 | def test(): 3 | """ 4 | >>> test() 5 | True 6 | """ 7 | cdef int x = 5 8 | return bool(x) 9 | 10 | def test_bool_and_int(): 11 | """ 12 | >>> test_bool_and_int() 13 | 1 14 | """ 15 | cdef int x = 5 16 | cdef int b = bool(x) 17 | return b 18 | -------------------------------------------------------------------------------- /tests/run/cimport_alias_subclass.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | 4 | cimport cimport_alias_subclass_helper as cash 5 | 6 | cdef class Derived(cash.Base): 7 | cdef bint foo(self): 8 | print "Hello" 9 | 10 | def run(): 11 | """ 12 | >>> run() 13 | Hello 14 | """ 15 | d = Derived() 16 | d.foo() 17 | -------------------------------------------------------------------------------- /docs/examples/userguide/wrapping_CPlusPlus/vector_demo.pyx: -------------------------------------------------------------------------------- 1 | # distutils: language = c++ 2 | 3 | from libcpp.vector cimport vector 4 | 5 | cdef vector[int] vect 6 | cdef int i, x 7 | 8 | for i in range(10): 9 | vect.push_back(i) 10 | 11 | for i in range(10): 12 | print(vect[i]) 13 | 14 | for x in vect: 15 | print(x) 16 | -------------------------------------------------------------------------------- /tests/compile/altet1.pyx.BROKEN: -------------------------------------------------------------------------------- 1 | __doc__ = """ 2 | >>> flub(25) 3 | 25 4 | >>> g() 5 | 0 6 | """ 7 | 8 | cdef extern from "altet1.h": 9 | ctypedef int blarg 10 | 11 | cdef blarg globvar 12 | 13 | def flub(blarg bobble): 14 | print bobble 15 | 16 | globvar = 0 17 | 18 | def g(): 19 | return globvar 20 | -------------------------------------------------------------------------------- /tests/compile/cimportfrom_T248.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 248 2 | # mode: compile 3 | 4 | from ewing8 cimport (Foo, 5 | 6 | 7 | Blarg) 8 | 9 | from declandimpl cimport (Sandwich 10 | 11 | 12 | , 13 | 14 | 15 | 16 | 17 | Tomato) 18 | 19 | cdef extern Foo yummy 20 | -------------------------------------------------------------------------------- /tests/errors/cdefspecial.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef class Test: 4 | cdef __cinit__(self): 5 | pass 6 | 7 | cdef __len__(self): 8 | pass 9 | 10 | _ERRORS = u""" 11 | 4:9: Special methods must be declared with 'def', not 'cdef' 12 | 7:9: Special methods must be declared with 'def', not 'cdef' 13 | """ 14 | -------------------------------------------------------------------------------- /tests/errors/missing_baseclass_in_predecl_T262.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 262 2 | # mode: error 3 | 4 | cdef class Album 5 | 6 | cdef class SessionStruct: 7 | cdef Album _create_album(self, void* album, bint take_owner): 8 | pass 9 | 10 | cdef class Album(SessionStruct): 11 | pass 12 | 13 | 14 | _ERROR = u""" 15 | """ 16 | -------------------------------------------------------------------------------- /tests/errors/w_uninitialized_generators.pyx: -------------------------------------------------------------------------------- 1 | # cython: warn.maybe_uninitialized=True 2 | # mode: error 3 | # tag: werror 4 | 5 | def unbound_inside_generator(*args): 6 | for i in args: 7 | yield x 8 | x = i + i 9 | 10 | _ERRORS = """ 11 | 7:14: local variable 'x' might be referenced before assignment 12 | """ 13 | -------------------------------------------------------------------------------- /tests/run/relativeimport_star_T542.pyx: -------------------------------------------------------------------------------- 1 | from distutils import core, version 2 | 3 | __name__='distutils.core.cytest_relativeimport_T542' # fool Python we are in distutils 4 | __package__='distutils.core' # fool Python we are in distutils 5 | 6 | from . import * 7 | 8 | __doc__ = """ 9 | >>> core.setup == setup 10 | True 11 | """ 12 | -------------------------------------------------------------------------------- /tests/compile/cassign.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef void foo(): 4 | cdef int i1, i2=0 5 | cdef char c1=0, c2 6 | cdef char *p1, *p2=NULL 7 | cdef object obj1 8 | i1 = i2 9 | i1 = c1 10 | p1 = p2 11 | obj1 = i1 12 | i1 = obj1 13 | p1 = obj1 14 | p1 = "spanish inquisition" 15 | 16 | foo() 17 | -------------------------------------------------------------------------------- /tests/errors/undefinedname.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | i = _this_global_name_does_not_exist_ 4 | 5 | def test(i): 6 | return _this_local_name_does_not_exist_ 7 | 8 | _ERRORS = u""" 9 | 3:4:undeclared name not builtin: _this_global_name_does_not_exist_ 10 | 6:11:undeclared name not builtin: _this_local_name_does_not_exist_ 11 | """ 12 | -------------------------------------------------------------------------------- /tests/run/cpdef_enums.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from *: 2 | cpdef enum: # ExternPxd 3 | FOUR "4" 4 | EIGHT "8" 5 | 6 | cdef enum: # ExternSecretPxd 7 | SIXTEEN "16" 8 | 9 | cpdef enum PxdEnum: 10 | RANK_0 = 11 11 | RANK_1 = 37 12 | RANK_2 = 389 13 | 14 | cdef enum PxdSecretEnum: 15 | RANK_3 = 5077 16 | -------------------------------------------------------------------------------- /tests/run/mangle_c_keywords.pyx: -------------------------------------------------------------------------------- 1 | # Tests that illegal member and vtab entries are mangled. 2 | cdef class A: 3 | """ 4 | >>> a = A(100) 5 | >>> a.case() 6 | 100 7 | """ 8 | def __init__(self, value): 9 | self.switch = value 10 | cdef int switch 11 | cpdef case(self): 12 | return self.switch 13 | -------------------------------------------------------------------------------- /tests/run/packedstruct_T290.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 290 2 | 3 | """ 4 | >>> f() 5 | (9, 9) 6 | """ 7 | 8 | cdef packed struct MyCdefStruct: 9 | char a 10 | double b 11 | 12 | ctypedef packed struct MyCTypeDefStruct: 13 | char a 14 | double b 15 | 16 | def f(): 17 | return (sizeof(MyCdefStruct), sizeof(MyCTypeDefStruct)) 18 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/to_char.pyx: -------------------------------------------------------------------------------- 1 | # define a global name for whatever char type is used in the module 2 | ctypedef unsigned char char_type 3 | 4 | cdef char_type[:] _chars(s): 5 | if isinstance(s, unicode): 6 | # encode to the specific encoding used inside of the module 7 | s = (s).encode('utf8') 8 | return s 9 | -------------------------------------------------------------------------------- /tests/compile/excvalcheck.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | extern DL_EXPORT(int) spam(void); 5 | extern DL_EXPORT(void) grail(void); 6 | extern DL_EXPORT(char *)tomato(void); 7 | #ifdef __cplusplus 8 | } 9 | #endif 10 | 11 | int spam(void) {return 0;} 12 | void grail(void) {return;} 13 | char *tomato(void) {return 0;} 14 | -------------------------------------------------------------------------------- /tests/errors/extended_unpacking_notuple.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | # very common mistake for new users (handled early by the parser) 4 | 5 | def no_tuple_assignment(): 6 | *a = [1] 7 | 8 | _ERRORS = u""" 9 | 6:4: a starred assignment target must be in a list or tuple - maybe you meant to use an index assignment: var[0] = ... 10 | """ 11 | -------------------------------------------------------------------------------- /tests/run/ishimoto3.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> c1 = C1() 3 | >>> c2 = C2(c1) 4 | >>> c1 is c2.getc1() 5 | True 6 | """ 7 | 8 | cdef class C1: 9 | pass 10 | 11 | cdef class C2: 12 | cdef C1 c1 13 | 14 | def __init__(self, arg): 15 | self.c1 = arg 16 | 17 | def getc1(self): 18 | return self.c1 19 | -------------------------------------------------------------------------------- /tests/run/r_mcintyre1.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> b = Bicycle() 3 | >>> b.fall_off() 4 | Falling off extremely hard 5 | >>> b.fall_off("somewhat") 6 | Falling off somewhat hard 7 | """ 8 | 9 | class Bicycle: 10 | 11 | def fall_off(self, how_hard = u"extremely"): 12 | print u"Falling off", how_hard, u"hard" 13 | -------------------------------------------------------------------------------- /tests/run/slice2b.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from *: 2 | ctypedef class __builtin__.list [ object PyListObject ]: 3 | pass 4 | 5 | def slice_of_typed_value(): 6 | 7 | """ 8 | >>> slice_of_typed_value() 9 | [1, 2, 3] 10 | """ 11 | cdef object a = [] 12 | cdef list L = [1, 2, 3] 13 | a[:] = L 14 | return a 15 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/struct_union_enum.pyx: -------------------------------------------------------------------------------- 1 | cdef struct Grail: 2 | int age 3 | float volume 4 | 5 | cdef union Food: 6 | char *spam 7 | float *eggs 8 | 9 | cdef enum CheeseType: 10 | cheddar, edam, 11 | camembert 12 | 13 | cdef enum CheeseState: 14 | hard = 1 15 | soft = 2 16 | runny = 3 17 | -------------------------------------------------------------------------------- /tests/run/cimport_cython_T505.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 505 2 | 3 | cimport cython 4 | 5 | cdef extern from "Python.h": 6 | cdef cython.unicode PyUnicode_DecodeUTF8(char* s, Py_ssize_t size, char* errors) 7 | 8 | def test_capi(): 9 | """ 10 | >>> print(test_capi()) 11 | abc 12 | """ 13 | return PyUnicode_DecodeUTF8("abc", 3, NULL) 14 | -------------------------------------------------------------------------------- /tests/run/classbody_exec.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> print(D) 3 | {u'answer': (42, 42)} 4 | """ 5 | 6 | import sys 7 | if sys.version_info[0] >= 3: 8 | __doc__ = __doc__.replace(u"u'", u"'") 9 | 10 | D = {} 11 | 12 | def foo(x): 13 | return x, x 14 | 15 | cdef class Spam: 16 | answer = 42 17 | D[u'answer'] = foo(answer) 18 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | 3 | *.pyc 4 | *.pyo 5 | __pycache__ 6 | *.egg 7 | *.egg-info 8 | 9 | Cython/Compiler/*.c 10 | Cython/Plex/*.c 11 | Cython/Runtime/refnanny.c 12 | 13 | TEST_TMP/ 14 | build/ 15 | dist/ 16 | .git/ 17 | .gitrev 18 | .coverage 19 | *.orig 20 | *.rej 21 | *.dep 22 | *.swp 23 | *.so 24 | *.o 25 | *~ 26 | 27 | tags 28 | TAGS 29 | -------------------------------------------------------------------------------- /docs/examples/tutorial/array/resize.pyx: -------------------------------------------------------------------------------- 1 | from cpython cimport array 2 | import array 3 | 4 | cdef array.array a = array.array('i', [1, 2, 3]) 5 | cdef array.array b = array.array('i', [4, 5, 6]) 6 | 7 | # extend a with b, resize as needed 8 | array.extend(a, b) 9 | # resize a, leaving just original three elements 10 | array.resize(a, len(a) - len(b)) 11 | -------------------------------------------------------------------------------- /docs/examples/tutorial/profiling_tutorial/calc_pi_2.pyx: -------------------------------------------------------------------------------- 1 | # cython: profile=True 2 | 3 | # calc_pi.pyx 4 | 5 | def recip_square(int i): 6 | return 1. / i ** 2 7 | 8 | def approx_pi(int n=10000000): 9 | cdef double val = 0. 10 | cdef int k 11 | for k in range(1, n + 1): 12 | val += recip_square(k) 13 | return (6 * val) ** .5 14 | -------------------------------------------------------------------------------- /docs/examples/tutorial/string/return_memview.pyx: -------------------------------------------------------------------------------- 1 | def process_byte_data(unsigned char[:] data): 2 | # ... process the data, here, dummy processing. 3 | cdef bint return_all = (data[0] == 108) 4 | 5 | if return_all: 6 | return bytes(data) 7 | else: 8 | # example for returning a slice 9 | return bytes(data[5:7]) 10 | -------------------------------------------------------------------------------- /docs/examples/userguide/extension_types/my_module.pyx: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | cdef class Shrubbery: 4 | 5 | def __init__(self, w, h): 6 | self.width = w 7 | self.height = h 8 | 9 | def describe(self): 10 | print("This shrubbery is", self.width, 11 | "by", self.height, "cubits.") 12 | -------------------------------------------------------------------------------- /docs/examples/userguide/external_C_code/c_code_docstring.pyx: -------------------------------------------------------------------------------- 1 | cdef extern from *: 2 | """ 3 | /* This is C code which will be put 4 | * in the .c file output by Cython */ 5 | static long square(long x) {return x * x;} 6 | #define assign(x, y) ((x) = (y)) 7 | """ 8 | long square(long x) 9 | void assign(long& x, long y) 10 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/view_string.pyx: -------------------------------------------------------------------------------- 1 | cdef bint is_y_in(const unsigned char[:] string_view): 2 | cdef int i 3 | for i in range(string_view.shape[0]): 4 | if string_view[i] == b'y': 5 | return True 6 | return False 7 | 8 | print(is_y_in(b'hello world')) # False 9 | print(is_y_in(b'hello Cython')) # True 10 | -------------------------------------------------------------------------------- /tests/compile/inplace_ops.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | def test(): 4 | cdef object a = 1, b = 2 5 | cdef char *p = 'abc' 6 | a += b 7 | a -= b 8 | a *= b 9 | a /= b 10 | a %= b 11 | a **= b 12 | a <<= b 13 | a >>= b 14 | a &= b 15 | a ^= b 16 | a |= b 17 | p += 42 18 | p -= 42 19 | p += a 20 | -------------------------------------------------------------------------------- /tests/errors/nonconst_def_tuple.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | DEF t = (1,2,3) 4 | DEF t_const = (1,t,2) 5 | DEF t_non_const = (1,[1,2,3],3,t[4]) 6 | 7 | x = t_non_const 8 | 9 | _ERRORS = u""" 10 | 5:32: Error in compile-time expression: IndexError: tuple index out of range 11 | 7:4: Invalid type for compile-time constant: [1, 2, 3] (type list) 12 | """ 13 | -------------------------------------------------------------------------------- /tests/errors/w_uninitialized_del.pyx: -------------------------------------------------------------------------------- 1 | # cython: warn.maybe_uninitialized=True 2 | # mode: error 3 | # tag: werror 4 | 5 | def foo(x): 6 | a = 1 7 | del a, b 8 | b = 2 9 | return a, b 10 | 11 | _ERRORS = """ 12 | 7:11: local variable 'b' referenced before assignment 13 | 9:11: local variable 'a' referenced before assignment 14 | """ 15 | -------------------------------------------------------------------------------- /tests/run/ass2cglobal.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> what() 3 | 0 5 4 | >>> f(5) 5 | >>> what() 6 | 42 5 7 | >>> f(6) 8 | >>> what() 9 | 42 6 10 | >>> f("spam") 11 | >>> what() 12 | 42 spam 13 | """ 14 | 15 | cdef int i = 0 16 | cdef x = 5 17 | 18 | def f(a): 19 | global i, x 20 | i = 42 21 | x = a 22 | 23 | def what(): 24 | print i,x 25 | -------------------------------------------------------------------------------- /tests/run/extclassbody.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> s = Spam() 3 | >>> s.a 4 | 2 5 | >>> s.c 6 | 3 7 | >>> s.test(5) 8 | 13 9 | >>> s.b 10 | 5 11 | """ 12 | 13 | cdef class Spam: 14 | a = 1 15 | def test(self, a): 16 | return a + self.b + self.c 17 | b = a + 2 # 3 18 | a = b - 1 # 2 19 | c = 3 # 3 20 | b = c + a # 5 21 | -------------------------------------------------------------------------------- /docs/examples/tutorial/profiling_tutorial/profile_2.py: -------------------------------------------------------------------------------- 1 | # profile.py 2 | 3 | import pstats, cProfile 4 | 5 | import pyximport 6 | pyximport.install() 7 | 8 | import calc_pi 9 | 10 | cProfile.runctx("calc_pi.approx_pi()", globals(), locals(), "Profile.prof") 11 | 12 | s = pstats.Stats("Profile.prof") 13 | s.strip_dirs().sort_stats("time").print_stats() 14 | -------------------------------------------------------------------------------- /docs/examples/userguide/language_basics/optional_subclassing.pyx: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | cdef class A: 4 | cdef foo(self): 5 | print("A") 6 | 7 | cdef class B(A): 8 | cdef foo(self, x=None): 9 | print("B", x) 10 | 11 | cdef class C(B): 12 | cpdef foo(self, x=True, int k=3): 13 | print("C", x, k) 14 | -------------------------------------------------------------------------------- /tests/broken/builtindict.pyx: -------------------------------------------------------------------------------- 1 | cdef int f() except -1: 2 | cdef dict d 3 | cdef object x, z 4 | cdef int i 5 | z = dict 6 | d = dict(x) 7 | d = dict(*x) 8 | d.clear() 9 | z = d.copy() 10 | z = d.items() 11 | z = d.keys() 12 | z = d.values() 13 | d.merge(x, i) 14 | d.update(x) 15 | d.merge_pairs(x, i) 16 | -------------------------------------------------------------------------------- /Cython/Utility/TestUtilityLoader.c: -------------------------------------------------------------------------------- 1 | ////////// TestUtilityLoader.proto ////////// 2 | test {{loader}} prototype 3 | 4 | ////////// TestUtilityLoader ////////// 5 | //@requires: OtherUtility 6 | test {{loader}} impl 7 | 8 | ////////// OtherUtility.proto ////////// 9 | req {{loader}} proto 10 | 11 | ////////// OtherUtility ////////// 12 | req {{loader}} impl 13 | -------------------------------------------------------------------------------- /tests/compile/ctypedefpubapi.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | ctypedef public api class Foo [type PyFoo_Type, object PyFooObject]: 4 | pass 5 | 6 | cdef api: 7 | ctypedef public class Bar [type PyBar_Type, object PyBarObject]: 8 | pass 9 | 10 | cdef public api: 11 | ctypedef class Baz [type PyBaz_Type, object PyBazObject]: 12 | pass 13 | -------------------------------------------------------------------------------- /tests/errors/cdefkwargs.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | __doc__ = u""" 4 | >>> call2() 5 | >>> call3() 6 | >>> call4() 7 | """ 8 | 9 | # the calls: 10 | 11 | def call2(): 12 | b(1,2) 13 | 14 | def call3(): 15 | b(1,2,3) 16 | 17 | def call4(): 18 | b(1,2,3,4) 19 | 20 | # the called function: 21 | 22 | cdef b(a, b, c=1, d=2): 23 | pass 24 | -------------------------------------------------------------------------------- /tests/errors/e_tempcast.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef object blarg 4 | 5 | def foo(obj): 6 | cdef void *p 7 | p = blarg # ok 8 | p = (obj + blarg) # error - temporary 9 | 10 | _ERRORS = u""" 11 | 8:5: Casting temporary Python object to non-numeric non-Python type 12 | 8:5: Storing unsafe C derivative of temporary Python reference 13 | """ 14 | -------------------------------------------------------------------------------- /tests/run/cdef_class_field.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: exttype 3 | # ticket: 677 4 | 5 | """ 6 | >>> str(Foo(4)) 7 | '4' 8 | >>> x 9 | 3 10 | """ 11 | 12 | x = 3 13 | cdef int y 14 | 15 | cdef class Foo: 16 | cdef int x 17 | cdef int y 18 | def __init__(self, x): 19 | self.x = x 20 | def __str__(self): 21 | return str(self.x) 22 | -------------------------------------------------------------------------------- /tests/run/pynumop.pyx: -------------------------------------------------------------------------------- 1 | def f(): 2 | """ 3 | >>> f() 4 | 6 5 | """ 6 | obj1 = 1 7 | obj2 = 2 8 | obj3 = 3 9 | obj1 = obj2 * obj3 10 | return obj1 11 | 12 | def g(): 13 | """ 14 | >>> g() 15 | 2 16 | """ 17 | obj1 = 12 18 | obj2 = 6 19 | obj3 = 3 20 | obj1 = obj2 / obj3 21 | return int(obj1) 22 | -------------------------------------------------------------------------------- /tests/run/r_bowden1.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> f(100) 3 | 101L 4 | >>> g(3000000000) 5 | 3000000001L 6 | """ 7 | 8 | import sys 9 | if sys.version_info[0] >= 3: 10 | __doc__ = __doc__.replace(u"L", u"") 11 | 12 | def f(x): 13 | cdef unsigned long long ull 14 | ull = x 15 | return ull + 1 16 | 17 | def g(unsigned long x): 18 | return x + 1 19 | -------------------------------------------------------------------------------- /tests/run/tupleunpack_T712.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # ticket: 712 3 | 4 | def single_from_string(): 5 | """ 6 | >>> print(single_from_string()) 7 | a 8 | """ 9 | (a,) = 'a' 10 | return a 11 | 12 | def single_from_set(): 13 | """ 14 | >>> print(single_from_set()) 15 | a 16 | """ 17 | (a,) = set(["a"]) 18 | return a 19 | -------------------------------------------------------------------------------- /tests/run/yield_inside_lambda.py: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: generators, lambda 3 | 4 | 5 | def test_inside_lambda(): 6 | """ 7 | >>> obj = test_inside_lambda()() 8 | >>> next(obj) 9 | 1 10 | >>> next(obj) 11 | 2 12 | >>> try: next(obj) 13 | ... except StopIteration: pass 14 | """ 15 | return lambda:((yield 1), (yield 2)) 16 | -------------------------------------------------------------------------------- /Cython/Includes/libc/setjmp.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "" nogil: 2 | ctypedef struct jmp_buf: 3 | pass 4 | int setjmp(jmp_buf state) 5 | void longjmp(jmp_buf state, int value) 6 | 7 | ctypedef struct sigjmp_buf: 8 | pass 9 | int sigsetjmp(sigjmp_buf state, int savesigs) 10 | void siglongjmp(sigjmp_buf state, int value) 11 | -------------------------------------------------------------------------------- /Cython/Includes/libcpp/stack.pxd: -------------------------------------------------------------------------------- 1 | cdef extern from "" namespace "std" nogil: 2 | cdef cppclass stack[T]: 3 | ctypedef T value_type 4 | stack() except + 5 | stack(stack&) except + 6 | #stack(Container&) 7 | bint empty() 8 | void pop() 9 | void push(T&) 10 | size_t size() 11 | T& top() 12 | -------------------------------------------------------------------------------- /tests/compile/arrayptrcompat.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef enum E: 4 | z 5 | 6 | cdef void f(): 7 | cdef int *p 8 | cdef void *v 9 | cdef int[5] a 10 | cdef int i=0 11 | cdef E e=z 12 | p = a 13 | v = a 14 | p = a + i 15 | p = a + e 16 | p = i + a 17 | p = e + a 18 | p = a - i 19 | p = a - e 20 | 21 | f() 22 | -------------------------------------------------------------------------------- /tests/errors/e_ctypedefornot.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef struct Foo 4 | 5 | ctypedef struct Foo: 6 | int i 7 | 8 | ctypedef struct Blarg: 9 | char c 10 | 11 | cdef struct Blarg 12 | 13 | cdef Foo f 14 | cdef Blarg b 15 | 16 | _ERRORS = u""" 17 | 5:0: 'Foo' previously declared using 'cdef' 18 | 11:5: 'Blarg' previously declared using 'ctypedef' 19 | """ 20 | -------------------------------------------------------------------------------- /tests/run/array_address.pyx: -------------------------------------------------------------------------------- 1 | ctypedef int five_ints[5] 2 | 3 | def test_array_address(int ix, int x): 4 | """ 5 | >>> test_array_address(0, 100) 6 | 100 7 | >>> test_array_address(2, 200) 8 | 200 9 | """ 10 | cdef five_ints a 11 | a[:] = [1, 2, 3, 4, 5] 12 | cdef five_ints *a_ptr = &a 13 | a_ptr[0][ix] = x 14 | return a[ix] 15 | -------------------------------------------------------------------------------- /tests/run/float_floor_division_T260.pyx: -------------------------------------------------------------------------------- 1 | # ticket: 260 2 | 3 | def floor_div_float(double a, double b): 4 | """ 5 | >>> floor_div_float(2, 1.5) 6 | 1.0 7 | >>> floor_div_float(2, -1.5) 8 | -2.0 9 | >>> floor_div_float(-2.3, 1.5) 10 | -2.0 11 | >>> floor_div_float(1e10, 1e-10) == 1e20 12 | True 13 | """ 14 | return a // b 15 | -------------------------------------------------------------------------------- /tests/run/str_ascii_auto_encoding.pyx: -------------------------------------------------------------------------------- 1 | #cython: c_string_type = str 2 | #cython: c_string_encoding = ascii 3 | 4 | "End of first directives" 5 | 6 | include "unicode_ascii_auto_encoding.pyx" 7 | 8 | auto_string_type = str 9 | 10 | def check_auto_string_type(): 11 | """ 12 | >>> check_auto_string_type() 13 | """ 14 | assert auto_string_type is str 15 | -------------------------------------------------------------------------------- /Demos/embed/assert_equal.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | 3 | import sys 4 | 5 | f1 = open(sys.argv[1]) 6 | f2 = open(sys.argv[2]) 7 | try: 8 | if f1.read() != f2.read(): 9 | print("Files differ") 10 | sys.exit(1) 11 | else: 12 | print("Files identical") 13 | finally: 14 | f1.close() 15 | f2.close() 16 | -------------------------------------------------------------------------------- /docs/examples/tutorial/profiling_tutorial/calc_pi_3.pyx: -------------------------------------------------------------------------------- 1 | # cython: profile=True 2 | 3 | # calc_pi.pyx 4 | 5 | cdef inline double recip_square(int i): 6 | return 1. / (i * i) 7 | 8 | def approx_pi(int n=10000000): 9 | cdef double val = 0. 10 | cdef int k 11 | for k in range(1, n + 1): 12 | val += recip_square(k) 13 | return (6 * val) ** .5 14 | -------------------------------------------------------------------------------- /pyximport/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.0 2 | Name: pyximport 3 | Version: 1.0 4 | Summary: Hooks to build and run Pyrex files as if they were simple Python files 5 | Home-page: http://www.prescod.net/pyximport 6 | Author: Paul Prescod 7 | Author-email: paul@prescod.net 8 | License: Python 9 | Description: UNKNOWN 10 | Keywords: pyrex import hook 11 | Platform: UNKNOWN 12 | -------------------------------------------------------------------------------- /tests/broken/r_extinherit.pyx: -------------------------------------------------------------------------------- 1 | cdef class Parrot: 2 | 3 | cdef object plumage 4 | 5 | def __init__(self): 6 | self.plumage = "yellow" 7 | 8 | def describe(self): 9 | print "This bird has lovely", self.plumage, "plumage." 10 | 11 | 12 | cdef class Norwegian(Parrot): 13 | 14 | def __init__(self): 15 | self.plumage = "blue" 16 | 17 | -------------------------------------------------------------------------------- /tests/build/basic_cythonize.srctree: -------------------------------------------------------------------------------- 1 | PYTHON setup.py build_ext --inplace 2 | PYTHON -c "import a" 3 | 4 | ######## setup.py ######## 5 | 6 | 7 | # TODO: Better interface... 8 | from Cython.Build.Dependencies import cythonize 9 | 10 | from distutils.core import setup 11 | 12 | setup( 13 | ext_modules = cythonize("*.pyx"), 14 | ) 15 | 16 | ######## a.pyx ######## 17 | -------------------------------------------------------------------------------- /tests/compile/excvalcheck.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern from "excvalcheck.h": 4 | pass 5 | 6 | cdef extern int spam() except -1 7 | cdef extern void grail() except * 8 | cdef extern char *tomato() except? NULL 9 | 10 | cdef void eggs(): 11 | cdef int i 12 | cdef char *p 13 | i = spam() 14 | grail() 15 | p = tomato() 16 | 17 | eggs() 18 | -------------------------------------------------------------------------------- /tests/errors/e_cdefassign.pyx: -------------------------------------------------------------------------------- 1 | # mode: error 2 | 3 | cdef class A: 4 | cdef int value = 3 5 | 6 | cdef extern from *: 7 | cdef struct B: 8 | int value = 3 9 | 10 | _ERRORS = u""" 11 | 4:13: Cannot assign default value to fields in cdef classes, structs or unions 12 | 8:12: Cannot assign default value to fields in cdef classes, structs or unions 13 | """ 14 | -------------------------------------------------------------------------------- /tests/run/class_scope_del_T684.py: -------------------------------------------------------------------------------- 1 | # mode:run 2 | # tag: class, scope, del 3 | # ticket: 684 4 | 5 | class DelInClass(object): 6 | """ 7 | >>> DelInClass.y 8 | 5 9 | >>> DelInClass.x 10 | Traceback (most recent call last): 11 | AttributeError: type object 'DelInClass' has no attribute 'x' 12 | """ 13 | x = 5 14 | y = x 15 | del x 16 | -------------------------------------------------------------------------------- /tests/run/memview_vector.pyx: -------------------------------------------------------------------------------- 1 | # mode: run 2 | # tag: cpp 3 | 4 | from libcpp.vector cimport vector 5 | 6 | def memview_test(L, int i, int x): 7 | """ 8 | >>> memview_test(range(10), 7, 100) 9 | [0, 1, 2, 3, 4, 5, 6, 100, 8, 9] 10 | """ 11 | cdef vector[int] v = L 12 | cdef int[::1] mv = &v[0] 13 | mv[i] = x 14 | return v 15 | -------------------------------------------------------------------------------- /tests/run/r_uintindex.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> print(idx_uint( ["buckle", "my", "shoe"], 2)) 3 | shoe 4 | >>> print(idx_ulong(["buckle", "my", "shoe"], 2)) 5 | shoe 6 | """ 7 | 8 | def idx_ulong(seq, i): 9 | cdef unsigned long u 10 | u = i 11 | return seq[u] 12 | 13 | def idx_uint(seq, i): 14 | cdef unsigned int u 15 | u = i 16 | return seq[u] 17 | -------------------------------------------------------------------------------- /tests/run/rodriguez_1.pyx: -------------------------------------------------------------------------------- 1 | __doc__ = u""" 2 | >>> b = B() 3 | >>> sorted(b.t.items()) 4 | [(1, ((1, 2, 3),)), (2, (1, 2, 3))] 5 | """ 6 | 7 | class B: 8 | def __init__(self): 9 | self.t = { 10 | 1 : ( 11 | (1, 2, 3) 12 | , 13 | ) 14 | 15 | , 2 : ( 1, 2, 3) 16 | } 17 | -------------------------------------------------------------------------------- /tests/run/switch_transform.pyx: -------------------------------------------------------------------------------- 1 | # cython: optimize.use_switch=False 2 | # cython: linetrace=True 3 | 4 | cdef extern from *: 5 | enum: 6 | ONE "1" 7 | ONE_AGAIN "1+0" 8 | 9 | def is_not_one(int i): 10 | """ 11 | >>> is_not_one(1) 12 | False 13 | >>> is_not_one(2) 14 | True 15 | """ 16 | return i != ONE and i != ONE_AGAIN 17 | -------------------------------------------------------------------------------- /Cython/Includes/libcpp/typeinfo.pxd: -------------------------------------------------------------------------------- 1 | from libcpp cimport bool 2 | 3 | cdef extern from "" namespace "std" nogil: 4 | cdef cppclass type_info: 5 | const char* name() 6 | int before(const type_info&) 7 | bool operator==(const type_info&) 8 | bool operator!=(const type_info&) 9 | # C++11-only 10 | size_t hash_code() 11 | -------------------------------------------------------------------------------- /Demos/benchmarks/meteor_contest.pxd: -------------------------------------------------------------------------------- 1 | cimport cython 2 | 3 | cdef list rotate(list ido, dict rd=*) 4 | 5 | cdef list flip(list ido, dict fd=*) 6 | 7 | cdef list permute(list ido, list r_ido) 8 | 9 | @cython.locals(n_i_min=long) 10 | cpdef solve(long n, long i_min, free, list curr_board, list pieces_left, list solutions, 11 | list fps=*, list se_nh=*, bisect=*) 12 | -------------------------------------------------------------------------------- /docs/examples/not_in_docs/great_circle/c1.pyx: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def great_circle(lon1, lat1, lon2, lat2): 4 | radius = 3956 # miles 5 | x = math.pi/180.0 6 | 7 | a = (90.0 - lat1)*x 8 | b = (90.0 - lat2)*x 9 | theta = (lon2 - lon1)*x 10 | c = math.acos(math.cos(a)*math.cos(b) + math.sin(a)*math.sin(b)*math.cos(theta)) 11 | 12 | return radius*c 13 | -------------------------------------------------------------------------------- /docs/examples/not_in_docs/great_circle/p1.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def great_circle(lon1, lat1, lon2, lat2): 4 | radius = 3956 # miles 5 | x = math.pi/180.0 6 | 7 | a = (90.0 - lat1)*x 8 | b = (90.0 - lat2)*x 9 | theta = (lon2 - lon1)*x 10 | c = math.acos(math.cos(a)*math.cos(b) + math.sin(a)*math.sin(b)*math.cos(theta)) 11 | 12 | return radius*c 13 | -------------------------------------------------------------------------------- /docs/examples/userguide/memoryviews/copy.pyx: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | cdef int[:, :, :] to_view, from_view 4 | to_view = np.empty((20, 15, 30), dtype=np.intc) 5 | from_view = np.ones((20, 15, 30), dtype=np.intc) 6 | 7 | # copy the elements in from_view to to_view 8 | to_view[...] = from_view 9 | # or 10 | to_view[:] = from_view 11 | # or 12 | to_view[:, :, :] = from_view 13 | -------------------------------------------------------------------------------- /docs/src/reference/interfacing_with_other_code.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: cython 2 | 3 | .. _interfacing_with_other_code: 4 | 5 | *************************** 6 | Interfacing with Other Code 7 | *************************** 8 | 9 | == 10 | C 11 | == 12 | 13 | === 14 | C++ 15 | === 16 | 17 | ======= 18 | Fortran 19 | ======= 20 | 21 | ===== 22 | NumPy 23 | ===== 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/compile/extexttype.pyx: -------------------------------------------------------------------------------- 1 | # mode: compile 2 | 3 | cdef extern class external.Spam [object SpamObject]: 4 | pass 5 | 6 | ctypedef extern class external.Grail [object Grail]: 7 | pass 8 | 9 | cdef extern from "food.h": 10 | 11 | class external.Tomato [object Tomato]: 12 | pass 13 | 14 | class external.Bicycle [object Bicycle]: 15 | pass 16 | --------------------------------------------------------------------------------