Stephen Witherden’s Website :: Work :: New generation

8/11/2006

New generation

Filed under: — Stephen @ 3:33 pm

Ok, so now it’s time for a boring work post. I wish I could show pictures of where I work but no recording devices of any kind are allowed in the building. Security is reasonably tight. I can’t even get back from the toilet without a swipe card.

Yeah, Cecil guys & gals, I have been there before, but this time knocking on the door is not allowed. I once forgot my card when I went to the toilet. I had to get the security person (her name is Barbra) to ring into the office so that someone could walk out with my swipecard. No swipecard, no entry. Our swipecards have our pictures on them too.

Anyway, So I am writing code (no specifics). The design is finished and one of our key problems is interfacing with a particular API. This API is all done in unmanaged C++ libraries and we’re programming in C#. Non-programmers, continue reading at your peril…

You geeks can immediately see the problem of course: native C++ libraries don’t interoperate easily with .Net. You need to recompile the C++ in “common language runtime” mode so that “it just works” or do a bunch of old fashioned dllimports.

Now, we don’t have the source code and the nature of the headers is such that dllimport is out of the question. So, the only solution is a managed C++ wrapper. Do you think there’s a way to generate a managed C++ wrapper to an unmanaged C++ library? No. A tool called Swig can get part-way there but because its implementation of the C++ parsing rules is incomplete it basically choked on 90% of the headers I threw at it.

My team lead was in favour of going ahead and writing the wrapper by hand. So, we started doing that. By the second day I was just getting into the swing of things when my Intellisense stopped working. Well, rather it went into overdrive and killed the CPU on my computer. Why? A bug in the implementation of the intellisense in VC++ 8 (.Net 2005) causes it to go into an infinite loop.

So, that was the last straw. There’s no way you can write a wrapper to a foreign API (particularly not this one) without heaps of code completion. So, I rolled up my metaphorical sleeves and wrote my own parser to parse the headers and then code to generate the wrappers myself. The headers follow a pattern so it was easier than writing a C++ compiler, it was still quite a challenge.

I generated over 60,000 lines of code with my generator today and I am only about half way through (the API is somewhat symmetrical around getters and setters). Imagine having to hand-code 120,000 lines worth of wrappers? I am glad I saved myself (and my team) from that particular nightmare.

11 Responses to “New generation”

  1. Sally Says:

    Stephen: “…..Yeah, Cecil guys & gals………”

    Sally: ZzzzzzzzZzzzz
    Sorry… :P

  2. Kyhwana Says:

    Jesus christ! (Re code stufF)

  3. Stephen Says:

    tsk tsk, I am sure Jesus wouldn’t appretiate you using his name in vain :)

  4. izzy Says:

    oh my! this story turns me on … in a geeky kindda way. No chance of getting frisky and looking at the source huh.

  5. Stephen Says:

    Sorry, dude, I’d have to kill you ;)
    Or at least make you go through security clearance which is about as bad :)

  6. George Says:

    Just a thought. Its really odd how the name of our Lord is used more in every day life by people who don’t believe in Him than by those of us who do.

  7. Stephen Says:

    *grins* It is strage.

    That said, it cuts both ways. I have caught myself saying “holy cow” which would be offensive to many people of different faiths & cultural backgrounds to me.

  8. Lindel Wiebesiek Says:

    Hi! I’m a really old friend of Susan’s from school in Durban and am trying to get into contact with her. Any chance you could send me her email address or send her mine? Thanks, Lindel

  9. Christine Says:

    Hi Stephen, i left a message somewhere else on your website. just in case you dont get it i thought i’d post one here too. I am an old school friend of Susans from Durban. Please oh please can you send me her email address!! I am so looking forward to contacting her.
    thank you!!

    Christine Bernard (used to CAZIN)

  10. Stephen Says:

    Hi Lindel. I remember you! Good to hear from you. I have sent you an email :)

  11. Stephen Says:

    Hi Christine, I have sent you an email. Thank you for posting, I am sure Susan will get a kick out of it ;)

(c) 2006, Stephen Witherden Powered by WordPress