cvsuser     04/02/09 07:54:51

  Modified:    src      interpreter.c nci_test.c
               t/pmc    nci.t
  Log:
  pdd16-4
  * fix and test int external data
  
  Revision  Changes    Path
  1.265     +18 -8     parrot/src/interpreter.c
  
  Index: interpreter.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/interpreter.c,v
  retrieving revision 1.264
  retrieving revision 1.265
  diff -u -w -r1.264 -r1.265
  --- interpreter.c     9 Feb 2004 14:47:04 -0000       1.264
  +++ interpreter.c     9 Feb 2004 15:54:46 -0000       1.265
  @@ -1,7 +1,7 @@
   /*
   ################################################################################
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: interpreter.c,v 1.264 2004/02/09 14:47:04 leo Exp $
  +$Id: interpreter.c,v 1.265 2004/02/09 15:54:46 leo Exp $
   ################################################################################
   
   =head1 NAME
  @@ -1336,7 +1336,7 @@
       STRING* sig_str;
       char *p;
       char pasm_sig[4];
  -    FLOATVAL d_param;
  +    FLOATVAL* d_param;
       INTVAL   i_param;
       void*    param;
   
  @@ -1355,25 +1355,35 @@
           case 'v':
               pasm_sig[2] = 'v';
               break;
  +#if 0
           case '2':
           case '3':
           case '4':
  +#endif
           case 'l':
  +            i_param = (INTVAL)(long) ext;
  +            goto case_I;
           case 'i':
  +            i_param = (INTVAL)(int) ext;
  +            goto case_I;
           case 's':
  +            i_param = (INTVAL)(short)(int) ext;
  +            goto case_I;
           case 'c':
  +            i_param = (INTVAL)(char)(int)ext;
  +case_I:
               pasm_sig[2] = 'I';
  -            i_param = *(INTVAL*) ext;
  -            param = &i_param;
  +            param = (void*) i_param;
               break;
  +#if 0
           case 'f':
           case 'd':
  -            pasm_sig[2] = 'N';
  -            d_param = *(FLOATVAL*) ext;
  -            param = &d_param;
  +            /* these types don't fit into a pointer, they will not
  +             * work
  +             */
               break;
  -#if 0
           case 'p':
  +            /* TODO created UnManagedStruct */
           case 'P':
               pasm_sig[2] = 'P';
               break;
  
  
  
  1.22      +10 -0     parrot/src/nci_test.c
  
  Index: nci_test.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/nci_test.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -w -r1.21 -r1.22
  --- nci_test.c        9 Feb 2004 14:47:05 -0000       1.21
  +++ nci_test.c        9 Feb 2004 15:54:47 -0000       1.22
  @@ -22,6 +22,8 @@
   
   typedef void (*cb_C1_func)(const char*, void*);
   void nci_cb_C1(cb_C1_func, void*);
  +typedef void (*cb_C2_func)(int, void*);
  +void nci_cb_C2(cb_C2_func, void*);
   
   typedef void (*cb_D1_func)(void*, const char*);
   void nci_cb_D1(cb_D1_func, void*);
  @@ -238,6 +240,14 @@
       /* call the cb synchronously */
       (cb)(result, user_data);
   }
  +
  +void
  +nci_cb_C2(cb_C2_func cb, void* user_data)
  +{
  +    /* call the cb synchronously */
  +    (cb)(77, user_data);
  +}
  +
   
   void
   nci_cb_D1(cb_D1_func cb, void* user_data)
  
  
  
  1.32      +58 -1     parrot/t/pmc/nci.t
  
  Index: nci.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/nci.t,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -w -r1.31 -r1.32
  --- nci.t     9 Feb 2004 14:47:07 -0000       1.31
  +++ nci.t     9 Feb 2004 15:54:51 -0000       1.32
  @@ -1,4 +1,4 @@
  -use Parrot::Test tests => 28;
  +use Parrot::Test tests => 29;
   use Parrot::Config;
   
   print STDERR $PConfig{jitcpuarch}, " JIT CPU\n";
  @@ -934,6 +934,63 @@
   in callback
   user data: 42
   external data: succeeded
  +done.
  +OUTPUT
  +
  +output_is(<<'CODE', <<'OUTPUT', "nci_cb_C2");
  +  # we need a flag if the call_back is already done
  +  new P10, .PerlInt
  +  store_global "cb_done", P10
  +  # first attempt - create cb manually (this step will be hidden later)
  +  newsub P6, .Sub, _call_back
  +  # prepare user data
  +  new P7, .PerlInt
  +  set P7, 42
  +  new_callback P5, P6, P7, "iU"      # Z in pdd16
  +  print "ok 1\n"
  +  # now call the external sub, that takes a call_back and user_data
  +  loadlib P1, "libnci"
  +  dlfunc P0, P1, "nci_cb_C2", "vpP"
  +  print "ok 2\n"
  +  # P5 is the cb
  +  # P6 is user_data - the Sub
  +  invoke
  +  # call_back will be called at any time
  +  # so spin a bit
  +  set I20, 0
  +loop:
  +  inc I20
  +  sleep 0.01
  +  find_global P11, "cb_done"
  +  if P11, fin
  +  gt I20, 10, err
  +  branch loop
  +fin:
  +  print "done.\n"
  +  end
  +err:
  +  print "cb didnt run\n"
  +  end
  +
  +_call_back:
  +  print "in callback\n"
  +  print "user data: "
  +  print P5
  +  print "\n"
  +  print "external data: "
  +  print I5
  +  print "\n"
  +  find_global P12, "cb_done"
  +  inc P12
  +  invoke P1
  +
  +
  +CODE
  +ok 1
  +ok 2
  +in callback
  +user data: 42
  +external data: 77
   done.
   OUTPUT
   } # SKIP
  
  
  

Reply via email to