pypdfium2-team / ctypesgen Goto Github PK
View Code? Open in Web Editor NEWThis project forked from ctypesgen/ctypesgen
Wrapper generator for Python ctypes
License: BSD 2-Clause "Simplified" License
This project forked from ctypesgen/ctypesgen
Wrapper generator for Python ctypes
License: BSD 2-Clause "Simplified" License
c_ptrdiff_t
a dependency node and include only as needed--all-headers
with --deepen [N]
. Behave like --all-headers
if the flag is specified without value, but allow e.g for --deepen 1
to eagerly add members from one nesting only, and not the whole include tree (which might be the most common case to currently use --all-headers
).--symbol-rules yes=...
.--symbol-rules yes=.+
should lead to the same result as --all-headers
)See below for an overview of this fork. Note, this writeup is a non-exhaustive work in progress.
This information may be valuable for working towards a basis that could be merged back into upstream at some point, though this seems fairly hypothetical for the near term, given time constraints, and mismatched design intents (e.g. relating to backwards compatibility).
However, this fork of ctypesgen may be a good starting point for any active future development, with a significantly overhauled code base that should be nicer to work with.
.
to the module directory, not the caller's CWD. Don't add compile libdirs to runtime.__slots__
declaration. This fix should be fairly easy for upstream to pick. See also ctypesgen#183--link-modules
, and library handle sharing with --no-embed-preamble
, Removed incorrect POINTER
override. This properly fixes ctypesgen#86 (shared headers), and allows to divide bindings to a library in multiple outputs (e.g. translate each header to a separate python file).--symbol-rules
.UNCHECKED
wrapper from preamble.c_void_p
-> int
auto-conversion (see Readme or commit for background).small, self-contained fixes have usually been submitted upstream and may have been merged
Restoring implicit UTF-8 string encoding/decoding as optional?
ctypesgen originally did implicit UTF-8 encoding/decoding of in/out strings.
While that tends to be bad practice and callers had better handle strings explicitly instead, it would seem reasonable to retain an optional backward compatibility layer for existing callers.
I also imagine it might be convenient for a library that consistently uses UTF-8 for everything.
Adding the old string classes back is certainly not an option for us. However, it may be possible to create a lean replacement. See ctypesgen#177 for a suggestion (copy below), or ctypesgen#77 (comment) for an alternative draft by @olsonse.
Note that in/out must be handled in a single class.
The windows-specific stdcall convention
Our fork lost it for simplicity while rewriting the library loader. It should be fairly easy to add back, just wondering how to test (as this lies beyond our use case), and how to integrate it nicely.
Does the calling convention really have to be decided on function level with two library handles for cdecl/stdcall, or would it be sufficient to decide at library level, with a single handle? Is there any example of a single library actually exporting functions with different calling conventions?
Note that the ctypes API is designed around deciding at library handle level, not at function level, which suggests the expected use case is a library ABI with homogeneous calling convention.
Possible resolution: Added an option to take a caller-given dll class. It requires a small user interaction and does not support mixed calling conventions, but seems like a nice bloatless way to support a pure stdcall binary.
Removal of support for multiple libraries in one bindings file
This feature was a significant complexity burden in some code areas, including pollution around symbols in printer/output code. For now we decided to remove it - callers can use --no-embed-preamble
and --link-modules
to create separate bindings files. This also encourages individual/explicit rather than unified loader config.
However, see ctypesgen#86 (comment) for some interesting considerations regarding a possible cleaner re-implementation.
Shifts in design intent: We would prefer to stick with plain ctypes as much as possible and avoid cluttering the bindings with custom wrappers.
CLI: We changed the command-line interface from action=append
to action=extend
and nargs=+/*
. This implied switching headers from positional to flag argument to avoid confusion/interference with flags that take multiple arguments. There are more CLI changes not listed here, see diff for details.
Note, this is meant for use with inherently ABI correct packaging only โฉ
Consider passing -dI
to the C pre-processor to preserve include statements, in order to later honor the position when translating to an import of a linked module, intending to address the following known limitation (quote from Readme):
Linked modules are naively prioritized in dependency resolver and conflicting names handler, i.e. intentional overrides are ignored. The position of includes is not honored; ctypesgen always imports linked modules at top level.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.