How to allocate and de-allocate memory for CFFI structure

Discussion in 'Python' started by ash4, Apr 15, 2016.

  1. ash4

    ash4

    Joined:
    Apr 15, 2016
    Messages:
    1
    Likes Received:
    0
    typedefstruct user{
    unsignedlong id;
    char*name;
    struct1 type;
    intPeriod;
    char*altername;
    char*description;
    struct2 state;
    struct3 *userDetails;
    }CUser;

    typedefstruct_CDeltaUser
    {
    CUser*deltaUser;
    struct3 *deletedUserDetails;
    struct3 *changedUserValues;}CDeltaUser;
    I am trying to create a object for this structure through CFFI and assign the values for the members and pass the created object to a API in C++.

    deltaUser = ffi.new("CDeltaUser*")

    deltaUser.deltaUser = ffi.new("CUser*")

    deltaUser.deltaUser.id=4
    Now when i try to pass this deltaUser to an API in C++ through the dll loaded using ffi.dlopenApiName(par1,par2,deltaUser,par4) python crashes at this point. crash occurs both in windows and Linux.

    What is wrong with this code ? I am using python2.7 and cffi 1.5.2

    on traceback gives the following log. Found that value is optimised

    in ffi_call (cif=0x7ffff1189260, fn=0x7ffff0488faa , rvalue=0x7ffff118e098, avalue=0x7ffff118e078) at src/x86/ffi64.c:484 in cdata_call (cd=0x7ffff118c0d0, args=0x7ffff7ee4310, kwds=) at c/_cffi_backend.c:2637 in PyObject_Call (func=0x7ffff118c0d0, arg=, kw=) at Objects/abstract.c:2529 in do_call (f=, throwflag=) at Python/ceval.c:4239 call_function (f=, throwflag=) at Python/ceval.c:4044

    Thanks in advance.
     
    ash4, Apr 15, 2016
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green
    Replies:
    3
    Views:
    3,726
    Roedy Green
    Aug 14, 2003
  2. sks_cpp
    Replies:
    7
    Views:
    630
    Jerry Coffin
    Jul 4, 2003
  3. Curt
    Replies:
    37
    Views:
    1,519
    Alexander Terekhov
    Jul 26, 2003
  4. OlgaM
    Replies:
    1
    Views:
    613
    Mike Wahler
    Oct 10, 2003
  5. pra_ramli@rediffmail.com

    Memory allocation in Structure to Structure

    pra_ramli@rediffmail.com, Mar 8, 2006, in forum: C++
    Replies:
    2
    Views:
    782
    pra_ramli@rediffmail.com
    Mar 9, 2006
  6. Dmytro Bablinyuk
    Replies:
    4
    Views:
    613
    peter koch
    Sep 5, 2006
  7. dtschoepe@gmail.com

    Allocate memory to char * variables in structure

    dtschoepe@gmail.com, Mar 5, 2007, in forum: C Programming
    Replies:
    17
    Views:
    1,369
    Flash Gordon
    Mar 6, 2007
  8. Eric Frederich
    Replies:
    0
    Views:
    198
    Eric Frederich
    Oct 10, 2013
Loading...