././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0235426 pybcj-1.0.7/0000755000175100017510000000000015112441274012275 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.flake80000644000175100017510000000010215112441263013437 0ustar00runnerrunner[flake8] max-line-length = 125 ignore = F841 extend-ignore = E203 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.git_archival.txt0000644000175100017510000000017415112441263015550 0ustar00runnerrunnernode: $Format:%H$ node-date: $Format:%cI$ describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ ref-names: $Format:%D$././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.gitattributes0000644000175100017510000000004015112441263015160 0ustar00runnerrunner.git_archival.txt export-subst ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0185425 pybcj-1.0.7/.github/0000755000175100017510000000000015112441274013635 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.github/FUNDING.yml0000644000175100017510000000124415112441263015451 0ustar00runnerrunner# These are supported funding model platforms github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: miurahr issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.github/dependabot.yml0000644000175100017510000000021715112441263016463 0ustar00runnerrunnerversion: 2 updates: - package-ecosystem: pip directory: "/" schedule: interval: daily time: "20:00" open-pull-requests-limit: 10 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0185425 pybcj-1.0.7/.github/workflows/0000755000175100017510000000000015112441274015672 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.github/workflows/publish-to-pypi.yml0000644000175100017510000000544615112441263021471 0ustar00runnerrunnername: Publish Python 🐍 distributions πŸ“¦ to PyPI and TestPyPI on: push: branches: - releases/* tags: - v* jobs: build_wheels: name: Build wheels on ${{ matrix.platform }} runs-on: ${{ matrix.platform }} strategy: matrix: platform: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm, windows-11-arm] env: CIBW_ARCHS_LINUX: "native" CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" # Include latest Python beta CIBW_PRERELEASE_PYTHONS: True steps: - name: Checkout πŸ›ŽοΈ uses: actions/checkout@v4 with: fetch-depth: 20 - name: Fetch release tags run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Set up Python 🐍 uses: actions/setup-python@v6 with: python-version: 3.13 - name: Install cibuildwheel & build wheels run: | python -m pip install -U pip python -m pip install -U cibuildwheel python -m cibuildwheel --output-dir wheelhouse - name: Upload wheels uses: actions/upload-artifact@v4 with: name: artifact-${{ matrix.platform }} path: wheelhouse/*.whl build_source_dist: name: Build source dist runs-on: ubuntu-latest steps: - name: Checkout πŸ›ŽοΈ uses: actions/checkout@v4 with: fetch-depth: 20 - name: Fetch release tags run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Set up Python 🐍 uses: actions/setup-python@v6 with: python-version: 3.13 - name: Build source distribution & wheels🎑 run: | python -m pip install -U pip setuptools setuptools_scm[toml] build python -m build --sdist - name: Upload source distribution uses: actions/upload-artifact@v4 with: name: artifact-source path: dist/*.tar.gz pypi-publish: name: publish Python 🐍 distributions πŸ“¦ to PyPI and TestPyPI runs-on: ubuntu-latest needs: [build_wheels, build_source_dist] environment: pypi permissions: id-token: write steps: - name: download dist artifacts uses: actions/download-artifact@v4 with: path: dist merge-multiple: true - name: Publish distribution πŸ“¦ to Test PyPI if: ${{ startsWith(github.event.ref, 'refs/heads/releases') }} uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1.12.4 with: repository-url: https://test.pypi.org/legacy/ - name: Publish distribution πŸ“¦ to PyPI if: startsWith(github.event.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1.12.4 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.github/workflows/run-tox-tests.yml0000644000175100017510000000234415112441263021172 0ustar00runnerrunnername: Run Tox tests on: push: branches: - main - releases/* pull_request: types: - opened - synchronize - reopened jobs: build: runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-24.04, windows-latest] python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.10", ] include: - os: macos-latest python-version: "3.14" - os: ubuntu-24.04-arm python-version: "3.13" - os: windows-11-arm python-version: "3.13" exclude: - os: windows-latest python-version: 'pypy-3.10' name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }} steps: - uses: actions/checkout@v4 with: fetch-depth: 20 - name: Setup python uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -U pip tox wheel setuptools setuptools_scm[toml] pip install tox-gh-actions - name: Test project with tox run: | tox ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.gitignore0000644000175100017510000000414015112441263014262 0ustar00runnerrunner# Created by .ignore support plugin (hsz.mobi) ### Python template # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ parts/ sdist/ var/ wheels/ pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ cover/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder .pybuilder/ target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv # For a library or package, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: # .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # pytype static type analyzer .pytype/ # Cython debug symbols cython_debug/ # PyCharm .idea/ cmake-build-*/ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0185425 pybcj-1.0.7/.woodpecker/0000755000175100017510000000000015112441274014515 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/.woodpecker/.check.yml0000644000175100017510000000074615112441263016400 0ustar00runnerrunnerwhen: - event: push branch: [main, releases/*] - event: pull_request clone: git: image: woodpeckerci/plugin-git settings: partial: false depth: 1 lfs: false tags: true steps: check: image: python:${TAG}-bullseye commands: - python -m pip install --upgrade pip - python -m pip install tox setuptools setuptools_scm[toml] - python -m tox -e py matrix: TAG: - 3.9 - 3.10 - 3.11 - 3.12 - 3.13 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/CMakeLists.txt0000644000175100017510000001015715112441263015037 0ustar00runnerrunnercmake_minimum_required(VERSION 3.19) project(pybcj C CXX) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) # TARGET PYTHON version set(PY_VERSION 3.12) set(Python_FIND_IMPLEMENTATIONS CPython) set(VENV_PATH "${CMAKE_BINARY_DIR}/venv") set(DEBUG_BUILD ON) # ################################################################################################## # Configuration for python-ext set(Python_FIND_STRATEGY VERSION) find_package(Python ${PY_VERSION}.0...${PY_VERSION}.99 COMPONENTS Interpreter Development) set(PY_EXT_FILE _bcj) set(PY_EXT_DIR src/bcj) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/get_ext.py "import sysconfig\nprint(sysconfig.get_config_var('EXT_SUFFIX'))\n") execute_process( COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/get_ext.py OUTPUT_VARIABLE PY_EXT_EXT OUTPUT_STRIP_TRAILING_WHITESPACE) set(PY_EXT ${PY_EXT_DIR}/${PY_EXT_FILE}.${PY_EXT_EXT}) set(PY_CFFI ${PY_CFFI_DIR}/PY_CFFI_FILE}.${PY_EXT_EXT}) # bulid ext by setup.py if (WIN32) if(DEBUG_BUILD) set(BUILD_EXT_PYTHON ${VENV_PATH}/Scripts/python_d.exe) else() set(BUILD_EXT_PYTHON ${VENV_PATH}/Scripts/python.exe) endif() set(BUILD_EXT_OPTION) else() set(BUILD_EXT_PYTHON ${VENV_PATH}/bin/python) set(BUILD_EXT_OPTION --warning-as-error) endif() set(pybcj_sources src/ext/Bra.c src/ext/Bra86.c src/ext/BraIA64.c) set(pybcj_ext_src src/ext/_bcjmodule.c) add_custom_target( generate_ext BYPRODUCTS ${PY_EXT} COMMAND ${BUILD_EXT_PYTHON} setup.py build_ext ${BUILD_EXT_OPTION} --inplace WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS venv.stamp SOURCES ${pybcj_sources} ${pybcj_ext_src}) add_library(_pybcj_ext MODULE ${pybcj_sources} ${pybcj_ext_src}) target_include_directories(_pybcj_ext PRIVATE ${Python_INCLUDE_DIRS} src/ext) target_link_libraries(_pybcj_ext PRIVATE ${Python_LIBRARIES}) # ################################################################################################## # create virtualenv file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/requirements.txt " hypothesis pytest>=6.0 ") if (WIN32) set(PIP_COMMAND ${VENV_PATH}/Scripts/pip.exe) else() set(PIP_COMMAND ${VENV_PATH}/bin/pip) endif() add_custom_target( venv.stamp BYPRODUCTS venv.stamp COMMAND ${Python_EXECUTABLE} -m venv ${VENV_PATH} COMMAND ${PIP_COMMAND} install -r ${CMAKE_BINARY_DIR}/requirements.txt COMMAND ${CMAKE_COMMAND} -E touch venv.stamp) set(SRC_PATH "${CMAKE_SOURCE_DIR}/src") set(VPKG_PATH_A "${VENV_PATH}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/") set(VPKG_PATH_B "${VENV_PATH}/Lib/site-packages/") set(VPKG_PATH_C "${CMAKE_BINARY_DIR}") # ################################################################################################## # For pytest file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/pytest_runner.cpp " #include #include #include int main(int argc, char **argv) { std::string args; if ( argc > 1) { args.append(\"[\"); for (int i = 1; i < argc; i++) { if (i > 2) args.append(\",\"); args.append(\"\\\"\"); args.append(argv[i]); args.append(\"\\\"\"); } args.append(\"]\"); } std::filesystem::path src_path = \"${SRC_PATH}\"; std::filesystem::path vsite_path_a = \"${VPKG_PATH_A}\"; std::filesystem::path vsite_path_b = \"${VPKG_PATH_B}\"; std::filesystem::path vsite_path_c = \"${VPKG_PATH_C}\"; std::string pycode = \"import sys\\n\" \"sys.path.append('\" + src_path.string() + \"')\\n\" \"sys.path.append('\" + vsite_path_a.string() + \"')\\n\" \"sys.path.append('\" + vsite_path_b.string() + \"')\\n\" \"import pytest\\n\" \"pytest.main(\" + args + \")\\n\"; execl(\"${Python_EXECUTABLE}\", \"${Python_EXECUTABLE}\", \"-c\", pycode.c_str(), (char*)0); return 0; }") add_executable(pytest_runner ${CMAKE_CURRENT_BINARY_DIR}/pytest_runner.cpp) target_include_directories(pytest_runner PRIVATE ${Python_INCLUDE_DIRS}) target_link_libraries(pytest_runner PRIVATE ${Python_LIBRARIES}) add_dependencies(pytest_runner venv.stamp generate_ext) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/Changelog.rst0000644000175100017510000000621015112441263014713 0ustar00runnerrunner=============== PyBCJ ChangeLog =============== All notable changes to this project will be documented in this file. `Unreleased`_ ============= v1.0.7_ ======= Added ----- - Support for python 3.14 Changed ------- - ci: fix test and release workflows v1.0.6_ ======= Changed ------- - ci: release workflows Added ----- - ci: add GitHub Actions as trusted publisher for PyPi Removed ------- - ci: azure-pipelines v1.0.3_ ======= Added ----- - Support python 3.13 Fixed ----- - Allow build on git export source tree Removed ------- - Support for python 3.8 `v1.0.2`_ ========= Added ----- - Support python 3.12 - Add cibuildwheel config `v1.0.1`_ ========= Fixed ----- - Add missing source distribution on pypi (#1) `v1.0.0`_ ========= Changed ------- - test: zipping test case data - Add type hint - test: use flake8 plugins * black, colors, isort, typing - Drop github workflows - Move forge to codeberg.org Fixed ----- - gitea: issue template `v0.6.1`_ ========= Changed ------- - Publish wheels for python 3.11 beta `v0.6.0`_ ========= Changed ------- - Change internal package path for extension (#17) - Deprecated package path ``bcj.c``. now we have ``bcj._bcj`` and ``bcj._bcjfilter`` and user should use ``import bcj`` Added ----- - Add pure python filter for PyPy (#17) that is ``bcj._bcjfilter`` - Add more test cases (#17) `v0.5.3`_ ========= Fixed ----- - Fix segmentation fault in a proper condition (#16) Changed ------- - Update copyright header. `v0.5.2`_ ========= Fixed ----- - Fix pyproject.toml: add missing dynamic property(#14) `v0.5.1`_ ========= Changed ------- - Update pyproject.toml to add project section(#13) - Test on msys2/mingw64(#11) `v0.5.0`_ ========= Fixed ----- - Failed to filter when multiple encode/decode call. - Wrong data size when auto flush happened Added ----- - Add fuzzer test. Changed ------- - Black/PEP8 rules - Change status to Beta. `v0.2.0`_ ========= - Add ARM, ARMT, PPC, Sparc and IA64 encoder/decoder. - Package is now bcj `v0.1.1`_ ========= - Introduce BCJEncoder and BCJDecoder. v0.1.0 ====== - First import. .. _Unreleased: https://codeberg.org/miurahr/pybcj/compare/v1.0.7...HEAD .. _v1.0.7: https://codeberg.org/miurahr/pybcj/compare/v1.0.6...v1.0.7 .. _v1.0.6: https://codeberg.org/miurahr/pybcj/compare/v1.0.3...v1.0.6 .. _v1.0.3: https://codeberg.org/miurahr/pybcj/compare/v1.0.2...v1.0.3 .. _v1.0.2: https://codeberg.org/miurahr/pybcj/compare/v1.0.1...v1.0.2 .. _v1.0.1: https://codeberg.org/miurahr/pybcj/compare/v1.0.0...v1.0.1 .. _v1.0.0: https://codeberg.org/miurahr/pybcj/compare/v0.6.1...v1.0.0 .. _v0.6.1: https://codeberg.org/miurahr/pybcj/compare/v0.6.0...v0.6.1 .. _v0.6.0: https://codeberg.org/miurahr/pybcj/compare/v0.5.3...v0.6.0 .. _v0.5.3: https://codeberg.org/miurahr/pybcj/compare/v0.5.2...v0.5.3 .. _v0.5.2: https://codeberg.org/miurahr/pybcj/compare/v0.5.1...v0.5.2 .. _v0.5.1: https://codeberg.org/miurahr/pybcj/compare/v0.5.0...v0.5.1 .. _v0.5.0: https://codeberg.org/miurahr/pybcj/compare/v0.2.0...v0.5.0 .. _v0.2.0: https://codeberg.org/miurahr/pybcj/compare/v0.1.1...v0.2.0 .. _v0.1.1: https://codeberg.org/miurahr/pybcj/compare/v0.1.0...v0.1.1 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/LICENSE0000644000175100017510000006364215112441263013313 0ustar00runnerrunner GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/MANIFEST.in0000644000175100017510000000035015112441263014027 0ustar00runnerrunnerinclude *.rst include *.yml include pyproject.toml include LICENSE include CMakeLists.txt recursive-include src *.py recursive-include src *.c recursive-include src *.h recursive-include src py.typed prune tests prune issue_template././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0235426 pybcj-1.0.7/PKG-INFO0000644000175100017510000000751615112441274013403 0ustar00runnerrunnerMetadata-Version: 2.4 Name: pybcj Version: 1.0.7 Summary: bcj filter library Author-email: Hiroshi Miura License: LGPL-2.1-or-later Project-URL: Homepage, https://pypi.org/project/pybcj Project-URL: Bug Tracker, https://github.com/miurahr/pybcj/issues Project-URL: Source, https://github.com/miurahr/pybcj Project-URL: Changelog, https://github.com/miurahr/pybcj/blob/main/Changelog.rst Keywords: lzma,bcj Classifier: Development Status :: 5 - Production/Stable Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+) Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Operating System :: POSIX Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: 3.14 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries :: Python Modules Requires-Python: >=3.10 Description-Content-Type: text/x-rst License-File: LICENSE Provides-Extra: test Requires-Dist: pytest>=6.0; extra == "test" Requires-Dist: pytest-cov; extra == "test" Requires-Dist: hypothesis; extra == "test" Requires-Dist: coverage[toml]>=5.2; extra == "test" Provides-Extra: check Requires-Dist: mypy>=1.10.0; extra == "check" Requires-Dist: check-manifest; extra == "check" Requires-Dist: flake8<8; extra == "check" Requires-Dist: flake8-black; extra == "check" Requires-Dist: flake8-colors; extra == "check" Requires-Dist: flake8-isort; extra == "check" Requires-Dist: flake8-pyi; extra == "check" Requires-Dist: flake8-typing-imports; extra == "check" Requires-Dist: readme-renderer; extra == "check" Requires-Dist: pygments; extra == "check" Dynamic: license-file ======================================= BCJ(Branch-Call-Jump) filter for python ======================================= .. image:: https://badge.fury.io/py/pybcj.svg :target: https://badge.fury.io/py/pybcj .. image:: https://img.shields.io/conda/vn/conda-forge/pybcj :target: https://anaconda.org/conda-forge/pybcj .. image:: https://coveralls.io/repos/github/miurahr/pybcj/badge.svg?branch=main :target: https://coveralls.io/github/miurahr/pybcj?branch=main In data compression, BCJ, short for Branch-Call-Jump, refers to a technique that improves the compression of machine code of executable binaries by replacing relative branch addresses with absolute ones. This allows a LZMA compressor to identify duplicate targets and archive higher compression rate. BCJ is used in 7-zip compression utility as default filter for executable binaries. pybcj is a python bindings with BCJ implementation by C language. The C codes are derived from p7zip, portable 7-zip implementation. pybcj support Intel/Amd x86/x86_64, Arm/Arm64, ArmThumb, Sparc, PPC, and IA64. Development status ================== A development status is considered as ``Beta`` state. Installation ============ As usual, you can install pybcj using python standard pip command. .. code-block:: pip install pybcj Alternatively, one can also use conda: .. code-block:: conda install -c conda-forge pybcj WARNING ------- * When use it on MSYS2/Mingw64 environment, please set environment variable `SETUPTOOLS_USE_DISTUTILS=stdlib` to install. License ======= - SPDX-License-Identifier: LGPL-2.1-or-later - SPDX-URL: https://spdx.org/licenses/LGPL-2.1-or-later.html * Copyright (C) 2020-2025 Hiroshi Miura * Copyright (C) 1999-2010 Igor Pavlov ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/README.rst0000644000175100017510000000331615112441263013765 0ustar00runnerrunner======================================= BCJ(Branch-Call-Jump) filter for python ======================================= .. image:: https://badge.fury.io/py/pybcj.svg :target: https://badge.fury.io/py/pybcj .. image:: https://img.shields.io/conda/vn/conda-forge/pybcj :target: https://anaconda.org/conda-forge/pybcj .. image:: https://coveralls.io/repos/github/miurahr/pybcj/badge.svg?branch=main :target: https://coveralls.io/github/miurahr/pybcj?branch=main In data compression, BCJ, short for Branch-Call-Jump, refers to a technique that improves the compression of machine code of executable binaries by replacing relative branch addresses with absolute ones. This allows a LZMA compressor to identify duplicate targets and archive higher compression rate. BCJ is used in 7-zip compression utility as default filter for executable binaries. pybcj is a python bindings with BCJ implementation by C language. The C codes are derived from p7zip, portable 7-zip implementation. pybcj support Intel/Amd x86/x86_64, Arm/Arm64, ArmThumb, Sparc, PPC, and IA64. Development status ================== A development status is considered as ``Beta`` state. Installation ============ As usual, you can install pybcj using python standard pip command. .. code-block:: pip install pybcj Alternatively, one can also use conda: .. code-block:: conda install -c conda-forge pybcj WARNING ------- * When use it on MSYS2/Mingw64 environment, please set environment variable `SETUPTOOLS_USE_DISTUTILS=stdlib` to install. License ======= - SPDX-License-Identifier: LGPL-2.1-or-later - SPDX-URL: https://spdx.org/licenses/LGPL-2.1-or-later.html * Copyright (C) 2020-2025 Hiroshi Miura * Copyright (C) 1999-2010 Igor Pavlov ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/pyproject.toml0000644000175100017510000000711215112441263015210 0ustar00runnerrunner[project] name = "pybcj" requires-python = ">=3.10" description = "bcj filter library" keywords = ["lzma", "bcj"] readme = "README.rst" license = {text = "LGPL-2.1-or-later"} authors = [ {name = "Hiroshi Miura", email = "miurahr@linux.com"}, ] classifiers = [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Operating System :: POSIX :: Linux", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules", ] dynamic=["version"] [project.optional-dependencies] test = [ "pytest>=6.0", "pytest-cov", "hypothesis", "coverage[toml]>=5.2", ] check = [ "mypy>=1.10.0", "check-manifest", "flake8<8", "flake8-black", "flake8-colors", "flake8-isort", "flake8-pyi", "flake8-typing-imports", "readme-renderer", "pygments", ] [project.urls] Homepage = "https://pypi.org/project/pybcj" "Bug Tracker" = "https://github.com/miurahr/pybcj/issues" Source = "https://github.com/miurahr/pybcj" Changelog = "https://github.com/miurahr/pybcj/blob/main/Changelog.rst" [build-system] requires = ["setuptools>=58", "wheel", "setuptools_scm[toml]>=6.0.1"] build-backend = "setuptools.build_meta" [tool.setuptools_scm] local_scheme = "no-local-version" [tool.coverage.run] branch = true parallel = true source = ["bcj"] [tool.coverage.report] show_missing = true exclude_lines = ["if __name__ == .__main__.:", "pragma: no-cover", "@abstract", "def __repr__"] [tool.black] line-length = 125 target-version = ['py312'] [tool.isort] known_first_party = ["bcj", "_bcj"] known_third_party = ["docutils","flake8","pyannotate_runtime","pytest","pytz","setuptools","sphinx","yaml"] multi_line_output = 3 include_trailing_comma = true force_grid_wrap = 0 use_parentheses = true ensure_newline_before_comments = true line_length = 125 [tool.cibuildwheel] skip = ["pp*", "*-win32", "*-manylinux_i686", "*-musllinux_i686"] manylinux-x86_64-image = "manylinux_2_28" manylinux-aarch64-image = "manylinux_2_28" manylinux-ppc64le-image = "manylinux_2_28" manylinux-s390x-image = "manylinux_2_28" musllinux-x86_64-image = "musllinux_1_2" musllinux-aarch64-image = "musllinux_1_2" musllinux-ppc64le-image = "musllinux_1_2" musllinux-s390x-image = "musllinux_1_2" [tool.cibuildwheel.linux] archs = ["auto64", "aarch64"] [tool.cibuildwheel.macos] archs = ["auto64", "universal2"] [tool.tox] legacy_tox_ini = """ [tox] envlist = py{310,311,312,313,314}, pypy3, check, mypy isolated_build=True [testenv] passenv = PYTEST_ADDOPTS SETUPTOOLS_USE_DISTUTILS extras = test commands = python -m pytest -vv -s [testenv:check] extras = check commands = check-manifest {toxinidir} flake8 src tests setup.py [testenv:mypy] extras = check commands = mypy src/bcj [mypy] warn_redundant_casts = True warn_unused_ignores = True strict_optional = True show_column_numbers = True [mypy-bcj.*] ignore_missing_imports = True [pytest] python_files = test*.py norecursedirs = .git _build tmp* .eggs addopts = """ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0235426 pybcj-1.0.7/setup.cfg0000644000175100017510000000004615112441274014116 0ustar00runnerrunner[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/setup.py0000644000175100017510000000355415112441263014014 0ustar00runnerrunner# pybcj library. # Copyright 2020-2022 Hiroshi Miura # SPDX-License-Identifier: LGPL-2.1-or-later # import os import sys from setuptools import Extension, setup from setuptools.command.build_ext import build_ext from setuptools.command.egg_info import egg_info sources = ["src/ext/Bra.c", "src/ext/Bra86.c", "src/ext/BraIA64.c", "src/ext/_bcjmodule.c"] kwargs = { "name": "bcj._bcj", "include_dirs": ["src/ext"], "library_dirs": [], "libraries": [], "sources": sources, "define_macros": [], } packages = ["bcj"] binary_extension = Extension(**kwargs) def has_option(option): if option in sys.argv: sys.argv = [s for s in sys.argv if s != option] return True else: return False WARNING_AS_ERROR = has_option("--warning-as-error") class build_ext_compiler_check(build_ext): def build_extensions(self): for extension in self.extensions: if self.compiler.compiler_type.lower() in ("unix", "mingw32"): if WARNING_AS_ERROR: extension.extra_compile_args.append("-Werror") elif self.compiler.compiler_type.lower() == "msvc": # /GF eliminates duplicate strings # /Gy does function level linking more_options = ["/GF", "/Gy"] if WARNING_AS_ERROR: more_options.append("/WX") extension.extra_compile_args.extend(more_options) super().build_extensions() # Work around pypa/setuptools#436. class my_egg_info(egg_info): def run(self): try: os.remove(os.path.join(self.egg_info, "SOURCES.txt")) except FileNotFoundError: pass super().run() setup( package_dir={"": "src"}, ext_modules=[binary_extension], packages=packages, cmdclass={"build_ext": build_ext_compiler_check, "egg_info": my_egg_info}, ) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0155425 pybcj-1.0.7/src/0000755000175100017510000000000015112441274013064 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0195425 pybcj-1.0.7/src/bcj/0000755000175100017510000000000015112441274013622 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/bcj/__init__.py0000644000175100017510000000337615112441263015742 0ustar00runnerrunner# PyBcj library. # Copyright 2020-2022 Hiroshi Miura # SPDX-License-Identifier: LGPL-2.1-or-later # try: from importlib.metadata import PackageNotFoundError # type: ignore from importlib.metadata import version # type: ignore except ImportError: from importlib_metadata import PackageNotFoundError # type: ignore from importlib_metadata import version # type: ignore try: from ._bcj import ( ARMDecoder, ARMEncoder, ARMTDecoder, ARMTEncoder, BCJDecoder, BCJEncoder, IA64Decoder, IA64Encoder, PPCDecoder, PPCEncoder, SparcDecoder, SparcEncoder, ) except ImportError: try: from ._bcjfilter import ( ARMDecoder, ARMEncoder, ARMTDecoder, ARMTEncoder, BCJDecoder, BCJEncoder, IA64Decoder, IA64Encoder, PPCDecoder, PPCEncoder, SparcDecoder, SparcEncoder, ) except ImportError: msg = "pybcj module: Neither C implementation nor Python implementation can be imported." raise ImportError(msg) __all__ = ( ARMDecoder, ARMEncoder, ARMTDecoder, ARMTEncoder, BCJDecoder, BCJEncoder, IA64Decoder, IA64Encoder, PPCDecoder, PPCEncoder, SparcDecoder, SparcEncoder, ) __copyright__ = "Copyright (C) 2021 Hiroshi Miura" try: __version__ = version(__name__) except PackageNotFoundError: # pragma: no-cover # package is not installed __version__ = "unknown" __doc__ = """\ Python bindings to BCJ filter library. Documentation: https://pybcj.readthedocs.io Github: https://github.com/miurahr/pybcj PyPI: https://pypi.org/project/pybcj""" ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/bcj/_bcjfilter.py0000644000175100017510000002233315112441263016300 0ustar00runnerrunner# PyBcj library. # Copyright (c) 2019,2020,2022 Hiroshi Miura # SPDX-License-Identifier: LGPL-2.1-or-later # import struct from typing import Union class BCJFilter: _mask_to_allowed_number = [0, 1, 2, 4, 8, 9, 10, 12] _mask_to_bit_number = [0, 1, 2, 2, 3, 3, 3, 3] def __init__(self, func, readahead: int, is_encoder: bool, stream_size: int = 0): self.is_encoder: bool = is_encoder # self.prev_mask: int = 0 self.prev_pos: int = -5 self.current_position: int = 0 self.stream_size: int = stream_size # should initialize in child class self.buffer = bytearray() # self._method = func self._readahead = readahead def sparc_code(self) -> int: limit: int = len(self.buffer) - 4 i: int = 0 while i <= limit: if (self.buffer[i], self.buffer[i + 1] & 0xC0) in [ (0x40, 0x00), (0x7F, 0xC0), ]: src = struct.unpack(">L", self.buffer[i : i + 4])[0] << 2 distance: int = self.current_position + i if self.is_encoder: dest = (src + distance) >> 2 else: dest = (src - distance) >> 2 dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000 self.buffer[i : i + 4] = struct.pack(">L", dest) i += 4 self.current_position = i return i def ppc_code(self) -> int: limit: int = len(self.buffer) - 4 i: int = 0 while i <= limit: # PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) distance: int = self.current_position + i if self.buffer[i] & 0xFC == 0x48 and self.buffer[i + 3] & 0x03 == 1: src = struct.unpack(">L", self.buffer[i : i + 4])[0] & 0x3FFFFFC if self.is_encoder: dest = src + distance else: dest = src - distance # lsb = int(self.buffer[i + 3]) & 0x03 == 1 dest = (0x48 << 24) | (dest & 0x03FFFFFF) | 1 self.buffer[i : i + 4] = struct.pack(">L", dest) i += 4 self.current_position = i return i def _unpack_thumb(self, b: Union[bytearray, bytes, memoryview]) -> int: return ((b[1] & 0x07) << 19) | (b[0] << 11) | ((b[3] & 0x07) << 8) | b[2] def _pack_thumb(self, val: int) -> bytes: b = bytes( [ (val >> 11) & 0xFF, 0xF0 | ((val >> 19) & 0x07), val & 0xFF, 0xF8 | ((val >> 8) & 0x07), ] ) return b def armt_code(self) -> int: limit: int = len(self.buffer) - 4 i: int = 0 while i <= limit: if self.buffer[i + 1] & 0xF8 == 0xF0 and self.buffer[i + 3] & 0xF8 == 0xF8: src = self._unpack_thumb(self.buffer[i : i + 4]) << 1 distance: int = self.current_position + i + 4 if self.is_encoder: dest = src + distance else: dest = src - distance dest >>= 1 self.buffer[i : i + 4] = self._pack_thumb(dest) i += 2 i += 2 self.current_position += i return i def arm_code(self) -> int: limit = len(self.buffer) - 4 i = 0 while i <= limit: if self.buffer[i + 3] == 0xEB: src = struct.unpack("> 2 else: dest = (src - distance) >> 2 self.buffer[i : i + 3] = struct.pack(" int: """ The code algorithm from liblzma/simple/x86.c It is slightly different from LZMA-SDK's bra86.c :return: buffer position """ size: int = len(self.buffer) if size < 5: return 0 if self.current_position - self.prev_pos > 5: self.prev_pos = self.current_position - 5 view = memoryview(self.buffer) limit: int = size - 5 buffer_pos: int = 0 pos1: int = 0 pos2: int = 0 while buffer_pos <= limit: # -- # The following is pythonic way as same as # if self.buffer[buffer_pos] not in [0xe9, 0xe8]: # buffer_pos += 1 # continue # -- if pos1 >= 0: pos1 = self.buffer.find(0xE9, buffer_pos, limit) if pos2 >= 0: pos2 = self.buffer.find(0xE8, buffer_pos, limit) if pos1 < 0 and pos2 < 0: buffer_pos = limit + 1 break elif pos1 < 0: buffer_pos = pos2 elif pos2 < 0: buffer_pos = pos1 else: buffer_pos = min(pos1, pos2) # -- offset = self.current_position + buffer_pos - self.prev_pos self.prev_pos = self.current_position + buffer_pos if offset > 5: self.prev_mask = 0 else: for i in range(offset): self.prev_mask &= 0x77 self.prev_mask <<= 1 # note: # condition (self.prev_mask >> 1) in [0, 1, 2, 4, 8, 9, 10, 12] # is as same as # condition _mask_to_allowed_status[(self.prev_mask >> 1) & 0x7] and (self.prev_mask >> 1) < 0x10: # when _mask_to_allowed_status = [True, True, True, False, True, False, False, False] # if view[buffer_pos + 4] in [0, 0xFF] and (self.prev_mask >> 1) in self._mask_to_allowed_number: jump_target = self.buffer[buffer_pos + 1 : buffer_pos + 5] src = struct.unpack("> 1] while True: if self.is_encoder: dest = (src + distance) & 0xFFFFFFFF # uint32 behavior else: dest = (src - distance) & 0xFFFFFFFF if self.prev_mask == 0: break b = 0xFF & (dest >> (24 - idx * 8)) if not (b == 0 or b == 0xFF): break src = dest ^ ((1 << (32 - idx * 8)) - 1) & 0xFFFFFFFF write_view = view[buffer_pos + 1 : buffer_pos + 5] write_view[0:3] = (dest & 0xFFFFFF).to_bytes(3, "little") write_view[3:4] = [b"\x00", b"\xff"][(dest >> 24) & 1] # (~(((dest >> 24) & 1) - 1)) & 0xFF buffer_pos += 5 self.prev_mask = 0 else: buffer_pos += 1 self.prev_mask |= 1 if self.buffer[buffer_pos + 3] in [0, 0xFF]: self.prev_mask |= 0x10 self.current_position += buffer_pos return buffer_pos def decode(self, data: Union[bytes, bytearray, memoryview], max_length: int = -1) -> bytes: self.buffer.extend(data) pos: int = self._method() if self.current_position > self.stream_size - self._readahead: offset: int = self.stream_size - self.current_position tmp = bytes(self.buffer[: pos + offset]) self.current_position = self.stream_size self.buffer = bytearray() else: tmp = bytes(self.buffer[:pos]) self.buffer = self.buffer[pos:] return tmp def encode(self, data: Union[bytes, bytearray, memoryview]) -> bytes: self.buffer.extend(data) pos: int = self._method() tmp = bytes(self.buffer[:pos]) self.buffer = self.buffer[pos:] return tmp def flush(self) -> bytes: return bytes(self.buffer) class BCJDecoder(BCJFilter): def __init__(self, size: int): super().__init__(self.x86_code, 5, False, size) class BCJEncoder(BCJFilter): def __init__(self): super().__init__(self.x86_code, 5, True) class SparcDecoder(BCJFilter): def __init__(self, size: int): super().__init__(self.sparc_code, 4, False, size) class SparcEncoder(BCJFilter): def __init__(self): super().__init__(self.sparc_code, 4, True) class PPCDecoder(BCJFilter): def __init__(self, size: int): super().__init__(self.ppc_code, 4, False, size) class PPCEncoder(BCJFilter): def __init__(self): super().__init__(self.ppc_code, 4, True) class ARMTDecoder(BCJFilter): def __init__(self, size: int): super().__init__(self.armt_code, 4, False, size) class ARMTEncoder(BCJFilter): def __init__(self): super().__init__(self.armt_code, 4, True) class ARMDecoder(BCJFilter): def __init__(self, size: int): super().__init__(self.arm_code, 4, False, size) class ARMEncoder(BCJFilter): def __init__(self): super().__init__(self.arm_code, 4, True) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/bcj/py.typed0000644000175100017510000000000015112441263015305 0ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0205426 pybcj-1.0.7/src/ext/0000755000175100017510000000000015112441274013664 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/ext/Arch.h0000644000175100017510000001057115112441263014714 0ustar00runnerrunner// // Created by miurahr on 2021/04/07. // Based on 7zTypes.h - 2017-07-17 : Igor Pavlov : Public domain // #ifndef BCJ_CFFI_ARCH_H #define BCJ_CFFI_ARCH_H #include #ifndef EXTERN_C_BEGIN #ifdef __cplusplus #define EXTERN_C_BEGIN extern "C" { #define EXTERN_C_END } #else #define EXTERN_C_BEGIN #define EXTERN_C_END #endif #endif EXTERN_C_BEGIN typedef unsigned char Byte; typedef short Int16; typedef unsigned short UInt16; typedef int Int32; typedef unsigned int UInt32; #if defined(_MSC_VER) || defined(__BORLANDC__) typedef __int64 Int64; typedef unsigned __int64 UInt64; #define UINT64_CONST(n) n #else typedef long long int Int64; typedef unsigned long long int UInt64; #define UINT64_CONST(n) n ## ULL #endif typedef size_t SizeT; typedef int Bool; #define True 1 #define False 0 #if defined(_M_IX86) \ || defined(__i386__) #define MY_CPU_X86 #endif #if defined(_M_X64) \ || defined(_M_AMD64) \ || defined(__x86_64__) \ || defined(__AMD64__) \ || defined(__amd64__) #define MY_CPU_AMD64 #endif #if defined(_M_ARM64) \ || defined(__AARCH64EL__) \ || defined(__AARCH64EB__) \ || defined(__aarch64__) #define MY_CPU_ARM64 #endif #if defined(MY_CPU_X86) || defined(MY_CPU_AMD64) || defined(MY_CPU_ARM64) \ || defined(__ARM_FEATURE_UNALIGNED) #if defined(_WIN32) \ || defined(__LITTLE_ENDIAN__) \ || defined(__ARMEL__) \ || defined(__THUMBEL__) \ || defined(__AARCH64EL__) \ || defined(__BFIN__) \ || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) #define MY_CPU_LE_UNALIGN #endif #endif #ifdef MY_CPU_LE_UNALIGN #define GetUi16(p) (*(const UInt16 *)(const void *)(p)) #define GetUi32(p) (*(const UInt32 *)(const void *)(p)) #define GetUi64(p) (*(const UInt64 *)(const void *)(p)) #define SetUi16(p, v) { *(UInt16 *)(p) = (v); } #define SetUi32(p, v) { *(UInt32 *)(p) = (v); } #define SetUi64(p, v) { *(UInt64 *)(p) = (v); } #else #define GetUi16(p) ( (UInt16) ( \ ((const Byte *)(p))[0] | \ ((UInt16)((const Byte *)(p))[1] << 8) )) #define GetUi32(p) ( \ ((const Byte *)(p))[0] | \ ((UInt32)((const Byte *)(p))[1] << 8) | \ ((UInt32)((const Byte *)(p))[2] << 16) | \ ((UInt32)((const Byte *)(p))[3] << 24)) #define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32)) #define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \ _ppp_[0] = (Byte)_vvv_; \ _ppp_[1] = (Byte)(_vvv_ >> 8); } #define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \ _ppp_[0] = (Byte)_vvv_; \ _ppp_[1] = (Byte)(_vvv_ >> 8); \ _ppp_[2] = (Byte)(_vvv_ >> 16); \ _ppp_[3] = (Byte)(_vvv_ >> 24); } #define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \ SetUi32(_ppp2_ , (UInt32)_vvv2_); \ SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); } #endif #ifdef __has_builtin #define MY__has_builtin(x) __has_builtin(x) #else #define MY__has_builtin(x) 0 #endif #if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300) /* Note: we use bswap instruction, that is unsupported in 386 cpu */ #include #pragma intrinsic(_byteswap_ushort) #pragma intrinsic(_byteswap_ulong) #pragma intrinsic(_byteswap_uint64) #define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p)) #define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p)) #define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v) #elif defined(MY_CPU_LE_UNALIGN) && ( \ (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \ || (defined(__clang__) && MY__has_builtin(__builtin_bswap16)) ) #define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p)) #define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p)) #define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v) #else #define GetBe32(p) ( \ ((UInt32)((const Byte *)(p))[0] << 24) | \ ((UInt32)((const Byte *)(p))[1] << 16) | \ ((UInt32)((const Byte *)(p))[2] << 8) | \ ((const Byte *)(p))[3] ) #define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4)) #define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \ _ppp_[0] = (Byte)(_vvv_ >> 24); \ _ppp_[1] = (Byte)(_vvv_ >> 16); \ _ppp_[2] = (Byte)(_vvv_ >> 8); \ _ppp_[3] = (Byte)_vvv_; } #endif EXTERN_C_END #endif //BCJ_CFFI_ARCH_H ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/ext/Bra.c0000644000175100017510000000767715112441263014553 0ustar00runnerrunner/* Bra.c -- Converters for RISC code 2017-04-04 : Igor Pavlov : Public domain */ #include "Bra.h" SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) { Byte *p; const Byte *lim; size &= ~(size_t)3; ip += 4; p = data; lim = data + size; if (encoding) for (;;) { for (;;) { if (p >= lim) return p - data; p += 4; if (p[-1] == 0xEB) break; } { UInt32 v = GetUi32(p - 4); v <<= 2; v += ip + (UInt32)(p - data); v >>= 2; v &= 0x00FFFFFF; v |= 0xEB000000; SetUi32(p - 4, v); } } for (;;) { for (;;) { if (p >= lim) return p - data; p += 4; if (p[-1] == 0xEB) break; } { UInt32 v = GetUi32(p - 4); v <<= 2; v -= ip + (UInt32)(p - data); v >>= 2; v &= 0x00FFFFFF; v |= 0xEB000000; SetUi32(p - 4, v); } } } SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) { Byte *p; const Byte *lim; size &= ~(size_t)1; p = data; lim = data + size - 4; if (encoding) for (;;) { UInt32 b1; for (;;) { UInt32 b3; if (p > lim) return p - data; b1 = p[1]; b3 = p[3]; p += 2; b1 ^= 8; if ((b3 & b1) >= 0xF8) break; } { UInt32 v = ((UInt32)b1 << 19) + (((UInt32)p[1] & 0x7) << 8) + (((UInt32)p[-2] << 11)) + (p[0]); p += 2; { UInt32 cur = (ip + (UInt32)(p - data)) >> 1; v += cur; } p[-4] = (Byte)(v >> 11); p[-3] = (Byte)(0xF0 | ((v >> 19) & 0x7)); p[-2] = (Byte)v; p[-1] = (Byte)(0xF8 | (v >> 8)); } } for (;;) { UInt32 b1; for (;;) { UInt32 b3; if (p > lim) return p - data; b1 = p[1]; b3 = p[3]; p += 2; b1 ^= 8; if ((b3 & b1) >= 0xF8) break; } { UInt32 v = ((UInt32)b1 << 19) + (((UInt32)p[1] & 0x7) << 8) + (((UInt32)p[-2] << 11)) + (p[0]); p += 2; { UInt32 cur = (ip + (UInt32)(p - data)) >> 1; v -= cur; } /* SetUi16(p - 4, (UInt16)(((v >> 11) & 0x7FF) | 0xF000)); SetUi16(p - 2, (UInt16)(v | 0xF800)); */ p[-4] = (Byte)(v >> 11); p[-3] = (Byte)(0xF0 | ((v >> 19) & 0x7)); p[-2] = (Byte)v; p[-1] = (Byte)(0xF8 | (v >> 8)); } } } SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) { Byte *p; const Byte *lim; size &= ~(size_t)3; ip -= 4; p = data; lim = data + size; for (;;) { for (;;) { if (p >= lim) return p - data; p += 4; /* if ((v & 0xFC000003) == 0x48000001) */ if ((p[-4] & 0xFC) == 0x48 && (p[-1] & 3) == 1) break; } { UInt32 v = GetBe32(p - 4); if (encoding) v += ip + (UInt32)(p - data); else v -= ip + (UInt32)(p - data); v &= 0x03FFFFFF; v |= 0x48000000; SetBe32(p - 4, v); } } } SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) { Byte *p; const Byte *lim; size &= ~(size_t)3; ip -= 4; p = data; lim = data + size; for (;;) { for (;;) { if (p >= lim) return p - data; /* v = GetBe32(p); p += 4; m = v + ((UInt32)5 << 29); m ^= (UInt32)7 << 29; m += (UInt32)1 << 22; if ((m & ((UInt32)0x1FF << 23)) == 0) break; */ p += 4; if ((p[-4] == 0x40 && (p[-3] & 0xC0) == 0) || (p[-4] == 0x7F && (p[-3] >= 0xC0))) break; } { UInt32 v = GetBe32(p - 4); v <<= 2; if (encoding) v += ip + (UInt32)(p - data); else v -= ip + (UInt32)(p - data); v &= 0x01FFFFFF; v -= (UInt32)1 << 24; v ^= 0xFF000000; v >>= 2; v |= 0x40000000; SetBe32(p - 4, v); } } } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/ext/Bra.h0000644000175100017510000000350315112441263014540 0ustar00runnerrunner/* Bra.h -- Branch converters for executables 2013-01-18 : Igor Pavlov : Public domain */ #ifndef __BRA_H #define __BRA_H #include "Arch.h" EXTERN_C_BEGIN /* These functions convert relative addresses to absolute addresses in CALL instructions to increase the compression ratio. In: data - data buffer size - size of data ip - current virtual Instruction Pinter (IP) value state - state variable for x86 converter encoding - 0 (for decoding), 1 (for encoding) Out: state - state variable for x86 converter Returns: The number of processed bytes. If you call these functions with multiple calls, you must start next call with first byte after block of processed bytes. Type Endian Alignment LookAhead x86 little 1 4 ARMT little 2 2 ARM little 4 0 PPC big 4 0 SPARC big 4 0 IA64 little 16 0 size must be >= Alignment + LookAhead, if it's not last block. If (size < Alignment + LookAhead), converter returns 0. Example: UInt32 ip = 0; for () { ; size must be >= Alignment + LookAhead, if it's not last block SizeT processed = Convert(data, size, ip, 1); data += processed; size -= processed; ip += processed; } */ #define x86_Convert_Init(state) { state = 0; } SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); EXTERN_C_END #endif ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/ext/Bra86.c0000644000175100017510000000324715112441263014716 0ustar00runnerrunner/* Bra86.c -- Converter for x86 code (BCJ) 2017-04-03 : Igor Pavlov : Public domain */ #include "Bra.h" #define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0) SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding) { SizeT pos = 0; UInt32 mask = *state & 7; if (size < 5) return 0; size -= 4; ip += 5; for (;;) { Byte *p = data + pos; const Byte *limit = data + size; for (; p < limit; p++) if ((*p & 0xFE) == 0xE8) break; { SizeT d = (SizeT)(p - data - pos); pos = (SizeT)(p - data); if (p >= limit) { *state = (d > 2 ? 0 : mask >> (unsigned)d); return pos; } if (d > 2) mask = 0; else { mask >>= (unsigned)d; if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(size_t)(mask >> 1) + 1]))) { mask = (mask >> 1) | 4; pos++; continue; } } } if (Test86MSByte(p[4])) { UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]); UInt32 cur = ip + (UInt32)pos; pos += 5; if (encoding) v += cur; else v -= cur; if (mask != 0) { unsigned sh = (mask & 6) << 2; if (Test86MSByte((Byte)(v >> sh))) { v ^= (((UInt32)0x100 << sh) - 1); if (encoding) v += cur; else v -= cur; } mask = 0; } p[1] = (Byte)v; p[2] = (Byte)(v >> 8); p[3] = (Byte)(v >> 16); p[4] = (Byte)(0 - ((v >> 24) & 1)); } else { mask = (mask >> 1) | 4; pos++; } } } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/ext/BraIA64.c0000644000175100017510000000207015112441263015115 0ustar00runnerrunner/* BraIA64.c -- Converter for IA-64 code 2017-01-26 : Igor Pavlov : Public domain */ #include "Bra.h" SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) { SizeT i; if (size < 16) return 0; size -= 16; i = 0; do { unsigned m = ((UInt32)0x334B0000 >> (data[i] & 0x1E)) & 3; if (m) { m++; do { Byte *p = data + (i + (size_t)m * 5 - 8); if (((p[3] >> m) & 15) == 5 && (((p[-1] | ((UInt32)p[0] << 8)) >> m) & 0x70) == 0) { unsigned raw = GetUi32(p); unsigned v = raw >> m; v = (v & 0xFFFFF) | ((v & (1 << 23)) >> 3); v <<= 4; if (encoding) v += ip + (UInt32)i; else v -= ip + (UInt32)i; v >>= 4; v &= 0x1FFFFF; v += 0x700000; v &= 0x8FFFFF; raw &= ~((UInt32)0x8FFFFF << m); raw |= (v << m); SetUi32(p, raw); } } while (++m <= 4); } i += 16; } while (i <= size); return i; } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377267.0 pybcj-1.0.7/src/ext/_bcjmodule.c0000644000175100017510000011111415112441263016130 0ustar00runnerrunner/** * PyBcj library. * Copyright 2020-2022, Hiroshi Miura * SPDX-License-Identifier: LGPL-2.1-or-later */ #include "Python.h" #include "pythread.h" /* For Python 3.6 */ #include "structmember.h" #include "Arch.h" #include "Bra.h" #ifndef Py_UNREACHABLE #define Py_UNREACHABLE() assert(0) #endif #define ACQUIRE_LOCK(obj) do { \ if (!PyThread_acquire_lock((obj)->lock, 0)) { \ Py_BEGIN_ALLOW_THREADS \ PyThread_acquire_lock((obj)->lock, 1); \ Py_END_ALLOW_THREADS \ } } while (0) #define RELEASE_LOCK(obj) PyThread_release_lock((obj)->lock) static const char init_twice_msg[] = "__init__ method is called twice."; enum Method { x86, arm, armt, ppc, sparc_arch, ia64 }; typedef struct { PyObject_HEAD /* Which variation used */ enum Method method; /* Encoder/decoder configuration and status */ UInt32 ip; UInt32 state; size_t readAhead; Bool isEncoder; /* thread lock */ PyThread_type_lock lock; /* __init__ has been called, 0 or 1. */ char inited; /* remaining data size when decode*/ size_t remiaining; /* working buffer */ Byte *buffer; SizeT bufSize; SizeT bufPos; } BCJFilter; /* * Common functions to initialize and dealloc. */ static PyObject * BCJFilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { BCJFilter *self; self = (BCJFilter *) type->tp_alloc(type, 0); if (self == NULL) { return NULL; } /* Thread lock */ self->lock = PyThread_allocate_lock(); if (self->lock == NULL) { goto error; } return (PyObject *) self; error: Py_XDECREF(self); PyErr_NoMemory(); return NULL; } static void BCJFilter_dealloc(BCJFilter *self) { if (self->lock) { PyThread_free_lock(self->lock); } PyTypeObject *tp = Py_TYPE(self); tp->tp_free((PyObject *) self); Py_DECREF(tp); } /* * Shared methods to process and flush. */ static SizeT BCJFilter_do_method(BCJFilter *self) { SizeT outLen; if (self->bufSize == self->bufPos) { return 0; } Byte* buf = self->buffer + self->bufPos; SizeT size = self->bufSize - self->bufPos; switch (self->method) { case x86: outLen = x86_Convert(buf, size, self->ip, &self->state, self->isEncoder); break; case arm: outLen = ARM_Convert(buf, size, self->ip, self->isEncoder); break; case armt: outLen = ARMT_Convert(buf, size, self->ip, self->isEncoder); break; case ppc: outLen = PPC_Convert(buf, size, self->ip, self->isEncoder); break; case sparc_arch: outLen = SPARC_Convert(buf, size, self->ip, self->isEncoder); break; case ia64: outLen = IA64_Convert(buf, size, self->ip, self->isEncoder); break; default: // should not come here. return 0; } self->ip += outLen; self->remiaining -= outLen; return outLen; } static PyObject * BCJFilter_do_filter(BCJFilter *self, Py_buffer *data) { ACQUIRE_LOCK(self); if (data->len > 0) { // allocate new buffer when current buffer is smaller than required. SizeT carrySize = self->bufSize - self->bufPos; SizeT newSize = data->len + carrySize; if (self->bufSize == newSize) { // reuse buffer memcpy(self->buffer, self->buffer + self->bufPos, carrySize); memcpy(self->buffer + carrySize, data->buf, data->len); self->bufPos = 0; } else { Byte *tmp = PyMem_Malloc(newSize); if (tmp == NULL) { PyErr_NoMemory(); goto error; } memcpy(tmp, self->buffer + self->bufPos, carrySize); if (self->buffer != NULL) { PyMem_Free(self->buffer); } memcpy(tmp + carrySize, data->buf, data->len); self->buffer = tmp; self->bufSize = newSize; self->bufPos = 0; } } else if (self->bufPos < self->bufSize) { // when input data size is zero and there is some carry data SizeT carrySize = self->bufSize - self->bufPos; Byte *tmp = PyMem_Malloc(carrySize); if (tmp == NULL) { PyErr_NoMemory(); goto error; } memcpy(tmp, self->buffer + self->bufPos, carrySize); PyMem_Free(self->buffer); self->buffer = tmp; self->bufSize = carrySize; self->bufPos = 0; } else { // there is no data, return data with zero size PyObject *result = PyBytes_FromStringAndSize(NULL, 0); RELEASE_LOCK(self); return result; } SizeT outLen = BCJFilter_do_method(self); if (self->remiaining <= self->readAhead) { // flush all the data outLen = self->bufSize - self->bufPos; } PyObject *result = PyBytes_FromStringAndSize(NULL, outLen); if (result == NULL) { if (self->buffer != NULL) { PyMem_Free(self->buffer); } PyErr_NoMemory(); goto error; } char *posi = PyBytes_AS_STRING(result); memcpy(posi, (const char*)(self->buffer + self->bufPos), outLen); self->bufPos += outLen; RELEASE_LOCK(self); return result; error: RELEASE_LOCK(self); return NULL; } static PyObject * BCJFilter_do_flush(BCJFilter *self) { PyObject *result; ACQUIRE_LOCK(self); if (self->bufPos == self->bufSize) { result = PyBytes_FromStringAndSize(NULL, 0); } else { SizeT out_len = BCJFilter_do_method(self); // override with all remaining data out_len = self->bufSize - self->bufPos; result = PyBytes_FromStringAndSize(NULL, out_len); if (result == NULL) { if (self->buffer != NULL) { PyMem_Free(self->buffer); } PyErr_NoMemory(); goto error; } char *posi = PyBytes_AS_STRING(result); memcpy(posi, (const char *) self->buffer + self->bufPos, out_len); if (self->buffer != NULL) { PyMem_Free(self->buffer); } } RELEASE_LOCK(self); return result; error: RELEASE_LOCK(self); return NULL; } /* * BCJ(X86) Encoder. */ static int BCJEncoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = x86; self->readAhead = 5; self->isEncoder = True; self->remiaining = INT_MAX; return 0; error: return -1; } PyDoc_STRVAR(BCJEncoder_encode_doc, ""); static PyObject * BCJEncoder_encode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:BCJEncoder.encode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } PyDoc_STRVAR(BCJEncoder_flush_doc, ""); static PyObject * BCJEncoder_flush(BCJFilter *self, PyObject *args, PyObject *kwargs) { PyObject* result = BCJFilter_do_flush(self); return result; } /* * BCJ(X86) Decoder. */ static int BCJDecoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"size", NULL}; int size; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:BCJDecoder.__init__", kwlist, &size)) { return -1; } /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = x86; self->readAhead = 5; self->isEncoder = False; self->remiaining = size; self->state = 0; return 0; error: return -1; } PyDoc_STRVAR(BCJDecoder_decode_doc, ""); static PyObject * BCJDecoder_decode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:BCJDecoder.decode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } /* * ARM Encoder. */ static int ARMEncoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = arm; self->readAhead = 4; self->isEncoder = True; self->remiaining = INT_MAX; return 0; error: return -1; } PyDoc_STRVAR(ARMEncoder_encode_doc, ""); static PyObject * ARMEncoder_encode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:ARMEncoder.encode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } PyDoc_STRVAR(ARMEncoder_flush_doc, ""); static PyObject * ARMEncoder_flush(BCJFilter *self, PyObject *args, PyObject *kwargs) { PyObject* result = BCJFilter_do_flush(self); return result; } /* * ARM Decoder. */ static int ARMDecoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"size", NULL}; int size; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:ARMDecoder.__init__", kwlist, &size)) { return -1; } /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = arm; self->readAhead = 4; self->isEncoder = False; self->remiaining = size; self->state = 0; return 0; error: return -1; } PyDoc_STRVAR(ARMDecoder_decode_doc, ""); static PyObject * ARMDecoder_decode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:ARMDecoder.decode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } /* * ARMT Encoder. */ static int ARMTEncoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = armt; self->readAhead = 4; self->isEncoder = True; self->remiaining = INT_MAX; return 0; error: return -1; } PyDoc_STRVAR(ARMTEncoder_encode_doc, ""); static PyObject * ARMTEncoder_encode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:ARMTEncoder.encode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } PyDoc_STRVAR(ARMTEncoder_flush_doc, ""); static PyObject * ARMTEncoder_flush(BCJFilter *self, PyObject *args, PyObject *kwargs) { PyObject* result = BCJFilter_do_flush(self); return result; } /* * ARMT Decoder. */ static int ARMTDecoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"size", NULL}; int size; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:ARMTDecoder.__init__", kwlist, &size)) { return -1; } /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = armt; self->readAhead = 4; self->isEncoder = False; self->remiaining = size; self->state = 0; return 0; error: return -1; } PyDoc_STRVAR(ARMTDecoder_decode_doc, ""); static PyObject * ARMTDecoder_decode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:ARMTDecoder.decode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } /* * PPC Encoder. */ static int PPCEncoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = ppc; self->readAhead = 4; self->isEncoder = True; self->remiaining = INT_MAX; return 0; error: return -1; } PyDoc_STRVAR(PPCEncoder_encode_doc, ""); static PyObject * PPCEncoder_encode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:PPCEncoder.encode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } PyDoc_STRVAR(PPCEncoder_flush_doc, ""); static PyObject * PPCEncoder_flush(BCJFilter *self, PyObject *args, PyObject *kwargs) { PyObject* result = BCJFilter_do_flush(self); return result; } /* * PPC Decoder. */ static int PPCDecoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"size", NULL}; int size; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:PPCDecoder.__init__", kwlist, &size)) { return -1; } /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = ppc; self->readAhead = 4; self->isEncoder = False; self->remiaining = size; self->state = 0; return 0; error: return -1; } PyDoc_STRVAR(PPCDecoder_decode_doc, ""); static PyObject * PPCDecoder_decode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:PPCDecoder.decode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } /* * IA64 Encoder. */ static int IA64Encoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = ia64; self->readAhead = 4; self->isEncoder = True; self->remiaining = INT_MAX; return 0; error: return -1; } PyDoc_STRVAR(IA64Encoder_encode_doc, ""); static PyObject * IA64Encoder_encode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:IA64Encoder.encode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } PyDoc_STRVAR(IA64Encoder_flush_doc, ""); static PyObject * IA64Encoder_flush(BCJFilter *self, PyObject *args, PyObject *kwargs) { PyObject* result = BCJFilter_do_flush(self); return result; } /* * IA64 Decoder. */ static int IA64Decoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"size", NULL}; int size; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:IA64Decoder.__init__", kwlist, &size)) { return -1; } /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = ia64; self->readAhead = 4; self->isEncoder = False; self->remiaining = size; self->state = 0; return 0; error: return -1; } PyDoc_STRVAR(IA64Decoder_decode_doc, ""); static PyObject * IA64Decoder_decode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:IA64Decoder.decode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } /* * Sparc Encoder. */ static int SparcEncoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = sparc_arch; self->readAhead = 4; self->isEncoder = True; self->remiaining = INT_MAX; return 0; error: return -1; } PyDoc_STRVAR(SparcEncoder_encode_doc, ""); static PyObject * SparcEncoder_encode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:SparcEncoder.encode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } PyDoc_STRVAR(SparcEncoder_flush_doc, ""); static PyObject * SparcEncoder_flush(BCJFilter *self, PyObject *args, PyObject *kwargs) { PyObject* result = BCJFilter_do_flush(self); return result; } /* * IA64 Decoder. */ static int SparcDecoder_init(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"size", NULL}; int size; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:SparcDecoder.__init__", kwlist, &size)) { return -1; } /* Only called once */ if (self->inited) { PyErr_SetString(PyExc_RuntimeError, init_twice_msg); goto error; } self->inited = 1; self->method = sparc_arch; self->readAhead = 4; self->isEncoder = False; self->remiaining = size; self->state = 0; return 0; error: return -1; } PyDoc_STRVAR(SparcDecoder_decode_doc, ""); static PyObject * SparcDecoder_decode(BCJFilter *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"data", NULL}; Py_buffer data; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:SparcDecoder.decode", kwlist, &data)) { return NULL; } PyObject* result = BCJFilter_do_filter(self, &data); PyBuffer_Release(&data); return result; } /* * common function for python object. */ PyDoc_STRVAR(reduce_cannot_pickle_doc, "Intentionally not supporting pickle."); static PyObject * reduce_cannot_pickle(PyObject *self) { PyErr_Format(PyExc_TypeError, "Cannot pickle %s object.", Py_TYPE(self)->tp_name); return NULL; } /* define class and methods */ /* BCJ encoder */ static PyMethodDef BCJEncoder_methods[] = { {"encode", (PyCFunction) BCJEncoder_encode, METH_VARARGS | METH_KEYWORDS, BCJEncoder_encode_doc}, {"flush", (PyCFunction) BCJEncoder_flush, METH_VARARGS | METH_KEYWORDS, BCJEncoder_flush_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot BCJEncoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, BCJEncoder_init}, {Py_tp_methods, BCJEncoder_methods}, {0, 0} }; static PyType_Spec BCJEncoder_type_spec = { .name = "_bcj.BCJEncoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = BCJEncoder_slots, }; /* BCJDecoder */ static PyMethodDef BCJDecoder_methods[] = { {"decode", (PyCFunction) BCJDecoder_decode, METH_VARARGS | METH_KEYWORDS, BCJDecoder_decode_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot BCJDecoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, BCJDecoder_init}, {Py_tp_methods, BCJDecoder_methods}, {0, 0} }; static PyType_Spec BCJDecoder_type_spec = { .name = "_bcj.BCJDecoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = BCJDecoder_slots, }; /* ARM encoder */ static PyMethodDef ARMEncoder_methods[] = { {"encode", (PyCFunction) ARMEncoder_encode, METH_VARARGS | METH_KEYWORDS, ARMEncoder_encode_doc}, {"flush", (PyCFunction) ARMEncoder_flush, METH_VARARGS | METH_KEYWORDS, ARMEncoder_flush_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot ARMEncoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, ARMEncoder_init}, {Py_tp_methods, ARMEncoder_methods}, {0, 0} }; static PyType_Spec ARMEncoder_type_spec = { .name = "_bcj.ARMEncoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = ARMEncoder_slots, }; /* ARMDecoder */ static PyMethodDef ARMDecoder_methods[] = { {"decode", (PyCFunction) ARMDecoder_decode, METH_VARARGS | METH_KEYWORDS, ARMDecoder_decode_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot ARMDecoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, ARMDecoder_init}, {Py_tp_methods, ARMDecoder_methods}, {0, 0} }; static PyType_Spec ARMDecoder_type_spec = { .name = "_bcj.ARMDecoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = ARMDecoder_slots, }; /* ARMT encoder */ static PyMethodDef ARMTEncoder_methods[] = { {"encode", (PyCFunction) ARMTEncoder_encode, METH_VARARGS | METH_KEYWORDS, ARMTEncoder_encode_doc}, {"flush", (PyCFunction) ARMTEncoder_flush, METH_VARARGS | METH_KEYWORDS, ARMTEncoder_flush_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot ARMTEncoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, ARMTEncoder_init}, {Py_tp_methods, ARMTEncoder_methods}, {0, 0} }; static PyType_Spec ARMTEncoder_type_spec = { .name = "_bcj.ARMTEncoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = ARMTEncoder_slots, }; /* ARMTDecoder */ static PyMethodDef ARMTDecoder_methods[] = { {"decode", (PyCFunction) ARMTDecoder_decode, METH_VARARGS | METH_KEYWORDS, ARMTDecoder_decode_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot ARMTDecoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, ARMTDecoder_init}, {Py_tp_methods, ARMTDecoder_methods}, {0, 0} }; static PyType_Spec ARMTDecoder_type_spec = { .name = "_bcj.ARMTDecoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = ARMTDecoder_slots, }; /* PPC encoder */ static PyMethodDef PPCEncoder_methods[] = { {"encode", (PyCFunction) PPCEncoder_encode, METH_VARARGS | METH_KEYWORDS, PPCEncoder_encode_doc}, {"flush", (PyCFunction) PPCEncoder_flush, METH_VARARGS | METH_KEYWORDS, PPCEncoder_flush_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot PPCEncoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, PPCEncoder_init}, {Py_tp_methods, PPCEncoder_methods}, {0, 0} }; static PyType_Spec PPCEncoder_type_spec = { .name = "_bcj.PPCEncoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = PPCEncoder_slots, }; /* PPCDecoder */ static PyMethodDef PPCDecoder_methods[] = { {"decode", (PyCFunction) PPCDecoder_decode, METH_VARARGS | METH_KEYWORDS, PPCDecoder_decode_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot PPCDecoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, PPCDecoder_init}, {Py_tp_methods, PPCDecoder_methods}, {0, 0} }; static PyType_Spec PPCDecoder_type_spec = { .name = "_bcj.PPCDecoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = PPCDecoder_slots, }; /* IA64 encoder */ static PyMethodDef IA64Encoder_methods[] = { {"encode", (PyCFunction) IA64Encoder_encode, METH_VARARGS | METH_KEYWORDS, IA64Encoder_encode_doc}, {"flush", (PyCFunction) IA64Encoder_flush, METH_VARARGS | METH_KEYWORDS, IA64Encoder_flush_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot IA64Encoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, IA64Encoder_init}, {Py_tp_methods, IA64Encoder_methods}, {0, 0} }; static PyType_Spec IA64Encoder_type_spec = { .name = "_bcj.IA64Encoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = IA64Encoder_slots, }; /* IA64Decoder */ static PyMethodDef IA64Decoder_methods[] = { {"decode", (PyCFunction) IA64Decoder_decode, METH_VARARGS | METH_KEYWORDS, IA64Decoder_decode_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot IA64Decoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, IA64Decoder_init}, {Py_tp_methods, IA64Decoder_methods}, {0, 0} }; static PyType_Spec IA64Decoder_type_spec = { .name = "_bcj.IA64Decoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = IA64Decoder_slots, }; /* Sparc encoder */ static PyMethodDef SparcEncoder_methods[] = { {"encode", (PyCFunction) SparcEncoder_encode, METH_VARARGS | METH_KEYWORDS, SparcEncoder_encode_doc}, {"flush", (PyCFunction) SparcEncoder_flush, METH_VARARGS | METH_KEYWORDS, SparcEncoder_flush_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot SparcEncoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, SparcEncoder_init}, {Py_tp_methods, SparcEncoder_methods}, {0, 0} }; static PyType_Spec SparcEncoder_type_spec = { .name = "_bcj.SparcEncoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = SparcEncoder_slots, }; /* IA64Decoder */ static PyMethodDef SparcDecoder_methods[] = { {"decode", (PyCFunction) SparcDecoder_decode, METH_VARARGS | METH_KEYWORDS, SparcDecoder_decode_doc}, {"__reduce__", (PyCFunction) reduce_cannot_pickle, METH_NOARGS, reduce_cannot_pickle_doc}, {NULL, NULL, 0, NULL} }; static PyType_Slot SparcDecoder_slots[] = { {Py_tp_new, BCJFilter_new}, {Py_tp_dealloc, BCJFilter_dealloc}, {Py_tp_init, SparcDecoder_init}, {Py_tp_methods, SparcDecoder_methods}, {0, 0} }; static PyType_Spec SparcDecoder_type_spec = { .name = "_bcj.SparcDecoder", .basicsize = sizeof(BCJFilter), .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .slots = SparcDecoder_slots, }; /* -------------------- Initialize code -------------------- */ static PyMethodDef _bcj_methods[] = { {NULL} }; typedef struct { PyTypeObject *BCJEncoder_type; PyTypeObject *BCJDecoder_type; PyTypeObject *ARMEncoder_type; PyTypeObject *ARMDecoder_type; PyTypeObject *ARMTEncoder_type; PyTypeObject *ARMTDecoder_type; PyTypeObject *PPCEncoder_type; PyTypeObject *PPCDecoder_type; PyTypeObject *IA64Encoder_type; PyTypeObject *IA64Decoder_type; PyTypeObject *SparcEncoder_type; PyTypeObject *SparcDecoder_type; } _bcj_state; static _bcj_state static_state; static int _bcj_traverse(PyObject *module, visitproc visit, void *arg) { Py_VISIT(static_state.BCJEncoder_type); Py_VISIT(static_state.BCJDecoder_type); Py_VISIT(static_state.ARMEncoder_type); Py_VISIT(static_state.ARMDecoder_type); Py_VISIT(static_state.ARMTEncoder_type); Py_VISIT(static_state.ARMTDecoder_type); Py_VISIT(static_state.PPCEncoder_type); Py_VISIT(static_state.PPCDecoder_type); Py_VISIT(static_state.IA64Encoder_type); Py_VISIT(static_state.IA64Decoder_type); Py_VISIT(static_state.SparcEncoder_type); Py_VISIT(static_state.SparcDecoder_type); return 0; } static int _bcj_clear(PyObject *module) { Py_CLEAR(static_state.BCJEncoder_type); Py_CLEAR(static_state.BCJDecoder_type); Py_CLEAR(static_state.ARMEncoder_type); Py_CLEAR(static_state.ARMDecoder_type); Py_CLEAR(static_state.ARMTEncoder_type); Py_CLEAR(static_state.ARMTDecoder_type); Py_CLEAR(static_state.PPCEncoder_type); Py_CLEAR(static_state.PPCDecoder_type); Py_CLEAR(static_state.IA64Encoder_type); Py_CLEAR(static_state.IA64Encoder_type); Py_CLEAR(static_state.SparcDecoder_type); Py_CLEAR(static_state.SparcDecoder_type); return 0; } static void _bcj_free(void *module) { _bcj_clear((PyObject *) module); } static PyModuleDef _bcjmodule = { PyModuleDef_HEAD_INIT, .m_name = "_bcj", .m_size = -1, .m_methods = _bcj_methods, .m_traverse = _bcj_traverse, .m_clear = _bcj_clear, .m_free = _bcj_free }; static inline int add_type_to_module(PyObject *module, const char *name, PyType_Spec *type_spec, PyTypeObject **dest) { PyObject *temp; temp = PyType_FromSpec(type_spec); if (PyModule_AddObject(module, name, temp) < 0) { Py_XDECREF(temp); return -1; } Py_INCREF(temp); *dest = (PyTypeObject *) temp; return 0; } PyMODINIT_FUNC PyInit__bcj(void) { PyObject *module; module = PyModule_Create(&_bcjmodule); if (!module) { goto error; } if (add_type_to_module(module, "BCJEncoder", &BCJEncoder_type_spec, &static_state.BCJEncoder_type) < 0) { goto error; } if (add_type_to_module(module, "BCJDecoder", &BCJDecoder_type_spec, &static_state.BCJDecoder_type) < 0) { goto error; } if (add_type_to_module(module, "ARMEncoder", &ARMEncoder_type_spec, &static_state.ARMEncoder_type) < 0) { goto error; } if (add_type_to_module(module, "ARMDecoder", &ARMDecoder_type_spec, &static_state.ARMDecoder_type) < 0) { goto error; } if (add_type_to_module(module, "ARMTEncoder", &ARMTEncoder_type_spec, &static_state.ARMTEncoder_type) < 0) { goto error; } if (add_type_to_module(module, "ARMTDecoder", &ARMTDecoder_type_spec, &static_state.ARMTDecoder_type) < 0) { goto error; } if (add_type_to_module(module, "PPCEncoder", &PPCEncoder_type_spec, &static_state.PPCEncoder_type) < 0) { goto error; } if (add_type_to_module(module, "PPCDecoder", &PPCDecoder_type_spec, &static_state.PPCDecoder_type) < 0) { goto error; } if (add_type_to_module(module, "IA64Encoder", &IA64Encoder_type_spec, &static_state.IA64Encoder_type) < 0) { goto error; } if (add_type_to_module(module, "IA64Decoder", &IA64Decoder_type_spec, &static_state.IA64Decoder_type) < 0) { goto error; } if (add_type_to_module(module, "SparcEncoder", &SparcEncoder_type_spec, &static_state.SparcEncoder_type) < 0) { goto error; } if (add_type_to_module(module, "SparcDecoder", &SparcDecoder_type_spec, &static_state.SparcDecoder_type) < 0) { goto error; } return module; error: _bcj_clear(NULL); Py_XDECREF(module); return NULL; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764377276.0215425 pybcj-1.0.7/src/pybcj.egg-info/0000755000175100017510000000000015112441274015665 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377275.0 pybcj-1.0.7/src/pybcj.egg-info/PKG-INFO0000644000175100017510000000751615112441273016772 0ustar00runnerrunnerMetadata-Version: 2.4 Name: pybcj Version: 1.0.7 Summary: bcj filter library Author-email: Hiroshi Miura License: LGPL-2.1-or-later Project-URL: Homepage, https://pypi.org/project/pybcj Project-URL: Bug Tracker, https://github.com/miurahr/pybcj/issues Project-URL: Source, https://github.com/miurahr/pybcj Project-URL: Changelog, https://github.com/miurahr/pybcj/blob/main/Changelog.rst Keywords: lzma,bcj Classifier: Development Status :: 5 - Production/Stable Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+) Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Operating System :: POSIX Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: 3.14 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries :: Python Modules Requires-Python: >=3.10 Description-Content-Type: text/x-rst License-File: LICENSE Provides-Extra: test Requires-Dist: pytest>=6.0; extra == "test" Requires-Dist: pytest-cov; extra == "test" Requires-Dist: hypothesis; extra == "test" Requires-Dist: coverage[toml]>=5.2; extra == "test" Provides-Extra: check Requires-Dist: mypy>=1.10.0; extra == "check" Requires-Dist: check-manifest; extra == "check" Requires-Dist: flake8<8; extra == "check" Requires-Dist: flake8-black; extra == "check" Requires-Dist: flake8-colors; extra == "check" Requires-Dist: flake8-isort; extra == "check" Requires-Dist: flake8-pyi; extra == "check" Requires-Dist: flake8-typing-imports; extra == "check" Requires-Dist: readme-renderer; extra == "check" Requires-Dist: pygments; extra == "check" Dynamic: license-file ======================================= BCJ(Branch-Call-Jump) filter for python ======================================= .. image:: https://badge.fury.io/py/pybcj.svg :target: https://badge.fury.io/py/pybcj .. image:: https://img.shields.io/conda/vn/conda-forge/pybcj :target: https://anaconda.org/conda-forge/pybcj .. image:: https://coveralls.io/repos/github/miurahr/pybcj/badge.svg?branch=main :target: https://coveralls.io/github/miurahr/pybcj?branch=main In data compression, BCJ, short for Branch-Call-Jump, refers to a technique that improves the compression of machine code of executable binaries by replacing relative branch addresses with absolute ones. This allows a LZMA compressor to identify duplicate targets and archive higher compression rate. BCJ is used in 7-zip compression utility as default filter for executable binaries. pybcj is a python bindings with BCJ implementation by C language. The C codes are derived from p7zip, portable 7-zip implementation. pybcj support Intel/Amd x86/x86_64, Arm/Arm64, ArmThumb, Sparc, PPC, and IA64. Development status ================== A development status is considered as ``Beta`` state. Installation ============ As usual, you can install pybcj using python standard pip command. .. code-block:: pip install pybcj Alternatively, one can also use conda: .. code-block:: conda install -c conda-forge pybcj WARNING ------- * When use it on MSYS2/Mingw64 environment, please set environment variable `SETUPTOOLS_USE_DISTUTILS=stdlib` to install. License ======= - SPDX-License-Identifier: LGPL-2.1-or-later - SPDX-URL: https://spdx.org/licenses/LGPL-2.1-or-later.html * Copyright (C) 2020-2025 Hiroshi Miura * Copyright (C) 1999-2010 Igor Pavlov ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377276.0 pybcj-1.0.7/src/pybcj.egg-info/SOURCES.txt0000644000175100017510000000112415112441274017547 0ustar00runnerrunner.flake8 .git_archival.txt .gitattributes .gitignore CMakeLists.txt Changelog.rst LICENSE MANIFEST.in README.rst pyproject.toml setup.py .github/FUNDING.yml .github/dependabot.yml .github/workflows/publish-to-pypi.yml .github/workflows/run-tox-tests.yml .woodpecker/.check.yml src/bcj/__init__.py src/bcj/_bcjfilter.py src/bcj/py.typed src/ext/Arch.h src/ext/Bra.c src/ext/Bra.h src/ext/Bra86.c src/ext/BraIA64.c src/ext/_bcjmodule.c src/pybcj.egg-info/PKG-INFO src/pybcj.egg-info/SOURCES.txt src/pybcj.egg-info/dependency_links.txt src/pybcj.egg-info/requires.txt src/pybcj.egg-info/top_level.txt././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377275.0 pybcj-1.0.7/src/pybcj.egg-info/dependency_links.txt0000644000175100017510000000000115112441273021732 0ustar00runnerrunner ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377275.0 pybcj-1.0.7/src/pybcj.egg-info/requires.txt0000644000175100017510000000031615112441273020264 0ustar00runnerrunner [check] mypy>=1.10.0 check-manifest flake8<8 flake8-black flake8-colors flake8-isort flake8-pyi flake8-typing-imports readme-renderer pygments [test] pytest>=6.0 pytest-cov hypothesis coverage[toml]>=5.2 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1764377275.0 pybcj-1.0.7/src/pybcj.egg-info/top_level.txt0000644000175100017510000000000415112441273020410 0ustar00runnerrunnerbcj