R14 vs R13 binary handling in driver_outputv

Tim Watson <>
Wed Mar 9 17:53:07 CET 2011


Hi all,

I have a linked in driver which receives data from port_command/2 in
driver_outputv and casts the binary into some shape using a couple of
structs. This approach works fine for R13, but in R14 I get extra data
at the end of the binary. I'm guessing I've screwed up by making an
assumption about the length of the binary - hoping someone can give me
a nudge in the right direction.

The iolist that goes to port_command/2 looks like this:

DataSizeMarkers = [ size(Input), size(Xsl) ],
[[ InputType, XslType, <<0:16/native-integer>> ],
    [ <<Marker:32/native-integer>> || Marker <- DataSizeMarkers ],
    [ Input, Xsl ]];

The variables are all binaries. This goes direct to driver outputv,
where it is processed like so:

  ErlDrvBinary *bin = ev->binv[1];
  int bin_size = bin->orig_size;
  Int32 offset = (Int32)(sizeof(InputSpecHeaders) +
sizeof(PayloadSizeHeaders));
  // error checking omitted for brevity
  const char *buffer = &(bin->orig_bytes[0]);
  const InputSpecHeaders *hspec = (const InputSpecHeaders* const)buffer;
  const PayloadSizeHeaders *hsoffset = (const PayloadSizeHeaders*)(hspec + 1);
  PayloadSizeHeaders hsize = *hsoffset;
  hsoffset++;
  buffer = (const char*)hsoffset;

And those structures:

typedef int8_t    Int8;
typedef int16_t   Int16;
typedef int32_t   Int32;

typedef struct {
  Int8 input_kind;
  Int8 xsl_kind;
  Int16 param_grp_arity;
} InputSpecHeaders;

typedef struct  {
  Int32 input_size;
  Int32 xsl_size;
} PayloadSizeHeaders;


Source code is here: http://github.com/hyperthunk/erlxsl.

Any advice would be most welcome - I'm still finding my way around
linked-in drivers!

Cheers,

Tim


More information about the erlang-questions mailing list