This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

dynl.c


Hi!

Now that guile mostly compiles with strict typing enabled (numbers.c is
also done with respect to that), the next step is to figure out places
where cell elements are written without using SCM_SET_CELL_WORD or
SCM_SET_CELL_OBJECT, and whenever possible replace such an access with one
of those two macros.  This will help to integrate the generational gc.

Critical places are those, where an address of SCM_CAR or SCM_CDR (or
any other cell accessing macro) is taken, which was common practice up to
now.  An easy way to figure those places out is to change the macros
SCM_CELL_WORD to work on _const_ SCM pointers.  Then, the compiler will
tell you about illegal accesses.

A first start made me look at dynl.c.  I enclose a proposed patch, but
would be grateful if someone with better knowledge of the workings of
dynamic loading could take a look at it.

However, I do have a question about the implementation:  Why is the user 
required to explicitly unlink a library?  Couldn't this be done
automatically by the gc?

Best regards
Dirk Herrmann
Warning: Remote host denied authentication agent forwarding.

Index: dynl.c
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/dynl.c,v
retrieving revision 1.44
diff -u -r1.44 dynl.c
--- dynl.c	2000/04/21 14:16:30	1.44
+++ dynl.c	2000/05/03 15:38:18
@@ -326,15 +326,10 @@
 
 int scm_tc16_dynamic_obj;
 
-struct dynl_obj {
-  SCM filename;
-  void *handle;
-};
-
-#define DYNL_OBJ(x)      ((struct dynl_obj *) &SCM_CDR (x))
+#define DYNL_FILENAME(x)        (SCM_CELL_OBJECT_1 (x))
+#define DYNL_HANDLE(x)          ((void *) SCM_CELL_WORD_2 (x))
+#define SET_DYNL_HANDLE(x, v)   (SCM_SET_CELL_WORD_2 ((x), (v)))
 
-#define DYNL_FILENAME(x) (DYNL_OBJ (x)->filename)
-#define DYNL_HANDLE(x)   (DYNL_OBJ (x)->handle)
 
 static SCM
 mark_dynl_obj (SCM ptr)
@@ -398,16 +393,6 @@
 }
 #undef FUNC_NAME
 
-static struct dynl_obj *
-get_dynl_obj (SCM dobj, const char *subr, int argn)
-{
-  struct dynl_obj *d;
-  SCM_ASSERT (SCM_NIMP (dobj) && SCM_UNPACK_CAR (dobj) == scm_tc16_dynamic_obj,
-	      dobj, argn, subr);
-  d = DYNL_OBJ (dobj);
-  SCM_ASSERT (d->handle != NULL, dobj, argn, subr);
-  return d;
-}
 
 SCM_DEFINE (scm_dynamic_object_p, "dynamic-object?", 1, 0, 0, 
             (SCM obj),
@@ -415,34 +400,37 @@
 	    "otherwise.")
 #define FUNC_NAME s_scm_dynamic_object_p
 {
-    return SCM_BOOL (SCM_NIMP (obj)
-		     && SCM_UNPACK_CAR (obj) == scm_tc16_dynamic_obj);
+  return SCM_BOOL (SCM_SMOB_PREDICATE (scm_tc16_dynamic_obj, obj));
 }
 #undef FUNC_NAME
 
+
 SCM_DEFINE (scm_dynamic_unlink, "dynamic-unlink", 1, 0, 0, 
             (SCM dobj),
-	    "Unlink the library represented by @var{library-handle}, and remove any\n"
-	    "imported symbols from the address space.\n"
+	    "Unlink the library represented by @var{library-handle},\n"
+	    "and remove any imported symbols from the address space.\n"
 	    "GJB:FIXME:DOC: 2nd version below:\n"
-	    "Unlink the indicated object file from the application.  The argument\n"
-	    "@var{dynobj} should be one of the values returned by\n"
-	    "@code{dynamic-link}.  When @code{dynamic-unlink} has been called on\n"
-	    "@var{dynobj}, it is no longer usable as an argument to the functions\n"
-	    "below and you will get type mismatch errors when you try to.\n"
-	    "")
+	    "Unlink the indicated object file from the application.  The\n"
+	    "argument @var{dynobj} must have been obtained by a call to\n"
+	    "@code{dynamic-link}.  After @code{dynamic-unlink} has been\n"
+	    "called on @var{dynobj}, its content is no longer accessible.\n")
 #define FUNC_NAME s_scm_dynamic_unlink
 {
   /*fixme* GC-problem */
-  struct dynl_obj *d = get_dynl_obj (dobj, FUNC_NAME, SCM_ARG1);
-  SCM_DEFER_INTS;
-  sysdep_dynl_unlink (d->handle, FUNC_NAME);
-  d->handle = NULL;
-  SCM_ALLOW_INTS;
-  return SCM_UNSPECIFIED;
+  SCM_VALIDATE_SMOB (SCM_ARG1, dobj, dynamic_obj);
+  if (DYNL_HANDLE (dobj) == NULL) {
+    SCM_MISC_ERROR ("Unlinking an already unlinked dynamic object.", dobj);
+  } else {
+    SCM_DEFER_INTS;
+    sysdep_dynl_unlink (DYNL_HANDLE (dobj), FUNC_NAME);
+    SET_DYNL_HANDLE (dobj, NULL);
+    SCM_ALLOW_INTS;
+    return SCM_UNSPECIFIED;
+  }
 }
 #undef FUNC_NAME
 
+
 SCM_DEFINE (scm_dynamic_func, "dynamic-func", 2, 0, 0, 
             (SCM symb, SCM dobj),
 	    "Import the symbol @var{func} from @var{lib} (a dynamic library handle).\n"
@@ -460,22 +448,24 @@
 	    "")
 #define FUNC_NAME s_scm_dynamic_func
 {
-  struct dynl_obj *d;
   void (*func) ();
 
   SCM_COERCE_ROSTRING (1, symb);
   /*fixme* GC-problem */
-  d = get_dynl_obj (dobj, FUNC_NAME, SCM_ARG2);
-
-  SCM_DEFER_INTS;
-  func = (void (*) ()) sysdep_dynl_func (SCM_CHARS (symb),
-					 d->handle,
-					 FUNC_NAME);
-  SCM_ALLOW_INTS;
-
-  return scm_ulong2num ((unsigned long) func);
+  SCM_VALIDATE_SMOB (SCM_ARG2, dobj, dynamic_obj);
+  if (DYNL_HANDLE (dobj) == NULL) {
+    SCM_MISC_ERROR ("Accessing an unlinked dynamic object.", dobj);
+  } else {
+    SCM_DEFER_INTS;
+    func = (void (*) ()) sysdep_dynl_func (SCM_CHARS (symb),
+					   DYNL_HANDLE (dobj),
+					   FUNC_NAME);
+    SCM_ALLOW_INTS;
+    return scm_ulong2num ((unsigned long) func);
+  }
 }
 #undef FUNC_NAME
+
 
 SCM_DEFINE (scm_dynamic_call, "dynamic-call", 2, 0, 0, 
             (SCM func, SCM dobj),

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]