Commit Graph

7035 Commits

Author SHA1 Message Date
Hans Goudey
aa62c1b5d1 Fix #129741: Two issues creating GPU shader from Python
1. Log printing casted a span of `StringRefNull` to a span of `char **`
2. Creating the shader tried to create `StringRefNull` from `nullptr`.
2024-11-03 10:49:16 +01:00
Campbell Barton
f17379a5d0 Merge branch 'blender-v4.3-release' 2024-11-03 16:07:40 +11:00
Campbell Barton
3bcfb151c1 PyDoc: use Python's type annotation syntax for doc-strings
Replace plain-text type information with the type syntax used
for Python's type annotations as it's more concise, especially for
callbacks which often didn't include useful type information.

Note that this change only applies to inline doc-strings,
generated doc-strings from RNA need to be updated separately.

Details:

- Many minor corrections were made when "list" was incorrectly used
  instead of "sequence".
- Some type information wasn't defined in the doc-strings and has been
  added.
- Verbose type info would benefit from support for type aliases.
2024-11-03 15:44:35 +11:00
Campbell Barton
71a38df6fa Merge branch 'blender-v4.3-release' 2024-11-02 18:02:15 +11:00
Campbell Barton
a05345e139 PyDoc: various corrections to function doc-strings
Add missing arguments, corrections & remove unchecked type info.
2024-11-02 17:48:21 +11:00
Campbell Barton
15c207a294 Merge branch 'blender-v4.3-release' 2024-11-02 17:34:00 +11:00
Campbell Barton
4df285ccd5 Cleanup: move function comments into headers or implementation notes
For C/C++ doc-strings should be located in headers,
move function comments into the headers, in some cases merging
with existing doc-strings, in other cases, moving implementation
notes into the function body.
2024-11-02 17:27:09 +11:00
Campbell Barton
e46c58df7c Merge branch 'blender-v4.3-release' 2024-11-02 15:44:22 +11:00
Campbell Barton
99387c0749 Cleanup: spelling in comments, docs & error 2024-11-02 15:43:27 +11:00
Campbell Barton
b394fd55b7 Merge branch 'blender-v4.3-release' 2024-11-02 15:27:50 +11:00
Campbell Barton
e7e6bf1dfe Fix memory leak in mathutils.geometry.box_pack_2d
The set macro doesn't handle the reference count for existing values.
2024-11-02 15:08:42 +11:00
Bastien Montagne
29c66dab88 Restore 'writable' handling in bpy_class_call.
Refactor 1dbe94c8ac restored the 'old' proper way to directly call the
python type (i.e. use the python's implementation to create objects),
instead of using the 'specialized' type creation code.

However, the handling of the ugly `rna_disallow_writes` global was only
added later to the 'workaround' part of the code, but not to the original
'canonical' one.

This commit copies the handling of `rna_disallow_writes` back into the
now active part of the code.

This solves the `is_readonly_init` unused variable build warning.

NOTE: At some point the BPY code needs a good cleanup pass, there are
way to many pieces of codes #ifdef'ed there.
2024-10-30 19:21:10 +01:00
Bastien Montagne
1dbe94c8ac RNA: Make the PointerRNA struct non-trivial.
For now, PointerRNA is made non-trivial by giving explicit default
values to its members.

Besides of BPY python binding code, the change is relatively trivial.
The main change (besides the creation/deletion part) is the replacement
of `memset` by zero-initialized assignment (using `{}`).

makesrna required changes are quite small too.

The big piece of this PR is the refactor of the BPY RNA code.

It essentially brings back allocation and deletion of the BPy_StructRNA,
BPy_Pointer etc. python objects into 'cannonical process', using `__new__`,
and `__init__` callbacks (and there matching CAPI functions).

Existing code was doing very low-level manipulations to create these
data, which is not really easy to understand, and AFAICT incompatible
with handling C++ data that needs to be constructed and destructed.

Unfortunately, similar change in destruction code (using `__del__` and
matching `tp_finalize` CAPI callback) is not possible, because of technical
low-level implementation details in CPython (see [1] for details).

`std::optional` pointer management is used to encapsulate PointerRNA
data. This allows to keep control on _when_ actual RNA creation is done,
and to have a safe destruction in `tp_dealloc` callbacks.

Note that a critical change in Blender's Python API will be that classes
inherinting from `bpy_struct` etc. will now have to properly call the
base class `__new__` and/or `__init__`if they define them.

Implements #122431.

[1] https://discuss.python.org/t/cpython-usage-of-tp-finalize-in-c-defined-static-types-with-no-custom-tp-dealloc/64100
2024-10-30 15:08:37 +01:00
Bastien Montagne
97f92a19b3 Cleanup: Better use references than copy by value for PointerRNA now.
While copying this used to be very cheap, this will soon be less
trivial.

Note that there are many more places where this type of cleanup will be
needed.
2024-10-29 16:10:35 +01:00
Campbell Barton
c3b180ef92 Merge branch 'blender-v4.3-release' 2024-10-29 18:28:02 +11:00
Campbell Barton
28a8486e2b Fix memory leak with PyConfig initialization 2024-10-29 18:25:21 +11:00
Campbell Barton
129982daf8 Merge branch 'blender-v4.3-release' 2024-10-25 09:17:41 +11:00
Campbell Barton
1cd2bece60 Fix memory leak on exit for bpy.app.translations members 2024-10-25 09:16:46 +11:00
Campbell Barton
05128991ec Merge branch 'blender-v4.3-release' 2024-10-23 19:50:09 +11:00
Campbell Barton
9a252c2e73 Fix #127097: Extension preferences crashes after "import multiprocesing"
Remove a workaround for #23871 which manipulated the module
to prevent classes defined in the text editor from having their
name-space cleared.

This caused the "multiprocessing" module to store the "__main__" module
as "__mp_main__" for later use.

Accessing attributes from this module would then attempt to read from
with a null "mp_dict" which crashed. This happened when showing the
extensions preferences but would have occurred if "__mp_main__" was
accessed from elsewhere too.

Resolve by removing the workaround since it has not been needed
since Python 3.2.
2024-10-23 19:45:57 +11:00
Campbell Barton
6dedfe15f8 Merge branch 'blender-v4.3-release' 2024-10-23 12:29:58 +11:00
Campbell Barton
1d286a1b93 Fix #129302: GIL not released if poll_message_set was passed a string
Regression in [0].

Co-authored-by: Jorn Visser <git@jornvisser.com>

[0]: ebe04bd3ca
2024-10-23 12:25:57 +11:00
Campbell Barton
f60f2b769b Unbreak building with Python 3.12
Support for 3.13 [0] broke 3.12.

[0]: d9f38fca5f
2024-10-21 20:47:07 +11:00
Campbell Barton
d9f38fca5f PyAPI: support Python 3.13
- `_PySet_NextEntry` has been removed, use generic iterator access
  which will has some additional overhead as it needs to create
  an iterator to access the values.

- Add v3.13 compatibility defines to account for renaming:
  _PyObject_LookupAttr -> PyObject_GetOptionalAttr
  _PyLong_AsInt -> PyLong_AsInt

- Unfortunately use of Python's internal API needs to be used to
  inspect op-codes in `bpy_driver.cc`.

Testing GLTF/FBX IO there isn't any significant performance impact
from these changes.

Resolves #123871.
2024-10-18 17:22:09 +11:00
Bastien Montagne
1e55d034a1 Fix massive amount of memleaks on exit in BPY.
Essentially, our current code would not properly remove (dereference)
its python objects matching various RNA data created during execution.

Some cases are fairly trivial to understand (like the lack of handling
of unregstering for our 'startup' operators and UI), other were more
subtle (like unregistered PropertyGroups who would remove/free their RNA
struct definition, without releasing first the potential matching python
object).

Co-authored-by: Campbell Barton <campbell@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/128899
2024-10-17 18:05:31 +02:00
Campbell Barton
2aa8d3cb4a Merge branch 'blender-v4.3-release' 2024-10-12 00:29:25 +11:00
Campbell Barton
094f7235bb Cleanup: replace own Py_INCREF_RET with CPython's Py_NewRef
These are both simple functions that serve the same purpose.
Py_NewRef didn't exist when Py_INCREF_RET was added to Blender.
2024-10-12 00:20:55 +11:00
Bastien Montagne
aecdb518db BPY: Add a debug utils to print Python backtrace from C++ code. 2024-10-11 14:17:50 +02:00
Campbell Barton
e83d8271ac Merge branch 'blender-v4.3-release' 2024-10-09 22:59:48 +11:00
nutti
1d07ec7bc9 PyAPI: add specific BMLayerCollection element type to doc-strings
Ref: !125851
2024-10-09 22:58:17 +11:00
Campbell Barton
434bc9213a Merge branch 'blender-v4.3-release' 2024-10-09 15:48:36 +11:00
nutti
933fb1978f PyAPI: correct types in doc-strings
Ref !116245
2024-10-09 15:45:23 +11:00
Campbell Barton
3525b83c6b Cleanup: use specific exception types where appropriate 2024-10-08 09:41:53 +11:00
Campbell Barton
1a1e75c253 Cleanup: replace implicit BaseException with Exception
Exception is more appropriate as a general exception in these cases.
2024-10-08 09:41:51 +11:00
Clément Foucault
9c0321ae9b Metal: Simplify MSL translation
Move most of the string preprocessing used for MSL
compatibility to `glsl_preprocess`.

Enforce some changes like matrix constructor and
array constructor to the GLSL codebase. This is
for C++ compatibility.

Additionally reduce the amount of code duplication
inside the compatibility code.

Pull Request: https://projects.blender.org/blender/blender/pulls/128634
2024-10-07 12:54:10 +02:00
Bastien Montagne
76e7770bc9 Python API: Add link/append pre/post handlers.
The `pre` handler is called after blender internal code is done populating
the link/append context with data to be processed, and before this data
starts being linked from library files.

The `post` handler is called after blender is done linking, and
potentailly appending and/or instantiating, the requested data and all
of their dependencies.

Both handlers are called with a single argument, the link/append
context.

An new RNA sets of wrappers have been added to expose relevant info from
these internal C++ structures.

NOTE: !113658 is very similar (but tied to asset drag & drop), whereas
this PR is more general (these could probably live hand-in-hand / side-
by-side).

Implements #122357

Pull Request: https://projects.blender.org/blender/blender/pulls/128279

-----------------

Some quick py example  code:

```python
import bpy

def my_handler_pre(lapp_context):
    print("About to {}:\n\t".format("link" if "LINK" in lapp_context.options else "append"),
          "\n\t".join("{} '{}', from libs ['{}']".format(item.id_type, item.name,
                                                         "', '".join([l.filepath for l in item.source_libraries]))
                      for item in lapp_context.import_items))

def my_handler_post(lapp_context):
    print("{}:\n\t".format("Linked" if "LINK" in lapp_context.options else "Appended"),
          "\n\t".join("{} '{}', from lib '{}'".format(item.id.id_type, item.id.name, item.source_library.filepath)
                      for item in lapp_context.import_items))

bpy.app.handlers.link_append_pre.append(my_handler_pre)
bpy.app.handlers.link_append_post.append(my_handler_post)
```
2024-10-02 16:44:38 +02:00
Campbell Barton
c6fd26a3f5 Cleanup: spelling in comments 2024-10-01 09:59:33 +10:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Campbell Barton
32c6f9bbd0 Cleanup: use PyModule_AddObjectRef where appropriate 2024-09-26 17:08:34 +10:00
Bastien Montagne
22477956e2 Refactor: Move BPY main/public extern headers to proper C++ ones.
Pull Request: https://projects.blender.org/blender/blender/pulls/128081
2024-09-25 18:04:33 +02:00
Bastien Montagne
6c0c53161e Refactor: Move BPY bmesh headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Bastien Montagne
c3247aa4f0 Refactor: Move BPY generic headers to proper C++ ones.
NOTE: `bgl.h` was left unchanged, as it is deprecated code anyway, and
its conversion to C++ does not seem immediately trivial.
2024-09-25 18:04:27 +02:00
Bastien Montagne
4fac7828e4 Refactor: Move BPY mathutils headers to proper C++ ones.
This module actually was confusing, since only a few headers were
effectively still C ones (using the `extern "C"` blocks)...
2024-09-25 18:04:27 +02:00
Bastien Montagne
4dd11465bc Refactor: Move BPY intern remaining headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Bastien Montagne
198a1ec7a9 Refactor: Move BPY intern bpy_app headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Bastien Montagne
91e4bcd204 Refactor: Move BPY intern bpy_rna headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Campbell Barton
01825a85cb Cleanup: quiet compiler warnings 2024-09-25 20:14:06 +10:00
Campbell Barton
72b6ffd508 Fix IDPropertyUIManager.as_dict() non-array default for arrays
When a non-array default was set for an array,
the returned default would be empty.
2024-09-23 16:25:13 +10:00
Campbell Barton
57eae31ce9 Fix #127952: Crash on load after id_properties_ui type change
Resolve regression in [0] which keeps UI data when ID property types
change.

[0]: 91466f71f1
2024-09-23 16:18:39 +10:00
Jesse Yurkovich
1dbf75ff52 Cleanup: Remove BLI_array macros in bmesh edgenet
This replaces the older dynamic c array macros with blender::Vector in
bmesh_polygon_edgenet. This is the only remaining use of the old array
machinery and removal of `BLI_array.h / .c` can happen immediately
afterwards.

See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/119975
2024-09-21 23:59:14 +02:00