2

I have to wrap this C function Abc_NtkCreateNodeAnd using Ruby:

Abc_Obj_t * Abc_NtkCreateNodeAnd( Abc_Ntk_t * pNtk, Vec_Ptr_t * vFanins )
{
  Abc_Obj_t * pNode;
  int i;
  assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsNetlist(pNtk) );
  pNode = Abc_NtkCreateNode( pNtk );   
  for ( i = 0; i < vFanins->nSize; i++ )
    Abc_ObjAddFanin( pNode, (Abc_Obj_t *)vFanins->pArray[i] );
    if ( Abc_NtkHasSop(pNtk) )
      pNode->pData = Abc_SopCreateAnd( (Mem_Flex_t *)pNtk->pManFunc, Vec_PtrSize(vFanins), NULL );
    else if ( Abc_NtkHasBdd(pNtk) )
      pNode->pData = Extra_bddCreateAnd( (DdManager *)pNtk->pManFunc, Vec_PtrSize(vFanins) ), Cudd_Ref((DdNode *)pNode->pData); 
    else if ( Abc_NtkHasAig(pNtk) )
      pNode->pData = Hop_CreateAnd( (Hop_Man_t *)pNtk->pManFunc, Vec_PtrSize(vFanins) ); 
    else
      assert( 0 );
  return pNode;
}

The code I wrote is:

static VALUE Abc_NtkCreateNode_And(VALUE self, VALUE netw ,VALUE vfan_ins)
{
  Abc_Ntk_t *netw_str;
  Vec_Ptr_t *vfan_ins_str;
  Data_Get_Struct(netw, Abc_Ntk_t, netw_str);
  Data_Get_Struct(vfan_ins, Abc_Ntk_t, vfan_ins_str );
  Abc_Obj_t *network = Abc_NtkCreateNodeAnd(netw_str,vfan_ins_str);
  return make_Network(network);
}

I want to pass the arguments using Ruby and directly call the C function. Is it possible to do so?

Neil Slater
  • 26,512
  • 6
  • 76
  • 94
Nuron
  • 109
  • 8
  • Re-reading your question, I am not sure what you are asking. Your code example looks fine (provided you have matching `Data_Wrap_Struct` etc), but not the complete story. Could you please add how you expect to invoke your method from Ruby, including how you construct the arguments. – Neil Slater Jul 11 '13 at 07:59
  • This article may be of some use. http://blog.firmhouse.com/wrapping-up-a-c-library-for-ruby-it-s-actually-pretty-easy – Max Woolf Jul 11 '13 at 08:16
  • Thanks for your replies.I have got it working. – Nuron Jul 11 '13 at 08:55

0 Answers0