FFI::Util - Some useful pointer utilities when writing FFI modules (Deprecated)
version 0.17
use FFI::Util;
Note: This module has largely been obsoleted by FFI::Platypus, which I recommend that you use instead of this module. This module may be removed from CPAN at a future date, but not before 31 January 2017.
This module provides some useful memory manipulation that is either difficult or impossible in pure Perl. It was originally intended to be used by Archive::Libarchive::FFI, but it may be useful in other projects.
my $path = locate_module_share_lib(); my $path = locate_module_share_lib($module_name, $module_filename);
Returns the path to the shared library for the current module, or the module specified by $module_name (example: Foo::Bar) $module_filename(example /full/path/Foo/Bar.pm).
$module_name
$module_filename
my($ptr, $size) = scalar_to_buffer $scalar;
Given a scalar string value, return a pointer to where the data is stored and the size of the scalar in bytes.
my $scalar = buffer_to_scalar($ptr, $size);
Given a pointer to a memory location and a size, construct a new scalar with the same content and size.
my $ptr2 = deref_ptr_get($ptr1);
equivalent to
void *ptr1; void *ptr2; *ptr2 = *ptr1;
deref_ptr_set($ptr1, $ptr2);
void **ptr1; void *ptr2; *ptr1 = ptr2;
my $string = deref_str_get($ptr);
const char *string; const char **ptr; string = *ptr;
deref_str_set($ptr, $string);
const char **ptr; const char *string; *ptr = string;
my $integer = deref_int_get($ptr);
int *ptr; int integer; integer = *ptr;
deref_int_set($ptr, $integer);
int *ptr; int integer; *ptr = integer;
my $unsigned_integer = deref_uint_get($ptr);
unsigned int unsigned_integer; unsigned int *ptr; unsigned_integer = *ptr;
deref_uint_set($ptr, $unsigned_integer);
unsigned int *ptr; unsigned int unsigned_integer; *ptr = unsigned_integer;
my $short_integer = deref_short_get($ptr);
short short_integer; short *ptr; short_integer = *ptr;
deref_short_set($ptr, $short_integer);
short *ptr; short short_integer; *ptr = short_integer;
my $unsigned_short_integer = deref_ushort_get($ptr);
unsigned short unsigned_short_integer; unsigned short *ptr; unsigned unsigned_short_integer = *ptr;
deref_ushort_set($ptr, $unsigned_short_integer);
unsigned short *ptr; unsigned short unsigned_short_integer; *ptr = unsigned_short_integer;
my $long_integer = deref_long_get($ptr);
long long_integer; long *ptr; long_integer = *ptr;
deref_long_set($ptr, $long_integer);
long *ptr; long long_integer; *ptr = long_integer;
my $unsigned_long_integer = deref_ulong_get($ptr);
unsigned long unsigned_long_integer; unsigned long *ptr; unsigned unsigned_long_integer = *ptr;
deref_ulong_set($ptr, $unsigned_long_integer);
unsigned long *ptr; unsigned long unsigned_long_integer; *ptr = unsigned_long_integer;
my $char_integer = deref_char_get($ptr);
char char_integer; char *ptr; char_integer = *ptr;
deref_char_set($ptr, $char_integer);
char *ptr; char char_integer; *ptr = char_integer;
my $unsigned_char_integer = deref_uchar_get($ptr);
unsigned char unsigned char_integer; unsigned char *ptr; unsigned_char_integer = *ptr;
deref_uchar_set($ptr, $unsigned_char_integer);
unsigned char *ptr; unsigned char unsigned_char_integer; *ptr = unsigned_char_integer;
my $single_float = deref_float_get($ptr);
float single_float; float *ptr; single_float = *ptr;
deref_float_set($ptr, $single_float);
float *ptr; float single_float; *ptr = single_float;
my $double_float = deref_double_get($ptr);
double double_float; double *ptr; double_float = *ptr;
deref_double_set($ptr, $double_float);
double *ptr; double double_float; *ptr = double_float;
my $int64 = deref_int64_get($ptr);
int64_t int64; int64_t *ptr; int64 = *ptr;
deref_int64_set($ptr, $int64);
int64_t *ptr; int64_t int64; *ptr = int64;
my $uint64 = deref_uint64_get($ptr);
uint64_t uint64; uint64_t *ptr; uint64 = *ptr;
deref_uint64_set($ptr, $uint64);
uint64_t *ptr; uint64_t uint64; *ptr = uint64;
Alias for appropriate derf_..._get if dev_t is provided by your compiler.
derf_..._get
Alias for appropriate derf_..._set if dev_t is provided by your compiler.
derf_..._set
Alias for appropriate derf_..._get if gid_t is provided by your compiler.
Alias for appropriate derf_..._set if gid_t is provided by your compiler.
Alias for appropriate derf_..._get if size_t is provided by your compiler.
Alias for appropriate derf_..._set if size_t is provided by your compiler.
Alias for appropriate derf_..._get if time_t is provided by your compiler.
Alias for appropriate derf_..._set if time_t is provided by your compiler.
Alias for appropriate derf_..._get if uid_t is provided by your compiler.
Alias for appropriate derf_..._set if uid_t is provided by your compiler.
Graham Ollis <plicease@cpan.org>
This software is copyright (c) 2013 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install FFI::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FFI::Util
CPAN shell
perl -MCPAN -e shell install FFI::Util
For more information on module installation, please visit the detailed CPAN module installation guide.