26196 Commits

Author SHA1 Message Date
rdb
0df17a00ca Merge branch 'bugfix/interrogate-gc-exception' of github.com:johnnyapol/panda3d 2024-05-14 22:46:53 +02:00
rdb
2436a06527 glgsg: Better error when invalid ShaderPtrSpec type is encountered 2024-05-14 22:45:01 +02:00
John C. Allwein
8cc62c9706 interrogate: avoid GC exceptions processing objects mid-construction
After 38692dd525525e20cd06204a646b35dd7e39902a, 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
Wizzerinus
3ffcce2cc2 add getPlayMode() for actor and anim interface 2024-05-14 11:06:06 +02:00
Disyer
a9206041d9 ffmpeg: Use ch_layout in favor of removed channel_layout and channels
Closes #1641
2024-04-08 13:32:51 +02:00
rdb
5da013e2e9 text: Properly handle surrogate pairs in text on Windows
Fixes #1629
2024-04-08 12:12:00 +02:00
rdb
2adc167f26 windisplay: Fix regression related to fullscreen switching
Fixes #1594
2024-04-08 11:29:43 +02:00
rdb
ee9b0b9c78
readme: Change placement of logo subtly
[skip ci]
2024-04-01 22:30:17 +02:00
rdb
96e2e7d357 tests: Remove testing for AssertionError
This crashes with `assert-abort` and doesn't work with release builds
2024-03-29 20:57:36 +01:00
rdb
5cad92cd56 interrogate: Fix missing header to fix non-unity build 2024-03-29 20:57:12 +01:00
rdb
e5bd00f91f task: Implement garbage collector support for PythonTask
This adds persistent wrapper support (introduced by the previous commit) to PythonTask, which makes it possible for reference cycles involving tasks to be found and destroyed.

The major caveat is that it always creates a reference cycle.  This can be broken automatically if there is no more Python reference to it by the time the last C++ reference is dropped, but the other way around requires the garbage collector.

For tasks, I think this it is generally the case that the last reference is in C++, since tasks are usually created and then handed off to the C++ task manager, and for applications that don't want to rely on the GC, it is easy to work around.  If this turns out to be a problem, though, we can add a special garbage collection pass to the task manager.
2024-03-29 20:51:45 +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
33cef0aca3 pgraph: Disable non-working __traverse__() on NodePath 2024-03-29 17:15:43 +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
1213d95560 Merge branch 'release/1.10.x' 2024-03-28 01:17:52 +01:00
rdb
0e2a706ec8 audio: Fix changing sound time not working on macOS
Fixes #1607
2024-03-27 12:02:12 +01:00
rdb
d44f9ae3dc makepanda: Use new dist hooks location introduced by 1f41edd
Fixes #1624
2024-03-27 12:01:53 +01:00
rdb
1f41edd0a0 dist: Remove panda3d dependency for global dist hook
Fixes #1624
2024-03-27 11:23:17 +01:00
kamgha
aa58b4ccf2 palettizer: Fix magfilter on KW_mipmap
Closes #1631
2024-03-27 11:12:58 +01:00
rdb
a50b9d83aa interval: Fix creating LerpFunctionInterval from partial
Fixes #1623
2024-03-27 11:10:08 +01:00
rdb
237d27dfd9 text: Error instead of crash when glyph does not fit into page
Fixes #1626
2024-03-27 10:59:52 +01:00
rdb
38a3048479 cppparser: Fix recursion in expanding function macro arguments
See #1635
2024-03-27 10:43:58 +01:00
rdb
8ea2301d16 pgui: Fix PGEntry::get_cursor_Y()
It returned the Y position, which is always 0.0, instead of the Z position.

Fixes #1633
2024-03-27 10:22:54 +01:00
rdb
06e72b5d7d text: Add docstring for set_text_color()
Fixes #1621
2024-03-27 10:06:39 +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