int32 vs uint32 issues with untyped language bindings

Daniel P. Berrange dan at berrange.com
Mon Dec 27 08:13:10 PST 2004


On Mon, Dec 27, 2004 at 08:50:53AM -0500, Andy Wingo wrote:
> On Sun, 26 Dec 2004, John (J5) Palmieri wrote:
> > There seems to be an issue with the ability for untyped language
> > bindings to deal with dbus methods that require uint parameters.
> 
> Guile's bindings allow you to add optional type specifiers:
> 
> http://lists.freedesktop.org/pipermail/dbus/2004-November/001782.html

For the Perl bindings I've ended up adding a 'dpack' method for
specifying types explicitly. For example in a method returning
an signed int, instead of doing

  my $pid = fork();
  ... do some stuff ...
  return $pid;

You would have

  my $pid = fork();
  ... do some stuff ...
  return dpack("i", $pid);

So, irrespective whether Perl (or the fork() method in particular) thinks
(or decided) that the scalar $pid is currently a  string, int or float, as 
the programmer I know PIDs are signed ints and thus specify 'i' as the format
string. I so far haven't found the burden of adding dpack() calls to be very
significant - particular since it gives you 100% reliable typing, removing a
whole class of unpredictable bugs. For the record, the format specifiers 
I've defined so far are

  o - boolean
  b - byte
  s - string
  i - int32
  I - unsigned int32
  l - int64
  L - unsigned in64
  d - double

Regards,
Dan.
-- 
|=-            GPG key: http://www.berrange.com/~dan/gpgkey.txt       -=|
|=-       Perl modules: http://search.cpan.org/~danberr/              -=|
|=-           Projects: http://freshmeat.net/~danielpb/               -=|
|=-   berrange at redhat.com  -  Daniel Berrange  -  dan at berrange.com    -=|
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.freedesktop.org/pipermail/dbus/attachments/20041227/ea7023ce/attachment.pgp


More information about the dbus mailing list