summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ModuleNode.py
Commit message (Collapse)AuthorAgeFilesLines
* Fix module struct C syntax error on windows (#5171)AnyLeftovers2022-12-121-1/+1
| | | The module struct was being initialized with `= {}` which isn't valid C until C23 so MSVC was rejecting it
* Refactor module state to always use struct (#5056)da-woods2022-12-011-33/+30
| | | | | | | | | | | | | | | | | | | | | First part of https://github.com/cython/cython/issues/3689 First part of https://github.com/cython/cython/issues/4495 This tries to put all the global static variables into the module state struct. When CYTHON_USE_MODULE_STATE is false, they're looked up from a single static instance of the struct. This allows a lot of semi-duplicated code to be dropped. It doesn't get rid of the awkward `#defines` to access the struct (that's probably the next step of the cleanup). It moves the stringtab from a global into a function local. It moves the statically defined coroutine types into the module state struct in the same way that CyFunction/FusedFunction already were. It's mostly an exercise in deleting things - it doesn't attempt to do any significant cleanup of the generation code.
* Use topological sort to speed up quadratic-time ↵Scott Wolchok2022-11-301-23/+26
| | | | ModuleNode.sort_types_by_inheritance() (GH-5139)
* Avoid warnings from bitwise '&' with boolean operands (#5096)Alexander Shadchin2022-11-201-4/+4
| | | | | | | | | | With clang 14+ and `-Werror,-Wbitwise-instead-of-logical` build failed with: ``` $(BUILD_ROOT)/library/python/cyson/cyson/_cyson.pyx.cpp:29973:39: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical] if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5cyson_6_cyson_InputStream < 16) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5cyson_6_cyson_InputStream)) & ((Py_TYPE(o)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0))) { ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ && $(BUILD_ROOT)/library/python/cyson/cyson/_cyson.pyx.cpp:29973:39: note: cast one or both operands to int to silence this warning ```
* Allow nested cppclass definitions (#3221)samaingw2022-11-121-1/+3
| | | | | | | | | | | | | | | | | This is a subset of PR #2951, containing the code concerning nested class definition support. For the records, you'll find below the original #2951 description of theses changes: 4 - Nested classes ------------------------ This is not about wrapping nested C++ classes, because it is already present and functional (and there's a test which can prove it). This is about being able to generate C++ classes definitions with nested classes. So it is exactly like the batch about method overloading: being able to define and not just declare. If I have understood it properly, this addresses issue #1218 a) Make cppclass generate code for nested definitions (for example nested cppclass) b) Fix Symtab for the inherited nested types: this is basically the same thing than for other attributes, have a separate "inherited types" array, to be able to have them in scope but ignore them during code generation. c) Amend the nested classes test
* Fix linkage for `cdef public` functions in C++ mode (#5040)Maximilien Colange2022-11-081-8/+11
| | | | | | | | | | | | Fixes #1839 cdef public functions should be declared with the appropriate linkage: * in C mode, either extern or extern "C", depending on whether the header file is included in (resp. object code is linked against) a C or a C++ compilation unit. Choice is made at compile-time through #ifdef __cplusplus macros. NB: This is the current behavior. * in C++ mode, extern "C++" is the only option, as C code cannot call C++ code. Note that extern "C++" should be preferred over extern to allow users to #include the C++ header inside a extern "C" block (which is legal, although barely used). Note that the current behavior is OK for C mode, but is incorrect for the C++ mode. As described in #1839, this incorrect behavior is diagnosed by compilers emitting warnings when cdef public functions return a C++ type (e.g. std::vector). The test introduced in this PR checks that the current behavior for C mode (with both C and C++ compatibility) is preserved, and that the behavior for C++ mode is fixed.
* Merge branch '0.29.x'da-woods2022-10-221-2/+2
|\
| * Fix various clang warnings (#5086)Lisandro Dalcin2022-10-171-2/+2
| | | | | | | | | | | | * Fix clang -Wcomma * Fix clang -Wextra-semi-stmt * Fix clang -Wconditional-uninitialized * Fix clang -Wunreachable-code-return
* | Make sure we call __del__ for final types (#4996)da-woods2022-09-051-2/+1
| | | | | | | | | | | | including final types that inherit __del__ from elsewhere (either known or unknown). Fixes #4995
* | Account for possible extension type struct padding when calculating the ↵da-woods2022-07-171-4/+4
| | | | | | | | itemsize for the "size changed" check (GH-4894)
* | Merge branch '0.29.x'Stefan Behnel2022-05-171-1/+1
|\ \ | |/
| * Use encoded string since `ModuleNode.full_module_name` may originate from ↵Stefan Behnel2022-05-171-1/+1
| | | | | | | | | | | | different sources. See https://github.com/cython/cython/pull/4764
| * Move from deprecated find_loader() to find_spec() for setting up the import ↵Matti Picus2022-05-171-8/+2
| | | | | | | | | | time package path (GH-4764) Closes https://github.com/cython/cython/issues/4763
| * Stop calling PyEval_InitThreads() In Py3.7+ (where it has become a no-op).Stefan Behnel2021-07-011-3/+2
| |
| * Only #define PY_SSIZE_T_CLEAN if it is not already #definedAndrew V. Jones2021-04-141-0/+3
| | | | | | | | Signed-off-by: Andrew V. Jones <andrew.jones@vector.com>
| * Prefer Element.iter() over the deprecated Element.getiterator(). (GH-3865)Nick Pope2020-10-061-1/+5
| | | | | | | | `xml.etree.ElementTree.Element.getiterator()` was deprecated in Python 2.7 & 3.2 and removed in Python 3.9.
| * Validate and fix temp releasing (GH-3708) (GH-3717)scoder2020-07-011-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Validate and fix temp releasing (GH-3708) Backports 92147baf11071352ffbfa475d0d21e091753e628. * Fix a temp leak in the type init code. * Fix temp leaks in fused types initialisation code. * Correctly release the buffer index temps allocated for index calculations. * Make tests fails hard if a temp variable is not released at the end of a generated function. * Fix temp leak in switch statement code. * Make end-to-end tests fail on refnanny output. * Fix result temp leak in PyTypeTestNode. * Fix result temp leak in external type/function import code and enable the refnanny check for them. * Fix temp leak when try-return-finally is used in generators. * Make it explicit when an allocated temp is not meant to be reused. * Fix temp leak when assigning to the real/imag attributes of complex numbers. * Fix temp leak when assigning to a memoryview slice. * Clean up "num_threads" result temp in parallel section, not only in prange loop. * Fix temp leak in Pythran buffer setitem code. * Simplify NumPyMethodCallNode since it does not need the Python function anymore. Previously, it generated code that needlessly looked up the Python function without actually using it. * Fix temp leak when deleting C++ objects. * Add a test that actually reusing temps when deleting C++ objects works correctly.
| * Fix FunctionState handling for module cleanup function.Stefan Behnel2020-06-301-0/+2
| |
| * Re-add "c_api_binop_methods" directive for backwards compatibility after ↵Stefan Behnel2020-06-171-0/+4
| | | | | | | | | | | | reverting https://github.com/cython/cython/pull/3633 and force it to "False". Closes #3688.
| * Revert "Python-style binary operation methods."Stefan Behnel2020-06-171-42/+1
| | | | | | | | This reverts commit e6a812402b0368cf930a55ed465a38820f606054.
| * Revert "Add support for pow operator."Stefan Behnel2020-06-171-10/+1
| | | | | | | | This reverts commit d849fb2379f4f892c8374b52385991c399c31a49.
| * Revert "Invoke binop super method via direct slot access."Stefan Behnel2020-06-171-7/+8
| | | | | | | | This reverts commit bcb938776c5a502a4a451c7a24c4b80d110a5c86.
| * Revert "Limited API updates and cleanup for #2056. GH-3635)"Stefan Behnel2020-06-171-47/+35
| | | | | | | | This reverts commit 02bb311d96359c7d2a359415612a9ffa24eda0a0.
* | Move from deprecated find_loader() to find_spec() for setting up the import ↵Matti Picus2022-05-171-8/+2
| | | | | | | | | | time package path (GH-4764) Closes https://github.com/cython/cython/issues/4763
* | Remove obselete memoryview getbuffer fallback code (GH-4685)da-woods2022-03-171-2/+0
| | | | | | | | | | | | It appears to have been be used for Python < 2.6 (which didn't have the new buffer protocol). Most of the mechanism had already been removed, but the capsule attributes that it relied on were still generated. Also removed some utility code that was only used for this feature.
* | Use PyType_GetSlot() and friends in more places to reduce the special cases ↵scoder2021-12-201-12/+6
| | | | | | | | for type-specs / Limited-API (GH-4506)
* | Support "__del__()" to implement "tp_finalize" according to PEP-442 (GH-3804)ax4872021-12-191-0/+27
| | | | | | Closes https://github.com/cython/cython/issues/3612
* | Remove warning from unused temp (GH-4482)da-woods2021-11-261-0/+1
| | | | | | | | | | Follow up to https://github.com/cython/cython/pull/4453 (01d323abea91f8b75caffa452f57320b06a57e9e). That PR creates a temp that's only used in the limited API (and therefore causes warnings on all other paths)
* | Make self argument for binops typed (GH-4436)da-woods2021-11-181-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The type for the self argument for binops depends on the compile directives. Therefore it needs a set of type slots that depends on the compiler directives. I've therefore got rid of the big static list of typeslots in TypeSlots.py in favour of a class that defines them all (and can be initialized with suitable compiler directives as needed). This involves moving a static dictionary and list out of the global scope too, so that they too can be part of the class. The passing of the dictionary and list to all the constructors is a bit awkward Fixes https://github.com/cython/cython/issues/4434
* | Only set HAVE_VECTORCALL flag when using vectorcall (GH-4453)da-woods2021-11-181-6/+9
| | | | | | | | | | | | | | | | Before this the _Py_TPFLAGS_HAVE_VECTORCALL was set all the time when using the limited api, but a CyFunction never sets up a vectorcall function. This caused basically all function calls to crash when binding=True with the limited API. Also removes the premature refnanny usage when setting up the module.
* | Avoid AddTraceback() if stringtab isn't set up (GH-4378)da-woods2021-09-271-3/+8
| | | | | | | | | | | | | | This can happen (rarely) with exceptions that occur very early in the module init process. Fixes https://github.com/cython/cython/issues/4377 Uses a fake Numpy module for testing to make a version of "import_array" that always fails.
* | Make __PYX_WARN_IF_INIT_CALLED name unique per-module in generated header ↵da-woods2021-07-231-3/+3
| | | | | | | | | | files (GH-4309) Fixes https://github.com/cython/cython/issues/4308
* | Fix a refcounting bug in the new @total_ordering decorator.Stefan Behnel2021-07-031-2/+2
| | | | | | | | See https://github.com/cython/cython/pull/3626
* | Declare a static method as @staticmethod.Stefan Behnel2021-07-021-1/+2
| |
* | Fix infinite recursion in binops code (GH-4204)da-woods2021-07-021-3/+6
| | | | | | Closes https://github.com/cython/cython/issues/4172
* | Fix a few bugs in the new "cpp_locals" directive implementation (GH-4259)da-woods2021-07-021-3/+8
| | | | | | | | | | | | | | 1) Entry utility_code wasn't being imported unless the entry was visibly used. The utility code is needed for the definition even if unused. I think this is what utility_code_definition is for, but I'm not completely sure. I also had to add some calls to ensure it's used. 2) CppOptionalTempCoercions weren't being moved correctly. Tested by printing from the destructor. 3) cdef-class attributes weren't being created or destroyed correctly. Tested by printing from the destructor
* | Add directive "cpp_locals" to handle C++ variables using std::optional (GH-4225)da-woods2021-06-291-5/+12
| | | | | | | | | | This avoids the need for default constructors of stack allocated variables and temps by allowing late initialisation. Closes https://github.com/cython/cython/issues/4160
* | Implement @total_ordering decorator for extension types (GH-3626)Spencer Brown2021-05-261-16/+134
| | | | | | Implements https://github.com/cython/cython/issues/2090
* | Split the current "CYTHON_COMPILING_IN_LIMITED_API" macro guard (GH-3611)scoder2021-05-251-18/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Split the current "CYTHON_COMPILING_IN_LIMITED_API" macro guard into separate feature guards: 1) using a global module state struct ("CYTHON_USE_MODULE_STATE") 2) using PyType_FromSpec() for extension types ("CYTHON_USE_TYPE_SPECS") 3) actual limited-API special casing ("CYTHON_COMPILING_IN_LIMITED_API") * Start using PyType_FromModuleAndSpec() for creating extension types since that adds the module reference with PEP-573. * Do not pass the module reference into *shared* extension types since we do not want to keep the module alive just because other modules still refer to the type. * Mark the Limited-API and module state struct features as experimental. * Add CI setups for using PyType_FromSpec() for creating extension types. * Avoid overly complicated code in __Pyx_FetchCommonTypeFromSpec() when we are not compiling against the Limited-API. * Correctly set up the bases tuple for PyType_FromSpecWithBases() and stop relying on the PyTypeObject struct being available in several places by using the type pointer instead (and setting it early enough). * Set the "tp_dealloc" slot from the type spec, also for the limited API case. * Generally re-enable the "heaptype bases hack" when creating extension types. * Implement "tp_dictoffset" slot when using type specs in Py3.9+. * Fix and simplify the vtable setup in the limited API config. * Make CyFunction inheritable to "correctly" allow FusedFunction subclassing it. * Enable buffer interface support when using type specs by assigning the "tp_as_buffer" slot explicitly after creating the type. * Set "vectorcalloffset" when using type specs. * Make "__bool__" slot prefer Py3+ name instead of Py2 name to make the correct name ("Py_nb_bool") appear in the type spec. * Validate and fix up all extension types when constructing them from type specs (not only the internal ones). * Only call PyType_Modified() once after changing a type, not once per change. * Turn the "no buffer protocol in the limited API" error into a warning since the user code might still work without it. * Enable the same flags for CyFunction in the static type and type spec case since it's shared across modules and thus, we might otherwise end up with differently configured types in the same runtime. * The names of Cython's internal types (functions, generator, coroutine, etc.) are now prefixed with the shared module name, instead of making them look like homeless builtins. See https://bugs.python.org/issue20204 See https://github.com/python/cpython/commit/490055a1673b524da2ebe2312f072aba2a826036 * Work around a CPython bug that makes it overwrite exttype member definitions for the "__module__" attribute. See https://bugs.python.org/issue40703 * Inherit buffer slots manually since type slots don't support them and thus PyType_Ready() does not see them. * Add METH_METHOD call support (currently unused). * Fix the vectorcall offset used in CyFunction type struct in Py3.9, if it inherits from PyCMethodObject instead of PyCFunctionObject. * Work around the duplicate creation of the "OverrideCheckNode" for fused cpdef functions. See https://github.com/cython/cython/issues/3628 * Decref the type when deallocating instances of heap types in Py3.8+. See https://bugs.python.org/issue35810 * Look up the fused dispatch function in the override check, not the specialisation (which shouldn't be overridden all by itself). Closes https://github.com/cython/cython/issues/3628 * Avoid running the override check for CyFunction, just because it's not a PyCFunction itself.
* | Include .h and _api.h files in target overwrite check.Stefan Behnel2021-05-201-7/+15
| | | | | | | | | | See https://github.com/cython/cython/issues/4177 See https://github.com/cython/cython/pull/4178
* | Refuse to overwrite output C/C++ files that probably were not created by ↵scoder2021-05-201-2/+9
| | | | | | | | | | | | | | Cython (GH-4178) This is a common gotcha for new users who name their .pyx file after the C file that they want to wrap. Closes https://github.com/cython/cython/issues/4177
* | Fix windows linkage error for unicode modules by providing a dummy function ↵da-woods2021-04-291-0/+16
| | | | | | | | | | | | | | (GH-4125) A bug in distutils means that it tries to export a slightly incorrectly named PyInitU function. The fix in https://bugs.python.org/issue39432 wasn't quite right (`"_name".encode("punycode") != "name".encode("punycode")`) and thus the "unicode_imports" test is failing on Windows 3.8+ when distutils explicitly tries to export a non-existing symbol. We now create a dummy function with that alternative name so that the export doesn't fail.
* | Allow searching for include/import files without passing a source pos tuple ↵Stefan Behnel2021-04-181-1/+1
| | | | | | | | and clean up the call chains a little.
* | Only #define PY_SSIZE_T_CLEAN if it is not already #definedAndrew V. Jones2021-04-081-0/+2
| | | | | | | | Signed-off-by: Andrew V. Jones <andrew.jones@vector.com>
* | Fix crash on memoryview self-assignments (GH-3874)da-woods2020-11-071-1/+1
| | | | | | | | * Fixed crash on memoryview self-assignment * Rename memoryview decref function to match what it does
* | Replace deprecated Element.getiterator() with Element.iter(). (GH-3864)Nick Pope2020-10-061-1/+1
| | | | | | | | `xml.etree.ElementTree.Element.getiterator()` was deprecated in Python 2.7 & 3.2 and removed in the freshly released Python 3.9.
* | Looks like the usual macro on Windows is "_WIN32" and not "WIN32". Let's ↵Stefan Behnel2020-10-041-2/+2
| | | | | | | | support both, to be on the safe side.
* | Support utility code in headers (GH-3779)da-woods2020-09-221-54/+56
| | | | | | Specifically this allows public packed structs but may also allow other public declarations that require small amounts of utility code.
* | Call destructors for structs in C++ (GH-3228)da-woods2020-09-041-8/+8
| | | | | | | | | | | | | | | | | | In C++ mode, structs can contain C++ classes. Therefore structs should have their destructors called to ensure any class contained is also destructed. Also, a bit more thorough about ensuring constructor is generated where necessary. Closes GH-3226.
* | Fix cygdb (GH-3542)Volker-Weissmann2020-08-241-8/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Cython debugger documentation: Added link to an installation script. * Got a new libpython.py from the cpython source distribution. * Default language level in tests is now 3 instead of 2 * Migrated codefile from python 2 to python 3. * Added testcase for the cy list command in cygdb. * Temporarily removing test case that freezes gdb. * Fixed a bug that broke several Cygdb tests. The cython_debug/cython_debug_info_* files map the names of the C-functions generated by the Cython compiler to the names of the functions in the *.pyx source. If the function was defined using "def" (and not "cpdef" or "cdef") in the *.pyx source file, the C-function named in cython_debug/cython_debug_info_* used to be __pyx_pw_*, which is the name of the wrapper function and now it is __pyx_f_*, which is the name of the actual function. This makes some Cygdb tests pass that did not pass before. * Better error messages: If a cygdb command raises, a traceback will be printed. * Fixed a bug in cygdb. The following now works: 1. Start cygdb 2. Type "cy exec" and hit enter 3. Type some other lines 4. Type "end" and hit enter. -> These "other lines" will get executed * Fixed a bug in cygdb: cy list now works outside of functions. * Added print_hr_allmarkers function for easier debugging. * Fixed a bug that broke cygdb: cy break did not work if you put the breakpoint outside of a function if there was e.g. the following somewhere in your *.pyx file: cdef class SomeClass(): pass * Added a Cygdb test for printing global variables. * Fixing cygdb: Replaced cy print with a simple, working solution. * If an exception in Cygdb occurs, a stacktrace will be printed. * Fixed a bug that broke cy break -p * Bugfix: The compiler now writes out correctly which cython linenumber and path corresponds to which c linenumber. * Set language_level=2 in runtests.py