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

Is anybody working on the C backend? #800

Closed
fHachenberg opened this issue Sep 23, 2016 · 10 comments
Closed

Is anybody working on the C backend? #800

fHachenberg opened this issue Sep 23, 2016 · 10 comments

Comments

@fHachenberg
Copy link

I think, creating a shallow C interface still would be of great benefit because many languages already have binding generators for C.

The most recent code for this backend seems to be in the branch gsoc2012-c
https://github.com/swig/swig/tree/gsoc2012-c

Has anyone looked into this? Is it beyond repair?

Here's the description and summary from gsoc 2012
https://opensource.googleblog.com/2008/11/swigs-first-google-summer-of-code.html
https://opensource.googleblog.com/2012/11/swig-swings-into-another-successful.html
http://swig-devel.narkive.com/jqdNrIxV/gsoc-c-backend-resume

@vadz
Copy link
Member

vadz commented Sep 23, 2016

The most recent (but still not really functional) version of this is in my fork, see this recent thread

@fHachenberg
Copy link
Author

I would like to help. Where do I start?

@vadz
Copy link
Member

vadz commented Sep 23, 2016

Pull requests fixing any of the existing test failures would be surely welcome. Perhaps the best would be to run the current code with your own header and fix the problems affecting your project (and maybe discover new ones :-)

Personally, my next goal is adding shared_ptr support as I absolutely need this for my own use, but, unfortunately, I'm not sure when I will have time to finish this...

Thanks in advance for your help!

@fHachenberg
Copy link
Author

I started to look into the test failures.
In some test cases I get a warning for an undefined SWIG_exit. Should the runme-files include swigmod.h or should the generated wrap-file include swigmod.h or should SWIG_exit just be replaced by return? I didn't find any documentation about SWIG_exit

@fHachenberg
Copy link
Author

Is there a design document available somewhere describing basic decisions regarding the C backend? For instance I wonder how are C++ exception mapped? Do all wrapper functions use their return value for error codes?

@ojwb
Copy link
Member

ojwb commented Sep 25, 2016

There's a SWIG_exit() function defined in Lib/c/c.swg which just calls exit() - I'm not sure why that redirection was thought useful.

In the source of SWIG itself, there's a SWIG_exit() function which is used instead of exit() in the SWIG source code - this has an optional infinite loop, presumably for debugging purpose, though this smacks of someone not knowing how to use their debugger properly:

void SWIG_exit(int exit_code) {
  while (freeze) {
  }
  exit(exit_code);
}

I don't know if there's a design document, but I'd expect the wrappers to return the return value of the wrapped function by default - exception handling would then be handled via %exception.

@wsfulton
Copy link
Member

The only documentation I can think of is the Doc/Manual/C.html file in the branch. If you find anything wrong in here, please feel free to correct it.

@vadz
Copy link
Member

vadz commented Sep 25, 2016

You can see the exception handling in action in Examples/c/exception. In short, it uses a global (ideally should per-thread) object to store the thrown exception, which can then be retrieved and examined from the C code.

This is definitely not ideal from C point of view, but this should be good enough for my ultimate goal of C++ wrapper for C++ API as such API could check for exception after every C function call and just rethrow it immediately. And other alternatives are not really better anyhow (but let's discuss them on the mailing list if you're interested).

@wsfulton
Copy link
Member

Please try out the proposed pull request to add in C support in #2086.

@ojwb
Copy link
Member

ojwb commented Feb 28, 2022

I'm going to close this as the question "Is anybody working on the C backend?" has been answered, and there's an open PR to track progress.

@ojwb ojwb closed this as completed Feb 28, 2022
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

No branches or pull requests

4 participants