Author: nickg
Date: Fri Jan 13 08:50:39 2006
New Revision: 11150

Added:
   branches/nci/config/inter/nci/nci_libffi.in
Modified:
   branches/nci/config/inter/nci.pm
   branches/nci/config/inter/nci/nci_ffcall.in
Log:
NCI #8. Add config test for libffi and add a return argument to ffcall test.


Modified: branches/nci/config/inter/nci.pm
==============================================================================
--- branches/nci/config/inter/nci.pm    (original)
+++ branches/nci/config/inter/nci.pm    Fri Jan 13 08:50:39 2006
@@ -8,7 +8,9 @@ config/inter/nci.pm - Determine which NC
 =head1 DESCRIPTION
 
 Determines whether to use the builtin NCI implementation, or one provided
-by ffcall.
+by ffcall or libffi.
+
+The favoured order is ffcall, liffi, builtin.
 
 =cut
 
@@ -33,6 +35,19 @@ sub runstep
 
     my @nci_implementations = ('builtin');
 
+
+    cc_gen('config/inter/nci/nci_libffi.in');
+
+    eval { cc_build('', '-lffi'); };
+
+    if (! $@) {
+        my $test = cc_run ();
+
+        unshift @nci_implementations, 'libffi'
+            if $test eq "Received: It worked!\nGot back -24\n";
+    }
+
+
     cc_gen('config/inter/nci/nci_ffcall.in');
 
     eval { cc_build('', '-lavcall -lcallback'); };
@@ -41,7 +56,7 @@ sub runstep
         my $test = cc_run ();
 
         unshift @nci_implementations, 'ffcall'
-            if $test eq 'Received: It worked!';
+            if $test eq "Received: It worked!\nGot back -24\n";
     }
 
     my $nci_implementation = $nci_implementations[0];
@@ -61,6 +76,8 @@ sub runstep
 
       * ffcall: Requires the ffcall library, and is more functional
 
+      * libffi: Requires the libffi library, and is more functional
+
 END
         $nci_implementation = 
             prompt ("\nWhich NCI implementation shall I use? (" .

Modified: branches/nci/config/inter/nci/nci_ffcall.in
==============================================================================
--- branches/nci/config/inter/nci/nci_ffcall.in (original)
+++ branches/nci/config/inter/nci/nci_ffcall.in Fri Jan 13 08:50:39 2006
@@ -1,22 +1,25 @@
 /* Test to determine if ffcall is available for NCI */
 
+#include <stdio.h>
 #include <avcall.h>
 
-void function (char * str)
+int function (char * str)
 {
-  printf ("Received: %s", str);
-
+  printf ("Received: %s\n", str);
+  return -24;
 }
 
 int main ()
 {
+  int rc;
   av_alist alist;
 
   char* message = "It worked!";
 
-  av_start_void (alist, &function);
+  av_start_int (alist, &function, &rc);
   av_ptr (alist, char *, message);
 
   av_call (alist);
 
+  printf ("Got back %d\n", rc);
 }

Added: branches/nci/config/inter/nci/nci_libffi.in
==============================================================================
--- (empty file)
+++ branches/nci/config/inter/nci/nci_libffi.in Fri Jan 13 08:50:39 2006
@@ -0,0 +1,36 @@
+/* Test to determine if libffi is available for NCI */
+
+#include <stdio.h>
+#include <ffi.h>
+
+int function (char * str)
+{
+  printf ("Received: %s\n", str);
+  return -24;
+
+}
+
+int main ()
+{
+  ffi_cif cif;
+  ffi_type *args[1];
+  void *values[1];
+  char *s;
+  int rc;
+      
+  /* Initialize the argument info vectors */    
+  args[0] = &ffi_type_uint;
+  values[0] = &s;
+      
+  /* Initialize the cif */
+  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 
+                   &ffi_type_uint, args) == FFI_OK)
+    {
+      s = "It worked!";
+      ffi_call(&cif, function, &rc, values);
+
+      printf ("Got back %d\n", rc);
+    }
+      
+  return 0;
+}

Reply via email to