load_bytecode handling with(out) extensions

Reini Urban rurban at x-ray.at
Sun Jan 4 22:00:08 UTC 2009


I'm walking in a src/library.c minefield. There more tests I write the 
more bugs I find.

I guess there once was a seperate codepath for finding .pir and .pbc. 
Parrot_load_bytecode() sets PARROT_RUNTIME_FT_PBC or 
PARROT_RUNTIME_FT_SOURCE. But it's lost now.
The 3rd arg in Parrot_locate_runtime_file_str(interp, file_str, 
file_type); is ignored.

I want to re-add the filetype check with TT #128, because other API's 
might want to use it also. Favor .pasm over .pir, find no .pbc.

But we have a more severe problem:

If we load_bytecode a file without extension, we favour .pbc,
.pir or .pasm. So load_bytecode should always set PARROT_RUNTIME_FT_PBC.

But when with load_bytecode "Date/Dumper" the .pbc is found, we 
currently try to compile the .pbc. Error! Because the file_type is wrong.

Or should we do a timestamp check as in python?
Only when no extension is given? Now we might find an older .pbc and 
load this instead.
With .pir the file is automatically compiled but the compilation is not 
stored. (unlike python)

I think I have to fix some code in Parrot_load_bytecode()

The current logic is like this:

When given an extension, load the file.
If not found, append all other extensions in the order: .pbc, .pasm, .pir

When given no extension, we might have a conflict with a directory which 
is solved in the pdd30install_stage3 branch.
http://www.parrotvm.org/svn/parrot/revision?rev=34932

The Parrot_load_bytecode() setting of PARROT_RUNTIME_FT_PBC or 
PARROT_RUNTIME_FT_SOURCE is ignored. So we always favor .pbc over .pir

We might think of checking the timestamps when we find .pir and .pbc and 
no extension is given. Python does so and does even automatic 
re-compilation.

This looks to be the first step, to get the extension handling right.
Check the file_type after the library search found it.

Index: src/packfile.c
===================================================================
--- src/packfile.c      (revision 34884)
+++ src/packfile.c      (working copy)
@@ -3759,17 +3759,19 @@
          interp->iglobals, IGLOBALS_PBC_LIBS);
      if (VTABLE_exists_keyed_str(interp, is_loaded_hash, wo_ext))
          return;
+
+    path = Parrot_locate_runtime_file_str(interp, file_str, 
PARROT_RUNTIME_FT_PBC);
+    if (!path)
+        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR,
+            "\"load_bytecode\" couldn't find file '%Ss'", file_str);
+
+    /* we might have found a different file_type now */
+    parrot_split_path_ext(interp, file_str, &wo_ext, &ext);
      pbc = CONST_STRING(interp, "pbc");
      if (string_equal(interp, ext, pbc) == 0)
          file_type = PARROT_RUNTIME_FT_PBC;
      else
          file_type = PARROT_RUNTIME_FT_SOURCE;
-
-    path = Parrot_locate_runtime_file_str(interp, file_str, file_type);
-    if (!path)
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR,
-            "\"load_bytecode\" couldn't find file '%Ss'", file_str);
-
      /* remember wo_ext => full_path mapping */
      VTABLE_set_string_keyed_str(interp, is_loaded_hash,
              wo_ext, path);

-- 
Reini Urban
http://phpwiki.org/  http://murbreak.at/


More information about the parrot-dev mailing list