Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,34 @@ jobs:
- name: Run tests
run: |
make test --no-print-directory -s

big-endian:

runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: s390x

- name: Run endian tests on s390x
run: |
docker run --rm --platform linux/s390x \
-v "${{ github.workspace }}:/work" \
-w /work \
python:3.13-bookworm \
bash -euxo pipefail -c '
apt-get update
apt-get install -y --no-install-recommends gcc make
python -m pip install -r compiler/requirements.txt -r tests/requirements_tests.txt
printf "%s\n" \
"#!/usr/bin/env sh" \
"PYTHONPATH=/work/compiler exec python -m bitproto._main \"\$@\"" \
>/usr/local/bin/bitproto
chmod +x /usr/local/bin/bitproto
PYTHONPATH=/work/compiler:/work/lib/py python -c "import sys; assert sys.byteorder == \"big\", sys.byteorder"
PYTHONPATH=/work/compiler:/work/lib/py python -m pytest tests/test_encoding/test_endian.py -v
'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ of 4 bytes after encoding.

This image shows the layout of data fields in the encoded bytes buffer:

![](docs/_static/images/data-encoding-sample.png)
![](https://raw.githubusercontent.com/hit9/bitproto/master/docs/_static/images/data-encoding-sample.png)

## Code Example

Expand Down
16 changes: 16 additions & 0 deletions changes.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
.. currentmodule:: bitproto

Version 1.3.1
-------------

.. _version-1.3.1:

- Bugfix: Broaden ``BP_BIG_ENDIAN`` auto-detection beyond GCC/Clang's
``__BYTE_ORDER__`` to also cover ACLE-compatible Arm toolchains such as TI
Arm Clang (``__ARM_BIG_ENDIAN``), legacy TI ARM CGT (``__big_endian__``),
other toolchains that define ``__BIG_ENDIAN__``, and IAR
(``__LITTLE_ENDIAN__ == 0``), in both the optimization-mode generated code and
the standard-mode C library. Previously these big-endian targets fell through
to the little-endian path and produced incorrect results for multi-byte
fields. PR #84.
- Packaging: Show the project README as the long description on the PyPI project
page for the ``bitproto`` package.

Version 1.3.0
-------------

Expand Down
1 change: 1 addition & 0 deletions compiler/README.md
2 changes: 1 addition & 1 deletion compiler/bitproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

"""

__version__ = "1.3.0"
__version__ = "1.3.1"
__description__ = "bit level data interchange format."
10 changes: 8 additions & 2 deletions compiler/bitproto/renderer/impls/c/renderer_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,18 @@ def render(self) -> None:
# Auto-detect a big-endian host so the default just works without
# the user defining BP_BIG_ENDIAN; still overridable via -D.
# __BYTE_ORDER__ / __ORDER_BIG_ENDIAN__ covers GCC/Clang.
# __BIG_ENDIAN__ covers TI ARM CGT (--be32) and some other toolchains.
# __ARM_BIG_ENDIAN covers ACLE-compatible Arm toolchains, including
# TI Arm Clang. __big_endian__ covers legacy TI ARM CGT (armcl).
# __BIG_ENDIAN__ covers some other toolchains.
# __LITTLE_ENDIAN__ == 0 covers IAR (which always defines it).
self.push("#if !defined(BP_BIG_ENDIAN) && (\\")
self.push(
" (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || \\"
)
self.push(" defined(__BIG_ENDIAN__))")
self.push(" defined(__ARM_BIG_ENDIAN) || \\")
self.push(" defined(__big_endian__) || \\")
self.push(" defined(__BIG_ENDIAN__) || \\")
self.push(" (defined(__LITTLE_ENDIAN__) && (__LITTLE_ENDIAN__ == 0)))")
self.push("#define BP_BIG_ENDIAN 1")
self.push("#endif")
# <string.h> is only needed for memset in the big-endian path.
Expand Down
3 changes: 2 additions & 1 deletion compiler/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ build-backend = "setuptools.build_meta"

[project]
name = "bitproto"
version = "1.3.0"
version = "1.3.1"
description = "bit level data interchange format."
readme = "README.md"
authors = [
{name = "Chao Wang", email = "hit9@icloud.com"},
]
Expand Down
16 changes: 11 additions & 5 deletions docs/endianness.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ about C.
C standard mode
---------------

The C library (``lib/c/bitproto.c``) detects a big-endian host automatically via
``__BYTE_ORDER__`` and selects an endian-neutral code path. You may also force it
by defining ``BP_BIG_ENDIAN`` when compiling the library, for toolchains that do
not define ``__BYTE_ORDER__``:
The C library (``lib/c/bitproto.c``) detects a big-endian host automatically
(via ``__BYTE_ORDER__`` for GCC/Clang, ``__ARM_BIG_ENDIAN`` for
ACLE-compatible Arm toolchains such as TI Arm Clang, ``__big_endian__`` for
legacy TI ARM CGT, ``__BIG_ENDIAN__`` for other toolchains, and
``__LITTLE_ENDIAN__ == 0`` for IAR) and selects an endian-neutral code path.
You may also force it by defining ``BP_BIG_ENDIAN`` when compiling the library,
for toolchains that expose none of these macros:

.. sourcecode:: bash

Expand All @@ -77,7 +80,10 @@ emits two equivalent code paths guarded by a preprocessor macro:
// portable bit-shift path (big-endian hosts)
#endif

A big-endian host is auto-detected via ``__BYTE_ORDER__``; you may also force the
A big-endian host is auto-detected (via ``__BYTE_ORDER__`` for GCC/Clang,
``__ARM_BIG_ENDIAN`` for ACLE-compatible Arm toolchains such as TI Arm Clang,
``__big_endian__`` for legacy TI ARM CGT, ``__BIG_ENDIAN__`` for other
toolchains, and ``__LITTLE_ENDIAN__ == 0`` for IAR); you may also force the
big-endian path by defining ``BP_BIG_ENDIAN`` when compiling the generated code.
The little-endian path is identical to earlier bitproto releases, so there is no
performance change on little-endian targets — only the generated source is a
Expand Down
Loading
Loading