[seed] [mpfr] Start of mpfr module



commit 675321d80b0d710b3747de47ae7be573e420da97
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date:   Thu Jul 2 12:29:35 2009 -0400

    [mpfr] Start of mpfr module

 configure.ac             |   42 ++++++++++++++++++++++++++++++++
 modules/Makefile.am      |    2 +-
 modules/mpfr/Makefile.am |   24 ++++++++++++++++++
 modules/mpfr/mpfr.c      |   60 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 127 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f3f55eb..7b916a7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -267,6 +267,46 @@ AC_ARG_ENABLE(gettext-module,
 AM_CONDITIONAL(BUILD_GETTEXT_MODULE, test "x$want_gettext_module" = "xyes")
 AC_SUBST(BUILD_GETTEXT_MODULE)
 
+dnl ==== mpfr ====
+AC_ARG_ENABLE(mpfr-module,
+			  AC_HELP_STRING([--enable-mpfr-module],
+							 [enable the mpfr Seed module. [default=yes]]),
+			  [want_mpfr_module=$enableval],[want_mpfr_module="yes"])
+
+if test x"$want_mpfr_module" == x"yes" ; then
+	AC_MSG_CHECKING(for mpfr.h)
+
+	AC_TRY_CPP([#include <mpfr.h>], have_mpfr_h=yes, have_mpfr_h=no)
+	if test x"$have_mpfr_h" = x"yes"; then
+		save_LIBS=$LIBS
+		if test x"$with_mpfr" = x"yes" || test x"$with_mpfr" = x"auto"; then
+			other_LIBS=
+		else
+			other_LIBS=$with_mpfr
+		fi
+
+        #this section...I don't get what it's doing
+		AC_SEARCH_LIBS(mpfr_init2,mpfr,,AC_MSG_ERROR([mpfr not found]),$other_LIBS)
+		if test x"$ac_cv_search_mpfr_call" = x"none required" ; then
+			MPFR_LDFLAGS=$other_LIBS
+		else
+			MPFR_LDFLAGS="$other_LIBS"
+		fi
+		LIBS=$save_LIBS
+	fi
+	if test x"$have_mpfr_h" != x"yes" ; then
+		AC_MSG_ERROR([mpfr.h not found])
+	fi
+
+	MPFR_CFLAGS=
+
+	AC_MSG_RESULT([$have_mpfr_h])
+
+fi
+
+AM_CONDITIONAL(BUILD_MPFR_MODULE, test "x$want_mpfr_module" = "xyes")
+AC_SUBST(BUILD_MPFR_MODULE)
+
 dnl =========================turtle example====================================
 AC_ARG_ENABLE(turtle-example,
 			  AC_HELP_STRING([--enable-turtle-example],
@@ -424,6 +464,7 @@ modules/libxml/Makefile
 modules/cairo/Makefile
 modules/gtkbuilder/Makefile
 modules/gettext/Makefile
+modules/mpfr/Makefile
 
 libseed/seed-path.h
 ])
@@ -451,6 +492,7 @@ Modules:
    cairo......................$want_cairo_module
    gtkbuilder.................$want_gtkbuilder_module
    gettext....................$want_gettext_module
+   mpfr.......................$want_mpfr_module
 
 Examples:
    Turtle.....................$want_turtle_example
diff --git a/modules/Makefile.am b/modules/Makefile.am
index 9ec9bf8..3701ce9 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -1 +1 @@
-SUBDIRS = example sqlite canvas Multiprocessing readline os sandbox dbus libxml cairo gtkbuilder gettext
+SUBDIRS = example sqlite canvas Multiprocessing readline os sandbox dbus libxml cairo gtkbuilder gettext mpfr
diff --git a/modules/mpfr/Makefile.am b/modules/mpfr/Makefile.am
new file mode 100644
index 0000000..a70dab2
--- /dev/null
+++ b/modules/mpfr/Makefile.am
@@ -0,0 +1,24 @@
+if BUILD_MPFR_MODULE
+
+seedlibdir = ${libdir}/seed
+
+seedlib_LTLIBRARIES = \
+	libmpfr.la
+
+libgettext_la_SOURCES = \
+	mpfr.c
+
+AM_CPPFLAGS = \
+	-I top_srcdir@/libseed/ \
+	$(GOBJECT_INTROSPECTION_CFLAGS) 
+	$(SEED_DEBUG_CFLAGS) \
+	$(SEED_PROFILE_CFLAGS)
+
+libmpfr_la_LDFLAGS = \
+	$(GOBJECT_INTROSPECTION_LDFLAGS) \
+	$(SEED_PROFILE_LIBS)
+
+endif
+
+
+
diff --git a/modules/mpfr/mpfr.c b/modules/mpfr/mpfr.c
new file mode 100644
index 0000000..e55579a
--- /dev/null
+++ b/modules/mpfr/mpfr.c
@@ -0,0 +1,60 @@
+#include <seed.h>
+#include <mpfr.h>
+
+SeedObject ns_ref;
+SeedEngine * eng;
+
+static void
+seed_mpfr_init2 (SeedContext ctx,
+                 SeedObject function,
+                 SeedObject this_object,
+                 gsize arg_count,
+                 const SeedValue args[],
+                 SeedException * exception)
+{
+    mpfr_prec_t prec;
+    mpfr_ptr ptr;
+
+    if ( arg_count != 2 )
+    {
+        seed_make_exception (ctx, exception, "ArgumentError",
+                             "mpfr_init2 expected 2 arguments, got %zd",
+                             arg_count);
+        return seed_make_null (ctx);
+    }
+
+    ptr = seed_pointer_get_pointer(ctx, args[0]);
+
+    #if _MPFR_PREC_FORMAT == 1
+    prec = seed_value_from_ushort(ctx, args[1], exception);
+    #elif _MPFR_PREC_FORMAT == 2
+    prec = seed_value_from_uint(ctx, args[1], exception);
+    #elif _MPFR_PREC_FORMAT == 3
+    prec = seed_value_from_ulong(ctx, args[1], exception);
+    #else
+    #error "Invalid MPFR Prec format"
+    #endif
+
+    mpfr_init2(ptr, prec);
+
+    return;
+}
+
+SeedObject
+seed_module_init(SeedEngine *local_eng)
+{
+    SeedGlobalContext ctx = local_eng->context;
+    ns_ref = seed_make_object (ctx, NULL, NULL);
+    seed_value_protect (ctx, namespace_ref);
+
+    seed_create_function(ctx, "init2",
+                         (SeedFunctionCallback) seed_mpfr_init2,
+                         ns_ref);
+
+    seed_object_set_property(ctx, namespace_ref, "LC_CTYPE",
+                             seed_value_from_long(ctx, LC_CTYPE, NULL));
+
+
+    return ns_ref;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]