logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

FFI::Platypus::Type::PointerSizeBuffer - Convert string scalar to a buffer as a pointer / size_t

Author

       Author: Graham Ollis <plicease@cpan.org>

       Contributors:

       Bakkiaraj Murugesan (bakkiaraj)

       Dylan Cali (calid)

       pipcet

       Zaki Mughal (zmughal)

       Fitz Elliott (felliott)

       Vickenty Fesunov (vyf)

       Gregor Herrmann (gregoa)

       Shlomi Fish (shlomif)

       Damyan Ivanov

       Ilya Pavlov (Ilya33)

       Petr Písař (ppisar)

       Mohammad S Anwar (MANWAR)

       Håkon Hægland (hakonhagland, HAKONH)

       Meredith (merrilymeredith, MHOWARD)

       Diab Jerius (DJERIUS)

       Eric Brine (IKEGAMI)

       szTheory

       José Joaquín Atria (JJATRIA)

       Pete Houston (openstrike, HOUSTON)

       Lukas Mai (MAUKE)

Description

       A common pattern in C code is to pass in a region of memory as a buffer, consisting of a pointer and a
       size of the memory region.  In Perl, string scalars also point to a contiguous series of bytes that has a
       size, so when interfacing with C libraries it is handy to be able to pass in a string scalar as a pointer
       / size buffer pair.

Name

       FFI::Platypus::Type::PointerSizeBuffer - Convert string scalar to a buffer as a pointer / size_t
       combination

See Also

       FFI::Platypus
           Main Platypus documentation.

       FFI::Platypus::Type
           Platypus types documentation.

Synopsis

       In your C code:

        void
        function_with_buffer(void *pointer, size_t size)
        {
          ...
        }

       In your Platypus::FFI code:

        use FFI::Platypus 2.00;

        my $ffi = FFI::Platypus->new( api => 2 );
        $ffi->load_custom_type('::PointerSizeBuffer' => 'buffer');

        $ffi->attach(function_with_buffer => ['buffer'] => 'void');
        my $string = "content of buffer";
        function_with_buffer($string);

Version

       version 2.10

See Also