[svn:parrot] r42377 - in trunk: src t/pmc tools/build

NotFound at svn.parrot.org NotFound at svn.parrot.org
Mon Nov 9 00:35:42 UTC 2009


Author: NotFound
Date: Mon Nov  9 00:35:40 2009
New Revision: 42377
URL: https://trac.parrot.org/parrot/changeset/42377

Log:
[nci] fix handling of null in 'p' type parameters and add tests for it

Modified:
   trunk/src/nci_test.c
   trunk/t/pmc/nci.t
   trunk/tools/build/nativecall.pl

Modified: trunk/src/nci_test.c
==============================================================================
--- trunk/src/nci_test.c	Sun Nov  8 22:19:53 2009	(r42376)
+++ trunk/src/nci_test.c	Mon Nov  9 00:35:40 2009	(r42377)
@@ -693,6 +693,8 @@
                 static int i = 55555;
                 return &i;
             }
+        case 10:
+            return NULL;
         default:
             fprintf(stderr, "unknown test number\n");
     }
@@ -1103,7 +1105,7 @@
     if (inOpaque)
         printf("got %d\n", inOpaque->x);
     else
-        printf("got null");
+        printf("got null\n");
 }
 
 /*

Modified: trunk/t/pmc/nci.t
==============================================================================
--- trunk/t/pmc/nci.t	Sun Nov  8 22:19:53 2009	(r42376)
+++ trunk/t/pmc/nci.t	Mon Nov  9 00:35:40 2009	(r42377)
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 70;
+use Parrot::Test tests => 71;
 use Parrot::Config qw(%PConfig);
 
 =head1 NAME
@@ -1355,6 +1355,31 @@
 31
 OUTPUT
 
+    pir_output_is( << 'CODE', << "OUTPUT", "nci_pi - null" );
+
+.include "datatypes.pasm"
+
+.sub test :main
+
+  # load library
+  .local pmc libnci_test
+  libnci_test = loadlib "libnci_test"
+  unless libnci_test goto FAILED
+
+  # calling a function in libnci_test
+  .local pmc nci_pi
+  dlfunc nci_pi, libnci_test, "nci_pi", "pi"
+  .local pmc result
+  result = nci_pi( 10 )
+  unless_null result, FAILED
+  print "got null"
+FAILED:
+  print "\n"
+.end
+CODE
+got null
+OUTPUT
+
     pasm_output_is( <<'CODE', <<'OUTPUT', "nci_vP" );
   loadlib P1, "libnci_test"
   dlfunc P0, P1, "nci_vP", "vP"
@@ -2660,12 +2685,16 @@
     nci_vp = dlfunc libnci_test, "nci_vp", "vp"
 
     .local pmc opaque
+    null opaque
+    nci_vp(opaque)
+
     opaque = new ['Pointer']
     $I0 = 10
     nci_vVi(opaque, $I0)
     nci_vp(opaque)
 .end
 CODE
+got null
 got 10
 OUTPUT
 

Modified: trunk/tools/build/nativecall.pl
==============================================================================
--- trunk/tools/build/nativecall.pl	Sun Nov  8 22:19:53 2009	(r42376)
+++ trunk/tools/build/nativecall.pl	Mon Nov  9 00:35:40 2009	(r42377)
@@ -41,9 +41,13 @@
 my %sig_table = (
     p => {
         as_proto => "void *",
-        other_decl => "PMC * const final_destination = pmc_new(interp, enum_class_UnManagedStruct);",
+        other_decl => "PMC * final_destination = PMCNULL;",
         sig_char => "P",
-        ret_assign => "VTABLE_set_pointer(interp, final_destination, return_data);\n    Parrot_pcc_fill_returns_from_c_args(interp, call_object, \"P\", final_destination);",
+        ret_assign => "if (return_data != NULL) {\n" .
+             "        final_destination = pmc_new(interp, enum_class_UnManagedStruct);\n" .
+             "        VTABLE_set_pointer(interp, final_destination, return_data);\n" .
+             "    }\n" .
+             "    Parrot_pcc_fill_returns_from_c_args(interp, call_object, \"P\", final_destination);",
     },
     i => { as_proto => "int",    sig_char => "I" },
     l => { as_proto => "long",   sig_char => "I" },
@@ -257,7 +261,7 @@
     /p/ && do {
         push @{$temps_ref},       "PMC *t_$temp_num;";
         push @{$fill_params_ref}, "&t_$temp_num";
-        return "VTABLE_get_pointer(interp, t_$temp_num)";
+        return "PMC_IS_NULL((PMC*)t_$temp_num)? (void*)NULL:VTABLE_get_pointer(interp, t_$temp_num)";
     };
     /V/ && do {
         push @{$temps_ref},          "PMC *t_$temp_num;";


More information about the parrot-commits mailing list