Skip Menu |

This queue is for tickets about the Win32-API CPAN distribution.

Report information
The Basics
Id: 39730
Status: resolved
Priority: 0/
Queue: Win32-API

People
Owner: cosimo [...] cpan.org
Requestors: IKEGAMI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 0.72



Subject: Passing NULL when has_proto is true
There doesn't seem to be any way of passing NULL to a function when has_proto is true. I'd like to recommend passing NULL when undef is passed where a pointer is expected. For example, Show quoted text
--- BEGIN EXAMPLE --- Win32::API->Import( 'kernel32', 'BOOL PeekNamedPipe( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage )', ); PeekNamedPipe( $osfh, undef, 0, undef, $nAvail, undef )
--- END EXAMPLE --- I believe the following change achieves this:
--- BEGIN PATCH --- case T_POINTER: params[i].t = T_POINTER; origST[i] = ST(i+1); if(has_proto) { - pointerCallPack(ST(i+1), i, intypes); - params[i].p = (char *) SvPV_nolen(ST(i+1)); + if(SvOK(ST(i+1)) { + pointerCallPack(ST(i+1), i, intypes); + params[i].p = (char *) SvPV_nolen(ST(i+1)); + } else { + params[i].p = NULL; + } } else { if(SvIOK(ST(i+1)) && SvIV(ST(i+1)) == 0) { params[i].p = NULL; } else { params[i].p = (char *) SvPV_nolen(ST(i+1)); } } ... if(params[i].t == T_POINTER && has_proto) { - pointerCallUnpack(origST[i], i, intypes); + if(SvOK(origST[i]) { + pointerCallUnpack(origST[i], i, intypes); + } }
--- END PATCH ---
RT-Send-CC: dada [...] perl.it
On Mer. 01 Oct. 2008 00:46:27, ikegami wrote: Show quoted text
> There doesn't seem to be any way of passing NULL to a function when > has_proto is true. > > I'd like to recommend passing NULL when undef is passed where > a pointer is expected. For example,
Thanks for your detailed bug report, example and patch. I'll try to look at it this week.
On Mer. 01 Oct. 2008 02:54:40, COSIMO wrote: Show quoted text
> On Mer. 01 Oct. 2008 00:46:27, ikegami wrote:
> > There doesn't seem to be any way of passing NULL to a function when > > has_proto is true. > > > > I'd like to recommend passing NULL when undef is passed where > > a pointer is expected. For example,
Can you try the attached Win32::API version and report if it works for you? I basically applied your patch over the new soon-to-be released version of Win32::API. Thanks!
Download Win32-API-0.56-RC1.tar.gz
application/x-gzip 68.1k

Message body not shown because it is not plain text.

CC: IKEGAMI [...] cpan.org
Subject: Re: [rt.cpan.org #39730] Passing NULL when has_proto is true
Date: Thu, 2 Oct 2008 03:45:09 -0400
To: bug-Win32-API [...] rt.cpan.org
From: "Eric Brine" <ikegami [...] adaelis.com>
On Wed, Oct 1, 2008 at 4:55 PM, Cosimo Streppone via RT < bug-Win32-API@rt.cpan.org> wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=39730 > > > On Mer. 01 Oct. 2008 02:54:40, COSIMO wrote:
> > On Mer. 01 Oct. 2008 00:46:27, ikegami wrote:
> > > There doesn't seem to be any way of passing NULL to a function when > > > has_proto is true. > > > > > > I'd like to recommend passing NULL when undef is passed where > > > a pointer is expected. For example,
> > Can you try the attached Win32::API version > and report if it works for you?
It does! Here's the test I used: Show quoted text
---------- BEGIN TEST ---------- #!/usr/bin/perl use strict; use warnings; use IPC::Open3 qw( open3 ); use Win32::API qw( ); use Win32API::File qw( GetOsFHandle INVALID_HANDLE_VALUE ); print( Win32::API->VERSION(), "\n" ); Win32::API->Import( 'kernel32', 'BOOL PeekNamedPipe( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage )', ) or die( "Import: $^E\n" ); open3( my $to_child, my $fr_child, undef, qq{$^X} ) or die( "open3: $!\n" ); ( my $fd_pipe = GetOsFHandle( $fr_child ) ) != INVALID_HANDLE_VALUE or die( "GetOsFHandle: $^E\n" ); PeekNamedPipe( $fd_pipe, undef, 0, undef, my $nAvail, undef ) or die( "PeekNamedPipe: $^E\n" ); print( "Success\n" );
---------- END TEST ---------- And here's the output I got:
---------- BEGIN TEST OUTPUT ----------
>perl test.pl
0.41 PeekNamedPipe: Invalid access to memory location
>perl -IWin32-API-0.56\blib\lib -IWin32-API-0.56\blib\arch test.pl
0.56 Success
---------- END TEST OUTPUT ---------- Feel free to make a .t file from it. Thanks for the super quick response! Eric "ikegami" Brine
CC: IKEGAMI [...] cpan.org
Subject: Re: [rt.cpan.org #39730] Passing NULL when has_proto is true
Date: Thu, 2 Oct 2008 03:59:25 -0400
To: bug-Win32-API [...] rt.cpan.org
From: "Eric Brine" <ikegami [...] adaelis.com>
On Thu, Oct 2, 2008 at 3:45 AM, Eric Brine <ikegami@adaelis.com> wrote: Show quoted text
> It does! Here's the test I used: >
The test I previously sent leaves a stray Perl process executing. Fix: Show quoted text
---------- BEGIN TEST ---------- #!/usr/bin/perl use strict; use warnings; use IPC::Open3 qw( open3 ); use Win32::API qw( ); use Win32API::File qw( GetOsFHandle INVALID_HANDLE_VALUE ); print( Win32::API->VERSION(), "\n" ); Win32::API->Import( 'kernel32', 'BOOL PeekNamedPipe( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage )', ) or die( "Import: $^E\n" ); my $pid; my $success = eval { $pid = open3(my $to_child, my $fr_child, undef, qq{"$^X"}) or die( "open3: $!\n" ); ( my $fd_pipe = GetOsFHandle( $fr_child ) ) != INVALID_HANDLE_VALUE or die( "GetOsFHandle: $^E\n" ); PeekNamedPipe( $fd_pipe, undef, 0, undef, my $nAvail, undef ) or die( "PeekNamedPipe: $^E\n" ); 1 }; STDERR->print( $@ ) if !$success; # Not very gentle, but closing $to_child and $fr_child don't end it. kill( TERM => $pid ) or warn( "kill: $!\n" ); print( $success ? "Success\n" : "Error\n" );
---------- END TEST ----------
Should be finally fixed in v0.56, on its way to CPAN. Thanks Eric!
I am sorry for reopenning this RT again but the proposed test - now t/03_undef.t - is failing on my Windows 7 (x64) box with both 32/64bit perl.

The same results with 64bit strawberry perl and active perl (both 5.12.0).

Could somebody involved in solving this RT have a look at the latest github version - http://github.com/cosimo/perl5-win32-api - and fix t/03_undef.t somehow?

Thanks.

--
kmx

I can't get it to build (Win7, 64bit, ActivePerl 5.12.1, Visual Studio 10) Show quoted text
---- BEGIN ---- CPAN.pm: Going to build C/CO/COSIMO/Win32-API-0.59.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Win32::API::Callback Writing Makefile for Win32::API CPAN: Module::CoreList loaded ok (v2.33) Microsoft (R) Program Maintenance Utility Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. cp Type.pm blib\lib\Win32/API/Type.pm cp Callback.pm blib\lib\Win32/API/Callback.pm cp Test.pm blib\lib\Win32/API/Test.pm cp Struct.pm blib\lib\Win32/API/Struct.pm cp API.pm blib\lib\Win32/API.pm C:\PROGRA~2\MICROS~1.0\VC\BIN\nmake.exe -f Makefile all -nologo C:\Progs\perl5121-ap1201\bin\perl.exe C:\Progs\perl5121-ap1201\lib\ExtUtils\xsubpp -typemap C:\Progs\perl5121-ap1201\lib\ExtUtils\typemap Callback.xs > Callback.xsc && C:\Progs\perl5121-ap1201\bin\perl.exe -MExtUtils::Command -e "mv" -- Callback.xsc Callback.c cl -c -nologo -GF -W3 -MD -Zi -DNDEBUG -Ox -GL -Wp64 -fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DWIN64 -DCONSERVATIVE -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -MD -Zi -DNDEBUG -Ox -GL -Wp64 -fp:precise -DVERSION=\"0.59\" -DXS_VERSION=\"0.59\" "-IC:\Progs\perl5121-ap1201\lib\CORE" Callback.c cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release Callback.c C:\Progs\perl5121-ap1201\lib\CORE\sys/socket.h(34) : warning C4005: 'ENOTSOCK' : macro redefinition C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\errno.h(120) : see previous definition of 'ENOTSOCK' Callback.xs(250) : warning C4311: 'type cast' : pointer truncation from 'char *' to 'long' Callback.xs(256) : warning C4996: 'itoa': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details. C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdlib.h(867) : see declaration of 'itoa' Callback.xs(257) : warning C4267: 'function' : conversion from 'size_t' to 'I32', possible loss of data Callback.xs(276) : warning C4312: 'type cast' : conversion from 'unsigned int' to 'SV *' of greater size Callback.xs(305) : warning C4312: 'type cast' : conversion from 'int' to 'char *' of greater size Callback.xs(313) : warning C4312: 'type cast' : conversion from 'int' to 'char *' of greater size Callback.xs(365) : warning C4996: 'itoa': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details. C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdlib.h(867) : see declaration of 'itoa' Callback.xs(366) : warning C4267: 'function' : conversion from 'size_t' to 'I32', possible loss of data Callback.xs(381) : warning C4244: '=' : conversion from 'IV' to 'int', possible loss of data Callback.xs(524) : warning C4018: '<' : signed/unsigned mismatch Callback.xs(559) : warning C4244: '=' : conversion from '__w64 int' to 'unsigned int', possible loss of data Callback.xs(581) : warning C4311: 'type cast' : pointer truncation from 'SV *' to 'int' Callback.xs(596) : warning C4311: 'type cast' : pointer truncation from 'unsigned char *' to 'long' Callback.xs(597) : warning C4311: 'type cast' : pointer truncation from 'SV *' to 'int' Callback.xs(623) : warning C4018: '<' : signed/unsigned mismatch Callback.xs(630) : warning C4244: '=' : conversion from '__w64 int' to 'unsigned int', possible loss of data Callback.xs(637) : warning C4311: 'type cast' : pointer truncation from 'int *__w64 ' to 'int' Callback.xs(680) : warning C4244: '=' : conversion from '__w64 int' to 'unsigned int', possible loss of data Callback.xs(687) : warning C4311: 'type cast' : pointer truncation from 'int *__w64 ' to 'int' Callback.xs(731) : warning C4244: '=' : conversion from '__w64 int' to 'unsigned int', possible loss of data Callback.xs(738) : warning C4311: 'type cast' : pointer truncation from 'int *__w64 ' to 'int' Callback.xs(784) : warning C4244: '=' : conversion from '__w64 int' to 'unsigned int', possible loss of data Callback.xs(847) : warning C4244: '=' : conversion from 'IV' to 'int', possible loss of data Callback.xs(864) : warning C4244: '=' : conversion from 'IV' to 'int', possible loss of data Callback.xs(868) : warning C4311: 'type cast' : pointer truncation from 'unsigned char *' to 'unsigned int' Callback.xs(896) : warning C4311: 'type cast' : pointer truncation from 'SV *' to 'int' Running Mkbootstrap for Win32::API::Callback () C:\Progs\perl5121-ap1201\bin\perl.exe -MExtUtils::Command -e "chmod" -- 644 Callback.bs C:\Progs\perl5121-ap1201\bin\perl.exe -MExtUtils::Mksymlists -e "Mksymlists('NAME'=>\"Win32::API::Callback\", 'DLBASE' => 'Callback', 'DL_FUNCS' => { }, 'FUNCLIST' => [], 'IMPORTS' => { }, 'DL_VARS' => []);" link -out:..\blib\arch\auto\Win32\API\Callback\Callback.dll -dll -nologo -nodefaultlib -debug -opt:ref,icf -ltcg -libpath:"C:\Progs\perl5121-ap1201\lib\CORE" -machine:AMD64 Callback.obj C:\Progs\perl5121-ap1201\lib\CORE\perl512.lib oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib bufferoverflowU.lib msvcrt.lib -def:Callback.def Callback.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' ---- END ---- Putting that aside, do you have the output of the failing test?
Different results with git @ 57d1ec7 Show quoted text
---- BEGIN ---- Microsoft (R) Program Maintenance Utility Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. cp Type.pm blib\lib\Win32/API/Type.pm cp Test.pm blib\lib\Win32/API/Test.pm cp Struct.pm blib\lib\Win32/API/Struct.pm cp API.pm blib\lib\Win32/API.pm C:\PROGRA~2\MICROS~1.0\VC\BIN\nmake.exe -f Makefile all -nologo cd .. C:\Progs\perl5121-ap1201\bin\perl.exe C:\Progs\perl5121-ap1201\lib\ExtUtils\xsubpp -typemap C:\Progs\perl5121-ap1201\lib\ExtUtils\typemap -typemap typemap API.xs > API.xsc && C:\Progs\perl5121-ap1201\bin\perl.exe -MExtUtils::Command -e "mv" -- API.xsc API.c cl -c -nologo -GF -W3 -MD -Zi -DNDEBUG -Ox -GL -Wp64 -fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DWIN64 -DCONSERVATIVE -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -MD -Zi -DNDEBUG -Ox -GL -Wp64 -fp:precise -DVERSION=\"0.60_64\" -DXS_VERSION=\"0.60_64\" "-IC:\Progs\perl5121-ap1201\lib\CORE" API.c cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release API.c C:\Progs\perl5121-ap1201\lib\CORE\sys/socket.h(34) : warning C4005: 'ENOTSOCK' : macro redefinition C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\errno.h(120) : see previous definition of 'ENOTSOCK' c:\users\ikegami\desktop\cosimo-perl5-win32-api-57d1ec7\call_i686.h(183) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. API.xs(108) : warning C4311: 'type cast' : pointer truncation from 'FARPROC' to 'long_ptr' API.xs(187) : warning C4311: 'type cast' : pointer truncation from 'char *' to 'long_ptr' API.xs(204) : warning C4312: 'type cast' : conversion from 'long_ptr' to 'char *' of greater size API.xs(277) : warning C4244: '=' : conversion from 'IV' to 'long_ptr', possible loss of data API.xs(392) : warning C4244: '=' : conversion from 'IV' to 'long_ptr', possible loss of data API.xs(236) : warning C4101: 'words_pushed' : unreferenced local variable ml64 -c call_asm_x64_msvc.asm 'ml64' is not recognized as an internal or external command, operable program or batch file. NMAKE : fatal error U1077: 'ml64' : return code '0x1' Stop. ---- END ---- Don't know if it's because something changed, or if it's because I'm missing some tools.
RT-Send-CC: ikegami [...] adaelis.com
On Mon Jul 12 17:56:02 2010, ikegami wrote: Show quoted text
> Different results with git @ 57d1ec7 > > ---- BEGIN ---- > Microsoft (R) Program Maintenance Utility Version 10.00.30319.01 > Copyright (C) Microsoft Corporation. All rights reserved. > > [...] > > API.xs(236) : warning C4101: 'words_pushed' : unreferenced local
variable Show quoted text
> ml64 -c call_asm_x64_msvc.asm > 'ml64' is not recognized as an internal or external command, operable > program or batch file. > NMAKE : fatal error U1077: 'ml64' : return code '0x1' > Stop. > ---- END ---- > > Don't know if it's because something changed, or if it's because I'm > missing some tools.
Yes, I think you need to copy your 64-bit ml.exe into ml64.exe for the linking to work correctly. Using a different name for the linker executable was done on purpose, IIRC. -- Cosimo
RT-Send-CC: dada [...] perl.it, ikegami [...] adaelis.com
On Tue Jul 13 12:48:56 2010, COSIMO wrote: Show quoted text
> On Mon Jul 12 17:56:02 2010, ikegami wrote:
> > Don't know if it's because something changed, or if it's because I'm > > missing some tools.
> > Yes, I think you need to copy your 64-bit ml.exe into ml64.exe for the > linking to work correctly. > Using a different name for the linker executable was done on purpose, > IIRC. >
Are there any issues left in this thread? I am planning to close this ticket soon as resolved unless any objections are brought up, since 0.72 does have a check for undef SV under has_proto, and then NULL.
RT-Send-CC: dada [...] perl.it, ikegami [...] adaelis.com
30 days no response, closing.