XS PPCODE not behaving -


i'm working on calling third-party dll perl project using xs, under cygwin on windows using g++. 1 of dll functions takes struct argument , returns main results in pointer struct. pass in flat list of 28 integers , populate first struct. call function. want flatten resulting struct list of 54 integers.

(this seems lot of integers, dll function quite complex , takes long time run, think it's worth it. unless has better idea?)

this close working. can tell results sensible. there 2 bizarre problems.

  1. when print out same variables, different results depending on whether it's in 'for' loop or not! show below. i've stared @ long now.

  2. i "out of memory" first xpushs.

here xs code.

#include "extern.h" #include "perl.h" #include "xsub.h" #include "ppport.h" #include "dll.h"  module = bridge::solver::dds_if package = bridge::solver::dds_if  prototypes: enable  void solveboard(inlist) sv * inlist init:   struct deal dl;   struct futuretricks fut;   int    target, solutions, mode, thrid;   int    i, j, ret;   if ((! svrok(inlist)) ||     (svtype(svrv(inlist)) != svt_pvav) ||     av_len((av *) svrv(inlist)) != 27)   {     xsreturn_undef;   }   printf("new init ok\n"); ppcode:   dl.trump =               sviv(*av_fetch((av *)svrv(inlist),  0, 0));   dl.first =               sviv(*av_fetch((av *)svrv(inlist),  1, 0));   dl.currenttricksuit[0] = sviv(*av_fetch((av *)svrv(inlist),  2, 0));   dl.currenttricksuit[1] = sviv(*av_fetch((av *)svrv(inlist),  3, 0));   dl.currenttricksuit[2] = sviv(*av_fetch((av *)svrv(inlist),  4, 0));   dl.currenttrickrank[0] = sviv(*av_fetch((av *)svrv(inlist),  5, 0));   dl.currenttrickrank[1] = sviv(*av_fetch((av *)svrv(inlist),  6, 0));   dl.currenttrickrank[2] = sviv(*av_fetch((av *)svrv(inlist),  7, 0));   dl.remaincards[0][0]   = svuv(*av_fetch((av *)svrv(inlist),  8, 0));   dl.remaincards[0][1]   = svuv(*av_fetch((av *)svrv(inlist),  9, 0));   dl.remaincards[0][2]   = svuv(*av_fetch((av *)svrv(inlist), 10, 0));   dl.remaincards[0][3]   = svuv(*av_fetch((av *)svrv(inlist), 11, 0));   dl.remaincards[1][0]   = svuv(*av_fetch((av *)svrv(inlist), 12, 0));   dl.remaincards[1][1]   = svuv(*av_fetch((av *)svrv(inlist), 13, 0));   dl.remaincards[1][2]   = svuv(*av_fetch((av *)svrv(inlist), 14, 0));   dl.remaincards[1][3]   = svuv(*av_fetch((av *)svrv(inlist), 15, 0));   dl.remaincards[2][0]   = svuv(*av_fetch((av *)svrv(inlist), 16, 0));   dl.remaincards[2][1]   = svuv(*av_fetch((av *)svrv(inlist), 17, 0));   dl.remaincards[2][2]   = svuv(*av_fetch((av *)svrv(inlist), 18, 0));   dl.remaincards[2][3]   = svuv(*av_fetch((av *)svrv(inlist), 19, 0));   dl.remaincards[3][0]   = svuv(*av_fetch((av *)svrv(inlist), 20, 0));   dl.remaincards[3][1]   = svuv(*av_fetch((av *)svrv(inlist), 21, 0));   dl.remaincards[3][2]   = svuv(*av_fetch((av *)svrv(inlist), 22, 0));   dl.remaincards[3][3]   = svuv(*av_fetch((av *)svrv(inlist), 23, 0));   target                 = sviv(*av_fetch((av *)svrv(inlist), 24, 0));   solutions              = sviv(*av_fetch((av *)svrv(inlist), 25, 0));   mode                   = sviv(*av_fetch((av *)svrv(inlist), 26, 0));   thrid                  = sviv(*av_fetch((av *)svrv(inlist), 27, 0));    ret = solveboard(dl, target, solutions, mode, &fut, thrid);    printf("return code %d\n", ret);   printf("nodes %d\n", fut.nodes);   printf("cards %d\n", fut.cards);    printf("%6s  %12s  %12s  %12s  %12s\n",     "", "suit", "rank", "equals", "score");   printf("%6d  %12d  %12d  %12d  %12d\n\n",     0, fut.suit[0], fut.rank[0], fut.equals[0], fut.score[0]);    (i = 0; < 13; i++)   {     printf("%6d  %12d  %12d  %12d  %12d\n",       i, fut.suit[i], fut.rank[i], fut.equals[i], fut.score[i]);   }    printf("\n%6d  %12d  %12d  %12d  %12d\n\n",     0, fut.suit[0], fut.rank[0], fut.equals[0], fut.score[0]);    printf("trying push nodes\n");   xpushs(sv_2mortal(newsviv(fut.nodes)));    printf("trying push cards\n");   xpushs(sv_2mortal(newsviv(fut.cards)));    printf("trying loop\n");   (i = 0; <= 12; i++)   {     xpushs(sv_2mortal(newsviv(fut.suit  [i])));     xpushs(sv_2mortal(newsviv(fut.rank  [i])));     xpushs(sv_2mortal(newsviv(fut.equals[i])));     xpushs(sv_2mortal(newsviv(fut.score [i])));   }    printf("done looping\n"); 

here relevant part of dll header file.

struct futuretricks  {   int nodes;   int cards;   int suit[13];   int rank[13];   int equals[13];   int score[13]; };  struct deal  {   int trump;   int first;   int currenttricksuit[3];   int currenttrickrank[3];   unsigned int remaincards[4][4]; };   extern "c" int solveboard(   struct deal dl,    int target,    int solutions,    int mode,    struct futuretricks *futp,    int threadindex); 

and here output. return code ok. nodes , cards not. if squint, might notice 0 , 768 occur within output table, maybe there's kind of offset going on.

the first bizarre thing 2 '0' lines before , after main table different '0' line in main table. data in main table expected, though, including garbage in lines 10-12.

the second problem xpushs doesn't intended.

new init ok return code 1 nodes 0 cards 768                 suit          rank        equals         score      0             0             2   -2147319000   -2147296756       0             2             2             0             2      1             2             6             0             2      2             2            10           768             2      3             2            13             0             2      4             3            14             0             2      5             0             6             0             1      6             0            10           512             1      7             0            13             0             1      8             3             4             0             0      9             3            11             0             0     10    1773292640   -2147056120             4   -2147319000     11    1772354411             0   -2146989552   -2146837752     12          8192            35       2665016   -2147319000       0             0             2   -2147319000   -2147296756  trying push nodes out of memory! 

with offset problem, there may because perl messes pretty bad c variable definitions.

including dll.h before others solve that.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -