Commit graph

16 commits

Author SHA1 Message Date
Protobuf Team Bot
ad6a7e8b64 Check return values and handle alloc failures in python
PiperOrigin-RevId: 955022274
2026-07-27 22:11:16 -07:00
Runze Wang
52e82c810c Emit future warning when mutating GetOptions() in OSS
PiperOrigin-RevId: 946657065
2026-07-12 13:41:24 -07:00
Runze Wang
be53faf37d internal change
PiperOrigin-RevId: 930072020
2026-06-10 14:17:37 -07:00
Joshua Haberman
8ff5d8ad3f Added free threading support to PyUpb_WeakMap
Previously we had a lock in the global object cache (an instance of `PyUpb_WeakMap`), but this CL refactors `PyUpb_WeakMap` to be internally synchronized.

We also add code to handle a tricky edge case that can occur when a dealloc operation races with lookup.  This implementation mirrors the code previously implemented in C++ (`PyWeakValueMap`).

PiperOrigin-RevId: 921534474
2026-05-26 10:13:14 -07:00
Jie Luo
f10c1de25f Protobuf Python UPB Free Threading support.
Add obj_cache lock to pass current free threading tests on python upb.

PiperOrigin-RevId: 864903528
2026-02-03 09:04:20 -08:00
Oleh Prypin
46061cb99d Prevent crashes when creating objects during interpreter shutdown
(The crashes happen only since Python 3.13)

In particular:

* Skip adding to the weak map if `Py_IsFinalizing()` is true. Calling `PyUpb_WeakMap_Add` may be caused by user code that creates protos inside `__del__`!

* `PyUpb_DescriptorPool_Get` and subsequently `PyUpb_ObjCache_Get` may *also* be called if users cause `PyUpb_RepeatedContainer_GetOrCreateWrapper` to be called. So make it nullable and skip the assertion if currently shutting down.

This follows a prior attempted fix d57d2708b3 but expands the scope of it.

PiperOrigin-RevId: 856589514
2026-01-15 03:45:00 -08:00
Joshua Haberman
2504a29b3d Fixed several cases of implicit bool->pointer conversion.
We had several cases where we were returning `false` in a function that returns `PyObject*`.  These need to be `return NULL` instead.

PiperOrigin-RevId: 840760349
2025-12-05 09:35:37 -08:00
Oleh Prypin
d57d2708b3 Fix a crash that happens during shutdown due to looking up modules in the cache
The crash happens only since Python 3.13. Conveniently, Python 3.13 introduces a function to check if the interpreter is shutting down at the moment.

There was a related issue https://github.com/protocolbuffers/protobuf/issues/22067 and related commit 87de6f795f
but it appears that the fix was incomplete. What actually causes a crash during shutdown is using `PyState_FindModule`, and `PyUpb_ModuleState_MaybeGet` still calls that anyway.

PiperOrigin-RevId: 807361381
2025-09-15 13:33:25 -07:00
Protobuf Team Bot
bfacde83ec upb: add support for size returning malloc
PiperOrigin-RevId: 753681000
2025-05-01 12:20:58 -07:00
Geoffry Song
8ccca3986f [python] Remove explicit visibility("default") on PyInit__message (#16125)
This is unnecessary as PyMODINIT_FUNC already implies Py_EXPORTED_SYMBOL.

Closes #16125

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/16125 from goffrie:upb_export 5e7fa70544
PiperOrigin-RevId: 700793109
2024-11-27 13:42:44 -08:00
Geoffry Song
5752b2d07b [python] Remove semicolon after PyObject_HEAD (#16123)
`PyObject_HEAD` already expands to a field with a semicolon; the extra semicolon is unnecessary, and makes some compilers unhappy.

Closes #16123

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/16123 from goffrie:pyobject_head 947438678f
PiperOrigin-RevId: 700735003
2024-11-27 10:08:21 -08:00
Joshua Haberman
8422e9795f Migrated upb to use Copybara-standard stripping.
This CL is mostly a no-op, except that now google3-only code is actually stripped from OSS, instead of being preserved in `# begin:google_only` blocks.

This follows the conventions of the greater Copybara ecosystem.

PiperOrigin-RevId: 669513564
2024-08-30 18:34:23 -07:00
Joshua Haberman
bffd01c649 Fixed a couple of compiler warnings.
PiperOrigin-RevId: 642339381
2024-06-11 11:43:35 -07:00
Sandy Zhang
5b32936822 Register Scalar/MessageMapContainerTypes as virtual subclasses of MutableMapping instead of inheriting directly.
This prevents these from using abc.ABCMeta metaclass to avoid deprecation warning:
```
DeprecationWarning: Type google._upb._message.MessageMapContainer uses PyType_Spec with a metaclass that has custom tp_new. This is deprecated and will no longer be allowed in Python 3.14.
```

Fixes #15077
Fixes #12186

PiperOrigin-RevId: 613029479
2024-03-05 17:56:32 -08:00
Protobuf Team Bot
0fab773c1d Update remainder of upb to new short license style.
PiperOrigin-RevId: 584116886
2023-11-20 13:43:32 -08:00
Adam Cozzette
501ececd39 Reorganize upb file structure
This change moves almost everything in the `upb/` directory up one level, so
that for example `upb/upb/generated_code_support.h` becomes just
`upb/generated_code_support.h`. The only exceptions I made to this were that I
left `upb/cmake` and `upb/BUILD` where they are, mostly because that avoids
conflict with other files and the current locations seem reasonable for now.

The `python/` directory is a little bit of a challenge because we had to merge
the existing directory there with `upb/python/`. I made `upb/python/BUILD` into
the BUILD file for the merged directory, and it effectively loads the contents
of the other BUILD file via `python/build_targets.bzl`, but I plan to clean
this up soon.

PiperOrigin-RevId: 568651768
2023-09-26 14:38:35 -07:00
Renamed from upb/python/protobuf.c (Browse further)