cvsuser 04/08/31 02:14:31
Modified: classes parrotlibrary.pmc
src dynext.c
t/pmc nci.t
Log:
I found following vtable functions for the PMC ParrotLibrary to be useful.
get_bool: true when library has been loaded successfully.
When the library could not be loaded, then a PMC Undef is created. This
evaluates to false in boolean context.
get_string: return the property '_filename'. Might be useful for a quick
check, what has been loaded.
Courtesy of Bernhard Schmalhofer <[EMAIL PROTECTED]>
Revision Changes Path
1.10 +34 -1 parrot/classes/parrotlibrary.pmc
Index: parrotlibrary.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/parrotlibrary.pmc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -r1.9 -r1.10
--- parrotlibrary.pmc 22 Aug 2004 09:15:51 -0000 1.9
+++ parrotlibrary.pmc 31 Aug 2004 09:14:28 -0000 1.10
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: parrotlibrary.pmc,v 1.9 2004/08/22 09:15:51 leo Exp $
+$Id: parrotlibrary.pmc,v 1.10 2004/08/31 09:14:28 leo Exp $
=head1 NAME
@@ -83,6 +83,39 @@
}
return dest;
}
+
+/*
+
+=item C<INTVAL get_bool()>
+
+Returns wether a library has been successfully loaded.
+
+=cut
+
+*/
+
+ INTVAL get_bool() {
+ return ( PMC_data(SELF) != NULL );
+ }
+
+/*
+
+=item C<STRING* get_string()>
+
+Returns wether a library has been successfully loaded.
+
+=cut
+
+*/
+
+ STRING* get_string() {
+ PMC *prop;
+ STRING *key;
+ key = const_string(interpreter, "_filename");
+ prop = VTABLE_getprop(interpreter, SELF, key);
+ return VTABLE_get_string(interpreter, prop);
+ }
+
}
/*
1.29 +4 -3 parrot/src/dynext.c
Index: dynext.c
===================================================================
RCS file: /cvs/public/parrot/src/dynext.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -w -r1.28 -r1.29
--- dynext.c 27 Aug 2004 13:16:37 -0000 1.28
+++ dynext.c 31 Aug 2004 09:14:30 -0000 1.29
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: dynext.c,v 1.28 2004/08/27 13:16:37 leo Exp $
+$Id: dynext.c,v 1.29 2004/08/31 09:14:30 leo Exp $
=head1 NAME
@@ -276,9 +276,10 @@
#endif
if (!path || !handle) {
/*
- * XXX internal_exception? return a PerlUndef?
+ * XXX internal_exception? return a PerlUndef? return PMCNULL?
+ * PMC Undef seems convenient, because it can be queried with get_bool()
*/
- return PMCNULL;
+ return pmc_new(interpreter, enum_class_Undef);
}
/*
1.47 +7 -5 parrot/t/pmc/nci.t
Index: nci.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/nci.t,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -w -r1.46 -r1.47
--- nci.t 22 Aug 2004 09:15:52 -0000 1.46
+++ nci.t 31 Aug 2004 09:14:31 -0000 1.47
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-# $Id: nci.t,v 1.46 2004/08/22 09:15:52 leo Exp $
+# $Id: nci.t,v 1.47 2004/08/31 09:14:31 leo Exp $
=head1 NAME
@@ -62,15 +62,19 @@
.local pmc lib
.local NCI dd
lib = loadlib "libnci"
- print "loaded\n"
+ unless lib goto NOT_LOADED
+ print "loaded "
+ print lib
+ print "\n"
dd = dlfunc lib, "nci_dd", "dd"
.local float r
r = dd(4.0)
print r
+ NOT_LOADED:
print "\n"
.end
CODE
-loaded
+loaded runtime/parrot/dynext/libnci.so
8.000000
OUTPUT
@@ -1359,5 +1363,3 @@
1
0
OUTPUT
-
-1;