[PD-cvs] externals/miXed/shared/unstable fragile.c, 1.8, 1.9 fragile.h, 1.6, 1.7 loader.c, 1.1.1.1, 1.2 loader.h, 1.1.1.1, 1.2

Krzysztof Czaja krzyszcz at users.sourceforge.net
Mon Nov 21 23:16:39 CET 2005


Update of /cvsroot/pure-data/externals/miXed/shared/unstable
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29556/shared/unstable

Modified Files:
	fragile.c fragile.h loader.c loader.h 
Log Message:
cyclone alpha55 (see notes.txt for cyclone and shared)

Index: fragile.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/unstable/fragile.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** fragile.c	10 May 2005 17:58:41 -0000	1.8
--- fragile.c	21 Nov 2005 22:16:37 -0000	1.9
***************
*** 11,14 ****
--- 11,20 ----
  #include "unstable/fragile.h"
  
+ /* this one rather belongs to fringe.c... */
+ t_symbol *fragile_class_getexterndir(t_class *c)
+ {
+     return (c->c_externdir);
+ }
+ 
  int fragile_class_count(void)
  {

Index: fragile.h
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/unstable/fragile.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** fragile.h	10 May 2005 17:58:41 -0000	1.6
--- fragile.h	21 Nov 2005 22:16:37 -0000	1.7
***************
*** 6,9 ****
--- 6,10 ----
  #define __FRAGILE_H__
  
+ t_symbol *fragile_class_getexterndir(t_class *c);
  int fragile_class_count(void);
  int fragile_class_getnames(t_atom *av, int maxnames);

Index: loader.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/unstable/loader.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** loader.c	23 May 2003 12:29:53 -0000	1.1.1.1
--- loader.c	21 Nov 2005 22:16:37 -0000	1.2
***************
*** 1,3 ****
! /* Copyright (c) 1997-2003 Miller Puckette, krzYszcz, and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
--- 1,3 ----
! /* Copyright (c) 1997-2005 Miller Puckette, krzYszcz, and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
***************
*** 6,11 ****
     (modulo differentiating the error return codes).  LATER use the original. */
  
- #include "loader.h"
- 
  #ifdef __linux__
  #include <dlfcn.h>
--- 6,9 ----
***************
*** 23,28 ****
  #endif
  #include <string.h>
- #include "m_pd.h"
  #include <stdio.h>
  
  typedef void (*t_xxx)(void);
--- 21,29 ----
  #endif
  #include <string.h>
  #include <stdio.h>
+ #include "m_pd.h"
+ #include "common/loud.h"
+ #include "common/os.h"
+ #include "loader.h"
  
  typedef void (*t_xxx)(void);
***************
*** 49,139 ****
  #endif
  
! int unstable_load_lib(char *dirname, char *classname)
  {
!     char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING],
!     	*nameptr, *lastdot;
      void *dlobj;
      t_xxx makeout;
-     int fd;
  #ifdef NT
      HINSTANCE ntdll;
  #endif
! #if 0
!     fprintf(stderr, "lib %s %s\n", dirname, classname);
! #endif
!     if ((fd = open_via_path(dirname, classname, sys_dllextent,
!     	dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
!     {
!     	return (LOADER_NOFILE);
!     }
!     else
!     {
!     	close(fd);
!     	    /* refabricate the pathname */
! 	strcpy(filename, dirbuf);
! 	strcat(filename, "/");
! 	strcat(filename, nameptr);
!     	    /* extract the setup function name */
!     	if (lastdot = strrchr(nameptr, '.'))
! 	    *lastdot = 0;
  
  #ifdef MACOSX
!     	strcpy(symname, "_");
!     	strcat(symname, nameptr);
  #else
!     	strcpy(symname, nameptr);
  #endif
! 	    /* if the last character is a tilde, replace with "_tilde" */
! 	if (symname[strlen(symname) - 1] == '~')
! 	    strcpy(symname + (strlen(symname) - 1), "_tilde");
! 	    /* and append _setup to form the C setup function name */
!     	strcat(symname, "_setup");
  #ifdef __linux__
! 	dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
! 	if (!dlobj)
! 	{
! 	    post("%s: %s", filename, dlerror());
! 	    return (LOADER_BADFILE);
! 	}
! 	makeout = (t_xxx)dlsym(dlobj,  symname);
  #endif
  #ifdef NT
! 	sys_bashfilename(filename, filename);
!     	ntdll = LoadLibrary(filename);
!     	if (!ntdll)
!     	{
  	    post("%s: couldn't load", filename);
  	    return (LOADER_BADFILE);
  	}
!     	makeout = (t_xxx)GetProcAddress(ntdll, symname);  
! #endif
! #ifdef MACOSX
!         {
!             NSObjectFileImage image; 
!             void *ret;
!             NSSymbol s; 
!             if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess )
!             {
!                 post("%s: couldn't load", filename);
!                 return (LOADER_BADFILE);
!             }
!             ret = NSLinkModule( image, filename,
! 				NSLINKMODULE_OPTION_BINDNOW
! 				+ NSLINKMODULE_OPTION_PRIVATE);
              
!             s = NSLookupSymbolInModule(ret, symname); 
          
!             if (s)
!                 makeout = (t_xxx)NSAddressOfSymbol( s);
!             else makeout = 0;
!         }
! #endif
      }
      if (!makeout)
      {
!     	post("load_object: Symbol \"%s\" not found", symname);
!     	return (LOADER_NOENTRY);
      }
      (*makeout)();
      return (LOADER_OK);
  }
--- 50,223 ----
  #endif
  
! static int unstable_doload_lib(char *dirname, char *classname)
  {
!     char symname[MAXPDSTRING], filename[MAXPDSTRING], *lastdot;
      void *dlobj;
      t_xxx makeout;
  #ifdef NT
      HINSTANCE ntdll;
  #endif
!     /* refabricate the pathname */
!     strcpy(filename, dirname);
!     strcat(filename, "/");
!     strcat(filename, classname);
!     /* extract the setup function name */
!     if (lastdot = strrchr(classname, '.'))
! 	*lastdot = 0;
  
  #ifdef MACOSX
!     strcpy(symname, "_");
!     strcat(symname, classname);
  #else
!     strcpy(symname, classname);
  #endif
!     /* if the last character is a tilde, replace with "_tilde" */
!     if (symname[strlen(symname) - 1] == '~')
! 	strcpy(symname + (strlen(symname) - 1), "_tilde");
!     /* and append _setup to form the C setup function name */
!     strcat(symname, "_setup");
  #ifdef __linux__
!     dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
!     if (!dlobj)
!     {
! 	post("%s: %s", filename, dlerror());
! 	return (LOADER_BADFILE);
!     }
!     makeout = (t_xxx)dlsym(dlobj,  symname);
  #endif
  #ifdef NT
!     sys_bashfilename(filename, filename);
!     ntdll = LoadLibrary(filename);
!     if (!ntdll)
!     {
! 	post("%s: couldn't load", filename);
! 	return (LOADER_BADFILE);
!     }
!     makeout = (t_xxx)GetProcAddress(ntdll, symname);  
! #endif
! #ifdef MACOSX
!     {
! 	NSObjectFileImage image; 
! 	void *ret;
! 	NSSymbol s; 
! 	if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess )
! 	{
  	    post("%s: couldn't load", filename);
  	    return (LOADER_BADFILE);
  	}
! 	ret = NSLinkModule( image, filename,
! 			    NSLINKMODULE_OPTION_BINDNOW
! 			    + NSLINKMODULE_OPTION_PRIVATE);
              
! 	s = NSLookupSymbolInModule(ret, symname); 
          
! 	if (s)
! 	    makeout = (t_xxx)NSAddressOfSymbol( s);
! 	else makeout = 0;
      }
+ #endif
      if (!makeout)
      {
! 	post("load_object: Symbol \"%s\" not found", symname);
! 	return (LOADER_NOENTRY);
      }
      (*makeout)();
      return (LOADER_OK);
  }
+ 
+ /* start searching from dirname, then search the path */
+ int unstable_load_lib(char *dirname, char *classname)
+ {
+     char dirbuf[MAXPDSTRING], *nameptr;
+     int fd;
+     if ((fd = open_via_path(dirname, classname, sys_dllextent,
+     	dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+     {
+     	return (LOADER_NOFILE);
+     }
+     else
+     {
+     	close(fd);
+ 	return (unstable_doload_lib(dirbuf, nameptr));
+     }
+ }
+ 
+ /* only dirname is searched */
+ int unstable_dirload_lib(char *dirname, char *classname)
+ {
+     if (strlen(dirname) + strlen(classname) + strlen(sys_dllextent) + 3 <
+ 	MAXPDSTRING)
+     {
+ 	char namebuf[MAXPDSTRING], *slash, *nameptr;
+ 	strcpy(namebuf, dirname);
+ 	if (*dirname && namebuf[strlen(namebuf)-1] != '/')
+ 	    strcat(namebuf, "/");
+ 	strcat(namebuf, classname);
+ 	strcat(namebuf, sys_dllextent);
+ 	slash = strrchr(namebuf, '/');
+ 	if (slash)
+ 	{
+ 	    *slash = 0;
+ 	    nameptr = slash + 1;
+ 	}
+ 	else nameptr = namebuf;
+ 	return (unstable_doload_lib(namebuf, nameptr));
+     }
+     else return (LOADER_FAILED);
+ }
+ 
+ /* return the number of successfully loaded libraries, or -1 on error */
+ int unstable_dirload_all(char *dirname, int beloud, int withclasses)
+ {
+     t_osdir *dp = osdir_open(dirname);
+     if (dp)
+     {
+ 	int result = 0;
+ 	char namebuf[MAXPDSTRING], *name;
+ 	osdir_setmode(dp, OSDIR_FILEMODE);
+ 	while (name = osdir_next(dp))
+ 	{
+ 	    int namelen = strlen(name), extlen = strlen(sys_dllextent);
+ 	    if ((namelen -= extlen) > 0 &&
+ 		strcmp(name + namelen, sys_dllextent) == 0)
+ 	    {
+ 		strncpy(namebuf, name, namelen);
+ 		namebuf[namelen] = 0;
+ 		if (zgetfn(&pd_objectmaker, gensym(namebuf)))
+ 		{
+ 		    if (beloud)
+ 			loud_warning(0, "xeq", "plugin \"%s\" already loaded",
+ 				     namebuf);
+ 		}
+ 		else
+ 		{
+ 		    int err;
+ 		    if (beloud)
+ 			post("loading xeq plugin \"%s\"", namebuf);
+ 		    err = unstable_dirload_lib(dirname, namebuf);
+ 		    if (err == LOADER_NOFILE)
+ 		    {
+ 			if (beloud)
+ 			    loud_error(0, "xeq plugin \"%s\" disappeared",
+ 				       namebuf);
+ 		    }
+ 		    else if (!zgetfn(&pd_objectmaker, gensym(namebuf)))
+ 		    {
+ 			if (beloud)
+ 			    loud_error(0, "library \"%s\" not compatible",
+ 				       namebuf);
+ 		    }
+ 		    else result++;
+ 		}
+ 	    }
+ 	}
+ 	osdir_close(dp);
+ 	return (result);
+     }
+     else
+     {
+ 	if (beloud)
+ 	    loud_syserror(0, "cannot open \"%s\"", dirname);
+ 	return (-1);
+     }
+ }

Index: loader.h
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/unstable/loader.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** loader.h	23 May 2003 12:29:53 -0000	1.1.1.1
--- loader.h	21 Nov 2005 22:16:37 -0000	1.2
***************
*** 1,3 ****
! /* Copyright (c) 2003 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
--- 1,3 ----
! /* Copyright (c) 2003-2005 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
***************
*** 6,12 ****
  #define __LOADER_H__
  
! enum { LOADER_OK, LOADER_NOFILE, LOADER_BADFILE, LOADER_NOENTRY };
  
  int unstable_load_lib(char *dirname, char *classname);
  
  #endif
--- 6,15 ----
  #define __LOADER_H__
  
! enum { LOADER_OK, LOADER_FAILED,
!        LOADER_NOFILE, LOADER_BADFILE, LOADER_NOENTRY };
  
  int unstable_load_lib(char *dirname, char *classname);
+ int unstable_dirload_lib(char *dirname, char *classname);
+ int unstable_dirload_all(char *dirname, int beloud, int withclasses);
  
  #endif





More information about the Pd-cvs mailing list