Skip to content

feat: Binding for custom HTTP resolver (with_resolver on Context) - #303

Open
tmathern wants to merge 78 commits into
mainfrom
mathern/http-resolver-custom
Open

feat: Binding for custom HTTP resolver (with_resolver on Context)#303
tmathern wants to merge 78 commits into
mainfrom
mathern/http-resolver-custom

Conversation

@tmathern

@tmathern tmathern commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Changes in this pull request

  • Add bindings to be able to set custom HTTP resolved...
  • ... which needed a way to retrieve the native malloc to free correctly (see _get_native_malloc), which is na interesting implementation detail
  • Adds test examples of resolvers (I don't think this is ready for prime time in the examples fodler), with disclaimers those a re examples examplifying only one aspect of a resolver each, and multiple likely need to be combined when someone writes their own.

Checklist

  • This PR represents a single feature, fix, or change.
  • All applicable changes have been documented.
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.

@tmathern tmathern changed the title (WIP) feat: Binding for custom HTTP resolver (with_resolver on Context) Jul 29, 2026
@tmathern tmathern self-assigned this Jul 29, 2026
@tmathern
tmathern marked this pull request as ready for review August 3, 2026 15:16
@@ -0,0 +1 @@
# Placeholder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that is for the moduling in Python, so various tools (who may not agree) don't complain. Unittest generally is happy with whatever, pytest is more easily confused, any linter loves to flag that as missing file otherwise.

Comment thread src/c2pa/c2pa.py
Comment on lines +295 to +319
_native_malloc = None

@staticmethod
def _get_native_malloc():
"""
Return malloc from the C runtime whose free() is used.

Some allocations must come from the matching runtime
or the free is heap corruption, so we retrieve that here.
Looked up lazily as needed, if needed,
"""
if ManagedResource._native_malloc is None:
if sys.platform == "win32":
try:
crt = ctypes.CDLL("ucrtbase")
except OSError:
crt = ctypes.CDLL("msvcrt")
else:
crt = ctypes.CDLL(None)
malloc = crt.malloc
malloc.argtypes = [ctypes.c_size_t]
# The default c_int restype truncates 64-bit pointers.
malloc.restype = ctypes.c_void_p
ManagedResource._native_malloc = malloc
return ManagedResource._native_malloc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this doesn't seem too ideal. Maybe the C FFI should be accepting a free callback so the caller can provide their own allocation. We discussed this a little bit when Colin was adding the functionality to the C FFI. I suppose this is fine for now but something to think about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants