FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add a C API by lemire · Pull Request #897 · simdutf/simdutf · GitHub

Add a C API - #897

Merged
lemire merged 27 commits into
masterfrom
add_c_api
Jan 6, 2026
Merged

Add a C API#897
lemire merged 27 commits into
masterfrom
add_c_api

Conversation

lemire commented Jan 4, 2026
edited
Loading

Copy link
Copy Markdown
Member

Short title (summary):
Add a C API

Description

This PR adds a C API to simdutf. Amazingly, I cannot find a corresponding open issue.

Note that simdutf itself depends on the C++ library.

Purpose: This should make it easy to call simdutf from Swift, Go and friends.

To keep it simpler, I am not adding the feature macros to it... I am concerned that it will add much complexity, although it can be done later.

See #893

cc @MahdiBM

Type of change

  • Bug fix
  • Optimization
  • New feature
  • Refactor / cleanup
  • Documentation / tests
  • Other (please describe):

lemire requested review from Copilot and pauldreik January 4, 2026 21:43

This comment was marked as outdated.

Copilot AI left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread singleheader/amalgamate.py Outdated
Comment thread include/simdutf_c.h
Comment thread README.md Outdated
Comment thread tests/simdutf_c_tests.cpp Outdated
Comment thread tests/simdutf_c_tests.cpp
lemire and others added 4 commits January 4, 2026 20:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread README.md Outdated
Comment thread include/simdutf_c.h
#include <stdbool.h>
#include <stdint.h>

#ifdef __has_include

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this seems to be a C23 feature, so I think it must be changed or we require C23.
https://en.cppreference.com/w/c/preprocessor/include

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this seems to be a C23 feature, so I think it must be changed or we require C23.

Formally, you are correct, but both clang and gcc have supported __has_include for a really long time.

https://godbolt.org/z/895hcr7ff

The issue is that uchar.his C11 but Apple does not have the header. I don't know why.

Comment thread src/simdutf_c.cpp
Comment thread src/simdutf_c.cpp
Comment thread tests/CMakeLists.txt
Comment thread tests/simdutf_c_tests.cpp Outdated
lemire changed the title Add a C API [WIP] Add a C API Jan 5, 2026
lemire marked this pull request as ready for review January 5, 2026 21:33
lemire requested a review from pauldreik January 5, 2026 21:33

lemire commented Jan 5, 2026

Copy link
Copy Markdown
Member Author

@pauldreik Making as 'ready for review'.

pauldreik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I tested the amalgamate script, it failed with:

FileNotFoundError: [Errno 2] No such file or directory: '/home/pauldreik/code/delaktig/simdutf/singleheader/simdutf_c.h'

Comment thread tests/simdutf_c_tests.cpp Outdated
Comment thread README.md

Copy link
Copy Markdown
Collaborator

@lemire I took the liberty to push some clang format changes and ci job, hope you don't mind.

lemire commented Jan 5, 2026

Copy link
Copy Markdown
Member Author

@pauldreik I don't mind if you push stuff, but the rvv CI changes seem to fail.

lemire commented Jan 5, 2026

Copy link
Copy Markdown
Member Author

so, I think row 4 and 6 should be deleted. agree?

Maybe I misunderstand you. Here is what I think. If I write a function definition in C++ and I want it to be callable from C, then I put it inside an extern 'C' scope.

lemire commented Jan 5, 2026

Copy link
Copy Markdown
Member Author

@pauldreik I pushed two changes.

  1. Fixed a logic error in the amalgamation script (thanks)
  2. Marked the C API as experimental (meaning we warn about possible bugs)

pauldreik commented Jan 6, 2026
edited
Loading

Copy link
Copy Markdown
Collaborator

@pauldreik I don't mind if you push stuff, but the rvv CI changes seem to fail.

it was not my push that caused the failure, I pushed a fix for one of the three failing riscv jobs. I have now pushed fixes for the remaining two.

Copy link
Copy Markdown
Collaborator

so, I think row 4 and 6 should be deleted. agree?

Maybe I misunderstand you. Here is what I think. If I write a function definition in C++ and I want it to be callable from C, then I put it inside an extern 'C' scope.

It is the declaration that needs to be in extern C. But that is not what I am after here, it is that the wrapping of extern C around the include is at best redundant and at worst wrong (since it unconditionally puts everything, including not functions, from the header file in extern C)

lemire commented Jan 6, 2026

Copy link
Copy Markdown
Member Author

@pauldreik I did not see that extern C at first, in the test file. Sorry. I just removed it.

It did not make sense, I agree.

Copy link
Copy Markdown
Collaborator

no problem! are we good to merge then?

lemire merged commit 2542805 into master Jan 6, 2026
106 checks passed

lemire commented Jan 6, 2026

Copy link
Copy Markdown
Member Author

Merged !

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL