Giter Club home page Giter Club logo

ffi-c's People

Contributors

kohaaloha avatar plicease avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ffi-c's Issues

t/ffi_c_util.t fails with -Duselongdouble

If perl was compiled with -Duselongdouble, then the test suite fails:

        # Failed test 'c_to_perl'
        # at t/ffi_c_util.t line 122.
        # +-------------+---------------------+----+-------+
        # | PATH        | GOT                 | OP | CHECK |
        # +-------------+---------------------+----+-------+
        # | {y}[1]{baz} | 8.80000000000000071 | eq | 8.8   |
        # +-------------+---------------------+----+-------+
    # Failed test 'generated classes'
    # at t/ffi_c_util.t line 135.
        # Failed test 'c_to_perl'
        # at t/ffi_c_util.t line 180.
        # +-------------+---------------------+----+-------+
        # | PATH        | GOT                 | OP | CHECK |
        # +-------------+---------------------+----+-------+
        # | {y}[1]{baz} | 8.80000000000000071 | eq | 8.8   |
        # +-------------+---------------------+----+-------+
    # Failed test 'ungenerated types'
    # at t/ffi_c_util.t line 194.

# Failed test 'perl_to_c / c_to_perl'
# at t/ffi_c_util.t line 196.
t/ffi_c_util.t ....... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests 

Create FFI::C::Array with preexisting objects rather than hash references

I'm trying to find a way to pass an array of ::Struct based objects into a newly created ::Array. Here's an example of my goal based on the synopsis from FFI::C::Array:

    use FFI::C::ArrayDef;
    use FFI::C::StructDef;
 
    my $point_def = FFI::C::StructDef->new(
      name  => 'point_t',
      class => 'Point',
      members => [
        x => 'double',
        y => 'double',
      ],
    );
     
    my $rect_def = FFI::C::ArrayDef->new(
      name    => 'rectangle_t',
      class   => 'Rectangle',
      members => [
        $point_def, 2,
      ]
    );
    
    # create a rectangle using the def's create method
    my $square = $rect_def->create([
       Point->new( {x => 1.0, y => 1.0} ), # Obtained somehow as full objects...
       Point->new( {x => 2.0, y => 2.0} )  # ...rather than hash references
    ]);
    
    printf "[[%d %d][%d %d]]\n",
      $square->[0]->x, $square->[0]->y,
      $square->[1]->x, $square->[1]->y;   # [[1 1][2 2]]

In my project, I would have these Point objects returned from C by yet another attached function. My only solution to FFI::C::Util::perl_to_c(...) croaking on this is to map { ... } the objects back to plain hash references and let FFI::C::Def instantiate brand new objects with the exposed data (this would break on complex C objects). Before I start looking for a place to do this quickly and cleanly enough for a PR (maybe), am I missing something obvious?

util function to convert to perl

The init util function takes perl data structures and initializes the members of an instance object. It would be helpful, if for nothing else debugging, to be able to do the reverse. That is, given an instance object, return the nested perl data structure that could re-init a new object. It's not ever going to be completely round-trip safe because of anonymous members and the fact that init doesn't write unspecified members, but it is probably good enough.

undefined or unsupported type: string at

How can I use string for char *?

  FFI::C::StructDef->new(
    $ffi,
    nullable =>  1,
    name     =>  'SDL_RendererInfo',
    class    =>  'SDL2::RendererInfo',
    members  =>  [
      name                =>  'string',
      flags               =>  'uint32',
      num_texture_formats =>  'uint32',
      texture_formats     =>  'uint32[16]',
      max_texture_width   =>  'int',
      max_texture_height  =>  'int',
    ],
  );
/**
 *  \brief Information on the capabilities of a render driver or context.
 */
typedef struct SDL_RendererInfo
{
    const char *name;           /**< The name of the renderer */
    Uint32 flags;               /**< Supported ::SDL_RendererFlags */
    Uint32 num_texture_formats; /**< The number of available texture formats */
    Uint32 texture_formats[16]; /**< The available texture formats */
    int max_texture_width;      /**< The maximum texture width */
    int max_texture_height;     /**< The maximum texture height */
} SDL_RendererInfo;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.