zeromq / zeromq3-x

ØMQ/3.2 release branch - bug fixes only
GNU General Public License v3.0
227 stars 96 forks source link

Adding Julia support: #define vs enum for constants #21

Closed timholy closed 12 years ago

timholy commented 12 years ago

Thanks for ZeroMQ!

I'm adding support for a new language, Julia: http://julialang.org/. Julia is a dynamic language that gets JIT-compiled by LLVM, achieving performance typical of C with all the nice features of a dynamic language. When linking to an external library like ZeroMQ, there's a zero-overhead "ccall" functionality, so that no C-wrapper needs to be written to access the library---calls to the library get compiled/linked inline via LLVM.

One of the things that would seem to make Julia's (and perhaps other languages?) ZeroMQ support cleaner would be to have the values of the various constants (e.g., all of the zmq_setsockopt options like ZMQ_SNDHWM) be exported to the library itself. We make no use of the zmq.h header, so we can't get the constants from there; currently the constants are (re)defined in Julia code (which may be true for quite a few other languages, too). Unfortunately, this introduces the risk that a constant might change its definition in some future version of ZeroMQ, and we'll then have problems.

This risk is avoided entirely if one can simply extract the values of constants from the library. I think this is possible if you use enum (or const int) rather than #define when specifying these constants. Would there be any downsides to making this switch? It might also help to have a constant for sizeof(zmq_msg_t), since currently Julia just allocates a blank buffer of the correct size and then has zmq_init* fill in the data.

If it would help to see our current code, it's here: https://github.com/timholy/julia/tree/zmq/extras/zmq The wrapper for ZeroMQ is just the one file, zmq.jl.

hintjens commented 12 years ago

I don't see any problem making these changes; the process is to make an issue in Jira (not here) and then a github pull request on the libzmq master.

timholy commented 12 years ago

Hmm, I went to work on this, and I'm not seeing that enums are exported after all. So, never mind.