2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05: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-24 23:29:39 -04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2009-09-28 09:46:18 -04:00
|
|
|
#ifdef RUBY_EXPORT
|
2007-06-09 23:06:15 -04:00
|
|
|
#include "ruby/ruby.h"
|
2009-09-28 09:46:18 -04:00
|
|
|
#define dln_notimplement rb_notimplement
|
|
|
|
#define dln_memerror rb_memerror
|
|
|
|
#define dln_exit rb_exit
|
|
|
|
#define dln_loaderror rb_loaderror
|
|
|
|
#else
|
|
|
|
#define dln_notimplement --->>> dln not implemented <<<---
|
|
|
|
#define dln_memerror abort
|
|
|
|
#define dln_exit exit
|
|
|
|
static void dln_loaderror(const char *format, ...);
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
#include "dln.h"
|
2018-01-02 01:46:40 -05:00
|
|
|
#include "internal.h"
|
2021-09-08 23:19:20 -04:00
|
|
|
#include "internal/compilers.h"
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-02-18 04:52:48 -05:00
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
# include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-24 14:33:50 -04:00
|
|
|
#if defined(HAVE_ALLOCA_H)
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#else
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifndef xmalloc
|
1998-01-16 07:13:05 -05:00
|
|
|
void *xmalloc();
|
|
|
|
void *xcalloc();
|
|
|
|
void *xrealloc();
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2014-06-05 01:16:46 -04:00
|
|
|
#undef free
|
* 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 06:01:40 -04:00
|
|
|
#define free(x) xfree(x)
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <stdio.h>
|
2008-10-04 09:57:06 -04:00
|
|
|
#if defined(_WIN32)
|
1998-01-16 07:13:05 -05:00
|
|
|
#include "missing/file.h"
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2001-05-30 05:12:34 -04:00
|
|
|
#ifndef S_ISDIR
|
2010-12-09 05:26:14 -05:00
|
|
|
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
2001-05-30 05:12:34 -04:00
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
# include <sys/param.h>
|
|
|
|
#endif
|
2002-11-27 04:11:55 -05:00
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
# define MAXPATHLEN 1024
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05: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-14 22:18:08 -05:00
|
|
|
#ifndef _WIN32
|
1998-01-16 07:13:05 -05:00
|
|
|
char *getenv();
|
|
|
|
#endif
|
|
|
|
|
2012-07-09 11:52:49 -04:00
|
|
|
#ifdef __APPLE__
|
2007-02-22 20:31:37 -05:00
|
|
|
# if defined(HAVE_DLOPEN)
|
|
|
|
/* Mac OS X with dlopen (10.3 or later) */
|
|
|
|
# define MACOSX_DLOPEN
|
|
|
|
# else
|
|
|
|
# define MACOSX_DYLD
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2009-09-28 09:46:18 -04:00
|
|
|
#ifndef dln_loaderror
|
|
|
|
static void
|
|
|
|
dln_loaderror(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
vfprintf(stderr, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-03-24 07:13:55 -04:00
|
|
|
#if defined(HAVE_DLOPEN) && !defined(_AIX) && !defined(MACOSX_DYLD) && !defined(_UNICOSMP)
|
1998-01-16 07:13:05 -05:00
|
|
|
/* dynamic load with dlopen() */
|
|
|
|
# define USE_DLN_DLOPEN
|
|
|
|
#endif
|
|
|
|
|
2015-10-17 22:23:18 -04:00
|
|
|
#if defined(__hp9000s300) || ((defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)) && !defined(__ELF__)) || defined(NeXT) || defined(MACOSX_DYLD)
|
2015-05-01 03:27:03 -04:00
|
|
|
# define EXTERNAL_PREFIX "_"
|
|
|
|
#else
|
|
|
|
# define EXTERNAL_PREFIX ""
|
|
|
|
#endif
|
|
|
|
#define FUNCNAME_PREFIX EXTERNAL_PREFIX"Init_"
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-11-09 07:57:53 -05:00
|
|
|
#if defined __CYGWIN__ || defined DOSISH
|
|
|
|
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
|
|
|
#else
|
|
|
|
#define isdirsep(x) ((x) == '/')
|
|
|
|
#endif
|
|
|
|
|
2009-03-13 21:56:15 -04:00
|
|
|
static size_t
|
2010-11-09 07:57:53 -05:00
|
|
|
init_funcname_len(const char **file)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2010-11-09 07:57:53 -05:00
|
|
|
const char *p = *file, *base, *dot = NULL;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* Load the file as an object one */
|
2010-11-09 07:57:53 -05:00
|
|
|
for (base = p; *p; p++) { /* Find position of last '/' */
|
2011-01-05 15:03:28 -05:00
|
|
|
if (*p == '.' && !dot) dot = p;
|
|
|
|
if (isdirsep(*p)) base = p+1, dot = NULL;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2010-11-09 07:57:53 -05:00
|
|
|
*file = base;
|
|
|
|
/* Delete suffix if it exists */
|
2011-01-05 15:03:28 -05:00
|
|
|
return (dot ? dot : p) - base;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2010-11-09 07:57:53 -05:00
|
|
|
static const char funcname_prefix[sizeof(FUNCNAME_PREFIX) - 1] = FUNCNAME_PREFIX;
|
|
|
|
|
2002-09-05 05:17:48 -04:00
|
|
|
#define init_funcname(buf, file) do {\
|
2010-12-09 05:26:14 -05:00
|
|
|
const char *base = (file);\
|
2010-11-09 07:57:53 -05:00
|
|
|
const size_t flen = init_funcname_len(&base);\
|
|
|
|
const size_t plen = sizeof(funcname_prefix);\
|
|
|
|
char *const tmp = ALLOCA_N(char, plen+flen+1);\
|
2002-09-05 05:17:48 -04:00
|
|
|
if (!tmp) {\
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_memerror();\
|
2002-09-05 05:17:48 -04:00
|
|
|
}\
|
2010-11-09 07:57:53 -05:00
|
|
|
memcpy(tmp, funcname_prefix, plen);\
|
|
|
|
memcpy(tmp+plen, base, flen);\
|
|
|
|
tmp[plen+flen] = '\0';\
|
2010-12-09 05:26:14 -05:00
|
|
|
*(buf) = tmp;\
|
2002-09-05 05:17:48 -04:00
|
|
|
} while (0)
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef USE_DLN_DLOPEN
|
2003-12-25 03:49:20 -05:00
|
|
|
# include <dlfcn.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef __hpux
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <errno.h>
|
|
|
|
#include "dl.h"
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#if defined(_AIX)
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <ctype.h> /* for isdigit() */
|
|
|
|
#include <errno.h> /* for global errno */
|
|
|
|
#include <sys/ldr.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NeXT
|
1999-01-19 23:59:39 -05: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-21 23:00:03 -05:00
|
|
|
#ifndef NSLINKMODULE_OPTION_BINDNOW
|
|
|
|
#define NSLINKMODULE_OPTION_BINDNOW 1
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05: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-21 23:00:03 -05:00
|
|
|
#else
|
2007-02-22 20:31:37 -05:00
|
|
|
#ifdef MACOSX_DYLD
|
1999-08-13 01: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-21 23:00:03 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2015-10-17 22:08:56 -04:00
|
|
|
#ifdef _WIN32
|
1998-01-16 07:19:22 -05:00
|
|
|
#include <windows.h>
|
2010-05-16 02:09:40 -04:00
|
|
|
#include <imagehlp.h>
|
1998-01-16 07:19:22 -05:00
|
|
|
#endif
|
|
|
|
|
2015-10-17 22:08:56 -04:00
|
|
|
#ifdef _WIN32
|
2010-05-16 02:09:40 -04:00
|
|
|
static const char *
|
|
|
|
dln_strerror(char *message, size_t size)
|
|
|
|
{
|
|
|
|
int error = GetLastError();
|
|
|
|
char *p = message;
|
|
|
|
size_t len = snprintf(message, size, "%d: ", error);
|
|
|
|
|
2010-10-15 19:39:16 -04:00
|
|
|
#define format_message(sublang) FormatMessage(\
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
|
2010-12-09 05:26:14 -05:00
|
|
|
NULL, error, MAKELANGID(LANG_NEUTRAL, (sublang)), \
|
2010-10-15 19:39:16 -04:00
|
|
|
message + len, size - len, NULL)
|
|
|
|
if (format_message(SUBLANG_ENGLISH_US) == 0)
|
|
|
|
format_message(SUBLANG_DEFAULT);
|
2010-05-16 02:09:40 -04:00
|
|
|
for (p = message + len; *p; p++) {
|
|
|
|
if (*p == '\n' || *p == '\r')
|
|
|
|
*p = ' ';
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
#define dln_strerror() dln_strerror(message, sizeof message)
|
|
|
|
#elif ! defined _AIX
|
1999-08-13 01: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 06:44:21 -04:00
|
|
|
dln_strerror(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifdef USE_DLN_DLOPEN
|
|
|
|
return (char*)dlerror();
|
|
|
|
#endif
|
|
|
|
}
|
2009-09-23 12:18:59 -04:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2019-06-19 05:06:57 -04:00
|
|
|
#if defined(_AIX)
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
1999-08-13 01:45:20 -04:00
|
|
|
aix_loaderror(const char *pathname)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2014-02-27 02:10:14 -05:00
|
|
|
char *message[1024], errbuf[1024];
|
|
|
|
int i;
|
2014-02-27 02:10:13 -05:00
|
|
|
#define ERRBUF_APPEND(s) strlcat(errbuf, (s), sizeof(errbuf))
|
2014-02-27 02:10:14 -05:00
|
|
|
snprintf(errbuf, sizeof(errbuf), "load failed - %s. ", pathname);
|
|
|
|
|
|
|
|
if (loadquery(L_GETMESSAGES, &message[0], sizeof(message)) != -1) {
|
|
|
|
ERRBUF_APPEND("Please issue below command for detailed reasons:\n\t");
|
|
|
|
ERRBUF_APPEND("/usr/sbin/execerror ruby ");
|
|
|
|
for (i=0; message[i]; i++) {
|
|
|
|
ERRBUF_APPEND("\"");
|
|
|
|
ERRBUF_APPEND(message[i]);
|
|
|
|
ERRBUF_APPEND("\" ");
|
|
|
|
}
|
|
|
|
ERRBUF_APPEND("\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ERRBUF_APPEND(strerror(errno));
|
|
|
|
ERRBUF_APPEND("[loadquery failed]");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2014-02-27 02:10:14 -05:00
|
|
|
dln_loaderror("%s", errbuf);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-16 02:09:40 -04:00
|
|
|
#if defined _WIN32 && defined RUBY_EXPORT
|
|
|
|
HANDLE rb_libruby_handle(void);
|
|
|
|
|
|
|
|
static int
|
|
|
|
rb_w32_check_imported(HMODULE ext, HMODULE mine)
|
|
|
|
{
|
|
|
|
ULONG size;
|
|
|
|
const IMAGE_IMPORT_DESCRIPTOR *desc;
|
|
|
|
|
|
|
|
desc = ImageDirectoryEntryToData(ext, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size);
|
|
|
|
if (!desc) return 0;
|
|
|
|
while (desc->Name) {
|
|
|
|
PIMAGE_THUNK_DATA pint = (PIMAGE_THUNK_DATA)((char *)ext + desc->Characteristics);
|
|
|
|
PIMAGE_THUNK_DATA piat = (PIMAGE_THUNK_DATA)((char *)ext + desc->FirstThunk);
|
2012-04-17 00:11:17 -04:00
|
|
|
for (; piat->u1.Function; piat++, pint++) {
|
2010-05-16 02:09:40 -04:00
|
|
|
static const char prefix[] = "rb_";
|
2012-04-16 08:25:29 -04:00
|
|
|
PIMAGE_IMPORT_BY_NAME pii;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (IMAGE_SNAP_BY_ORDINAL(pint->u1.Ordinal)) continue;
|
|
|
|
pii = (PIMAGE_IMPORT_BY_NAME)((char *)ext + (size_t)pint->u1.AddressOfData);
|
|
|
|
name = (const char *)pii->Name;
|
2010-10-12 10:53:59 -04:00
|
|
|
if (strncmp(name, prefix, sizeof(prefix) - 1) == 0) {
|
|
|
|
FARPROC addr = GetProcAddress(mine, name);
|
2010-05-16 02:09:40 -04:00
|
|
|
if (addr) return (FARPROC)piat->u1.Function == addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
desc++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-23 21:52:08 -05:00
|
|
|
#if defined(DLN_NEEDS_ALT_SEPARATOR) && DLN_NEEDS_ALT_SEPARATOR
|
|
|
|
#define translit_separator(src) do { \
|
|
|
|
char *tmp = ALLOCA_N(char, strlen(src) + 1), *p = tmp, c; \
|
|
|
|
do { \
|
|
|
|
*p++ = ((c = *file++) == '/') ? DLN_NEEDS_ALT_SEPARATOR : c; \
|
|
|
|
} while (c); \
|
2010-12-09 05:26:14 -05:00
|
|
|
(src) = tmp; \
|
2010-02-23 21:52:08 -05:00
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define translit_separator(str) (void)(str)
|
|
|
|
#endif
|
|
|
|
|
2018-01-03 04:05:18 -05:00
|
|
|
#ifdef USE_DLN_DLOPEN
|
2020-05-08 05:31:09 -04:00
|
|
|
# include "ruby/internal/stdbool.h"
|
2019-12-04 03:16:30 -05:00
|
|
|
# include "internal/warnings.h"
|
2018-07-30 03:07:48 -04:00
|
|
|
COMPILER_WARNING_PUSH
|
|
|
|
#if defined(__clang__) || GCC_VERSION_SINCE(4, 2, 0)
|
|
|
|
COMPILER_WARNING_IGNORED(-Wpedantic)
|
2018-01-02 01:41:55 -05:00
|
|
|
#endif
|
2018-01-03 04:19:11 -05:00
|
|
|
static bool
|
|
|
|
dln_incompatible_library_p(void *handle)
|
2018-01-02 01:41:55 -05:00
|
|
|
{
|
|
|
|
void *ex = dlsym(handle, EXTERNAL_PREFIX"ruby_xmalloc");
|
2020-02-07 00:14:05 -05:00
|
|
|
void *const fp = (void *)ruby_xmalloc;
|
|
|
|
return ex && ex != fp;
|
2018-01-02 01:41:55 -05:00
|
|
|
}
|
2018-07-30 03:07:48 -04:00
|
|
|
COMPILER_WARNING_POP
|
2018-01-03 04:05:18 -05:00
|
|
|
#endif
|
2018-01-02 01:41:55 -05:00
|
|
|
|
2001-05-02 00: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 06:44:21 -04:00
|
|
|
dln_load(const char *file)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2016-04-07 19:46:45 -04:00
|
|
|
#if (defined _WIN32 || defined USE_DLN_DLOPEN) && defined RUBY_EXPORT
|
|
|
|
static const char incompatible[] = "incompatible library version";
|
|
|
|
#endif
|
2002-06-16 21:54:51 -04:00
|
|
|
#if !defined(_AIX) && !defined(NeXT)
|
|
|
|
const char *error = 0;
|
|
|
|
#endif
|
|
|
|
|
2015-10-17 22:08:56 -04:00
|
|
|
#if defined _WIN32
|
1998-01-16 07:19:22 -05:00
|
|
|
HINSTANCE handle;
|
2014-04-05 19:52:52 -04:00
|
|
|
WCHAR *winfile;
|
2010-05-16 02:09:40 -04:00
|
|
|
char message[1024];
|
2021-05-06 11:04:36 -04:00
|
|
|
void (*init_fct)(void);
|
2002-02-18 04:52:48 -05:00
|
|
|
char *buf;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
|
|
|
/* Load the file as an object one */
|
2002-02-18 04:52:48 -05:00
|
|
|
init_funcname(&buf, file);
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2014-04-05 19:52:52 -04:00
|
|
|
/* Convert the file path to wide char */
|
|
|
|
winfile = rb_w32_mbstr_to_wstr(CP_UTF8, file, -1, NULL);
|
|
|
|
if (!winfile) {
|
|
|
|
dln_memerror();
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
|
|
|
|
/* Load file */
|
2014-04-05 19:52:52 -04:00
|
|
|
handle = LoadLibraryW(winfile);
|
|
|
|
free(winfile);
|
|
|
|
|
|
|
|
if (!handle) {
|
2002-06-16 21:54:51 -04:00
|
|
|
error = dln_strerror();
|
1998-01-16 07:19:22 -05:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2010-05-16 12:23:19 -04:00
|
|
|
#if defined _WIN32 && defined RUBY_EXPORT
|
2010-05-16 02:09:40 -04:00
|
|
|
if (!rb_w32_check_imported(handle, rb_libruby_handle())) {
|
|
|
|
FreeLibrary(handle);
|
2016-04-07 19:46:45 -04:00
|
|
|
error = incompatible;
|
2010-05-16 02:09:40 -04:00
|
|
|
goto failed;
|
|
|
|
}
|
2010-05-16 12:23:19 -04:00
|
|
|
#endif
|
2010-05-16 02:09:40 -04:00
|
|
|
|
2021-05-06 11:04:36 -04:00
|
|
|
if ((init_fct = (void(*)(void))GetProcAddress(handle, buf)) == NULL) {
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_loaderror("%s - %s\n%s", dln_strerror(), buf, file);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2002-02-18 04:52:48 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
/* Call the init code */
|
|
|
|
(*init_fct)();
|
2001-05-02 00:22:21 -04:00
|
|
|
return handle;
|
1998-01-16 07:19:22 -05:00
|
|
|
#else
|
2002-02-18 04:52:48 -05:00
|
|
|
char *buf;
|
1998-01-16 07:13:05 -05:00
|
|
|
/* Load the file as an object one */
|
2002-02-18 04:52:48 -05:00
|
|
|
init_funcname(&buf, file);
|
2010-02-23 21:52:08 -05:00
|
|
|
translit_separator(file);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#ifdef USE_DLN_DLOPEN
|
|
|
|
#define DLN_DEFINED
|
|
|
|
{
|
|
|
|
void *handle;
|
2021-05-06 11:04:36 -04:00
|
|
|
void (*init_fct)(void);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifndef RTLD_LAZY
|
|
|
|
# define RTLD_LAZY 1
|
|
|
|
#endif
|
2004-02-02 05:01:57 -05:00
|
|
|
#ifdef __INTERIX
|
|
|
|
# undef RTLD_GLOBAL
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifndef RTLD_GLOBAL
|
|
|
|
# define RTLD_GLOBAL 0
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* Load file */
|
1999-01-19 23:59:39 -05:00
|
|
|
if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {
|
2002-06-16 21:54:51 -04:00
|
|
|
error = dln_strerror();
|
1998-01-16 07:13:05 -05:00
|
|
|
goto failed;
|
|
|
|
}
|
2015-05-01 00:30:26 -04:00
|
|
|
# if defined RUBY_EXPORT
|
|
|
|
{
|
2018-01-03 04:19:11 -05:00
|
|
|
if (dln_incompatible_library_p(handle)) {
|
2015-05-01 00:30:26 -04:00
|
|
|
|
2016-11-18 20:16:50 -05:00
|
|
|
# if defined __APPLE__ && \
|
|
|
|
defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
|
|
|
|
(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
|
2015-05-01 00:30:26 -04:00
|
|
|
/* dlclose() segfaults */
|
2015-05-01 00:41:27 -04:00
|
|
|
rb_fatal("%s - %s", incompatible, file);
|
|
|
|
# else
|
2015-05-01 00:30:26 -04:00
|
|
|
dlclose(handle);
|
|
|
|
error = incompatible;
|
|
|
|
goto failed;
|
2015-05-01 00:41:27 -04:00
|
|
|
# endif
|
2015-05-01 00:30:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2021-05-06 11:04:36 -04:00
|
|
|
init_fct = (void(*)(void))(VALUE)dlsym(handle, buf);
|
2002-02-18 04:52:48 -05:00
|
|
|
if (init_fct == NULL) {
|
2016-12-26 04:28:46 -05:00
|
|
|
const size_t errlen = strlen(error = dln_strerror()) + 1;
|
|
|
|
error = memcpy(ALLOCA_N(char, errlen), error, errlen);
|
2001-05-02 00:22:21 -04:00
|
|
|
dlclose(handle);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
/* Call the init code */
|
|
|
|
(*init_fct)();
|
2002-02-18 04:52:48 -05:00
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
return handle;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif /* USE_DLN_DLOPEN */
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
#ifdef __hpux
|
1998-01-16 07:13:05 -05:00
|
|
|
#define DLN_DEFINED
|
|
|
|
{
|
|
|
|
shl_t lib = NULL;
|
|
|
|
int flags;
|
2021-05-06 11:04:36 -04:00
|
|
|
void (*init_fct)(void);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
flags = BIND_DEFERRED;
|
|
|
|
lib = shl_load(file, flags, 0);
|
|
|
|
if (lib == NULL) {
|
1999-01-19 23:59:39 -05:00
|
|
|
extern int errno;
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_loaderror("%s - %s", strerror(errno), file);
|
1998-01-16 07:13:05 -05: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;
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_loaderror("%s - %s", strerror(ENOSYM), file);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(*init_fct)();
|
2001-05-02 00:22:21 -04:00
|
|
|
return (void*)lib;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif /* hpux */
|
|
|
|
|
2019-06-19 05:06:57 -04:00
|
|
|
#if defined(_AIX)
|
1998-01-16 07:13:05 -05:00
|
|
|
#define DLN_DEFINED
|
|
|
|
{
|
2021-05-06 11:04:36 -04:00
|
|
|
void (*init_fct)(void);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2021-05-06 11:04:36 -04:00
|
|
|
init_fct = (void(*)(void))load((char*)file, 1, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (init_fct == NULL) {
|
|
|
|
aix_loaderror(file);
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
if (loadbind(0, (void*)dln_load, (void*)init_fct) == -1) {
|
|
|
|
aix_loaderror(file);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
(*init_fct)();
|
2001-05-02 00:22:21 -04:00
|
|
|
return (void*)init_fct;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif /* _AIX */
|
|
|
|
|
2011-09-25 20:19:03 -04:00
|
|
|
#if defined(MACOSX_DYLD)
|
1998-01-16 07:13:05 -05:00
|
|
|
#define DLN_DEFINED
|
|
|
|
/*----------------------------------------------------
|
|
|
|
By SHIROYAMA Takayuki Psi@fortune.nest.or.jp
|
2009-02-22 09:23:33 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
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-21 23:00:03 -05:00
|
|
|
sunshine@sunshineco.com,
|
1998-01-16 07:13:05 -05:00
|
|
|
and... Miss ARAI Akino(^^;)
|
|
|
|
----------------------------------------------------*/
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
int dyld_result;
|
|
|
|
NSObjectFileImage obj_file; /* handle, but not use it */
|
1999-01-19 23:59:39 -05:00
|
|
|
/* "file" is module file name .
|
2002-02-18 04:52:48 -05:00
|
|
|
"buf" is pointer to initial function name with "_" . */
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2021-05-06 11:04:36 -04:00
|
|
|
void (*init_fct)(void);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
dyld_result = NSCreateObjectFileImageFromFile(file, &obj_file);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
if (dyld_result != NSObjectFileImageSuccess) {
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_loaderror("Failed to load %.200s", file);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
NSLinkModule(obj_file, file, NSLINKMODULE_OPTION_BINDNOW);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
/* lookup the initial function */
|
2012-12-01 10:25:28 -05:00
|
|
|
if (!NSIsSymbolNameDefined(buf)) {
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_loaderror("Failed to lookup Init function %.200s",file);
|
2009-02-22 09:23:33 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
|
1999-01-19 23:59:39 -05:00
|
|
|
(*init_fct)();
|
|
|
|
|
2001-05-02 00:22:21 -04:00
|
|
|
return (void*)init_fct;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DLN_DEFINED
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_notimplement();
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
#if !defined(_AIX) && !defined(NeXT)
|
|
|
|
failed:
|
2009-09-28 09:46:18 -04:00
|
|
|
dln_loaderror("%s - %s", error, file);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
2005-04-20 10:25:34 -04:00
|
|
|
|
2001-05-16 05:05:54 -04:00
|
|
|
return 0; /* dummy return */
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|