loads of warnings when using the module:
return $self->{align} unless $self->{align} eq 'auto';
Should it be:
return $self->{align} unless ! defined $self->{align} || $self->
{align} eq 'auto';
But not 100% sure?
In addition there are a number of debug lines which also cause loads
of warnings:
Struct.pm:221 DEBUG "(PM)Struct::getPack: $self->{__typedef__}
(buffer) = pack($packing, @items)\n";
Struct.pm:229 DEBUG "(PM)Struct::Pack: $self->{__typedef__}(buffer)
= pack($packing, @$items)\n";
Hope this helps.
Regards
Steve
I think there are some bugs in there too. Does sizeof work properly
in the current version ? There might be alignment issues too.
I'm using 0.50.
Here's a test case that should show the sizeof problem:
use strict;
use warnings;
use Win32::API::Struct;
typedef Win32::API::Struct PROCESSENTRY32 => qw(
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID;
DWORD th32DefaultHeapID;
DWORD th32ModuleID;
DWORD cntThreads;
DWORD th32ParentProcessID;
LONG pcPriClassBase;
DWORD dwFlags;
char szExeFile[260];
); # 9*4=36+260=296
my $pe32 = new Win32::API::Struct ('PROCESSENTRY32');
my $size = $pe32->sizeof;
print "size=$size should be 296\n";
__END__
This produces:
size=40 should be 296
I changed my version of Struct.pm to alleviate the symptom, but
not sure if it's the correct change (my changes on the right >):
143,147c144,148
< if(defined $align and $align > 0) {
< return scalar(@{ $self->{typedef} }) * $align;
< } else {
< return $size;
< }
---
> # if(defined $align and $align > 0) { $Bill - comment out this align test
> # return scalar(@{ $self->{typedef} }) * $align; $Bill
> # } else { $Bill
> # return $size; $Bill
> # } $Bill
189c190
< ($name, $type, my $orig) = @$member; # $Bill - just a strict issue
---
> ($name, $type, $orig) = @$member;
246c247
< ($name, $type, $orig) = @$member;
---
> ($name, $type, my $orig) = @$member; # $Bill - just a strict issue
There may be other issues.
Thanks Bill,
this is now a test case, so I can track progress.
Here's two useful articles on structs and packing. Thanks Bill for the
pointer.
Data alignment considerations
http://msdn.microsoft.com/en-us/library/aa505951(loband).aspx
Data alignment examples
http://msdn.microsoft.com/en-us/library/aa505952.aspx
Cosimo Streppone via RT wrote:
>
> Here's two useful articles on structs and packing. Thanks Bill for the
> pointer.
>
> Data alignment considerations
> http://msdn.microsoft.com/en-us/library/aa505951(loband).aspx
>
> Data alignment examples
> http://msdn.microsoft.com/en-us/library/aa505952.aspx
Wouldn't it be nice if they could just concisely state the rules
in an ordered bullet list instead of forcing you to guess and test ? :)
This bug should be fixed in HEAD.
I'm rolling out a new release soon,
but would be nice if you guys could confirm it works for you.
http://github.com/cosimo/perl5-win32-api/
This is going to be 0.60_dev.