2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
dln.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Tue Jan 18 17:05:06 JST 1994
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include "dln.h"
|
|
|
|
|
2002-02-18 12:52:48 +03:00
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
# include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2000-08-07 09:05:04 +04:00
|
|
|
#ifdef __CHECKER__
|
|
|
|
#undef HAVE_DLOPEN
|
|
|
|
#undef USE_DLN_A_OUT
|
|
|
|
#undef USE_DLN_DLOPEN
|
|
|
|
#endif
|
|
|
|
|
2002-03-25 05:09:16 +03:00
|
|
|
#ifdef USE_DLN_A_OUT
|
1998-01-16 15:13:05 +03:00
|
|
|
char *dln_argv0;
|
2002-03-25 05:09:16 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-07-24 22:33:50 +04:00
|
|
|
#if defined(HAVE_ALLOCA_H)
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#else
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifndef xmalloc
|
1998-01-16 15:13:05 +03:00
|
|
|
void *xmalloc();
|
|
|
|
void *xcalloc();
|
|
|
|
void *xrealloc();
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
#define free(x) xfree(x)
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <stdio.h>
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined(_WIN32) || defined(__VMS)
|
1998-01-16 15:13:05 +03:00
|
|
|
#include "missing/file.h"
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2001-05-30 13:12:34 +04:00
|
|
|
#ifndef S_ISDIR
|
|
|
|
# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
# include <sys/param.h>
|
|
|
|
#endif
|
2002-11-27 12:11:55 +03:00
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
# define MAXPATHLEN 1024
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#ifndef _WIN32
|
1998-01-16 15:13:05 +03:00
|
|
|
char *getenv();
|
|
|
|
#endif
|
|
|
|
|
2002-03-22 10:26:42 +03:00
|
|
|
#if defined(__VMS)
|
|
|
|
#pragma builtins
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#ifdef __MACOS__
|
|
|
|
# include <TextUtils.h>
|
|
|
|
# include <CodeFragments.h>
|
|
|
|
# include <Aliases.h>
|
1999-08-13 09:45:20 +04:00
|
|
|
# include "macruby_private.h"
|
1999-01-20 07:59:39 +03:00
|
|
|
#endif
|
|
|
|
|
2007-02-23 04:31:37 +03:00
|
|
|
#if defined(__APPLE__) && defined(__MACH__) /* Mac OS X */
|
|
|
|
# if defined(HAVE_DLOPEN)
|
|
|
|
/* Mac OS X with dlopen (10.3 or later) */
|
|
|
|
# define MACOSX_DLOPEN
|
|
|
|
# else
|
|
|
|
# define MACOSX_DYLD
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#ifdef __BEOS__
|
|
|
|
# include <image.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-20 18:25:34 +04:00
|
|
|
#ifndef NO_DLN_LOAD
|
|
|
|
|
2007-02-23 04:31:37 +03:00
|
|
|
#if defined(HAVE_DLOPEN) && !defined(USE_DLN_A_OUT) && !defined(_AIX) && !defined(MACOSX_DYLD) && !defined(_UNICOSMP)
|
1998-01-16 15:13:05 +03:00
|
|
|
/* dynamic load with dlopen() */
|
|
|
|
# define USE_DLN_DLOPEN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef FUNCNAME_PATTERN
|
2007-02-23 04:31:37 +03:00
|
|
|
# if defined(__hp9000s300) || (defined(__NetBSD__) && !defined(__ELF__)) || defined(__BORLANDC__) || (defined(__FreeBSD__) && !defined(__ELF__)) || (defined(__OpenBSD__) && !defined(__ELF__)) || defined(NeXT) || defined(__WATCOMC__) || defined(MACOSX_DYLD)
|
2001-03-13 08:45:13 +03:00
|
|
|
# define FUNCNAME_PATTERN "_Init_%s"
|
1998-01-16 15:13:05 +03:00
|
|
|
# else
|
2001-03-13 08:45:13 +03:00
|
|
|
# define FUNCNAME_PATTERN "Init_%s"
|
1998-01-16 15:13:05 +03:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2002-09-05 13:17:48 +04:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
init_funcname_len(char **buf, const char *file)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-12-29 17:51:22 +03:00
|
|
|
char *p;
|
|
|
|
const char *slash;
|
2002-11-27 12:11:55 +03:00
|
|
|
int len;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* Load the file as an object one */
|
2002-12-29 17:51:22 +03:00
|
|
|
for (slash = file-1; *file; file++) /* Find position of last '/' */
|
1999-01-20 07:59:39 +03:00
|
|
|
#ifdef __MACOS__
|
2002-12-29 17:51:22 +03:00
|
|
|
if (*file == ':') slash = file;
|
1999-01-20 07:59:39 +03:00
|
|
|
#else
|
2002-12-29 17:51:22 +03:00
|
|
|
if (*file == '/') slash = file;
|
1999-01-20 07:59:39 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-11-27 12:11:55 +03:00
|
|
|
len = strlen(FUNCNAME_PATTERN) + strlen(slash + 1);
|
|
|
|
*buf = xmalloc(len);
|
|
|
|
snprintf(*buf, len, FUNCNAME_PATTERN, slash + 1);
|
2002-02-18 12:52:48 +03:00
|
|
|
for (p = *buf; *p; p++) { /* Delete suffix if it exists */
|
1998-01-16 15:13:05 +03:00
|
|
|
if (*p == '.') {
|
|
|
|
*p = '\0'; break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-05 13:17:48 +04:00
|
|
|
return p - *buf;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-09-05 13:17:48 +04:00
|
|
|
#define init_funcname(buf, file) do {\
|
|
|
|
int len = init_funcname_len(buf, file);\
|
|
|
|
char *tmp = ALLOCA_N(char, len+1);\
|
|
|
|
if (!tmp) {\
|
|
|
|
free(*buf);\
|
|
|
|
rb_memerror();\
|
|
|
|
}\
|
|
|
|
strcpy(tmp, *buf);\
|
|
|
|
free(*buf);\
|
|
|
|
*buf = tmp;\
|
|
|
|
} while (0)
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef USE_DLN_A_OUT
|
|
|
|
|
|
|
|
#ifndef LIBC_NAME
|
|
|
|
# define LIBC_NAME "libc.a"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DLN_DEFAULT_LIB_PATH
|
|
|
|
# define DLN_DEFAULT_LIB_PATH "/lib:/usr/lib:/usr/local/lib:."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
static int dln_errno;
|
|
|
|
|
|
|
|
#define DLN_ENOEXEC ENOEXEC /* Exec format error */
|
2000-07-27 13:49:34 +04:00
|
|
|
#define DLN_ECONFL 1201 /* Symbol name conflict */
|
2005-02-07 07:00:58 +03:00
|
|
|
#define DLN_ENOINIT 1202 /* No initializer given */
|
2000-07-27 13:49:34 +04:00
|
|
|
#define DLN_EUNDEF 1203 /* Undefine symbol remains */
|
|
|
|
#define DLN_ENOTLIB 1204 /* Not a library file */
|
|
|
|
#define DLN_EBADLIB 1205 /* Malformed library file */
|
|
|
|
#define DLN_EINIT 1206 /* Not initialized */
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static int dln_init_p = 0;
|
|
|
|
|
|
|
|
#include <ar.h>
|
|
|
|
#include <a.out.h>
|
|
|
|
#ifndef N_COMM
|
|
|
|
# define N_COMM 0x12
|
|
|
|
#endif
|
|
|
|
#ifndef N_MAGIC
|
|
|
|
# define N_MAGIC(x) (x).a_magic
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define INVALID_OBJECT(h) (N_MAGIC(h) != OMAGIC)
|
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/util.h"
|
|
|
|
#include "ruby/st.h"
|
2000-07-27 13:49:34 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static st_table *sym_tbl;
|
|
|
|
static st_table *undef_tbl;
|
|
|
|
|
|
|
|
static int load_lib();
|
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
load_header(int fd, struct exec *hdrp, long disp)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
lseek(fd, disp, 0);
|
|
|
|
size = read(fd, hdrp, sizeof(struct exec));
|
|
|
|
if (size == -1) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (size != sizeof(struct exec) || N_BADMAG(*hdrp)) {
|
|
|
|
dln_errno = DLN_ENOEXEC;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(sequent)
|
|
|
|
#define RELOC_SYMBOL(r) ((r)->r_symbolnum)
|
|
|
|
#define RELOC_MEMORY_SUB_P(r) ((r)->r_bsr)
|
|
|
|
#define RELOC_PCREL_P(r) ((r)->r_pcrel || (r)->r_bsr)
|
|
|
|
#define RELOC_TARGET_SIZE(r) ((r)->r_length)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Default macros */
|
|
|
|
#ifndef RELOC_ADDRESS
|
|
|
|
#define RELOC_ADDRESS(r) ((r)->r_address)
|
|
|
|
#define RELOC_EXTERN_P(r) ((r)->r_extern)
|
|
|
|
#define RELOC_SYMBOL(r) ((r)->r_symbolnum)
|
|
|
|
#define RELOC_MEMORY_SUB_P(r) 0
|
|
|
|
#define RELOC_PCREL_P(r) ((r)->r_pcrel)
|
|
|
|
#define RELOC_TARGET_SIZE(r) ((r)->r_length)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(sun) && defined(sparc)
|
|
|
|
/* Sparc (Sun 4) macros */
|
|
|
|
# undef relocation_info
|
|
|
|
# define relocation_info reloc_info_sparc
|
|
|
|
# define R_RIGHTSHIFT(r) (reloc_r_rightshift[(r)->r_type])
|
|
|
|
# define R_BITSIZE(r) (reloc_r_bitsize[(r)->r_type])
|
|
|
|
# define R_LENGTH(r) (reloc_r_length[(r)->r_type])
|
|
|
|
static int reloc_r_rightshift[] = {
|
|
|
|
0, 0, 0, 0, 0, 0, 2, 2, 10, 0, 0, 0, 0, 0, 0,
|
|
|
|
};
|
|
|
|
static int reloc_r_bitsize[] = {
|
|
|
|
8, 16, 32, 8, 16, 32, 30, 22, 22, 22, 13, 10, 32, 32, 16,
|
|
|
|
};
|
|
|
|
static int reloc_r_length[] = {
|
|
|
|
0, 1, 2, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
};
|
|
|
|
# define R_PCREL(r) \
|
|
|
|
((r)->r_type >= RELOC_DISP8 && (r)->r_type <= RELOC_WDISP22)
|
|
|
|
# define R_SYMBOL(r) ((r)->r_index)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(sequent)
|
|
|
|
#define R_SYMBOL(r) ((r)->r_symbolnum)
|
|
|
|
#define R_MEMORY_SUB(r) ((r)->r_bsr)
|
|
|
|
#define R_PCREL(r) ((r)->r_pcrel || (r)->r_bsr)
|
|
|
|
#define R_LENGTH(r) ((r)->r_length)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef R_SYMBOL
|
|
|
|
# define R_SYMBOL(r) ((r)->r_symbolnum)
|
|
|
|
# define R_MEMORY_SUB(r) 0
|
|
|
|
# define R_PCREL(r) ((r)->r_pcrel)
|
|
|
|
# define R_LENGTH(r) ((r)->r_length)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct relocation_info *
|
2006-08-13 13:44:16 +04:00
|
|
|
load_reloc(int fd, struct exec *hdrp, long disp)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct relocation_info *reloc;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
lseek(fd, disp + N_TXTOFF(*hdrp) + hdrp->a_text + hdrp->a_data, 0);
|
|
|
|
size = hdrp->a_trsize + hdrp->a_drsize;
|
|
|
|
reloc = (struct relocation_info*)xmalloc(size);
|
|
|
|
if (reloc == NULL) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(fd, reloc, size) != size) {
|
|
|
|
dln_errno = errno;
|
|
|
|
free(reloc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return reloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nlist *
|
2006-08-13 13:44:16 +04:00
|
|
|
load_sym(int fd, struct exec *hdrp, long disp)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct nlist * buffer;
|
|
|
|
struct nlist * sym;
|
|
|
|
struct nlist * end;
|
|
|
|
long displ;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
lseek(fd, N_SYMOFF(*hdrp) + hdrp->a_syms + disp, 0);
|
|
|
|
if (read(fd, &size, sizeof(int)) != sizeof(int)) {
|
|
|
|
goto err_noexec;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = (struct nlist*)xmalloc(hdrp->a_syms + size);
|
|
|
|
if (buffer == NULL) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
lseek(fd, disp + N_SYMOFF(*hdrp), 0);
|
|
|
|
if (read(fd, buffer, hdrp->a_syms + size) != hdrp->a_syms + size) {
|
|
|
|
free(buffer);
|
|
|
|
goto err_noexec;
|
|
|
|
}
|
|
|
|
|
|
|
|
sym = buffer;
|
|
|
|
end = sym + hdrp->a_syms / sizeof(struct nlist);
|
|
|
|
displ = (long)buffer + (long)(hdrp->a_syms);
|
|
|
|
|
|
|
|
while (sym < end) {
|
|
|
|
sym->n_un.n_name = (char*)sym->n_un.n_strx + displ;
|
|
|
|
sym++;
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
|
|
|
|
err_noexec:
|
|
|
|
dln_errno = DLN_ENOEXEC;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static st_table *
|
2006-08-13 13:44:16 +04:00
|
|
|
sym_hash(struct exec *hdrp, struct nlist *syms)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
st_table *tbl;
|
|
|
|
struct nlist *sym = syms;
|
|
|
|
struct nlist *end = syms + (hdrp->a_syms / sizeof(struct nlist));
|
|
|
|
|
|
|
|
tbl = st_init_strtable();
|
|
|
|
if (tbl == NULL) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (sym < end) {
|
|
|
|
st_insert(tbl, sym->n_un.n_name, sym);
|
|
|
|
sym++;
|
|
|
|
}
|
|
|
|
return tbl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
dln_init(const char *prog)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-07-27 04:15:31 +04:00
|
|
|
char *file, fbuf[MAXPATHLEN];
|
1998-01-16 15:13:05 +03:00
|
|
|
int fd;
|
|
|
|
struct exec hdr;
|
|
|
|
struct nlist *syms;
|
|
|
|
|
|
|
|
if (dln_init_p == 1) return 0;
|
|
|
|
|
2008-07-27 04:15:31 +04:00
|
|
|
file = dln_find_exe_r(prog, NULL, fbuf, sizeof(fbuf));
|
1998-01-16 15:13:05 +03:00
|
|
|
if (file == NULL || (fd = open(file, O_RDONLY)) < 0) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_header(fd, &hdr, 0) == -1) return -1;
|
|
|
|
syms = load_sym(fd, &hdr, 0);
|
|
|
|
if (syms == NULL) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sym_tbl = sym_hash(&hdr, syms);
|
|
|
|
if (sym_tbl == NULL) { /* file may be start with #! */
|
|
|
|
char c = '\0';
|
|
|
|
char buf[MAXPATHLEN];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
free(syms);
|
|
|
|
lseek(fd, 0L, 0);
|
|
|
|
if (read(fd, &c, 1) == -1) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (c != '#') goto err_noexec;
|
|
|
|
if (read(fd, &c, 1) == -1) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (c != '!') goto err_noexec;
|
|
|
|
|
|
|
|
p = buf;
|
2005-02-07 07:00:58 +03:00
|
|
|
/* skip forwarding spaces */
|
1998-01-16 15:13:05 +03:00
|
|
|
while (read(fd, &c, 1) == 1) {
|
|
|
|
if (c == '\n') goto err_noexec;
|
|
|
|
if (c != '\t' && c != ' ') {
|
|
|
|
*p++ = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* read in command name */
|
|
|
|
while (read(fd, p, 1) == 1) {
|
|
|
|
if (*p == '\n' || *p == '\t' || *p == ' ') break;
|
|
|
|
p++;
|
2000-05-09 08:53:16 +04:00
|
|
|
if (p-buf >= MAXPATHLEN) {
|
|
|
|
dln_errno = ENAMETOOLONG;
|
|
|
|
return -1;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return dln_init(buf);
|
|
|
|
}
|
|
|
|
dln_init_p = 1;
|
|
|
|
undef_tbl = st_init_strtable();
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_noexec:
|
|
|
|
close(fd);
|
|
|
|
dln_errno = DLN_ENOEXEC;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
2006-08-13 13:44:16 +04:00
|
|
|
load_text_data(int fd, struct exec *hdrp, int bss, long disp)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
unsigned char* addr;
|
|
|
|
|
|
|
|
lseek(fd, disp + N_TXTOFF(*hdrp), 0);
|
|
|
|
size = hdrp->a_text + hdrp->a_data;
|
|
|
|
|
|
|
|
if (bss == -1) size += hdrp->a_bss;
|
|
|
|
else if (bss > 1) size += bss;
|
|
|
|
|
|
|
|
addr = (unsigned char*)xmalloc(size);
|
|
|
|
if (addr == NULL) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read(fd, addr, size) != size) {
|
|
|
|
dln_errno = errno;
|
|
|
|
free(addr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bss == -1) {
|
|
|
|
memset(addr + hdrp->a_text + hdrp->a_data, 0, hdrp->a_bss);
|
|
|
|
}
|
|
|
|
else if (bss > 0) {
|
|
|
|
memset(addr + hdrp->a_text + hdrp->a_data, 0, bss);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (long)addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
undef_print(char *key, char *value)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
fprintf(stderr, " %s\n", key);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dln_print_undef()
|
|
|
|
{
|
|
|
|
fprintf(stderr, " Undefined symbols:\n");
|
1999-08-13 09:45:20 +04:00
|
|
|
st_foreach(undef_tbl, undef_print, NULL);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dln_undefined()
|
|
|
|
{
|
|
|
|
if (undef_tbl->num_entries > 0) {
|
|
|
|
fprintf(stderr, "dln: Calling undefined function\n");
|
|
|
|
dln_print_undef();
|
|
|
|
rb_exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct undef {
|
|
|
|
char *name;
|
|
|
|
struct relocation_info reloc;
|
|
|
|
long base;
|
|
|
|
char *addr;
|
|
|
|
union {
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
long l;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
static st_table *reloc_tbl = NULL;
|
|
|
|
static void
|
2006-08-13 13:44:16 +04:00
|
|
|
link_undef(const char *name, long base, struct relocation_info *reloc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
static int u_no = 0;
|
|
|
|
struct undef *obj;
|
|
|
|
char *addr = (char*)(reloc->r_address + base);
|
|
|
|
|
|
|
|
obj = (struct undef*)xmalloc(sizeof(struct undef));
|
|
|
|
obj->name = strdup(name);
|
|
|
|
obj->reloc = *reloc;
|
|
|
|
obj->base = base;
|
|
|
|
switch (R_LENGTH(reloc)) {
|
|
|
|
case 0: /* byte */
|
|
|
|
obj->u.c = *addr;
|
|
|
|
break;
|
|
|
|
case 1: /* word */
|
|
|
|
obj->u.s = *(short*)addr;
|
|
|
|
break;
|
|
|
|
case 2: /* long */
|
|
|
|
obj->u.l = *(long*)addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (reloc_tbl == NULL) {
|
|
|
|
reloc_tbl = st_init_numtable();
|
|
|
|
}
|
|
|
|
st_insert(reloc_tbl, u_no++, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct reloc_arg {
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *name;
|
1998-01-16 15:13:05 +03:00
|
|
|
long value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
reloc_undef(int no, struct undef *undef, struct reloc_arg *arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int datum;
|
|
|
|
char *address;
|
|
|
|
#if defined(sun) && defined(sparc)
|
|
|
|
unsigned int mask = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (strcmp(arg->name, undef->name) != 0) return ST_CONTINUE;
|
|
|
|
address = (char*)(undef->base + undef->reloc.r_address);
|
|
|
|
datum = arg->value;
|
|
|
|
|
|
|
|
if (R_PCREL(&(undef->reloc))) datum -= undef->base;
|
|
|
|
#if defined(sun) && defined(sparc)
|
|
|
|
datum += undef->reloc.r_addend;
|
|
|
|
datum >>= R_RIGHTSHIFT(&(undef->reloc));
|
|
|
|
mask = (1 << R_BITSIZE(&(undef->reloc))) - 1;
|
|
|
|
mask |= mask -1;
|
|
|
|
datum &= mask;
|
|
|
|
switch (R_LENGTH(&(undef->reloc))) {
|
|
|
|
case 0:
|
|
|
|
*address = undef->u.c;
|
|
|
|
*address &= ~mask;
|
|
|
|
*address |= datum;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
*(short *)address = undef->u.s;
|
|
|
|
*(short *)address &= ~mask;
|
|
|
|
*(short *)address |= datum;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*(long *)address = undef->u.l;
|
|
|
|
*(long *)address &= ~mask;
|
|
|
|
*(long *)address |= datum;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
switch (R_LENGTH(&(undef->reloc))) {
|
|
|
|
case 0: /* byte */
|
|
|
|
if (R_MEMORY_SUB(&(undef->reloc)))
|
|
|
|
*address = datum - *address;
|
|
|
|
else *address = undef->u.c + datum;
|
|
|
|
break;
|
|
|
|
case 1: /* word */
|
|
|
|
if (R_MEMORY_SUB(&(undef->reloc)))
|
|
|
|
*(short*)address = datum - *(short*)address;
|
|
|
|
else *(short*)address = undef->u.s + datum;
|
|
|
|
break;
|
|
|
|
case 2: /* long */
|
|
|
|
if (R_MEMORY_SUB(&(undef->reloc)))
|
|
|
|
*(long*)address = datum - *(long*)address;
|
|
|
|
else *(long*)address = undef->u.l + datum;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
free(undef->name);
|
|
|
|
free(undef);
|
|
|
|
return ST_DELETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-08-13 13:44:16 +04:00
|
|
|
unlink_undef(const char *name, long value)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct reloc_arg arg;
|
|
|
|
|
|
|
|
arg.name = name;
|
|
|
|
arg.value = value;
|
|
|
|
st_foreach(reloc_tbl, reloc_undef, &arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef N_INDR
|
|
|
|
struct indr_data {
|
|
|
|
char *name0, *name1;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
reloc_repl(int no, struct undef *undef, struct indr_data *data)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
if (strcmp(data->name0, undef->name) == 0) {
|
|
|
|
free(undef->name);
|
|
|
|
undef->name = strdup(data->name1);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
load_1(int fd, long disp, const char *need_init)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-07-26 08:57:48 +04:00
|
|
|
static const char *libc = LIBC_NAME;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct exec hdr;
|
|
|
|
struct relocation_info *reloc = NULL;
|
|
|
|
long block = 0;
|
|
|
|
long new_common = 0; /* Length of new common */
|
|
|
|
struct nlist *syms = NULL;
|
|
|
|
struct nlist *sym;
|
|
|
|
struct nlist *end;
|
|
|
|
int init_p = 0;
|
|
|
|
|
|
|
|
if (load_header(fd, &hdr, disp) == -1) return -1;
|
|
|
|
if (INVALID_OBJECT(hdr)) {
|
|
|
|
dln_errno = DLN_ENOEXEC;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
reloc = load_reloc(fd, &hdr, disp);
|
|
|
|
if (reloc == NULL) return -1;
|
2002-09-05 13:17:48 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
syms = load_sym(fd, &hdr, disp);
|
2002-09-05 13:17:48 +04:00
|
|
|
if (syms == NULL) {
|
|
|
|
free(reloc);
|
|
|
|
return -1;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
sym = syms;
|
|
|
|
end = syms + (hdr.a_syms / sizeof(struct nlist));
|
|
|
|
while (sym < end) {
|
|
|
|
struct nlist *old_sym;
|
|
|
|
int value = sym->n_value;
|
|
|
|
|
|
|
|
#ifdef N_INDR
|
|
|
|
if (sym->n_type == (N_INDR | N_EXT)) {
|
|
|
|
char *key = sym->n_un.n_name;
|
|
|
|
|
|
|
|
if (st_lookup(sym_tbl, sym[1].n_un.n_name, &old_sym)) {
|
2003-07-25 09:36:55 +04:00
|
|
|
if (st_delete(undef_tbl, (st_data_t*)&key, NULL)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
unlink_undef(key, old_sym->n_value);
|
|
|
|
free(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct indr_data data;
|
|
|
|
|
|
|
|
data.name0 = sym->n_un.n_name;
|
|
|
|
data.name1 = sym[1].n_un.n_name;
|
|
|
|
st_foreach(reloc_tbl, reloc_repl, &data);
|
|
|
|
|
|
|
|
st_insert(undef_tbl, strdup(sym[1].n_un.n_name), NULL);
|
2003-07-25 09:36:55 +04:00
|
|
|
if (st_delete(undef_tbl, (st_data_t*)&key, NULL)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
free(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sym += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (sym->n_type == (N_UNDF | N_EXT)) {
|
|
|
|
if (st_lookup(sym_tbl, sym->n_un.n_name, &old_sym) == 0) {
|
|
|
|
old_sym = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
if (old_sym) {
|
|
|
|
sym->n_type = N_EXT | N_COMM;
|
|
|
|
sym->n_value = old_sym->n_value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int rnd =
|
|
|
|
value >= sizeof(double) ? sizeof(double) - 1
|
|
|
|
: value >= sizeof(long) ? sizeof(long) - 1
|
|
|
|
: sizeof(short) - 1;
|
|
|
|
|
|
|
|
sym->n_type = N_COMM;
|
|
|
|
new_common += rnd;
|
|
|
|
new_common &= ~(long)rnd;
|
|
|
|
sym->n_value = new_common;
|
|
|
|
new_common += value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (old_sym) {
|
|
|
|
sym->n_type = N_EXT | N_COMM;
|
|
|
|
sym->n_value = old_sym->n_value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sym->n_value = (long)dln_undefined;
|
|
|
|
st_insert(undef_tbl, strdup(sym->n_un.n_name), NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sym++;
|
|
|
|
}
|
|
|
|
|
|
|
|
block = load_text_data(fd, &hdr, hdr.a_bss + new_common, disp);
|
|
|
|
if (block == 0) goto err_exit;
|
|
|
|
|
|
|
|
sym = syms;
|
|
|
|
while (sym < end) {
|
|
|
|
struct nlist *new_sym;
|
|
|
|
char *key;
|
|
|
|
|
|
|
|
switch (sym->n_type) {
|
|
|
|
case N_COMM:
|
|
|
|
sym->n_value += hdr.a_text + hdr.a_data;
|
|
|
|
case N_TEXT|N_EXT:
|
|
|
|
case N_DATA|N_EXT:
|
|
|
|
|
|
|
|
sym->n_value += block;
|
|
|
|
|
|
|
|
if (st_lookup(sym_tbl, sym->n_un.n_name, &new_sym) != 0
|
|
|
|
&& new_sym->n_value != (long)dln_undefined) {
|
|
|
|
dln_errno = DLN_ECONFL;
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = sym->n_un.n_name;
|
2003-07-25 09:36:55 +04:00
|
|
|
if (st_delete(undef_tbl, (st_data_t*)&key, NULL) != 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
unlink_undef(key, sym->n_value);
|
|
|
|
free(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
new_sym = (struct nlist*)xmalloc(sizeof(struct nlist));
|
|
|
|
*new_sym = *sym;
|
|
|
|
new_sym->n_un.n_name = strdup(sym->n_un.n_name);
|
|
|
|
st_insert(sym_tbl, new_sym->n_un.n_name, new_sym);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case N_TEXT:
|
|
|
|
case N_DATA:
|
|
|
|
sym->n_value += block;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sym++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First comes the text-relocation
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct relocation_info * rel = reloc;
|
|
|
|
struct relocation_info * rel_beg = reloc +
|
|
|
|
(hdr.a_trsize/sizeof(struct relocation_info));
|
|
|
|
struct relocation_info * rel_end = reloc +
|
|
|
|
(hdr.a_trsize+hdr.a_drsize)/sizeof(struct relocation_info);
|
|
|
|
|
|
|
|
while (rel < rel_end) {
|
|
|
|
char *address = (char*)(rel->r_address + block);
|
|
|
|
long datum = 0;
|
|
|
|
#if defined(sun) && defined(sparc)
|
|
|
|
unsigned int mask = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(rel >= rel_beg)
|
|
|
|
address += hdr.a_text;
|
|
|
|
|
|
|
|
if (rel->r_extern) { /* Look it up in symbol-table */
|
|
|
|
sym = &(syms[R_SYMBOL(rel)]);
|
|
|
|
switch (sym->n_type) {
|
|
|
|
case N_EXT|N_UNDF:
|
|
|
|
link_undef(sym->n_un.n_name, block, rel);
|
|
|
|
case N_EXT|N_COMM:
|
|
|
|
case N_COMM:
|
|
|
|
datum = sym->n_value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
} /* end.. look it up */
|
|
|
|
else { /* is static */
|
|
|
|
switch (R_SYMBOL(rel)) {
|
|
|
|
case N_TEXT:
|
|
|
|
case N_DATA:
|
|
|
|
datum = block;
|
|
|
|
break;
|
|
|
|
case N_BSS:
|
|
|
|
datum = block + new_common;
|
|
|
|
break;
|
|
|
|
case N_ABS:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* end .. is static */
|
|
|
|
if (R_PCREL(rel)) datum -= block;
|
|
|
|
|
|
|
|
#if defined(sun) && defined(sparc)
|
|
|
|
datum += rel->r_addend;
|
|
|
|
datum >>= R_RIGHTSHIFT(rel);
|
|
|
|
mask = (1 << R_BITSIZE(rel)) - 1;
|
|
|
|
mask |= mask -1;
|
|
|
|
datum &= mask;
|
|
|
|
|
|
|
|
switch (R_LENGTH(rel)) {
|
|
|
|
case 0:
|
|
|
|
*address &= ~mask;
|
|
|
|
*address |= datum;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
*(short *)address &= ~mask;
|
|
|
|
*(short *)address |= datum;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*(long *)address &= ~mask;
|
|
|
|
*(long *)address |= datum;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
switch (R_LENGTH(rel)) {
|
|
|
|
case 0: /* byte */
|
|
|
|
if (datum < -128 || datum > 127) goto err_exit;
|
|
|
|
*address += datum;
|
|
|
|
break;
|
|
|
|
case 1: /* word */
|
|
|
|
*(short *)address += datum;
|
|
|
|
break;
|
|
|
|
case 2: /* long */
|
|
|
|
*(long *)address += datum;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rel++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_init) {
|
|
|
|
int len;
|
|
|
|
char **libs_to_be_linked = 0;
|
2002-02-18 12:52:48 +03:00
|
|
|
char *buf;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (undef_tbl->num_entries > 0) {
|
|
|
|
if (load_lib(libc) == -1) goto err_exit;
|
|
|
|
}
|
|
|
|
|
2002-02-18 12:52:48 +03:00
|
|
|
init_funcname(&buf, need_init);
|
1998-01-16 15:13:05 +03:00
|
|
|
len = strlen(buf);
|
|
|
|
|
|
|
|
for (sym = syms; sym<end; sym++) {
|
|
|
|
char *name = sym->n_un.n_name;
|
|
|
|
if (name[0] == '_' && sym->n_value >= block) {
|
1999-01-20 07:59:39 +03:00
|
|
|
if (strcmp(name+1, "dln_libs_to_be_linked") == 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
libs_to_be_linked = (char**)sym->n_value;
|
|
|
|
}
|
|
|
|
else if (strcmp(name+1, buf) == 0) {
|
|
|
|
init_p = 1;
|
|
|
|
((int (*)())sym->n_value)();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (libs_to_be_linked && undef_tbl->num_entries > 0) {
|
|
|
|
while (*libs_to_be_linked) {
|
|
|
|
load_lib(*libs_to_be_linked);
|
|
|
|
libs_to_be_linked++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(reloc);
|
|
|
|
free(syms);
|
|
|
|
if (need_init) {
|
|
|
|
if (init_p == 0) {
|
|
|
|
dln_errno = DLN_ENOINIT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (undef_tbl->num_entries > 0) {
|
|
|
|
if (load_lib(libc) == -1) goto err_exit;
|
|
|
|
if (undef_tbl->num_entries > 0) {
|
|
|
|
dln_errno = DLN_EUNDEF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_exit:
|
|
|
|
if (syms) free(syms);
|
|
|
|
if (reloc) free(reloc);
|
|
|
|
if (block) free((char*)block);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int target_offset;
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
search_undef(const char *key, int value, st_table *lib_tbl)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-05-24 08:34:26 +04:00
|
|
|
long offset;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (st_lookup(lib_tbl, key, &offset) == 0) return ST_CONTINUE;
|
|
|
|
target_offset = offset;
|
|
|
|
return ST_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct symdef {
|
1999-01-20 07:59:39 +03:00
|
|
|
int rb_str_index;
|
1998-01-16 15:13:05 +03:00
|
|
|
int lib_offset;
|
|
|
|
};
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
char *dln_librrb_ary_path = DLN_DEFAULT_LIB_PATH;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
load_lib(const char *lib)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-07-28 09:29:56 +04:00
|
|
|
char *path, *file, fbuf[MAXPATHLEN];
|
1998-01-16 15:13:05 +03:00
|
|
|
char armagic[SARMAG];
|
|
|
|
int fd, size;
|
|
|
|
struct ar_hdr ahdr;
|
|
|
|
st_table *lib_tbl = NULL;
|
|
|
|
int *data, nsym;
|
|
|
|
struct symdef *base;
|
|
|
|
char *name_base;
|
|
|
|
|
|
|
|
if (dln_init_p == 0) {
|
|
|
|
dln_errno = DLN_ENOINIT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (undef_tbl->num_entries == 0) return 0;
|
|
|
|
dln_errno = DLN_EBADLIB;
|
|
|
|
|
|
|
|
if (lib[0] == '-' && lib[1] == 'l') {
|
2005-07-19 12:31:04 +04:00
|
|
|
long len = strlen(lib) + 4;
|
|
|
|
char *p = alloca(len);
|
|
|
|
snprintf(p, len, "lib%s.a", lib+2);
|
1998-01-16 15:13:05 +03:00
|
|
|
lib = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* library search path: */
|
|
|
|
/* look for environment variable DLN_LIBRARY_PATH first. */
|
1999-01-20 07:59:39 +03:00
|
|
|
/* then variable dln_librrb_ary_path. */
|
1998-01-16 15:13:05 +03:00
|
|
|
/* if path is still NULL, use "." for path. */
|
|
|
|
path = getenv("DLN_LIBRARY_PATH");
|
1999-01-20 07:59:39 +03:00
|
|
|
if (path == NULL) path = dln_librrb_ary_path;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-07-28 09:29:56 +04:00
|
|
|
file = dln_find_file_r(lib, path, fbuf, sizeof(fbuf));
|
1998-01-16 15:13:05 +03:00
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
if (fd == -1) goto syserr;
|
|
|
|
size = read(fd, armagic, SARMAG);
|
|
|
|
if (size == -1) goto syserr;
|
|
|
|
|
|
|
|
if (size != SARMAG) {
|
|
|
|
dln_errno = DLN_ENOTLIB;
|
|
|
|
goto badlib;
|
|
|
|
}
|
|
|
|
size = read(fd, &ahdr, sizeof(ahdr));
|
|
|
|
if (size == -1) goto syserr;
|
|
|
|
if (size != sizeof(ahdr) || sscanf(ahdr.ar_size, "%d", &size) != 1) {
|
|
|
|
goto badlib;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(ahdr.ar_name, "__.SYMDEF", 9) == 0) {
|
|
|
|
/* make hash table from __.SYMDEF */
|
|
|
|
|
|
|
|
lib_tbl = st_init_strtable();
|
|
|
|
data = (int*)xmalloc(size);
|
|
|
|
if (data == NULL) goto syserr;
|
|
|
|
size = read(fd, data, size);
|
|
|
|
nsym = *data / sizeof(struct symdef);
|
|
|
|
base = (struct symdef*)(data + 1);
|
|
|
|
name_base = (char*)(base + nsym) + sizeof(int);
|
|
|
|
while (nsym > 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
char *name = name_base + base->rb_str_index;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
st_insert(lib_tbl, name, base->lib_offset + sizeof(ahdr));
|
|
|
|
nsym--;
|
|
|
|
base++;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
target_offset = -1;
|
|
|
|
st_foreach(undef_tbl, search_undef, lib_tbl);
|
|
|
|
if (target_offset == -1) break;
|
|
|
|
if (load_1(fd, target_offset, 0) == -1) {
|
|
|
|
st_free_table(lib_tbl);
|
|
|
|
free(data);
|
|
|
|
goto badlib;
|
|
|
|
}
|
|
|
|
if (undef_tbl->num_entries == 0) break;
|
|
|
|
}
|
|
|
|
free(data);
|
|
|
|
st_free_table(lib_tbl);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* linear library, need to scan (FUTURE) */
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int offset = SARMAG;
|
|
|
|
int found = 0;
|
|
|
|
struct exec hdr;
|
|
|
|
struct nlist *syms, *sym, *end;
|
|
|
|
|
|
|
|
while (undef_tbl->num_entries > 0) {
|
|
|
|
found = 0;
|
|
|
|
lseek(fd, offset, 0);
|
|
|
|
size = read(fd, &ahdr, sizeof(ahdr));
|
|
|
|
if (size == -1) goto syserr;
|
|
|
|
if (size == 0) break;
|
|
|
|
if (size != sizeof(ahdr)
|
|
|
|
|| sscanf(ahdr.ar_size, "%d", &size) != 1) {
|
|
|
|
goto badlib;
|
|
|
|
}
|
|
|
|
offset += sizeof(ahdr);
|
|
|
|
if (load_header(fd, &hdr, offset) == -1)
|
|
|
|
goto badlib;
|
|
|
|
syms = load_sym(fd, &hdr, offset);
|
|
|
|
if (syms == NULL) goto badlib;
|
|
|
|
sym = syms;
|
|
|
|
end = syms + (hdr.a_syms / sizeof(struct nlist));
|
|
|
|
while (sym < end) {
|
|
|
|
if (sym->n_type == N_EXT|N_TEXT
|
|
|
|
&& st_lookup(undef_tbl, sym->n_un.n_name, NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sym++;
|
|
|
|
}
|
|
|
|
if (sym < end) {
|
|
|
|
found++;
|
|
|
|
free(syms);
|
|
|
|
if (load_1(fd, offset, 0) == -1) {
|
|
|
|
goto badlib;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += size;
|
|
|
|
if (offset & 1) offset++;
|
|
|
|
}
|
|
|
|
if (found) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
syserr:
|
|
|
|
dln_errno = errno;
|
|
|
|
badlib:
|
|
|
|
if (fd >= 0) close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-08-13 13:44:16 +04:00
|
|
|
load(const char *file)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (dln_init_p == 0) {
|
|
|
|
if (dln_init(dln_argv0) == -1) return -1;
|
|
|
|
}
|
|
|
|
result = strlen(file);
|
|
|
|
if (file[result-1] == 'a') {
|
|
|
|
return load_lib(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
if (fd == -1) {
|
|
|
|
dln_errno = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
result = load_1(fd, 0, file);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2006-08-13 13:44:16 +04:00
|
|
|
dln_sym(const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct nlist *sym;
|
|
|
|
|
|
|
|
if (st_lookup(sym_tbl, name, &sym))
|
|
|
|
return (void*)sym->n_value;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_DLN_A_OUT */
|
|
|
|
|
|
|
|
#ifdef USE_DLN_DLOPEN
|
2003-12-25 11:49:20 +03:00
|
|
|
# include <dlfcn.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifdef __hpux
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <errno.h>
|
|
|
|
#include "dl.h"
|
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#if defined(_AIX)
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <ctype.h> /* for isdigit() */
|
|
|
|
#include <errno.h> /* for global errno */
|
|
|
|
#include <sys/ldr.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NeXT
|
1999-01-20 07:59:39 +03:00
|
|
|
#if NS_TARGET_MAJOR < 4
|
|
|
|
#include <mach-o/rld.h>
|
|
|
|
#else
|
|
|
|
#include <mach-o/dyld.h>
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
#ifndef NSLINKMODULE_OPTION_BINDNOW
|
|
|
|
#define NSLINKMODULE_OPTION_BINDNOW 1
|
1999-01-20 07:59:39 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
#else
|
2007-02-23 04:31:37 +03:00
|
|
|
#ifdef MACOSX_DYLD
|
1999-08-13 09:45:20 +04:00
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
#endif
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-06-07 19:49:37 +04:00
|
|
|
#if defined _WIN32 && !defined __CYGWIN__
|
1998-01-16 15:19:22 +03:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2002-12-02 10:57:17 +03:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
#undef FormatMessage
|
|
|
|
#define FormatMessage FormatMessageA
|
|
|
|
#undef LoadLibrary
|
|
|
|
#define LoadLibrary LoadLibraryA
|
|
|
|
#undef GetProcAddress
|
|
|
|
#define GetProcAddress GetProcAddressA
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static const char *
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
dln_strerror(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifdef USE_DLN_A_OUT
|
|
|
|
char *strerror();
|
|
|
|
|
|
|
|
switch (dln_errno) {
|
|
|
|
case DLN_ECONFL:
|
|
|
|
return "Symbol name conflict";
|
|
|
|
case DLN_ENOINIT:
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-19 03:19:47 +04:00
|
|
|
return "No initializer given";
|
1998-01-16 15:13:05 +03:00
|
|
|
case DLN_EUNDEF:
|
|
|
|
return "Unresolved symbols";
|
|
|
|
case DLN_ENOTLIB:
|
|
|
|
return "Not a library file";
|
|
|
|
case DLN_EBADLIB:
|
|
|
|
return "Malformed library file";
|
|
|
|
case DLN_EINIT:
|
|
|
|
return "Not initialized";
|
|
|
|
default:
|
|
|
|
return strerror(dln_errno);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_DLN_DLOPEN
|
|
|
|
return (char*)dlerror();
|
|
|
|
#endif
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2000-06-07 19:49:37 +04:00
|
|
|
#if defined _WIN32 && !defined __CYGWIN__
|
1998-01-16 15:19:22 +03:00
|
|
|
static char message[1024];
|
1999-01-20 07:59:39 +03:00
|
|
|
int error = GetLastError();
|
|
|
|
char *p = message;
|
|
|
|
p += sprintf(message, "%d: ", error);
|
1998-01-16 15:19:22 +03:00
|
|
|
FormatMessage(
|
2001-08-24 09:45:55 +04:00
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
1998-01-16 15:19:22 +03:00
|
|
|
NULL,
|
1999-01-20 07:59:39 +03:00
|
|
|
error,
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
p,
|
|
|
|
sizeof message - strlen(message),
|
1998-01-16 15:19:22 +03:00
|
|
|
NULL);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
for (p = message; *p; p++) {
|
|
|
|
if (*p == '\n' || *p == '\r')
|
|
|
|
*p = ' ';
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
return message;
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-09 10:26:21 +03:00
|
|
|
#if defined(_AIX) && ! defined(_IA64)
|
1998-01-16 15:13:05 +03:00
|
|
|
static void
|
1999-08-13 09:45:20 +04:00
|
|
|
aix_loaderror(const char *pathname)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
char *message[8], errbuf[1024];
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
struct errtab {
|
2003-12-05 00:57:35 +03:00
|
|
|
int errnum;
|
1998-01-16 15:13:05 +03:00
|
|
|
char *errstr;
|
|
|
|
} load_errtab[] = {
|
|
|
|
{L_ERROR_TOOMANY, "too many errors, rest skipped."},
|
|
|
|
{L_ERROR_NOLIB, "can't load library:"},
|
|
|
|
{L_ERROR_UNDEF, "can't find symbol in library:"},
|
|
|
|
{L_ERROR_RLDBAD,
|
|
|
|
"RLD index out of range or bad relocation type:"},
|
|
|
|
{L_ERROR_FORMAT, "not a valid, executable xcoff file:"},
|
|
|
|
{L_ERROR_MEMBER,
|
|
|
|
"file not an archive or does not contain requested member:"},
|
|
|
|
{L_ERROR_TYPE, "symbol table mismatch:"},
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-19 03:19:47 +04:00
|
|
|
{L_ERROR_ALIGN, "text alignment in file is wrong."},
|
1998-01-16 15:13:05 +03:00
|
|
|
{L_ERROR_SYSTEM, "System error:"},
|
|
|
|
{L_ERROR_ERRNO, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LOAD_ERRTAB_LEN (sizeof(load_errtab)/sizeof(load_errtab[0]))
|
|
|
|
#define ERRBUF_APPEND(s) strncat(errbuf, s, sizeof(errbuf)-strlen(errbuf)-1)
|
|
|
|
|
2001-03-13 08:45:13 +03:00
|
|
|
snprintf(errbuf, 1024, "load failed - %s ", pathname);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (!loadquery(1, &message[0], sizeof(message)))
|
|
|
|
ERRBUF_APPEND(strerror(errno));
|
|
|
|
for(i = 0; message[i] && *message[i]; i++) {
|
|
|
|
int nerr = atoi(message[i]);
|
1999-08-13 09:45:20 +04:00
|
|
|
for (j=0; j<LOAD_ERRTAB_LEN; j++) {
|
2003-12-05 00:57:35 +03:00
|
|
|
if (nerr == load_errtab[i].errnum && load_errtab[i].errstr)
|
1998-01-16 15:13:05 +03:00
|
|
|
ERRBUF_APPEND(load_errtab[i].errstr);
|
|
|
|
}
|
2001-02-26 08:29:06 +03:00
|
|
|
while (isdigit(*message[i])) message[i]++;
|
1998-01-16 15:13:05 +03:00
|
|
|
ERRBUF_APPEND(message[i]);
|
|
|
|
ERRBUF_APPEND("\n");
|
|
|
|
}
|
|
|
|
errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_loaderror(errbuf);
|
1998-01-16 15:13:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-20 18:25:34 +04:00
|
|
|
#endif /* NO_DLN_LOAD */
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
void*
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
dln_load(const char *file)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2005-04-20 18:25:34 +04:00
|
|
|
#ifdef NO_DLN_LOAD
|
|
|
|
rb_raise(rb_eLoadError, "this executable file can't load extension libraries");
|
|
|
|
#else
|
|
|
|
|
2002-06-17 05:54:51 +04:00
|
|
|
#if !defined(_AIX) && !defined(NeXT)
|
|
|
|
const char *error = 0;
|
|
|
|
#define DLN_ERROR() (error = dln_strerror(), strcpy(ALLOCA_N(char, strlen(error) + 1), error))
|
|
|
|
#endif
|
|
|
|
|
2000-06-07 19:49:37 +04:00
|
|
|
#if defined _WIN32 && !defined __CYGWIN__
|
1998-01-16 15:19:22 +03:00
|
|
|
HINSTANCE handle;
|
2000-05-10 06:58:41 +04:00
|
|
|
char winfile[MAXPATHLEN];
|
1998-01-16 15:19:22 +03:00
|
|
|
void (*init_fct)();
|
2002-02-18 12:52:48 +03:00
|
|
|
char *buf;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2000-05-10 06:58:41 +04:00
|
|
|
if (strlen(file) >= MAXPATHLEN) rb_loaderror("filename too long");
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
/* Load the file as an object one */
|
2002-02-18 12:52:48 +03:00
|
|
|
init_funcname(&buf, file);
|
1998-01-16 15:19:22 +03:00
|
|
|
|
|
|
|
strcpy(winfile, file);
|
|
|
|
|
|
|
|
/* Load file */
|
2002-03-06 12:00:32 +03:00
|
|
|
if ((handle = LoadLibrary(winfile)) == NULL) {
|
2002-06-17 05:54:51 +04:00
|
|
|
error = dln_strerror();
|
1998-01-16 15:19:22 +03:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((init_fct = (void(*)())GetProcAddress(handle, buf)) == NULL) {
|
2001-03-26 09:11:18 +04:00
|
|
|
rb_loaderror("%s - %s\n%s", dln_strerror(), buf, file);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2002-02-18 12:52:48 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
/* Call the init code */
|
|
|
|
(*init_fct)();
|
2001-05-02 08:22:21 +04:00
|
|
|
return handle;
|
1998-01-16 15:19:22 +03:00
|
|
|
#else
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef USE_DLN_A_OUT
|
|
|
|
if (load(file) == -1) {
|
2002-06-17 05:54:51 +04:00
|
|
|
error = dln_strerror();
|
1998-01-16 15:13:05 +03:00
|
|
|
goto failed;
|
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
return 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
|
|
|
|
2002-02-18 12:52:48 +03:00
|
|
|
char *buf;
|
1998-01-16 15:13:05 +03:00
|
|
|
/* Load the file as an object one */
|
2002-02-18 12:52:48 +03:00
|
|
|
init_funcname(&buf, file);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#ifdef USE_DLN_DLOPEN
|
|
|
|
#define DLN_DEFINED
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
void (*init_fct)();
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#ifndef RTLD_LAZY
|
|
|
|
# define RTLD_LAZY 1
|
|
|
|
#endif
|
2004-02-02 13:01:57 +03:00
|
|
|
#ifdef __INTERIX
|
|
|
|
# undef RTLD_GLOBAL
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
#ifndef RTLD_GLOBAL
|
|
|
|
# define RTLD_GLOBAL 0
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* Load file */
|
1999-01-20 07:59:39 +03:00
|
|
|
if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {
|
2002-06-17 05:54:51 +04:00
|
|
|
error = dln_strerror();
|
1998-01-16 15:13:05 +03:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2002-02-18 12:52:48 +03:00
|
|
|
init_fct = (void(*)())dlsym(handle, buf);
|
|
|
|
if (init_fct == NULL) {
|
2002-06-17 05:54:51 +04:00
|
|
|
error = DLN_ERROR();
|
2001-05-02 08:22:21 +04:00
|
|
|
dlclose(handle);
|
1998-01-16 15:13:05 +03:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Call the init code */
|
|
|
|
(*init_fct)();
|
2002-02-18 12:52:48 +03:00
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
return handle;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#endif /* USE_DLN_DLOPEN */
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifdef __hpux
|
1998-01-16 15:13:05 +03:00
|
|
|
#define DLN_DEFINED
|
|
|
|
{
|
|
|
|
shl_t lib = NULL;
|
|
|
|
int flags;
|
|
|
|
void (*init_fct)();
|
|
|
|
|
|
|
|
flags = BIND_DEFERRED;
|
|
|
|
lib = shl_load(file, flags, 0);
|
|
|
|
if (lib == NULL) {
|
1999-01-20 07:59:39 +03:00
|
|
|
extern int errno;
|
|
|
|
rb_loaderror("%s - %s", strerror(errno), file);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
shl_findsym(&lib, buf, TYPE_PROCEDURE, (void*)&init_fct);
|
|
|
|
if (init_fct == NULL) {
|
|
|
|
shl_findsym(&lib, buf, TYPE_UNDEFINED, (void*)&init_fct);
|
|
|
|
if (init_fct == NULL) {
|
|
|
|
errno = ENOSYM;
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_loaderror("%s - %s", strerror(ENOSYM), file);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(*init_fct)();
|
2001-05-02 08:22:21 +04:00
|
|
|
return (void*)lib;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#endif /* hpux */
|
|
|
|
|
2001-01-09 10:26:21 +03:00
|
|
|
#if defined(_AIX) && ! defined(_IA64)
|
1998-01-16 15:13:05 +03:00
|
|
|
#define DLN_DEFINED
|
|
|
|
{
|
|
|
|
void (*init_fct)();
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
init_fct = (void(*)())load((char*)file, 1, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (init_fct == NULL) {
|
|
|
|
aix_loaderror(file);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (loadbind(0, (void*)dln_load, (void*)init_fct) == -1) {
|
|
|
|
aix_loaderror(file);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
(*init_fct)();
|
2001-05-02 08:22:21 +04:00
|
|
|
return (void*)init_fct;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#endif /* _AIX */
|
|
|
|
|
2007-02-23 04:31:37 +03:00
|
|
|
#if defined(NeXT) || defined(MACOSX_DYLD)
|
1998-01-16 15:13:05 +03:00
|
|
|
#define DLN_DEFINED
|
|
|
|
/*----------------------------------------------------
|
|
|
|
By SHIROYAMA Takayuki Psi@fortune.nest.or.jp
|
|
|
|
|
|
|
|
Special Thanks...
|
|
|
|
Yu tomoak-i@is.aist-nara.ac.jp,
|
|
|
|
Mi hisho@tasihara.nest.or.jp,
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
sunshine@sunshineco.com,
|
1998-01-16 15:13:05 +03:00
|
|
|
and... Miss ARAI Akino(^^;)
|
|
|
|
----------------------------------------------------*/
|
1999-08-13 09:45:20 +04:00
|
|
|
#if defined(NeXT) && (NS_TARGET_MAJOR < 4)/* NeXTSTEP rld functions */
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
NXStream* s;
|
1998-01-16 15:13:05 +03:00
|
|
|
unsigned long init_address;
|
|
|
|
char *object_files[2] = {NULL, NULL};
|
|
|
|
|
|
|
|
void (*init_fct)();
|
|
|
|
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
object_files[0] = (char*)file;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
s = NXOpenFile(2,NX_WRITEONLY);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/* Load object file, if return value ==0 , load failed*/
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
if(rld_load(s, NULL, object_files, NULL) == 0) {
|
|
|
|
NXFlush(s);
|
|
|
|
NXClose(s);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_loaderror("Failed to load %.200s", file);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* lookup the initial function */
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
if(rld_lookup(s, buf, &init_address) == 0) {
|
|
|
|
NXFlush(s);
|
|
|
|
NXClose(s);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_loaderror("Failed to lookup Init function %.200s", file);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
NXFlush(s);
|
|
|
|
NXClose(s);
|
|
|
|
|
|
|
|
/* Cannot call *init_address directory, so copy this value to
|
|
|
|
funtion pointer */
|
1998-01-16 15:13:05 +03:00
|
|
|
init_fct = (void(*)())init_address;
|
|
|
|
(*init_fct)();
|
2001-05-02 08:22:21 +04:00
|
|
|
return (void*)init_address;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
#else/* OPENSTEP dyld functions */
|
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
int dyld_result;
|
|
|
|
NSObjectFileImage obj_file; /* handle, but not use it */
|
1999-01-20 07:59:39 +03:00
|
|
|
/* "file" is module file name .
|
2002-02-18 12:52:48 +03:00
|
|
|
"buf" is pointer to initial function name with "_" . */
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
void (*init_fct)();
|
|
|
|
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
dyld_result = NSCreateObjectFileImageFromFile(file, &obj_file);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
if (dyld_result != NSObjectFileImageSuccess) {
|
|
|
|
rb_loaderror("Failed to load %.200s", file);
|
|
|
|
}
|
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
NSLinkModule(obj_file, file, NSLINKMODULE_OPTION_BINDNOW);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
/* lookup the initial function */
|
2002-10-17 20:13:44 +04:00
|
|
|
if(!NSIsSymbolNameDefined(buf)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_loaderror("Failed to lookup Init function %.200s",file);
|
2002-10-17 20:13:44 +04:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
|
1999-01-20 07:59:39 +03:00
|
|
|
(*init_fct)();
|
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
return (void*)init_fct;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
#endif /* rld or dyld */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#ifdef __BEOS__
|
|
|
|
# define DLN_DEFINED
|
|
|
|
{
|
|
|
|
status_t err_stat; /* BeOS error status code */
|
|
|
|
image_id img_id; /* extention module unique id */
|
|
|
|
void (*init_fct)(); /* initialize function for extention module */
|
|
|
|
|
|
|
|
/* load extention module */
|
|
|
|
img_id = load_add_on(file);
|
|
|
|
if (img_id <= 0) {
|
2008-09-19 04:33:19 +04:00
|
|
|
rb_loaderror("Failed to load add_on %.200s error_code=%x",
|
|
|
|
file, img_id);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find symbol for module initialize function. */
|
2000-05-09 08:53:16 +04:00
|
|
|
/* The Be Book KernelKit Images section described to use
|
|
|
|
B_SYMBOL_TYPE_TEXT for symbol of function, not
|
|
|
|
B_SYMBOL_TYPE_CODE. Why ? */
|
|
|
|
/* strcat(init_fct_symname, "__Fv"); */ /* parameter nothing. */
|
|
|
|
/* "__Fv" dont need! The Be Book Bug ? */
|
1999-01-20 07:59:39 +03:00
|
|
|
err_stat = get_image_symbol(img_id, buf,
|
1999-08-13 09:45:20 +04:00
|
|
|
B_SYMBOL_TYPE_TEXT, (void **)&init_fct);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
if (err_stat != B_NO_ERROR) {
|
2000-05-09 08:53:16 +04:00
|
|
|
char real_name[MAXPATHLEN];
|
2000-05-10 06:58:41 +04:00
|
|
|
|
2000-05-09 08:53:16 +04:00
|
|
|
strcpy(real_name, buf);
|
|
|
|
strcat(real_name, "__Fv");
|
1999-01-20 07:59:39 +03:00
|
|
|
err_stat = get_image_symbol(img_id, real_name,
|
2000-05-09 08:53:16 +04:00
|
|
|
B_SYMBOL_TYPE_TEXT, (void **)&init_fct);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((B_BAD_IMAGE_ID == err_stat) || (B_BAD_INDEX == err_stat)) {
|
|
|
|
unload_add_on(img_id);
|
|
|
|
rb_loaderror("Failed to lookup Init function %.200s", file);
|
|
|
|
}
|
|
|
|
else if (B_NO_ERROR != err_stat) {
|
|
|
|
char errmsg[] = "Internal of BeOS version. %.200s (symbol_name = %s)";
|
|
|
|
unload_add_on(img_id);
|
|
|
|
rb_loaderror(errmsg, strerror(err_stat), buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call module initialize function. */
|
|
|
|
(*init_fct)();
|
2001-05-02 08:22:21 +04:00
|
|
|
return (void*)img_id;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
#endif /* __BEOS__*/
|
|
|
|
|
2007-02-23 04:31:37 +03:00
|
|
|
#ifdef __MACOS__ /* Mac OS 9 or before */
|
1999-01-20 07:59:39 +03:00
|
|
|
# define DLN_DEFINED
|
|
|
|
{
|
|
|
|
OSErr err;
|
|
|
|
FSSpec libspec;
|
|
|
|
CFragConnectionID connID;
|
|
|
|
Ptr mainAddr;
|
|
|
|
char errMessage[1024];
|
|
|
|
Boolean isfolder, didsomething;
|
|
|
|
Str63 fragname;
|
|
|
|
Ptr symAddr;
|
|
|
|
CFragSymbolClass class;
|
|
|
|
void (*init_fct)();
|
|
|
|
char fullpath[MAXPATHLEN];
|
|
|
|
|
|
|
|
strcpy(fullpath, file);
|
|
|
|
|
|
|
|
/* resolve any aliases to find the real file */
|
|
|
|
c2pstr(fullpath);
|
|
|
|
(void)FSMakeFSSpec(0, 0, fullpath, &libspec);
|
|
|
|
err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (err) {
|
|
|
|
rb_loaderror("Unresolved Alias - %s", file);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the fragment (or return the connID if it is already loaded */
|
|
|
|
fragname[0] = 0;
|
|
|
|
err = GetDiskFragment(&libspec, 0, 0, fragname,
|
|
|
|
kLoadCFrag, &connID, &mainAddr,
|
|
|
|
errMessage);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (err) {
|
|
|
|
p2cstr(errMessage);
|
|
|
|
rb_loaderror("%s - %s",errMessage , file);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Locate the address of the correct init function */
|
|
|
|
c2pstr(buf);
|
|
|
|
err = FindSymbol(connID, buf, &symAddr, &class);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (err) {
|
|
|
|
rb_loaderror("Unresolved symbols - %s" , file);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
init_fct = (void (*)())symAddr;
|
|
|
|
(*init_fct)();
|
2001-05-02 08:22:21 +04:00
|
|
|
return (void*)init_fct;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
#endif /* __MACOS__ */
|
|
|
|
|
2002-03-22 10:26:42 +03:00
|
|
|
#if defined(__VMS)
|
|
|
|
#define DLN_DEFINED
|
|
|
|
{
|
|
|
|
void *handle, (*init_fct)();
|
|
|
|
char *fname, *p1, *p2;
|
|
|
|
|
|
|
|
fname = (char *)__alloca(strlen(file)+1);
|
|
|
|
strcpy(fname,file);
|
|
|
|
if (p1 = strrchr(fname,'/'))
|
|
|
|
fname = p1 + 1;
|
|
|
|
if (p2 = strrchr(fname,'.'))
|
2002-03-26 06:01:30 +03:00
|
|
|
*p2 = '\0';
|
2002-03-22 10:26:42 +03:00
|
|
|
|
|
|
|
if ((handle = (void*)dlopen(fname, 0)) == NULL) {
|
2002-06-17 05:54:51 +04:00
|
|
|
error = dln_strerror();
|
2002-03-22 10:26:42 +03:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((init_fct = (void (*)())dlsym(handle, buf)) == NULL) {
|
2002-06-17 05:54:51 +04:00
|
|
|
error = DLN_ERROR();
|
2002-03-22 10:26:42 +03:00
|
|
|
dlclose(handle);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Call the init code */
|
|
|
|
(*init_fct)();
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
#endif /* __VMS */
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifndef DLN_DEFINED
|
2002-06-17 17:42:15 +04:00
|
|
|
rb_notimplement();
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* USE_DLN_A_OUT */
|
1998-01-16 15:19:22 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
#if !defined(_AIX) && !defined(NeXT)
|
|
|
|
failed:
|
2002-06-17 05:54:51 +04:00
|
|
|
rb_loaderror("%s - %s", error, file);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2005-04-20 18:25:34 +04:00
|
|
|
|
|
|
|
#endif /* NO_DLN_LOAD */
|
2001-05-16 13:05:54 +04:00
|
|
|
return 0; /* dummy return */
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-05-08 01:43:54 +04:00
|
|
|
static char *dln_find_1(const char *fname, const char *path, char *buf, int size, int exe_flag);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
char *
|
2008-05-08 01:43:54 +04:00
|
|
|
dln_find_exe_r(const char *fname, const char *path, char *buf, int size)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!path) {
|
2003-06-20 10:22:50 +04:00
|
|
|
path = getenv(PATH_ENV);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!path) {
|
2008-10-04 17:12:13 +04:00
|
|
|
#if defined(MSDOS) || defined(_WIN32) || defined(__MACOS__)
|
1999-01-20 07:59:39 +03:00
|
|
|
path = "/usr/local/bin;/usr/ucb;/usr/bin;/bin;.";
|
|
|
|
#else
|
|
|
|
path = "/usr/local/bin:/usr/ucb:/usr/bin:/bin:.";
|
|
|
|
#endif
|
|
|
|
}
|
2008-05-08 01:43:54 +04:00
|
|
|
return dln_find_1(fname, path, buf, size, 1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2008-05-08 01:43:54 +04:00
|
|
|
dln_find_file_r(const char *fname, const char *path, char *buf, int size)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifndef __MACOS__
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!path) path = ".";
|
2008-05-08 01:43:54 +04:00
|
|
|
return dln_find_1(fname, path, buf, size, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
#else
|
|
|
|
if (!path) path = ".";
|
2008-05-08 01:43:54 +04:00
|
|
|
return _macruby_path_conv_posix_to_macos(dln_find_1(fname, path, buf, size, 0));
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char fbuf[MAXPATHLEN];
|
|
|
|
|
2008-05-08 01:43:54 +04:00
|
|
|
char *
|
|
|
|
dln_find_exe(const char *fname, const char *path)
|
|
|
|
{
|
|
|
|
return dln_find_exe_r(fname, path, fbuf, sizeof(fbuf));
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
dln_find_file(const char *fname, const char *path)
|
|
|
|
{
|
|
|
|
return dln_find_file_r(fname, path, fbuf, sizeof(fbuf));
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static char *
|
2008-05-08 01:43:54 +04:00
|
|
|
dln_find_1(const char *fname, const char *path, char *fbuf, int size,
|
|
|
|
int exe_flag /* non 0 if looking for executable. */)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2005-09-12 15:03:24 +04:00
|
|
|
register const char *dp;
|
|
|
|
register const char *ep;
|
1998-01-16 15:13:05 +03:00
|
|
|
register char *bp;
|
|
|
|
struct stat st;
|
2001-05-30 13:12:34 +04:00
|
|
|
#ifdef __MACOS__
|
1999-08-13 09:45:20 +04:00
|
|
|
const char* mac_fullpath;
|
1999-01-20 07:59:39 +03:00
|
|
|
#endif
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2005-09-12 15:03:24 +04:00
|
|
|
#define RETURN_IF(expr) if (expr) return (char *)fname;
|
|
|
|
|
|
|
|
RETURN_IF(!fname);
|
|
|
|
RETURN_IF(fname[0] == '/');
|
|
|
|
RETURN_IF(strncmp("./", fname, 2) == 0 || strncmp("../", fname, 3) == 0);
|
|
|
|
RETURN_IF(exe_flag && strchr(fname, '/'));
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#ifdef DOSISH
|
2005-09-12 15:03:24 +04:00
|
|
|
RETURN_IF(fname[0] == '\\');
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
# ifdef DOSISH_DRIVE_LETTER
|
2005-09-12 15:03:24 +04:00
|
|
|
RETURN_IF(strlen(fname) > 2 && fname[1] == ':');
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
# endif
|
2005-09-12 15:03:24 +04:00
|
|
|
RETURN_IF(strncmp(".\\", fname, 2) == 0 || strncmp("..\\", fname, 3) == 0);
|
|
|
|
RETURN_IF(exe_flag && strchr(fname, '\\'));
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
2005-09-12 15:03:24 +04:00
|
|
|
#undef RETURN_IF
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
for (dp = path;; dp = ++ep) {
|
|
|
|
register int l;
|
|
|
|
int i;
|
|
|
|
int fspace;
|
|
|
|
|
|
|
|
/* extract a component */
|
1999-08-13 09:45:20 +04:00
|
|
|
ep = strchr(dp, PATH_SEP[0]);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (ep == NULL)
|
|
|
|
ep = dp+strlen(dp);
|
|
|
|
|
|
|
|
/* find the length of that component */
|
|
|
|
l = ep - dp;
|
|
|
|
bp = fbuf;
|
2008-05-08 01:43:54 +04:00
|
|
|
fspace = size - 2;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (l > 0) {
|
|
|
|
/*
|
|
|
|
** If the length of the component is zero length,
|
|
|
|
** start from the current directory. If the
|
|
|
|
** component begins with "~", start from the
|
|
|
|
** user's $HOME environment variable. Otherwise
|
|
|
|
** take the path literally.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (*dp == '~' && (l == 1 ||
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined(DOSISH)
|
1999-01-20 07:59:39 +03:00
|
|
|
dp[1] == '\\' ||
|
|
|
|
#endif
|
|
|
|
dp[1] == '/')) {
|
1998-01-16 15:13:05 +03:00
|
|
|
char *home;
|
|
|
|
|
|
|
|
home = getenv("HOME");
|
|
|
|
if (home != NULL) {
|
|
|
|
i = strlen(home);
|
|
|
|
if ((fspace -= i) < 0)
|
|
|
|
goto toolong;
|
|
|
|
memcpy(bp, home, i);
|
|
|
|
bp += i;
|
|
|
|
}
|
|
|
|
dp++;
|
|
|
|
l--;
|
|
|
|
}
|
|
|
|
if (l > 0) {
|
|
|
|
if ((fspace -= l) < 0)
|
|
|
|
goto toolong;
|
|
|
|
memcpy(bp, dp, l);
|
|
|
|
bp += l;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a "/" between directory and filename */
|
|
|
|
if (ep[-1] != '/')
|
|
|
|
*bp++ = '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now append the file name */
|
|
|
|
i = strlen(fname);
|
|
|
|
if ((fspace -= i) < 0) {
|
|
|
|
toolong:
|
|
|
|
fprintf(stderr, "openpath: pathname too long (ignored)\n");
|
|
|
|
*bp = '\0';
|
|
|
|
fprintf(stderr, "\tDirectory \"%s\"\n", fbuf);
|
|
|
|
fprintf(stderr, "\tFile \"%s\"\n", fname);
|
2003-03-26 14:27:00 +03:00
|
|
|
goto next;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
memcpy(bp, fname, i + 1);
|
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined(DOSISH)
|
1998-01-16 15:13:05 +03:00
|
|
|
if (exe_flag) {
|
2008-04-24 09:15:13 +04:00
|
|
|
static const char extension[][5] = {
|
1998-01-16 15:13:05 +03:00
|
|
|
#if defined(MSDOS)
|
|
|
|
".com", ".exe", ".bat",
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#elif defined(__EMX__) || defined(_WIN32)
|
1999-08-13 09:45:20 +04:00
|
|
|
".exe", ".com", ".cmd", ".bat",
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
/* end of __EMX__ or _WIN32 */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
int j;
|
|
|
|
|
2008-04-24 09:15:13 +04:00
|
|
|
for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) {
|
1998-01-16 15:13:05 +03:00
|
|
|
if (fspace < strlen(extension[j])) {
|
|
|
|
fprintf(stderr, "openpath: pathname too long (ignored)\n");
|
|
|
|
fprintf(stderr, "\tDirectory \"%.*s\"\n", (int) (bp - fbuf), fbuf);
|
|
|
|
fprintf(stderr, "\tFile \"%s%s\"\n", fname, extension[j]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strcpy(bp + i, extension[j]);
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifndef __MACOS__
|
1998-01-16 15:13:05 +03:00
|
|
|
if (stat(fbuf, &st) == 0)
|
|
|
|
return fbuf;
|
1999-08-13 09:45:20 +04:00
|
|
|
#else
|
|
|
|
if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf))
|
|
|
|
return mac_fullpath;
|
2003-03-26 14:27:00 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-04-24 09:15:13 +04:00
|
|
|
goto next;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-10-04 17:12:13 +04:00
|
|
|
#endif /* MSDOS or _WIN32 or __EMX__ */
|
2003-03-26 14:28:39 +03:00
|
|
|
|
2008-04-24 09:15:13 +04:00
|
|
|
#ifndef __MACOS__
|
|
|
|
if (stat(fbuf, &st) == 0) {
|
|
|
|
if (exe_flag == 0) return fbuf;
|
|
|
|
/* looking for executable */
|
|
|
|
if (!S_ISDIR(st.st_mode) && eaccess(fbuf, X_OK) == 0)
|
|
|
|
return fbuf;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (mac_fullpath = _macruby_exist_file_in_libdir_as_posix_name(fbuf)) {
|
|
|
|
if (exe_flag == 0) return mac_fullpath;
|
|
|
|
/* looking for executable */
|
|
|
|
if (stat(mac_fullpath, &st) == 0) {
|
|
|
|
if (!S_ISDIR(st.st_mode) && eaccess(mac_fullpath, X_OK) == 0)
|
|
|
|
return mac_fullpath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-03-26 14:28:39 +03:00
|
|
|
next:
|
1998-01-16 15:13:05 +03:00
|
|
|
/* if not, and no other alternatives, life is bleak */
|
|
|
|
if (*ep == '\0') {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise try the next component in the search path */
|
|
|
|
}
|
|
|
|
}
|