Metadata-Version: 2.4
Name: c2py23
Version: 0.3.1
Summary: Wrap C99 code to Python via the buffer protocol
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
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.15
Requires-Python: >=2.7
Description-Content-Type: text/markdown
Requires-Dist: PyYAML>=5.1; python_version >= "3"
Requires-Dist: PyYAML<6,>=3.10; python_version == "2.7"
Dynamic: description
Dynamic: description-content-type

# c2py23

> All code in this repository was generated by [DeepSeek V4](https://deepseek.com)
> and other large language models, in collaboration with jonwright.

Wrap C99 functions as Python C extensions via the buffer protocol.
One compiled `.so` works on Python 2.7 through 3.15 with no recompilation.
Zero copies, zero allocations. No numpy required.

## Install

```bash
pip install c2py23
```

Requires PyYAML and a C99 compiler (gcc, clang, or MSVC on Windows).

## Quick Start

Create a C function:

```c
/* arraysum.c */
#include <stdint.h>
int array_sum(const double *a, const double *b, double *out, intptr_t n) {
    for (intptr_t i = 0; i < n; i++) out[i] = a[i] + b[i];
    return n;
}
```

Write the interface file:

```yaml
# arraysum.c2py
module: arraysum
source: [arraysum.c]

functions:
  - py_sig: "array_sum(a: buffer, b: buffer, out: buffer) -> int"
    checks:
      - "a.format == 'd'"
      - "b.format == 'd'"
      - "out.format == 'd'"
    c_overloads:
      - sig: "array_sum(const double *a, const double *b, double *out, intptr_t n) -> int"
        map: {a: "a.ptr", b: "b.ptr", out: "out.ptr", n: "a.n"}
```

Build and use:

```bash
c2py23 build arraysum.c2py
python3 -c "
import ctypes, sys; sys.path.insert(0, '.')
import arraysum
a = (ctypes.c_double * 4)(1, 2, 3, 4)
b = (ctypes.c_double * 4)(5, 6, 7, 8)
r = (ctypes.c_double * 4)(0, 0, 0, 0)
arraysum.array_sum(a, b, r)
print(list(r))  # [6.0, 8.0, 10.0, 12.0]
"
```

## Usage

```bash
c2py23 build file.c2py                       # parse + generate + compile
c2py23 build file.c2py --generate-only       # generate wrapper .c only
c2py23 build wrapper.c --compile-only -s src.c -I inc/
                                              # compile existing wrapper
c2py23 build file.c2py --asan                # compile with address sanitizer
c2py23 generate file.c2py -o wrapper.c       # generate without building
```

## Supported Platforms

Linux (x86_64, gcc) and Windows (x64, MSVC/MinGW). 32-bit not supported.

## Examples

The [GitHub repository](https://github.com/jonwright/c2py23) includes build examples
(not in the PyPI sdist):

- `examples/kissfft_wrap/` — real + complex FFT over float buffers
- `examples/lz4_wrap/` — compress/decompress over byte buffers
- `examples/simd_dispatch/` — CPU feature dispatch (SSE2/AVX2/AVX-512, NEON, Altivec)
- `examples/threading_bench/` — GIL release, free-threading, OpenMP
- `examples/wheel_demo/` — multi-platform wheel packaging
- `examples/cmake_demo/`, `examples/meson_demo/` — build system integration

## Documentation

- `docs/specification.md` — full `.c2py` grammar, supported types, architecture
- `docs/user_guide.md` — thread safety, wheel packaging, GIL release
- `AGENTS.md` — contributor guide, CI workflows, coding standards
- `audit/` — LLM peer review toolchain

## License

MIT. See LICENSE.
