cvsuser     03/09/30 02:29:42

  Modified:    classes  pmc2c.pl
               .        core.ops dynext.c pmc.c
               dynclasses Makefile dynfoo.pasm
               include/parrot dynext.h
               languages/imcc parser_util.c
  Added:       config/init/hints linux.pl
  Log:
  adapt the load_pmc stuff to loadlib - no init yet
  this currently breaks the nci tests
  
  Revision  Changes    Path
  1.1                  parrot/config/init/hints/linux.pl
  
  Index: linux.pl
  ===================================================================
  Configure::Data->set(
      linkflags => '-Wl,-E'     # --export-dynamic, s. info gcc, ld
  );
  
  
  
  
  1.46      +15 -36    parrot/classes/pmc2c.pl
  
  Index: pmc2c.pl
  ===================================================================
  RCS file: /cvs/public/parrot/classes/pmc2c.pl,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -w -r1.45 -r1.46
  --- pmc2c.pl  27 Sep 2003 18:31:38 -0000      1.45
  +++ pmc2c.pl  30 Sep 2003 09:29:36 -0000      1.46
  @@ -813,51 +813,30 @@
         my $lc_classname = lc $classname;
         $OUT .= <<EOC;
   /*
  - * This init function will be called to setup/init/whatever
  - * is needed to get this extension running
  + * This load function will be called to do global (once) setup
  + * whatever is needed to get this extension running
    */
   #include "parrot/dynext.h"
   
  -int Parrot_dynext_${lc_classname}_init(Interp *interp, int action, void *param)
  +int Parrot_lib_${lc_classname}_load(Interp *interpreter)
   {
  -    dynext_pmc_info_t *info = (dynext_pmc_info_t*) param;
  -    int ok;
  -    int i;
       STRING *whoami;
  +    PMC *pmc;
  +    INTVAL type;
   
       /*
  -     * These are globals. As the shared lib is linked against libparrot
  -     * the shared libs has its own globals, so we must initialize these
  -     * yep, that's ugly
  +     * TODO which PMC type to return
        */
  -    for (i = 1; i < *(info->class_max); i++)
  -     Parrot_base_vtables[i] = info->base_vtable[i];
  -    enum_class_max = *info->class_max;
  -    switch (action) {
  -     case DYNEXT_SETUP_PMC:
  +    pmc = new_pmc_header(interpreter);
  +    add_pmc_ext(interpreter, pmc);
            string_init();      /* default type/encoding */
  -         /* one time setup code */
   
            /* for all PMCs we want to register:
             */
  -         whoami = string_from_cstring(interp, "$classname", 0);
  -         info->class_name = whoami;
  -         ok = Parrot_dynext_setup_pmc(interp, info);
  -         if (ok == DYNEXT_INIT_OK) {
  -             $initname(interp, info->class_enum);
  -             /* set our class enum */
  -             Parrot_base_vtables[info->class_enum]->base_type =
  -                 info->class_enum;
  -             /* copy vtable back to caller */
  -             info->base_vtable[info->class_enum] =
  -                 Parrot_base_vtables[info->class_enum];
  -         }
  -         return ok;
  -     case DYNEXT_INIT_PMC:
  -         /* per interpreter/thread init code */
  -         return Parrot_dynext_init_pmc(interp, info);
  -    }
  -    return DYNEXT_INIT_ERR;  /* error, unsupported action */
  +    whoami = string_from_cstring(interpreter, "$classname", 0);
  +    type = pmc_register(interpreter, whoami);
  +    /* do class_init code */
  +    $initname(interpreter, type);
   }
   
   EOC
  
  
  
  1.327     +2 -26     parrot/core.ops
  
  Index: core.ops
  ===================================================================
  RCS file: /cvs/public/parrot/core.ops,v
  retrieving revision 1.326
  retrieving revision 1.327
  diff -u -w -r1.326 -r1.327
  --- core.ops  27 Sep 2003 15:19:11 -0000      1.326
  +++ core.ops  30 Sep 2003 09:29:38 -0000      1.327
  @@ -926,12 +926,6 @@
   
   ########################################
   
  -=item B<load_pmc>(in STR, in PMC)
  -
  -Load in a pmc extension library. $1 is the name of the extension library,
  -$2 is an initializer that may have additional information for the PMCs
  -in that extension.
  -
   =item B<loadlib>(out PMC, in STR)
   
   Load a dynamic link library named $2 and store it in $1.
  @@ -968,27 +962,9 @@
   
   =cut
   
  -inline op load_pmc(in STR, in PMC) {
  -  int err = Parrot_load_pmc(interpreter, $1, $2);
  -  if (err)
  -      internal_exception(-1, "Failed to load dynamic PMC extension");
  -  goto NEXT();
  -}
  -
   inline op loadlib(out PMC, in STR) {
  -  PMC * pmc;
  -  void * p;
  -  const char * s = string_to_cstring(interpreter, ($2));
  -  p = Parrot_dlopen(s);
  -  if(p == NULL) {
  -     const char * err = Parrot_dlerror();
  -     fprintf(stderr, "%s\n", err);
  -     PANIC("Failed to load native library");
  -  }
  -  pmc = new_pmc_header(interpreter);
  -  add_pmc_ext(interpreter, pmc);
  -  PMC_data(pmc) = (void *)p;
  -  $1 = pmc;
  +
  +  $1 = Parrot_load_lib(interpreter, $2, NULL);
     goto NEXT();
   }
   
  
  
  
  1.6       +28 -63    parrot/dynext.c
  
  Index: dynext.c
  ===================================================================
  RCS file: /cvs/public/parrot/dynext.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- dynext.c  22 Sep 2003 19:27:36 -0000      1.5
  +++ dynext.c  30 Sep 2003 09:29:38 -0000      1.6
  @@ -1,7 +1,7 @@
   /* dynext.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: dynext.c,v 1.5 2003/09/22 19:27:36 dan Exp $
  + *     $Id: dynext.c,v 1.6 2003/09/30 09:29:38 leo Exp $
    *  Overview:
    *     Dynamic extension stuff
    *  Data Structure and Algorithms:
  @@ -14,56 +14,26 @@
   #include "parrot/parrot.h"
   #include "parrot/dynext.h"
   
  -/*
  - * if this pmc class isn't already in our global vtable
  - * reallocate it and assign class enum
  - */
  -int
  -Parrot_dynext_setup_pmc(Interp *interp, dynext_pmc_info_t *info)
  -{
  -    int i;
  -
  -    for (i = 1; i < (int)enum_class_max; i++) {
  -        if (!string_compare(interp, info->class_name,
  -                    Parrot_base_vtables[i]->whoami)) {
  -            info->class_enum = i;
  -            return DYNEXT_INIT_EXISTS;
  -        }
  -    }
  -#if 0
  -    Parrot_base_vtables = mem_sys_realloc(
  -            Parrot_base_vtables, sizeof(VTABLE *) * (enum_class_max + 1));
  -#endif
  -    info->class_enum = (*info->class_max)++;
  -
  -    return DYNEXT_INIT_OK;
  -}
   
   /*
  - * register a dynamic class pmc in the interpreter's registry
  + * dynamic library loader
  + * the initializer is currently unused
  + *
  + * calls Parrot_lib_load_%s which performs the registration of the lib once
  + *       Parrot_lib_init_%s gets called (if exists) to perform thread specific setup
    */
  -int
  -Parrot_dynext_init_pmc (Interp *interp, dynext_pmc_info_t *info)
  -{
  -    PMC *classname_hash;
  -    PMC *key;
   
  -    classname_hash = VTABLE_get_pmc_keyed_int(interp,
  -            interp->iglobals, (INTVAL)IGLOBALS_CLASSNAME_HASH);
  -    key = key_new_string(interp, info->class_name);
  -    VTABLE_set_integer_keyed(interp, classname_hash, key, info->class_enum);
  -    return DYNEXT_INIT_OK;
  -}
  -
  -int
  -Parrot_load_pmc(Interp *interpreter, STRING *lib, PMC *initializer)
  +PMC *
  +Parrot_load_lib(Interp *interpreter, STRING *lib, PMC *initializer)
   {
  -    STRING *path, *init_func;
  +    STRING *path, *load_func_name, *init_func_name;
       void * handle;
  -    void (*func)(Interp *, int, void *);
  -    char *cpath, *cinit_func;
  -    dynext_pmc_info_t info;
  +    PMC *(*load_func)(Interp *);
  +    void (*init_func)(Interp *, PMC *);
  +    char *cpath, *cinit_func_name, *cload_func_name;
  +    PMC *lib_pmc;
   
  +    UNUSED(initializer);
       /* TODO runtime path for dynamic extensions */
       /* TODO $SO extension */
   #ifndef RUNTIME_DYNEXT
  @@ -73,7 +43,7 @@
   #  define SO_EXTENSION ".so"
   #endif
   
  -    path = Parrot_sprintf_c(interpreter, "%s%Ss_pmc%s",
  +    path = Parrot_sprintf_c(interpreter, "%s%Ss%s",
               RUNTIME_DYNEXT,
               lib,
               SO_EXTENSION);
  @@ -81,29 +51,24 @@
       handle = Parrot_dlopen(cpath);
       if (!handle) {
           const char * err = Parrot_dlerror();
  -        fprintf(stderr, "%s\n", err);
  -        return -1;
  +        fprintf(stderr, "Couldn't load '%s': %s\n", cpath, err ? err : "unknow 
reason");
  +        return NULL;
       }
       string_cstring_free(cpath);
  -    init_func = Parrot_sprintf_c(interpreter, "Parrot_dynext_%Ss_init", lib);
  -    cinit_func = string_to_cstring(interpreter, init_func);
  -    func = (void (*)(Interp *, int, void*))D2FPTR(Parrot_dlsym(handle, cinit_func));
  -    if (!func) {
  +    load_func_name = Parrot_sprintf_c(interpreter, "Parrot_lib_%Ss_load", lib);
  +    cload_func_name = string_to_cstring(interpreter, load_func_name);
  +    load_func = (PMC * (*)(Interp *))D2FPTR(Parrot_dlsym(handle, cload_func_name));
  +    if (!load_func) {
           fprintf(stderr, "Failed to find symbol '%s' in native library\n",
  -                cinit_func);
  -        return -1;
  +                cload_func_name);
  +        return NULL;
       }
  -    string_cstring_free(cinit_func);
  +    string_cstring_free(cload_func_name);
  +    lib_pmc = (*load_func)(interpreter);
       /*
  -     * setup init info structure */
  -    info.class_name = lib;
  -    info.initializer = initializer;
  -    info.class_max = &enum_class_max;
  -    info.base_vtable = Parrot_base_vtables;
  -    /* TODO error checks */
  -    (*func)(interpreter, DYNEXT_SETUP_PMC, (void *) &info);
  -    (*func)(interpreter, DYNEXT_INIT_PMC, (void *) &info);
  -    return 0;
  +     * TODO call init, if it exists
  +     */
  +    return lib_pmc;
   }
   
   /*
  
  
  
  1.42      +4 -4      parrot/pmc.c
  
  Index: pmc.c
  ===================================================================
  RCS file: /cvs/public/parrot/pmc.c,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -w -r1.41 -r1.42
  --- pmc.c     29 Sep 2003 21:08:31 -0000      1.41
  +++ pmc.c     30 Sep 2003 09:29:38 -0000      1.42
  @@ -1,7 +1,7 @@
   /* pmc.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: pmc.c,v 1.41 2003/09/29 21:08:31 dan Exp $
  + *     $Id: pmc.c,v 1.42 2003/09/30 09:29:38 leo Exp $
    *  Overview:
    *     The base vtable calling functions.
    *  Data Structure and Algorithms:
  @@ -201,7 +201,7 @@
                                                 IGLOBALS_CLASSNAME_HASH);
       key = key_new_string(interp, name);
       
  -    type = ++enum_class_max;
  +    type = enum_class_max++;
       VTABLE_set_integer_keyed(interp, classname_hash, key, type);
       
       UNLOCK(class_count_mutex);
  
  
  
  1.5       +5 -4      parrot/dynclasses/Makefile
  
  Index: Makefile
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/Makefile,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- Makefile  24 Aug 2003 14:11:25 -0000      1.4
  +++ Makefile  30 Sep 2003 09:29:39 -0000      1.5
  @@ -2,18 +2,19 @@
   # sample Makefile
   #
   
  -all: foo_pmc.so #subproxy_pmc.so
  +all: foo.so #subproxy.so
   
   .SUFFIXES: .pmc .c .so
   # preserve .c if needed
   #.PRECIOUS: foo.c subproxy.c
   
   %.c  : %.pmc
  -     cd .. ; perl classes/pmc2c.pl dynclasses/$<
  +     perl ../classes/pmc2c.pl $<
   
  -%_pmc.so : %.c
  -     cc -shared -g -o $@  \
  +%.so : %.c
  +     $(CC) -shared -g -o $@  \
        -I../include -I../classes -L../blib/lib -lparrot $<
  +     cp $@ ../runtime/parrot/dynext/$@
   
   clean :
        rm -f *.c *.h *.so
  
  
  
  1.2       +2 -1      parrot/dynclasses/dynfoo.pasm
  
  Index: dynfoo.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/dynclasses/dynfoo.pasm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- dynfoo.pasm       8 Aug 2003 08:15:41 -0000       1.1
  +++ dynfoo.pasm       30 Sep 2003 09:29:39 -0000      1.2
  @@ -1,4 +1,5 @@
  -     load_pmc "foo", P0
  +     null P0
  +     loadlib P1, "foo"
        print "ok 1\n"
        find_type I0, "Foo"
        print I0
  
  
  
  1.4       +3 -27     parrot/include/parrot/dynext.h
  
  Index: dynext.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/dynext.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- dynext.h  22 Sep 2003 19:27:44 -0000      1.3
  +++ dynext.h  30 Sep 2003 09:29:41 -0000      1.4
  @@ -1,6 +1,6 @@
   /* dynext.h
   *
  -* $Id: dynext.h,v 1.3 2003/09/22 19:27:44 dan Exp $
  +* $Id: dynext.h,v 1.4 2003/09/30 09:29:41 leo Exp $
   *
   *   Parrot dynamic extensions
   */
  @@ -8,33 +8,9 @@
   #if !defined(DYNEXT_H_GUARD)
   #define DYNEXT_H_GUARD
   
  -typedef enum  {
  -    DYNEXT_NONE,
  -    DYNEXT_SETUP_PMC,
  -    DYNEXT_INIT_PMC,
  -    DYNEXT_SETUP_OPLIB,
  -    DYNEXT_INIT_OPLIB
  -} dynex_enum_action_t;
   
  -typedef enum  {
  -    DYNEXT_INIT_OK,
  -    DYNEXT_INIT_EXISTS,
  -    DYNEXT_INIT_ERR
  -} dynex_enum_err_t;
  -
  -typedef struct {
  -    INTVAL class_enum;
  -    STRING *class_name;
  -    PMC *initializer;
  -    INTVAL *class_max;
  -    VTABLE **base_vtable;
  -} dynext_pmc_info_t;
  -
  -/* dynamic PMC loading */
  -int Parrot_load_pmc(Interp *interpreter, STRING *lib, PMC *initializer);
  -/* callbacks for these */
  -int Parrot_dynext_setup_pmc(Interp *, dynext_pmc_info_t *);
  -int Parrot_dynext_init_pmc (Interp *, dynext_pmc_info_t *);
  +/* dynamic lib/oplib/PMC loading */
  +PMC *Parrot_load_lib(Interp *interpreter, STRING *lib, PMC *initializer);
   
   #endif
   
  
  
  
  1.36      +5 -5      parrot/languages/imcc/parser_util.c
  
  Index: parser_util.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/parser_util.c,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -w -r1.35 -r1.36
  --- parser_util.c     30 Sep 2003 06:42:31 -0000      1.35
  +++ parser_util.c     30 Sep 2003 09:29:42 -0000      1.36
  @@ -219,11 +219,11 @@
               /* emit a debug seg, if this op is seen */
               PARROT_WARNINGS_on(interpreter, PARROT_WARNINGS_ALL_FLAG);
           }
  -        if (!strcmp(name, "load_pmc")) {
  -            SymReg *r0 = r[0];   /* lib name */
  -            STRING *lib = string_from_cstring(interpreter, r0->name + 1,
  -                strlen(r0->name) - 2);
  -            Parrot_load_pmc(interpreter, lib, NULL);
  +        if (!strcmp(name, "loadlib")) {
  +            SymReg *r1 = r[1];   /* lib name */
  +            STRING *lib = string_from_cstring(interpreter, r1->name + 1,
  +                strlen(r1->name) - 2);
  +            Parrot_load_lib(interpreter, lib, NULL);
           }
           /* set up branch flags */
           if (op_info->jump) {
  
  
  

Reply via email to