Search code examples
erlangerlang-driver

Are there macros which can be used to test Erlang version in driver C code?


Erlang R15B added ErlDrvSSizeT typedef, and R16B added erl_drv_output_term function and deprecated the old equivalent. Is there a way to test for these differences with preprocessor macros in order to support older Erlang versions with the same code?


Solution

  • You can use the ERL_DRV_EXTENDED_MAJOR_VERSION and ERL_DRV_EXTENDED_MINOR_VERSION macro values, supplied in erl_driver.h, to make decisions about features. Whenever the driver API changes, these values are suitably incremented. These increments are always explained in the Erlang/OTP release notes.

    For example, Erlang/OTP R15B changed some API function parameter types from int to a new type ErlDrvSizeT to better cope with 64-bit platforms. You can test for this and compensate for it for older pre-R15B versions using the code below:

    #if ERL_DRV_EXTENDED_MAJOR_VERSION < 2
    typedef int ErlDrvSizeT;
    #endif
    

    This typedef allows you to use the type ErlDrvSizeT even for older driver versions.

    As of this writing, Erlang/OTP version 17.3 and version 6.2 of the Erlang runtime system (erts) are current. For erts 6.2, ERL_DRV_EXTENDED_MAJOR_VERSION and ERL_DRV_EXTENDED_MINOR_VERSION have the values 3 and 1, respectively. The changes in this Erlang/OTP commit created these version values.