Commit Graph

3338 Commits

Author SHA1 Message Date
rdb 6d54aee0c7 Remove runtime dependency on interrogatedb 2024-10-30 17:46:26 +01:00
rdb 0c1a0799b1 Fix faulty auto-merge 2024-10-30 14:41:06 +01:00
rdb e58449cde7 dtoolutil: Let Python do Filename conversion to UTF-8 2024-10-30 13:42:33 +01:00
rdb 7560a1edd1 Merge branch 'release/1.10.x' 2024-10-30 13:42:21 +01:00
rdb f47b34d2a1 Fix remaining uses of ._PyType member in extension code
This should be replaced with Dtool_GetPyTypeObject, hiding the implementation details a bit so that we can more easily change the underlying structure if we need later

Also adds Py_NewRef to py_compat.h, backporting from master
2024-10-30 13:26:34 +01:00
rdb 0ba2aadcd6 Introduce Py_IS_TYPE, use for Py_TYPE comparisons 2024-10-30 13:17:11 +01:00
rdb 64454b1c9f Replace direct uses of ob_type, which gives problems in nogil build 2024-10-30 13:17:11 +01:00
rdb 6885edc811 build: Update interrogate to 0.3.0 to support 3.13t build 2024-10-29 16:10:39 +01:00
rdb f50fef3744 Switch over to C++14, drop support for MSVC 2015
The main reason is that the current development version of Eigen requires C++14 to be enabled, so otherwise we can't compile with the latest Eigen.

If really needed, we can keep support for MSVC 2015 (please make your voice heard) but that would lock us out of a few features of C++14.
2024-10-19 13:16:36 +02:00
rdb beff684af3 Further thread safety changes for Python 3.13 free threading
See #1683
2024-09-19 20:43:06 +02:00
rdb 4b2fa45578 Make use of PyImport_GetModule function 2024-09-19 20:42:31 +02:00
rdb 5106fc879f Changes for compatibility with Python 3.13
Includes some preliminary work to make free-threading safe, see also #1683
2024-09-19 16:01:10 +02:00
rdb b32459ffa1 Merge branch 'release/1.10.x' 2024-09-19 15:51:25 +02:00
rdb cdafd81764 Fix compilation issues with Python 3.13 2024-09-19 15:47:50 +02:00
rdb f5401b19fa Merge branch 'release/1.10.x' 2024-09-16 13:54:22 +02:00
John Cote f2b421e005 Merge remote-tracking branch 'upstream/master'
Conflicts:
    makepanda/makepanda.py
2024-09-06 22:40:10 -04:00
rdb 78ace53dbe dtoolutil: Fix typo in pfstream causing compiler warning 2024-08-14 19:08:49 +02:00
rdb ddaeb05367 Fix compilation when building without bison 2024-08-14 19:08:16 +02:00
rdb 8d2407d553 Delete cppparser and interrogate from tree
These tools now live in https://github.com/panda3d/interrogate/

See also #1074
2024-08-10 16:55:03 +02:00
rdb c9cddb8d92 CMake: Stop building interrogate from tree
Instead, either build it externally (BUILD_INTERROGATE) or accept INTERROGATE_EXECUTABLE / INTERROGATE_MODULE_EXECUTABLE settings
2024-08-10 16:54:12 +02:00
rdb fc1d95ae1d dtoolbase: Add missing includes to pstrtod.cxx 2024-08-08 21:36:21 +02:00
rdb abf0b38705 dtoolutil: Use string compare instead of strcmp in filename.I 2024-08-08 21:36:00 +02:00
rdb ad57762e9f Merge branch 'release/1.10.x' 2024-08-07 22:34:08 +02:00
rdb 8c8cbeea98 linmath: For repr, use as much precision as needed for roundtrip
Will use as few digits as is necessary to ensure that round-tripping the same number with pstrtod will result in the same vector.  This prevents eg. 3.3 formatting as 3.29999995 while still ensuring that two floats that are not equal (other than nan) are guaranteed to have a different string representation.

Uses a hacky pftoa function that can be abandoned as soon as we adopt C++17, which has to_chars that does what we need

Fixes #1671
2024-08-07 17:24:11 +02:00
rdb ca7ba4eab3 py_panda: Add Dtool_GetPyTypeObject macro
This is a cleaner, future-proof way of accessing a Panda type as PyTypeObject pointer
2024-08-07 15:53:27 +02:00
rdb 1cc0676e41 dtoolutil: Fix misnamed include guard 2024-08-04 17:08:45 +02:00
rdb 58ea174eb2 interrogate: Use the limited Python API for simple Python back-end 2024-08-03 21:50:19 +02:00
rdb 0215b02985 interrogate: Replace a use of std::cerr with nout 2024-08-03 16:36:55 +02:00
rdb ae04533527 dtoolutil: Fix typo in error message 2024-08-03 16:36:37 +02:00
rdb 7a13d86d93 CMake: remove vestigial HAVE_ROCKET_PYTHON macro 2024-08-03 15:00:44 +02:00
rdb 105f938d68 interrogate: Fix non-deterministic order of external import types
Fixes #1651
2024-05-28 11:11:21 +02:00
rdb 0df17a00ca Merge branch 'bugfix/interrogate-gc-exception' of github.com:johnnyapol/panda3d 2024-05-14 22:46:53 +02:00
John C. Allwein 8cc62c9706 interrogate: avoid GC exceptions processing objects mid-construction
After 38692dd525, GC pauses occuring before
the __init__ function of the C++ backed object is called in a inheritance chain will
cause an exception during garbage collection and cause the python runtime to exit.

This can be observed by say, forcing a GC-pause in MetaInterval.__init__ before it calls CMetaInterval::__init__.
2024-05-14 09:48:55 -06:00
Open Toontown 6d182ccb5e Merge remote-tracking branch 'upstream/master' 2024-03-30 19:09:37 -04:00
rdb 5cad92cd56 interrogate: Fix missing header to fix non-unity build 2024-03-29 20:57:12 +01:00
rdb 38692dd525 interrogate: Support subclassing C++ objects from Python
This change enables persistent Python wrapper objects for Python subclasses of typed, reference counted C++ objects.  That means that these objects will store a reference to `self` on the C++ object, and interrogate will always return that instead of making a new Python wrapper every time it is returned from C++.

Practically, this means that you could subclass eg. PandaNode, Event, Fog, what have you, and store these in the scene graph - the Python data in the subclass will be retained and Panda will return your subclass when you ask for the object back rather than creating a new wrapper object without your original data.

To do this, Interrogate generates a proxy class inheriting from the C++ type with additional room to store a `self` pointer and a TypeHandle (which is returned by an overridden `get_type()`).  This TypeHandle is automatically created by registering the Python subclass with the typing system.  The proxy class is only used when the constructor detects that it's constructing for a subtype, so that regular uses of the C++ type are not affected by this mechanism.

(The registration with the typing system could use some improvement.  There's no regard for namespacing right now, in particular.  Furthermore, we could move the registration to an `__init_subclass__()` method, with parameters to specify an existing TypeHandle or to customize the type name.)

This creates a reference cycle, which must be cleared somehow.  One way this happens is by overriding `unref()` in the proxy, which checks that if the Python and C++ reference counts are both 1, this must be the circular reference, and then it breaks the cycle.  Note that this will _only_ work if all other Python references have been cleared before the last C++ reference goes away.  For the other case, we need to rely on Python's garbage collector, so these classes also implement tp_traverse and tp_clear.

This commit also therefore re-enables Python garbage collector support (ie. defining `__traverse__()`), which was previously disabled due to the problems caused by multiple Python wrappers referring to the same C++ object.  To avoid these problems, Panda will only cooperate with Python's GC if the C++ reference count is 1, in which case we can trivially prove that the last reference must be from the Python wrapper.  Note that this explains why we need persistent wrappers for traversal to work--if there are multiple Python wrappers pointing to the C++ object, and they are all participating in a reference cycle, the reference count cannot be 1, and cycle detection does not work.  By default, the GC is only enabled for Python subclasses, but a class may define `__traverse__()` in order to opt-in, keeping the previous limitation in mind.

There is a second mechanism introduced by this commit: classes may define a public `__self__` member of type `PyObject *` if they want to use persistent objects even if they aren't being subclassed.  This allows these classes to participate in Python's GC and avoid the situation above.

The cycle detection is implemented for PandaNode's Python tags, but this is very incomplete, since the traversal doesn't recurse into children and it won't work if there is more than one wrapper object that is part of a cycle, since PandaNode by default doesn't use persistent wrappers.  This problem may need more attention later.

Fixes #1410
2024-03-29 20:51:34 +01:00
rdb 61665dc8ba cppparser: Remove unused `<list>` include 2024-03-29 16:12:01 +01:00
rdb 4430f16cda cppparser: Minor performance improvements 2024-03-29 16:04:04 +01:00
rdb 12a188b116 cppparser: Allow move semantics for CPPToken
This should make it a bit more efficient to move tokens around
2024-03-29 15:00:39 +01:00
rdb e1870047c6 cppparser: In preprocess mode, add newline when switching files 2024-03-29 14:59:50 +01:00
rdb 329fa728a7 cppparser: Change `check_keyword()` to an unordered_set lookup 2024-03-29 13:04:24 +01:00
rdb a3745af451 parser-inc: additions to `sys/stat.h` and `signal.h` 2024-03-29 13:01:40 +01:00
rdb 04a9264e68 cppparser: Fix slow parser performance 2024-03-29 12:22:54 +01:00
rdb acf118c96a cppparser: Update prebuilt bison files 2024-03-29 12:19:48 +01:00
rdb c1e494c083 cppparser: Fix `volatile` keyword not being parsed in all places 2024-03-29 11:39:51 +01:00
rdb 6e81fb5cdf cppparser: Support `__restrict` and `__restrict__` keywords
To compile C code, you can do `-Drestrict=__restrict`
2024-03-29 11:36:14 +01:00
rdb e16cb8af98 cppparser: Add special __builtin_va_list type 2024-03-29 11:34:56 +01:00
rdb d1c277ef6a cppparser: prevent enum values having long chain of additions
See #1638

[skip ci]
2024-03-28 22:49:15 +01:00
rdb bddb7cb262 cppparser: fix escaping of string literals in preprocessor mode
[skip ci]
2024-03-28 22:17:49 +01:00
rdb ba51b2cdca cppparser: Fix wide character literals in `#if` 2024-03-28 21:55:36 +01:00
rdb e29b326dd8 cppparser: Parse macro directly following string literal
This allows the following C code to parse:

    #define SUFFIX "bar"
    const char *str = "foo"SUFFIX;

This is technically not valid C++ since C++ uses this syntax for custom string literals, but we might as well check if there is a macro defined with this name if we can't find a matching string literal and are about to throw an error
2024-03-28 21:09:40 +01:00
rdb ae8d643907 cppparser: Prefer function over type when searching symbol
This is meant to fix the "stat problem", which means you can define a function with the same name as a struct, which is allowed, since you can still refer to the struct with an explicit `struct stat`.

It can be reproduced with the following code:

struct stat;

void stat();

void *ptr = (void *)stat;
2024-03-28 21:02:32 +01:00
rdb 50538203ce cppparser: Fix regression parsing `defined MACRO` without parens 2024-03-28 20:00:47 +01:00
rdb 87d3a1d553 cppparser: Add missing include to fix non-unity build 2024-03-28 17:19:04 +01:00
rdb fb68f82c5b cppparser: Add preprocessor option (-E) to parse_file
This makes it easier to test the behaviour of the preprocessor
2024-03-28 17:15:24 +01:00
rdb a769808af0 cppparser: Add missing keywords to CPPToken::output() 2024-03-28 17:01:47 +01:00
rdb 360216656e cppparser: assorted preprocessor improvements:
* Fix function-like macro arguments being expanded even when they were participating in token expansion or stringification
* Fix __has_include with comma or closing parenthesis in angle-quoted filename
* Don't issue warning if macro is redefined with identical definition
* Fixes for extraneous spaces being added to expansions
* Assorted refactoring

This should resolve #1638.
2024-03-28 17:01:24 +01:00
rdb 78f1a5b15a cppparser: Fix crash redefining struct as typedef
This would crash on the following code:

    struct aaa;
    typedef struct {} aaa;
2024-03-28 11:18:41 +01:00
rdb 014fd97fef cppparser: Fix string handling in expansion of macro arguments
See #1638
2024-03-28 10:07:12 +01:00
rdb e63ba11af2 cppparser: Fix expansion of function macro used without parentheses 2024-03-28 01:18:19 +01:00
rdb 38a3048479 cppparser: Fix recursion in expanding function macro arguments
See #1635
2024-03-27 10:43:58 +01:00
rdb c923cf6ee5 cppparser: Perform macro expansion on macro arguments
Fixes #1638
2024-03-27 02:26:14 +01:00
rdb 674c037c50 cppparser: Trim whitespace around macro arguments 2024-03-27 02:25:56 +01:00
rdb c5ab6573b0 cppparser: Improve error messages involving macro expansion
Now shows the expansion of the macro if a parse error occurs in one.
2024-03-27 02:23:58 +01:00
rdb 6f6cbf318e Merge branch 'release/1.10.x' 2024-03-26 17:08:52 +01:00
rdb 80147990cc cppparser: Fix problems with recursive expansion in preprocessor
Other half of #1635
2024-03-26 15:55:50 +01:00
mingodad 685b98021c cppparser: Skip comments after preprocessor directive
See #1635
2024-03-26 15:54:33 +01:00
rdb af27a9523c Merge branch 'release/1.10.x' 2024-03-12 15:39:16 +01:00
rdb 0ce7215ee9 interrogate: Fix typo in code
Fixes #1627

[skip ci]
2024-03-12 15:10:14 +01:00
darktohka b049c891d1 ext: Use different names for each gen_next method 2024-02-10 23:49:28 +01:00
rdb 73360393df Switch use of Py_INCREF to new Py_NewRef function
This is more idiomatic, simplifies the code, makes it easier to port to eg. HPy later on, and makes it easier to use the limited ABI (where it can be optimized to a tail call) later on

A polyfill is provided for compatibility with Python versions 3.8 and 3.9
2024-01-29 17:57:53 +01:00
rdb 4b748d1aba dtoolutil: Fix issue compiling interrogate without HAVE_PYTHON
Closes #1608

Co-authored-by: pmp-p <mail.peny@free.fr>
2024-01-28 15:15:27 +01:00
rdb 128000b03a dtoolutil: writelines() should accept any iterable 2024-01-28 15:15:27 +01:00
rdb 84ed141b2a Squash merge webgl-port branch into master
Adds support for emscripten as a build target / platform, and adds a WebGL renderer back-end
2024-01-25 15:37:38 +01:00
rdb b49dbaca2b Report errors if calls to `close()` fail 2024-01-25 12:33:20 +01:00
rdb 26ce3eab29 Update version number to 1.10.15 2024-01-23 14:24:23 +01:00
rdb c6c75092e1 interrogate: Reduce generated code, refactor bad args error code 2024-01-05 17:15:02 +01:00
rdb e04daec2fe Merge branch 'release/1.10.x' 2024-01-05 16:08:53 +01:00
rdb 7926a3a929 interrogate: Fix some pointless code generation case
Some cases of eg. inplace ternary operator would needlessly construct and then immediately destruct a tuple
2024-01-05 14:52:52 +01:00
rdb 37c9e58ea0 interrogate: Fix handling of RF_self / inplace binary operator 2024-01-05 14:32:26 +01:00
rdb 46e662bd8e interrogate: Add cleverness to avoid writing out dead code
Hopefully fixes GCC 13 compile regression, see #1580
2024-01-05 13:56:02 +01:00
rdb 034f1ea358 patomic: Implement futexes on macOS using ulock API
This is what is also used by the libc++ futex implementation on macOS, and should be more efficient than the fallback hash table approach
2023-10-21 14:46:51 +02:00
rdb 39e4e4167c CMake: Switch use of distutils.sysconfig to sysconfig in Python 3.12
Part of #1395
2023-10-15 11:43:42 +02:00
rdb c48fcba3d8 CMake: build tinydisplay using CMake
Based on work by @toadkarter (#1487) and @pmp-p (#1547)

Fixes #1481
2023-10-15 11:34:47 +02:00
Open Toontown 00e452ede6 Merge remote-tracking branch 'upstream/master' 2023-10-14 18:06:35 -04:00
rdb e01cb590de Merge branch 'release/1.10.x' 2023-10-13 23:24:48 +02:00
rdb c45e14a563 interrogatedb: Switch T_OBJECT to T_OBJECT_EX for this_metatype
T_OBJECT has been deprecated.
2023-10-13 21:21:29 +02:00
Mitchell Stokes 893f5ce492 Fix assert on Py_SIZE(long) when using Python 3.12
Starting with Python 3.12, passing a PyLong into Py_SIZE() triggers an
assertion. PyLong (and the whole C API) is transitioning to be more
opaque and expose fewer implementation details.
2023-10-13 10:54:33 +02:00
rdb 86aa437804 dtoolbase: Fix static init ordering regression
This was a regression in bf65624298 that caused crashes on startup in static builds due to the "small" DeletedBufferChain array not being initialized early enough

For some reason it wasn't being constant-initialized, it is now by setting the _buffer_size field to 0 initially and changing it later in get_deleted_chain
2023-10-09 12:49:04 +02:00
Open Toontown c7ebf71634 Merge remote-tracking branch 'upstream/master' 2023-10-09 00:06:40 -04:00
rdb 3160d7f3e9 py_panda: Don't use _PyUnicode_EqualToASCIIString in Python 3.13+
See #1523
2023-08-03 22:22:45 +02:00
Disyer 596ff9ddb8 python: Remove usage of private _PyUnicode C API calls 2023-08-03 21:35:33 +03:00
rdb 8cbf93162a cppparser: Backport enum scope fix to 1.10
From bc039a0476
2023-08-02 12:40:37 +02:00
rdb bc039a0476 cppparser: Allow referencing enumerant within enum scope 2023-08-02 11:06:32 +02:00
WMOkiishi ea84547805 general: Mark many constructors as `explicit`
Closes #1514
Fixes #1431
2023-08-02 08:18:43 +02:00
rdb 115a716a7d Implement support for custom TypedWritable subclasses in Python
Fixes #1495
2023-07-26 19:55:40 +02:00
rdb cdc95acf81 Merge branch 'release/1.10.x' 2023-05-08 20:08:48 +02:00
rdb 96b2f3a4d5 CMake: Split out Objective-C++ flags on macOS to fix crash
This now requires CMake 3.16

This is a similar fix as 987f2f036b but for CMake
2023-05-08 20:00:39 +02:00
rdb 75abee73e2 CMake: Disable FMOD Ex on macOS
There's no version of FMOD Ex that isn't linked against libstdc++.6.dylib, which is no longer available in the SDKs
2023-05-08 19:59:50 +02:00
rdb 600fa45d6e CMake: Fix typo in CMAKE_CXX_FLAGS variable on MSVC 2023-05-08 19:59:15 +02:00