dep-protobuf/python/google/protobuf/internal/allocation_count.py
Protobuf Team Bot ad6a7e8b64 Check return values and handle alloc failures in python
PiperOrigin-RevId: 955022274
2026-07-27 22:11:16 -07:00

39 lines
1 KiB
Python

# Protocol Buffers - Google's data interchange format
# Copyright 2026 Google LLC. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""allocation_count helper for testing OOM/allocation failures."""
_upb_allocation_count = None
try:
from google.protobuf.internal import api_implementation
if api_implementation.Type() == 'upb':
from google._upb import _message
_upb_allocation_count = _message
except ImportError:
pass
def is_available():
if _upb_allocation_count is not None:
return _upb_allocation_count._AllocationCount_IsAvailable()
return False
def get():
if _upb_allocation_count is not None:
return _upb_allocation_count._AllocationCount_Get()
return 0
def reset():
if _upb_allocation_count is not None:
_upb_allocation_count._AllocationCount_Reset()
def fail_on(n):
if _upb_allocation_count is not None:
_upb_allocation_count._AllocationCount_FailOn(n)