Skip to content

Commit

Permalink
use struct instead of ctype. allows the protobuf python library to wo…
Browse files Browse the repository at this point in the history
…rk on cpython 3.11's new wasm target [1]

For #12212

PiperOrigin-RevId: 631237602
  • Loading branch information
anandolee authored and copybara-github committed May 7, 2024
1 parent d0b016f commit 9de810a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/google/protobuf/internal/type_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

__author__ = '[email protected] (Will Robinson)'

import ctypes
import struct
import numbers

from google.protobuf.internal import decoder
Expand All @@ -34,7 +34,7 @@


def TruncateToFourByteFloat(original):
return ctypes.c_float(original).value
return struct.unpack('<f', struct.pack('<f', original))[0]


def ToShortestFloat(original):
Expand Down

1 comment on commit 9de810a

@igoforth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear Google,

Please release this change.

Sincerely,
Someone who wants to work with protobuf in pure-python without reliance on ctypes.

Please sign in to comment.