Discussion:
[racket] FFI and C header defines
Bartosz Przygoda
2015-02-05 21:38:21 UTC
Permalink
Hello,

I'm implementing FFI for termios functions (I noticed Python has got all
this covered: serial, termios, fnctl and so on, whereas Racket seemed not
(at least serial, which I'm trying to do next)), and I'm wondering how to
tackle the values defined in C headers (especially those that are depending
on other defines), for example:

#ifdef __USE_MISC
# define XTABS 0014000
#endif


I'd like to have such values define in my library module, but then what
about differences? Some should be part of POSIX standard, but from what I
see there is lots of ifdefs so some could vary.

I checked Python, and seems such modules are implemented natively, so that
when they get build proper consts are introduced and then such module is
depending on a environment it was build in. Does similar way could be used
for racket? Or what should be generaly favored way of doing such things
here?
Jens Axel Søgaard
2015-02-05 22:01:07 UTC
Permalink
Maybe you can find something useful here:
http://pkg-build.racket-lang.org/doc/c-utils/index.html

/Jens Axel
Post by Bartosz Przygoda
Hello,
I'm implementing FFI for termios functions (I noticed Python has got all
this covered: serial, termios, fnctl and so on, whereas Racket seemed not
(at least serial, which I'm trying to do next)), and I'm wondering how to
tackle the values defined in C headers (especially those that are depending
#ifdef __USE_MISC
# define XTABS 0014000
#endif
I'd like to have such values define in my library module, but then what
about differences? Some should be part of POSIX standard, but from what I
see there is lots of ifdefs so some could vary.
I checked Python, and seems such modules are implemented natively, so that
when they get build proper consts are introduced and then such module is
depending on a environment it was build in. Does similar way could be used
for racket? Or what should be generaly favored way of doing such things
here?
____________________
http://lists.racket-lang.org/users
--
--
Jens Axel Søgaard

____________________
Racket
Bartosz Przygoda
2015-02-05 22:22:40 UTC
Permalink
This looks great, but for what I want to achieve, something else is needed
- as far as I understand - something akin to simple native callback that
would be called on the beginning of module evaluation and it would add some
defines (using Racket C API).
Post by Jens Axel Søgaard
http://pkg-build.racket-lang.org/doc/c-utils/index.html
/Jens Axel
Post by Bartosz Przygoda
Hello,
I'm implementing FFI for termios functions (I noticed Python has got all
this covered: serial, termios, fnctl and so on, whereas Racket seemed not
(at least serial, which I'm trying to do next)), and I'm wondering how to
tackle the values defined in C headers (especially those that are
depending
Post by Bartosz Przygoda
#ifdef __USE_MISC
# define XTABS 0014000
#endif
I'd like to have such values define in my library module, but then what
about differences? Some should be part of POSIX standard, but from what I
see there is lots of ifdefs so some could vary.
I checked Python, and seems such modules are implemented natively, so
that
Post by Bartosz Przygoda
when they get build proper consts are introduced and then such module is
depending on a environment it was build in. Does similar way could be
used
Post by Bartosz Przygoda
for racket? Or what should be generaly favored way of doing such things
here?
____________________
http://lists.racket-lang.org/users
--
--
Jens Axel SÞgaard
Anthony Carrico
2015-02-06 01:01:26 UTC
Permalink
Post by Jens Axel Søgaard
http://pkg-build.racket-lang.org/doc/c-utils/index.html
Hey, this is pretty cool. I wonder if Dave Herman has thought of bolting
this to Clang.
--
Anthony Carrico
Bartosz Przygoda
2015-02-06 22:26:48 UTC
Permalink
Hello again,

Looks like this
<http://docs.racket-lang.org/inside/Writing_Racket_Extensions.html?q=#%28part._.Declaring_a_.Module_in_an_.Extension%29>
(
http://docs.racket-lang.org/inside/Writing_Racket_Extensions.html?q=#%28part._.Declaring_a_.Module_in_an_.Extension%29)
solves it the way I wanted (and it's quite easy to build, thanks to
documentation). So at worst, I could use an extension (would be very
similar to the way python does it). I said 'at worst', cause it's gonna
involve lots of tedious typing on the C side.

I'm gonna check out those c parsing libs for that reason.

Thanks!
Post by Anthony Carrico
Post by Jens Axel Søgaard
http://pkg-build.racket-lang.org/doc/c-utils/index.html
Hey, this is pretty cool. I wonder if Dave Herman has thought of bolting
this to Clang.
--
Anthony Carrico
____________________
http://lists.racket-lang.org/users
Eric Dobson
2015-02-06 23:17:52 UTC
Permalink
I wrote something similar for my LLVM bindings, after running into many
issues with Dave's code. It follows the c spec not c++, and doesn't support
gcc extensions which many libaries use.

It is no where near production quality, but may give you a starting point:
https://github.com/shekari/racket-llvm/blob/master/private/llvm-headers.rkt
Post by Bartosz Przygoda
Hello again,
Looks like this
<http://docs.racket-lang.org/inside/Writing_Racket_Extensions.html?q=#%28part._.Declaring_a_.Module_in_an_.Extension%29>
(
http://docs.racket-lang.org/inside/Writing_Racket_Extensions.html?q=#%28part._.Declaring_a_.Module_in_an_.Extension%29)
solves it the way I wanted (and it's quite easy to build, thanks to
documentation). So at worst, I could use an extension (would be very
similar to the way python does it). I said 'at worst', cause it's gonna
involve lots of tedious typing on the C side.
I'm gonna check out those c parsing libs for that reason.
Thanks!
Post by Anthony Carrico
Post by Jens Axel Søgaard
http://pkg-build.racket-lang.org/doc/c-utils/index.html
Hey, this is pretty cool. I wonder if Dave Herman has thought of bolting
this to Clang.
--
Anthony Carrico
____________________
http://lists.racket-lang.org/users
____________________
http://lists.racket-lang.org/users
Loading...