Commit graph

21 commits

Author SHA1 Message Date
Protobuf Team Bot
c6b856d785 Introduce overflow checking functions for add and multiply in upb to replace error-prone manual checks
PiperOrigin-RevId: 966266256
2026-08-17 17:17:05 -07:00
Protobuf Team Bot
ad6a7e8b64 Check return values and handle alloc failures in python
PiperOrigin-RevId: 955022274
2026-07-27 22:11:16 -07:00
Charlie Beattie
0b1b3fa234 Internal change.
PiperOrigin-RevId: 947803839
2026-07-14 11:25:48 -07:00
Runze Wang
52e82c810c Emit future warning when mutating GetOptions() in OSS
PiperOrigin-RevId: 946657065
2026-07-12 13:41:24 -07:00
Charlie Beattie
4f5350ef98 Internal change.
PiperOrigin-RevId: 943935338
2026-07-07 09:27:46 -07:00
Runze Wang
a70d121865 Warn on out-of-range pop index in upb repeated fields.
PiperOrigin-RevId: 934743764
2026-06-18 23:11:19 -07:00
Charlie Beattie
2bda7ee751 Internal change
PiperOrigin-RevId: 933111478
2026-06-16 08:49:46 -07:00
Charlie Beattie
ea40f1d32a Support assigning repeated scalar fields using Python Buffer API.
PiperOrigin-RevId: 932284662
2026-06-15 00:51:15 -07:00
Runze Wang
be53faf37d internal change
PiperOrigin-RevId: 930072020
2026-06-10 14:17:37 -07:00
Runze Wang
eebe9b7737 [py/C++] Implement Make GetOptions() return immutable options. C++ will raise a TypeError when options returned GetOptions() by is mutated.
PiperOrigin-RevId: 926215827
2026-06-03 13:10:50 -07:00
Runze Wang
12baad3caa internal change
PiperOrigin-RevId: 922907524
2026-05-28 12:21:38 -07:00
Runze Wang
403d429eab [py/upb] Make GetOptions() return immutable options for scalar type. UPB will raise a TypeError when options returned GetOptions() by is mutated.
PiperOrigin-RevId: 918559519
2026-05-20 11:33:26 -07:00
Runze Wang
78a09ada5c Fix RepeatedContainer_pop to raise IndexError for out-of-bounds indices.
The previous implementation of RepeatedContainer_pop would clamp the index to the last element if it was out of bounds. This change removes the index clamping, ensuring that pop() raises an IndexError when given an index that is out of range, matching the other 2 pyproto implementation as well as standard Python list behavior. Tests are added to confirm this corrected behavior.

This is the 5th bug listed in https://github.com/protocolbuffers/protobuf/issues/26596

PiperOrigin-RevId: 902737839
2026-04-20 11:30:37 -07:00
Jie Luo
1eb4e5290a Python Proto scalar repeated numpy binding.
Add __array__ magic method to scalar repeated field. The default returned dtype of numpy/tensorflow usages like np.arrary() np.asarray() will be change.
Cpp_Type | np.array() dtype | Old tf.reshape() dtype | New dtype
float.   | float64/float64  | float32/float32.       | float32
double.  | float64/float64. | float32/float32.       | float64
int32.   | int64/float64.   | int32/float32.         | int32
int64.   | int64/float64.   | int32/float32.         | int64
uint32.  | int64/float64.   | int32/float32.         | uint32
uint64.  | int64/float64.   | int32/float32.         | uint64
bool.    | bool/float64.    | bool/float32.          | bool
enum     | int64/float64    | int32/float32          | int32
string   | U/float64        | string/float32         | U (Unicode string)
bytes    | S/float64        | string/float32.        | S (Byte string)

Performance improvement:
For non-string repeated:
  -upb/cpp are about 50-100 times faster.
  -pure python is ~3x times faster.
For string repeated: numbers are noise, no regression (maybe a slight win)

PiperOrigin-RevId: 836264273
2025-11-24 09:59:08 -08:00
Jie Luo
42749093dc Fix python upb crashes on map/repeated reference stub destructor
The original code removes map/repeated stub from the weak map without reifying in some situations. Changed _Reify() functions to decide if need to delete from WeakMap or SetConcreteSubobj.

PiperOrigin-RevId: 752524491
2025-04-28 18:35:14 -07:00
Jie Luo
0324f39dab Add clear() method to repeated fields in Python.
Example usage:
  msg.repeated_int32.extend([1,2])
  msg.repeated_int32.clear()

PiperOrigin-RevId: 736221526
2025-03-12 15:58:57 -07:00
Jie Luo
6c3ff5aa9e Performance optimization for upb python extend repeated scalars.
Before:
_bench_append, 100000, 241.9
_bench_extend, 100000, 112.3
_bench_assign, 100000, 83.3
_bench_pybind11, 100000, 16.2

After:
_bench_append, 100000, 224.3
_bench_extend, 100000, 71.2
_bench_assign, 100000, 81.1
_bench_pybind11, 100000, 14.7
PiperOrigin-RevId: 711909495
2025-01-03 18:29:24 -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
Jie Luo
7cf02389b3 fix upb python: DO NOT create empty optional field after sorting empty repeated field
PiperOrigin-RevId: 618350866
2024-03-22 20:00:05 -07: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/repeated.c (Browse further)