Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
brew install libffi
brew install jq
curl https://cpanmin.us | perl - App::cpanminus -n
echo "##[add-path]/Users/runner/perl5/bin"
echo "/Users/runner/perl5/bin" >> $GITHUB_PATH

- name: perl -V
run: perl -V
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ jobs:
- name: Set up Perl
run: |
choco install strawberryperl
echo "##[add-path]C:\cx\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin"
echo "C:\cx\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\strawberry\c\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\strawberry\perl\site\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\strawberry\perl\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: perl -V
run: perl -V
- name: Install Static Dependencies
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FFI::C [![Build Status](https://travis-ci.org/PerlFFI/FFI-C.svg)](http://travis-ci.org/PerlFFI/FFI-C) ![windows](https://github.com/PerlFFI/FFI-C/workflows/windows/badge.svg) ![macos](https://github.com/PerlFFI/FFI-C/workflows/macos/badge.svg)
# FFI::C [![Build Status](https://api.travis-ci.com/PerlFFI/FFI-C.svg?branch=main)](https://travis-ci.com/github/PerlFFI/FFI-C) ![windows](https://github.com/PerlFFI/FFI-C/workflows/windows/badge.svg) ![macos](https://github.com/PerlFFI/FFI-C/workflows/macos/badge.svg)

C data types for FFI

Expand Down Expand Up @@ -265,6 +265,7 @@ So-called "pass-by-value" is not and will not be supported. For
- [FFI::C::Def](https://metacpan.org/pod/FFI::C::Def)
- [FFI::C::File](https://metacpan.org/pod/FFI::C::File)
- [FFI::C::PosixFile](https://metacpan.org/pod/FFI::C::PosixFile)
- [FFI::C::String](https://metacpan.org/pod/FFI::C::String)
- [FFI::C::Struct](https://metacpan.org/pod/FFI::C::Struct)
- [FFI::C::StructDef](https://metacpan.org/pod/FFI::C::StructDef)
- [FFI::C::Union](https://metacpan.org/pod/FFI::C::Union)
Expand Down
4 changes: 4 additions & 0 deletions author.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pod_spelling_system:
stopwords:
- ffi
- nullable
- endianness
- libc
- CPU
- WTF

pod_coverage:
skip: 0
Expand Down
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ github_user = PerlFFI
test2_v0 = 1
workflow = windows
workflow = macos
travis_com = 1
irc = irc://irc.perl.org/#native
diag = +Math::Int64

Expand Down
5 changes: 5 additions & 0 deletions examples/synopsis/string.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use strict;
use warnings;
use FFI::C::String;

# TODO
2 changes: 2 additions & 0 deletions lib/FFI/C.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ So-called "pass-by-value" is not and will not be supported. For

=item L<FFI::C::PosixFile>

=item L<FFI::C::String>

=item L<FFI::C::Struct>

=item L<FFI::C::StructDef>
Expand Down
4 changes: 3 additions & 1 deletion lib/FFI/C/Array.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use overload

# EXAMPLE: examples/synopsis/array.pl

=head2 DESCRIPTION
=head1 DESCRIPTION

This class represents an instance of a C an array. This class can be created using
C<new> on the generated class, if that was specified for the L<FFI::C::ArrayDef>,
Expand Down Expand Up @@ -139,6 +139,8 @@ sub CLEAR

=item L<FFI::C::PosixFile>

=item L<FFI::C::String>

=item L<FFI::C::Struct>

=item L<FFI::C::StructDef>
Expand Down
2 changes: 2 additions & 0 deletions lib/FFI/C/ArrayDef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ sub create

=item L<FFI::C::PosixFile>

=item L<FFI::C::String>

=item L<FFI::C::Struct>

=item L<FFI::C::StructDef>
Expand Down
2 changes: 2 additions & 0 deletions lib/FFI/C/Def.pm
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ sub rev { shift->{rev} }

=item L<FFI::C::PosixFile>

=item L<FFI::C::String>

=item L<FFI::C::Struct>

=item L<FFI::C::StructDef>
Expand Down
52 changes: 30 additions & 22 deletions lib/FFI/C/FFI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package FFI::C::FFI;
use strict;
use warnings;
use FFI::Platypus 1.24;
use constant ();
use base qw( Exporter );

# ABSTRACT: Private module for FFI::C
Expand All @@ -20,28 +21,33 @@ This module is private for L<FFI::C>

our @EXPORT_OK = qw( malloc free memset memcpy_addr );

my $ffi;
BEGIN { $ffi = FFI::Platypus->new( api => 1, lib => [undef] ) };

use constant memcpy_addr => FFI::Platypus->new( lib => [undef] )->find_symbol( 'memcpy' );

sub malloc ($)
{
$ffi->function( malloc => ['size_t'] => 'opaque' )
->call(@_);
}

sub free ($)
{
$ffi->function( free => ['opaque'] => 'void' )
->call(@_);
}

sub memset ($$$)
{
$ffi->function( memset => ['opaque','int','size_t'] => 'opaque' )
->call(@_);
}
my $ffi = FFI::Platypus->new( api => 1, lib => [undef] );

constant->import( memcpy_addr => $ffi->find_symbol( 'memcpy' ) );

$ffi->attach( malloc => ['size_t'] => 'opaque', '$' );
$ffi->attach( free => ['opaque'] => 'void', '$' );
$ffi->attach( memset => ['opaque','int','size_t'] => 'opaque', '$$$' );
$ffi->attach( memcpy => ['opaque','string','size_t'] => 'opaque', '$$$' );

## should this be configurable for when we hunt for memory leaks?
#sub malloc ($)
#{
# $ffi->function( malloc => ['size_t'] => 'opaque' )
# ->call(@_);
#}
#
#sub free ($)
#{
# $ffi->function( free => ['opaque'] => 'void' )
# ->call(@_);
#}
#
#sub memset ($$$)
#{
# $ffi->function( memset => ['opaque','int','size_t'] => 'opaque' )
# ->call(@_);
#}

1;

Expand All @@ -61,6 +67,8 @@ sub memset ($$$)

=item L<FFI::C::PosixFile>

=item L<FFI::C::String>

=item L<FFI::C::Struct>

=item L<FFI::C::StructDef>
Expand Down
2 changes: 2 additions & 0 deletions lib/FFI/C/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ sub DESTROY

=item L<FFI::C::PosixFile>

=item L<FFI::C::String>

=item L<FFI::C::Struct>

=item L<FFI::C::StructDef>
Expand Down
4 changes: 3 additions & 1 deletion lib/FFI/C/PosixFile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use base qw( FFI::C::File );
=head1 SYNOPSIS

use FFI::C::PosixFile;

my $stdout = FFI::C::PosixFile->fdopen(1, "w");
say $stdout->fileno; # prints 1

Expand Down Expand Up @@ -107,6 +107,8 @@ else

=item L<FFI::C::PosixFile>

=item L<FFI::C::String>

=item L<FFI::C::Struct>

=item L<FFI::C::StructDef>
Expand Down
Loading