TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

SWIG author on the complexity of SWIG

48 pointsby progover 13 years ago

6 comments

phaedrusover 13 years ago
I wrote a library that makes C++ callable from script languages, but instead of parsing headers it uses C++11 template metaprogramming and type inference, so it always parses exactly what the types are because it runs in the same compiler as your code. Unlike SWIG it is becoming simpler over time as I develop more powerful abstractions and I <i>do</i> understand 100% of how it works (although admittedly you have to have advanced C++ knowledge).<p>Definitely agree with the C++ corner cases thing being a challenge - at times I felt like I was writing another compiler on top of the C++ type system to handle the corner cases. But again, I used powerful abstractions to handle that. For instance, my library uses boost graph library and djikstra's algorithm to handle C++'s tangled web of automatic type conversions.<p><a href="http://github.com/dennisferron/LikeMagic" rel="nofollow">http://github.com/dennisferron/LikeMagic</a>
评论 #2940199 未加载
daekenover 13 years ago
I've been thinking about how to do this effectively and cleanly for a while now, and I wonder if the right path isn't to use clang to parse the C or C++ code and then generate interfaces from the LLVM IR. As far as I know, all the metadata you need is there, so it might prove simpler than parsing things on your own.
评论 #2940657 未加载
评论 #2938223 未加载
mynegationover 13 years ago
If it shows anything, it is a horrible language design of C++. I wrote a C++ front-end long ago, and it is excruciating.<p>Later, when I had to write native code to speed up Python, I always used plain old C and swig worked flawlessly.
评论 #2937706 未加载
评论 #2937744 未加载
lylejohnsonover 13 years ago
I was one of the maintainers of SWIG's Ruby module during that rewrite he mentions, and I remember how difficult it became for me to really understand how the code worked. I would just hack features into the Ruby module and be glad when they seemed to work, but it always felt like a house of cards. Fortunately some more talented developers took my place when I gave it up.
sigilover 13 years ago
The SWIG author in question, Dave Beazley, also gave a couple great talks on the Python GIL: <a href="http://www.dabeaz.com/GIL/" rel="nofollow">http://www.dabeaz.com/GIL/</a>
gaiusover 13 years ago
I had a bit of a nightmare with SWIG recently, glad to hear I'm not alone! <a href="http://gaiustech.wordpress.com/2011/08/03/ocaml-bindings-for-coherence-with-swig/" rel="nofollow">http://gaiustech.wordpress.com/2011/08/03/ocaml-bindings-for...</a>