Commit graph

1025 commits

Author SHA1 Message Date
Eric Salo
64dbf0dba4 upb: delete the aliases for upb:hash, upb:lex, upb:reflection_internal
PiperOrigin-RevId: 594992691
2024-01-01 18:21:58 -08:00
Adam Cozzette
4ec9170bcd Fix layering check for usage of gtest
To satisfy the layering check, we need to depend on :gtest for the headers, in
addition to :gtest_main which provides the main() function.

There are a bunch of formatting changes as a side effect of this, but they
should be harmless.

PiperOrigin-RevId: 594318263
2023-12-28 14:41:48 -08:00
Jie Luo
4f77929203 BREAKING CHANGE in v26: check if Timestamp is valid.
Seconds should be in range [-62135596800, 253402300799]
Nanos should be in range [0, 999999999]

PiperOrigin-RevId: 594119545
2023-12-27 16:38:51 -08:00
Eric Salo
2fb0b93d9d upb: tighten up and lock down upb/wire/
PiperOrigin-RevId: 593821827
2023-12-26 10:58:17 -08:00
Eric Salo
b997cb6d8d upb: add a non-void typedef for upb_Message
PiperOrigin-RevId: 592863926
2023-12-21 08:12:16 -08:00
Jie Luo
706c0d03f8 Automated rollback of commit 1250d5f6cc.
PiperOrigin-RevId: 592707509
2023-12-20 18:21:25 -08:00
Eric Salo
33cb42e33b upb: add 'static' to several Python map functions
PiperOrigin-RevId: 592391399
2023-12-19 17:52:06 -08:00
Jie Luo
1250d5f6cc BREAKING CHANGE in v26: check if Timestamp is valid.
Seconds should be in range [-62135596800, 253402300799]
Nanos should be in range [0, 999999999]

PiperOrigin-RevId: 592365636
2023-12-19 15:49:41 -08:00
Protobuf Team Bot
9c7d2b9d83 Make the utf8_range implementation just in C
PiperOrigin-RevId: 590961088
2023-12-14 09:25:06 -08:00
Joshua Haberman
de52944f38 [Python/upb] Fixed SEGV when attempting to delete a message attribute
Deleting an attribute is not allowed in any Proto Python implementation, but upb was not checking for this case.

PiperOrigin-RevId: 589995449
2023-12-11 16:57:49 -08:00
Jie Luo
0eac77c2c6 Breaking change in 26 release: Remove msg.UnknownFields() support in pure python and cpp extension.
Users should use the add-on unknown_fields.py support.
Old usage example:
unknown_field_set = msg.UnknownFields()

New usage should be:
from google.protobuf import unknown_fields
unknown_field_set = unknown_fields.UnknownFieldSet(msg)
PiperOrigin-RevId: 589969095
2023-12-11 15:25:41 -08:00
Mike Kruskal
cf2d6965dc Breaking change: Remove C++ legacy syntax descriptor APIs
PiperOrigin-RevId: 589879506
2023-12-11 11:09:26 -08:00
Mike Kruskal
fd40c87bef Breaking change: Remove deprecated syntax accessor.
This has been replaced by edition and feature getters.  Any code depending on syntax will likely be broken by editions files, and should be migrated to the finer-grained feature helpers.

PiperOrigin-RevId: 589866745
2023-12-11 10:30:26 -08:00
Joshua Haberman
c05b320d9c Fixed a bug where FileDescriptor maps like message_types_by_name could return descriptors from other files.
Fixes: https://github.com/protocolbuffers/protobuf/issues/13740
PiperOrigin-RevId: 587135054
2023-12-01 15:12:41 -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
Richard Levasseur
06776d20a5 Add load() statements for builtin Python rules/providers
PiperOrigin-RevId: 584089414
2023-11-20 11:54:29 -08:00
Protobuf Team Bot
00e783d113 Apply clang-tidy fixes to change static_cast to proto2::DownCastToGenerated in sr_www dependencies.
As a prerequisite of enabling go/protobuf-weak-speed-messages downcasts using built-in cast operations need to be changed to cast functions recommended by protobuf team (go/protobuf-downcast-recommendation)

**More information**: go/protobuf-stripping-lsc

#codehealth

PiperOrigin-RevId: 582977861
2023-11-16 03:21:10 -08:00
Mike Kruskal
c23d5333c3 Expose editions in Python/upb.
This also fixes a few minor bugs in the editions implementation that were caught in python/conformance tests, and adds a new SetFeatureSetDefaults API to the def pool for consistency with C++ and other python implementations.

PiperOrigin-RevId: 581384108
2023-11-10 15:20:41 -08:00
Mike Kruskal
e8377f12e1 Expose editions in Python/C++.
This was already fully implemented in C++, but we need to expose features methods to the Python runtime to fully enable it.  This also enables conformance and unit-testing for C++.

PiperOrigin-RevId: 581364355
2023-11-10 14:14:05 -08:00
Adam Cozzette
5ca84008fc Move utf8_range into the protobuf repo
This makes third_party/utf8_range no longer a Git subtree, but instead the
permanent location and source of truth for utf8_range. It is also now
incorporated into the @com_google_protobuf Bazel repo. Utf8_range still has its
own separate CMake build for now, though.

PiperOrigin-RevId: 580682733
2023-11-08 15:43:35 -08:00
Adam Cozzette
24fef03259 Add support and partial CI coverage for Python 3.12
There's a test run in test_python.yml that is non-trivial to get working with
Python 3.12 due to some refactoring of our Docker images that would be needed.
But this change updates everything else to add coverage for Python 3.12.

The main changes necessary to get the builds working were to upgrade some Pip
packages via requirements.txt, including in a patch to `rules_fuzzing` that I
plan to upstream soon. I also had to take an explicit dependency on
`setuptools`.

I removed tox.ini, since it was outdated and we have not been actively
maintaining it.

PiperOrigin-RevId: 580548224
2023-11-08 08:53:27 -08:00
Mike Kruskal
15eccf3ec4 Implement Editions in Pure Python.
This change only covers pure python, and follow-up changes will handle C++/upb variants and actually enable editions support.  The C++ one works (as evident from the conformance tests), but needs some APIs added to allow for testing.

PiperOrigin-RevId: 580304039
2023-11-07 14:40:26 -08:00
Adam Cozzette
7e0e8ef385 Move python/BUILD to python/BUILD.bazel
This should address the issue in #14600 by avoiding a conflict on with the
`build` directory created by setup.py on a case-insensitive filesystem.

Closes #14600.

PiperOrigin-RevId: 579859556
2023-11-06 09:00:19 -08:00
Protobuf Team Bot
e32d0948e7 Properly untrack Python GC objects during deallocation.
Add PyObject_GC_UnTrack() in deallocation functions for Python types that
have PyTPFLAGS_HAVE_GC set, either explicitly or by inheriting from a type
with GC set. Not untracking before clearing instance data introduces
potential race conditions (if GC happens to run between the partial clearing
and the actual deallocation) and produces a warning under Python 3.11.

(The warning then triggered an assertion failure, which only showed up when
building in Py_DEBUG mode; this therefor also fixes that assertion failure.)

PiperOrigin-RevId: 579827001
2023-11-06 06:44:56 -08:00
Jie Luo
c508a40f40 Raise warnings for python syntax usages
PiperOrigin-RevId: 579344748
2023-11-03 17:17:00 -07:00
Jie Luo
1231af10c7 merge 25.x to main (#14617)
Closes #14617

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14617 from anandolee:25.x ac86c5ef32
PiperOrigin-RevId: 578996979
2023-11-02 15:29:36 -07:00
Protobuf Team Bot
3ea774370a Internal change
PiperOrigin-RevId: 578944754
2023-11-02 13:34:12 -07:00
Jie Luo
a077f68b1c
Merge branch 'main' into 25.x 2023-11-02 11:07:24 -07:00
Protobuf Team Bot
6b5d8db01f Updating version.json and repo version numbers to: 25.0 2023-11-01 13:03:44 -07:00
Joshua Haberman
1711ebd455 Fixed Python memory leak in map lookup.
Previously we were allocating memory on the message's arena every time we performed a `map[key]` or `map.get(key)` operation.  This is unnecessary, as the key's data is only needed ephemerally, for the duration of the lookup, and we can therefore alias the Python object's string data instead of copying it.

This required fixing a bug in the convert.c operation.  Previously in the `arena==NULL` case, if the user passes a bytes object instead of a unicode string, the code would return a pointer to a temporary Python object that had already been freed, leading to use-after-free.  I fixed this by referencing the bytes object's data directly, and using utf8_range to verify the UTF-8.

Fixes: https://github.com/protocolbuffers/protobuf/issues/14571
PiperOrigin-RevId: 578563555
2023-11-01 17:36:05 +00:00
Joshua Haberman
b0eeb356b8 Fixed Python memory leak in map lookup.
Previously we were allocating memory on the message's arena every time we performed a `map[key]` or `map.get(key)` operation.  This is unnecessary, as the key's data is only needed ephemerally, for the duration of the lookup, and we can therefore alias the Python object's string data instead of copying it.

This required fixing a bug in the convert.c operation.  Previously in the `arena==NULL` case, if the user passes a bytes object instead of a unicode string, the code would return a pointer to a temporary Python object that had already been freed, leading to use-after-free.  I fixed this by referencing the bytes object's data directly, and using utf8_range to verify the UTF-8.

Fixes: https://github.com/protocolbuffers/protobuf/issues/14571
PiperOrigin-RevId: 578563555
2023-11-01 10:34:44 -07:00
Mike Kruskal
88249acbfd Internal change
PiperOrigin-RevId: 578290521
2023-10-31 13:48:51 -07:00
Mike Kruskal
63f4c503a2 Editions: Embed resolved features of descriptor.proto for pure python.
Because pure python builds all descriptors at runtime via reflection, it's unable to parse options during the build of descriptor.proto (i.e. before we've built the options schemas).  We always lazily parse these options to avoid this, but that still means options can't be *used* during this build.  Since the current build process makes heavy use of features (which previously just relied on syntax), this poses a problem for editions.

To get around this, we just embed the resolved features directly into the gencode for this one file.  This will allow us to skip feature resolution for these descriptors and still consider features in their build.

PiperOrigin-RevId: 577495949
2023-10-28 13:05:32 -07:00
Jie Luo
e9953d2155 internal change
PiperOrigin-RevId: 576966982
2023-10-26 13:17:27 -07:00
Eric Salo
8d67a40d30 upb: fix wheels build errors
PiperOrigin-RevId: 576925248
2023-10-26 10:59:04 -07:00
Protobuf Team Bot
ba1aab2baf Updating version.json and repo version numbers to: 25.0-rc2 2023-10-18 09:57:30 -07:00
Protobuf Team Bot
62a435c1ab Fix handling of Unicode escapes in string data in textproto files.
PiperOrigin-RevId: 573926175
2023-10-16 14:14:32 -07:00
Protobuf Team Bot
896f3d8ced Updating version.json and repo version numbers to: 25.0-rc1 2023-10-16 12:36:52 -07:00
Edgar Riba
1639639c40 unused miport sys and variable (#13869)
detected not accessed by pylance

Closes #13869

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/13869 from edgarriba:patch-1 177a0c44ab
PiperOrigin-RevId: 573316929
2023-10-13 14:28:33 -07:00
ottmar-zittlau
41c686368d Fix protoc search path in setup.py (#14318)
This PR is fixing small inconsistencies in the paths where the protobuf compiler is searched for in the protobuf python setup.py.

Closes #14318

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14318 from ottmar-zittlau:main 598d13406f
PiperOrigin-RevId: 573315569
2023-10-13 14:21:20 -07:00
Jie Luo
8c8cbc43a7 Add client_streaming and server_streaming in MethodDescriptor for upb python
PiperOrigin-RevId: 573268712
2023-10-13 11:12:41 -07:00
Jie Luo
656d62ae32 internal change
PiperOrigin-RevId: 572965793
2023-10-12 11:35:58 -07:00
Jie Luo
41af1d53a2 loosen upb for json name conflict check in proto2 between json name and field
name. Once editions is supported this check should turn into a check on LEGACY_BEST_EFFORT

PiperOrigin-RevId: 572041162
2023-10-09 14:31:17 -07:00
Eric Salo
5b6543edb5 upb: first attempt at implementing name mangling for minitable symbols
PiperOrigin-RevId: 571636273
2023-10-07 16:29:19 -07:00
Adam Cozzette
8970072608 Migrate away from distutils
Python 3.12 has removed the `distutils` module, so we need to stop relying on
it. Most of the parts we were using had a straightforward replacement in
`setuptools` or elsewhere in the Python standard library. I couldn't find a
good replacement for `distutils.command.clean`, though. We were only using it
to enable `python setup.py clean`, so I just removed that functionality since
directly invoking setup.py is deprecated anyway.

While I was looking at this I realized that our python/release.sh script is
unused, so I also removed that.

PiperOrigin-RevId: 571035275
2023-10-05 09:08:21 -07:00
Protobuf Team Bot
ebb1b0550a GetArena() instead of GetArenaForAllocation().
PiperOrigin-RevId: 570142494
2023-10-02 12:28:04 -07:00
Eric Salo
07fba1da07 upb: merge ":collections" into ":message"
PiperOrigin-RevId: 569594353
2023-09-29 14:53:28 -07:00
Protobuf Team Bot
e33e0d2ba5 Add ABSL_ATTRIBUTE_LIFETIME_BOUND attribute on generated oneof accessors.
This allows the compiler to statically detect use-after-free bugs.

PiperOrigin-RevId: 569504371
2023-09-29 09:01:46 -07:00
Adam Cozzette
8f831e973a Update Python versions to reflect that we now support 3.8 through 3.11
PiperOrigin-RevId: 569317472
2023-09-28 16:12:04 -07:00
Samuel Freilich
f5e6fb02cc Use a more general and simpler (but slower) approach in Timestamp.ToDatetime
The attempt at a more optimized approach doesn't round-trip all values of `datetime` on all platforms because `datetime.fromtimestamp(tzinfo)` is limited by the range of values accepted by `time.gmtime`, which can be substantially narrower than `datetime.min` to `datetime.max`. (The documentation notes that either `OverflowError` or `OSError` can be raised in that case, and that often this is limited to 1970 through 2038, versus 1 to 9999. See also https://github.com/python/cpython/issues/110042, the use of `gmtime` here seems unnecessary when the tzinfo supports the entire range.) So, supporting that whole range would require need fallback logic that uses this general approach anyways, which then requires a redundant set of tests for error behavior that amounts to a reimplementation of the whole function.

In addition, `datetime.fromtimestamp` doesn't support the full precision of `datetime` (https://github.com/python/cpython/issues/109849), which required adding additional code and an additional assumption (that neither tz offsets were sub-second nor tz changes mid-second).

Added test-cases for `datetime.min` in addition to the ones for `datetime.max`. Adjusted the examples and variable names slightly.

PiperOrigin-RevId: 569259168
2023-09-28 12:35:34 -07:00