Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV] 2.2.0 - C API Breaking changes #11

Merged
merged 29 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
883dbd7
Updated name schema of C atoms
MatrixEditor Sep 7, 2024
fc8f68b
Renamed _Py to py and added c importer module
MatrixEditor Sep 7, 2024
fac0cd3
ConsAtom (C)
MatrixEditor Sep 7, 2024
b261135
Changed CpLayer parsing logic
MatrixEditor Sep 8, 2024
6e00b01
CpConditionAtom implementation
MatrixEditor Sep 8, 2024
bf727f2
Changed CAPI definition file
MatrixEditor Sep 8, 2024
8983f26
Added CpOffsetAtom
MatrixEditor Sep 8, 2024
039aea7
New primitive atom for python classes
MatrixEditor Sep 8, 2024
f2b3333
Updated pack_many catom callback
MatrixEditor Sep 8, 2024
7e65756
CpBytesAtom implementation
MatrixEditor Sep 8, 2024
214d108
Pascal-String C implementation
MatrixEditor Sep 8, 2024
a9a2dda
Implementation for C enum atoms
MatrixEditor Sep 8, 2024
d531275
Change version to 2.2.0-rc
MatrixEditor Sep 8, 2024
64802f3
C varint implementation
MatrixEditor Sep 9, 2024
162b208
Removed CpContext_GetAttr* methods
MatrixEditor Sep 9, 2024
2fa8817
Fix CpVarIntAtom on Windows
MatrixEditor Sep 9, 2024
c85b45e
Renamed atom implementation files
MatrixEditor Sep 11, 2024
06a278a
CpComputedAtom implementation
MatrixEditor Sep 14, 2024
f5d4931
CpLazyAtom implementation
MatrixEditor Sep 14, 2024
792f15c
CpCStringAtom implementation
MatrixEditor Sep 14, 2024
9966a7e
Renamed *_t python types
MatrixEditor Sep 15, 2024
875f520
Moved C sources into ccaterpillar directory
MatrixEditor Sep 15, 2024
29d91e9
CpIntAtomObject Docs
MatrixEditor Sep 15, 2024
4eac7b1
Added Python class names of C types to capi.dat
MatrixEditor Sep 15, 2024
3aa6bae
Updated Tutorial documentation
MatrixEditor Sep 15, 2024
2ec7343
Removed all field-* related types
MatrixEditor Sep 28, 2024
a1cde82
Updated stub file
MatrixEditor Sep 28, 2024
d21f29e
New feature: global type handlers for capi structs
MatrixEditor Sep 29, 2024
5a27851
Updated documentation and bumped version to 2.2.0
MatrixEditor Sep 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ jobs:

steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install
run: |
pip install -e .
pip install -ve ./src/ccaterpillar
pip install -r requirements.txt
pip install -r test/requirements.txt

Expand Down
74 changes: 50 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,51 @@ find_package(

add_compile_definitions(_CPMODULE)

# TODO: document this change
set(CP_C_CONFIGURED DEFINED ENV{CP_ENABLE_NATIVE} OR DEFINED CP_ENABLE_NATIVE)

if (DEFINED ENV{CP_ENABLE_NATIVE})
if (CP_C_CONFIGURED)
python_add_library(
_C
MODULE

src/arch.c
src/atomobj.c
src/context.c
src/field.c
src/option.c
src/module.c
src/context.c
src/state.c
src/struct.c

src/parsing_typeof.c
src/parsing_sizeof.c
src/parsing_pack.c
src/parsing_unpack.c

src/atomimpl/intatomobj.c
src/atomimpl/floatatomobj.c
src/atomimpl/boolatomobj.c
src/atomimpl/charatomobj.c
src/atomimpl/padatomobj.c
src/atomimpl/stringatomobj.c
src/ccaterpillar/arch.c
src/ccaterpillar/atomobj.c
src/ccaterpillar/context.c
src/ccaterpillar/option.c
src/ccaterpillar/module.c
src/ccaterpillar/context.c
src/ccaterpillar/state.c
src/ccaterpillar/struct.c
src/ccaterpillar/layer.c
src/ccaterpillar/default.c

src/ccaterpillar/parsing_typeof.c
src/ccaterpillar/parsing_sizeof.c
src/ccaterpillar/parsing_pack.c
src/ccaterpillar/parsing_unpack.c

src/ccaterpillar/atomimpl/int.c
src/ccaterpillar/atomimpl/float.c
src/ccaterpillar/atomimpl/bool.c
src/ccaterpillar/atomimpl/char.c
src/ccaterpillar/atomimpl/pad.c
src/ccaterpillar/atomimpl/string.c
src/ccaterpillar/atomimpl/const.c
src/ccaterpillar/atomimpl/bytes.c
src/ccaterpillar/atomimpl/pstring.c
src/ccaterpillar/atomimpl/enum.c
src/ccaterpillar/atomimpl/varint.c
src/ccaterpillar/atomimpl/computed.c
src/ccaterpillar/atomimpl/lazy.c
src/ccaterpillar/atomimpl/cstring.c

src/ccaterpillar/atomimpl/builtins/builtin.c
src/ccaterpillar/atomimpl/builtins/repeated.c
src/ccaterpillar/atomimpl/builtins/condition.c
src/ccaterpillar/atomimpl/builtins/switch.c
src/ccaterpillar/atomimpl/builtins/atoffset.c
src/ccaterpillar/atomimpl/builtins/primitive.c

WITH_SOABI
)
Expand All @@ -44,10 +62,18 @@ target_include_directories(_C PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpilla
message(STATUS "CMake ${CMAKE_VERSION}")
message(STATUS "Python ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")

set (CP_GENAPI_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/src/code_gen/genapi.py)
set (CP_CAPI_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillar/include/caterpillar/caterpillarapi.h.in)
set (CP_CAPI_CSRC ${CMAKE_CURRENT_SOURCE_DIR}/src/ccaterpillar/caterpillarapi.c.in)
set (CP_CAPI_HEADER_OUT ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillar/include/caterpillar/caterpillarapi.h)
set (CP_CAPI_CSRC_OUT ${CMAKE_CURRENT_SOURCE_DIR}/src/ccaterpillar/caterpillarapi.c)

add_custom_target(
genapi ALL
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/code_gen/genapi.py ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillar/include/caterpillar/caterpillarapi.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillarapi.c.in
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillar/include/caterpillar/caterpillarapi.h ${CMAKE_CURRENT_SOURCE_DIR}/src/caterpillarapi.c
# execute python ./src/code_gen/genapi.py ./src/caterpillar/include/caterpillar/caterpillarapi.h.in ./src/ccaterpillar/caterpillarapi.c.in
# in the root directory
COMMAND ${PYTHON_EXECUTABLE} ${CP_GENAPI_SCRIPT} ${CP_CAPI_HEADER} ${CP_CAPI_CSRC}
BYPRODUCTS ${CP_CAPI_HEADER_OUT} ${CP_CAPI_CSRC_OUT}
COMMENT "Generating Public Caterpillar API"
)

Expand Down
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ options will be added in the future. Documentation is [here >](https://matrixedi
* it helps you to create cleaner and more compact code.
* You can even extend Caterpillar and write your parsing logic in C or C++!!

## What does it look like?
## Give me some code!

```python
from caterpillar._Py import *
from caterpillar.py import *

@struct(order=LittleEndian)
class Format:
Expand Down Expand Up @@ -61,24 +61,19 @@ on its powerful features, explore the official [documentation](https://matrixedi
> As of Caterpillar v2.1.2 it is possible to install the library without the need of
> compiling the C extension.

Simply use pip to install the package with all tools, all extra packages and the C extension:
### Python-only installation

```bash
pip install "caterpillar[all]@git+https://github.com/MatrixEditor/caterpillar.git"
pip install "caterpillar[all]@git+https://github.com/MatrixEditor/caterpillar"
```

If you want to use the native C extension you can specify the following environment variables:

* `CP_ENABLE_NATIVE` - Enables installation of the native C extension
* `CP_ENABLE_TOOLS` - Enables installation of extra tools (proposed)
### C-extension installation

For instance, the following command will install the `caterpillar` package with
a native interface and with extra tools:
```bash
CP_ENABLE_NATIVE=1 \
CP_ENABLE_TOOLS=1 \
pip install git+https://github.com/MatrixEditor/caterpillar
pip install "caterpillar[all]@git+https://github.com/MatrixEditor/caterpillar/#subdirectory=src/ccaterpillar"
```


## Starting Point

Please visit the [Documentation](https://matrixeditor.github.io/caterpillar/), it contains a complete tutorial on how to use this library.
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sphinx
pydata-sphinx-theme
sphinx-design
breathe
breathe
sphinx-copybutton
5 changes: 3 additions & 2 deletions docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"sphinx.ext.viewcode",
"sphinx_design",
"breathe",
"c_annotations"
"c_annotations",
"sphinx_copybutton"
]

templates_path = ["_templates"]
Expand Down Expand Up @@ -61,7 +62,7 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False

refcount_file = 'extensions/refcounts.dat'
refcount_file = '../../../src/capi.dat'

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/source/development/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ Development
:numbered:
:maxdepth: 2

roadmap.rst
contribution.rst
changelog.rst
111 changes: 111 additions & 0 deletions docs/sphinx/source/development/roadmap.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
.. _dev-roadmap:

********
Roadmap
********

.. |check_| raw:: html

<input checked="" disabled="" type="checkbox">

.. |uncheck_| raw:: html

<input disabled="" type="checkbox">

.. role:: text-danger

.. role:: text-warning

Python API
----------

- |check_| Implementation of parsing process (unpack, pack)
- |check_| Struct class (:class:`Struct`) with wrapper function (:code:`@struct`)
- |uncheck_| Python docs and examples
- |uncheck_| Python tests

C API
-----

- |check_| Implementation of parsing process (unpack, pack)
- |uncheck_| Struct class (:c:type:`CpStructObject`)
- |uncheck_| Struct wrapper function
- |uncheck_| Python docs

Struct Objects:
^^^^^^^^^^^^^^^

- |check_| Struct (C type: :c:type:`CpStructObject`, Py type: :class:`Struct`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |uncheck_| Bitfield

Atom Objects:
^^^^^^^^^^^^^

- |check_| Integer (uint8-128 and int8-128) (C type: :c:type:`CpIntAtomObject`, Py type: :class:`int_t`)
[:text-danger:`missing docs`]

- |check_| Float, Double (C type: :c:type:`CpFloatAtomObject`, Py type: :class:`float_t`)
[:text-danger:`missing docs`]

- |check_| Boolean (C type: :c:type:`CpBoolAtomObject`, Py type: :class:`bool_t`)
Global instance: :code:`boolean`,
[:text-danger:`missing docs`]

- |check_| Char (C type: :c:type:`CpCharAtomObject`, Py type: :class:`char_t`)
Global instance: :code:`char`,
[:text-danger:`missing docs`]

- |check_| Padding (C type: :c:type:`CpPaddingAtomObject`, Py type: :class:`padding_t`)
Global instance: :code:`padding`,
[:text-danger:`missing docs`]

- |check_| String (C type: :c:type:`CpStringAtomObject`, Py type: :class:`string`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |check_| Const (C type: :c:type:`CpConstAtomObject`, Py type: :class:`const_t`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |uncheck_| CString (C type: :c:type:`CpCStringAtomObject`, Py type: :class:`cstring`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |check_| Bytes (C type: :c:type:`CpBytesAtomObject`, Py type: :class:`octetstring`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |check_| Enum (C type: :c:type:`CpEnumAtomObject`, Py type: :class:`enumeration`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |check_| Computed (C type: :c:type:`CpComputedAtomObject`, Py type: :class:`computed`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |check_| PString (C type: :c:type:`CpPStringAtomObject`, Py type: :class:`pstring`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |uncheck_| Prefixed
.. seealso:: *link issue here*

- |check_| Lazy
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |uncheck_| uuid
.. seealso:: *link issue here*

- |uncheck_| Conditional: If, Else, ElseIf
.. seealso:: *link issue here*

- |check_| VarInt (C type: :c:type:`CpVarIntAtomObject`, Py type: :class:`varint_t`)
[:text-danger:`missing docs`],
[:text-warning:`missing perftest`]

- |uncheck_| While
.. seealso:: *link issue here*
Loading