5
5
#include "ruby/ruby.h"
6
6
#include "ruby/util.h"
8
9
#include "eval_intern.h"
10
11
VALUE ruby_dln_librefs;
12
#define IS_RBEXT(e) (strcmp(e, ".rb") == 0)
13
#define IS_SOEXT(e) (strcmp(e, ".so") == 0 || strcmp(e, ".o") == 0)
13
#define IS_RBEXT(e) (strcmp((e), ".rb") == 0)
14
#define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
15
#define IS_DLEXT(e) (strcmp(e, DLEXT) == 0 || strcmp(e, DLEXT2) == 0)
16
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0 || strcmp((e), DLEXT2) == 0)
17
#define IS_DLEXT(e) (strcmp(e, DLEXT) == 0)
18
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
73
74
int type, VALUE load_path)
80
if(vlen < len) return 0;
81
if (!strncmp(name+(vlen-len),feature,len)){
82
plen = vlen - len - 1;
84
for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
87
strncmp(e-len,feature,len) )
89
plen = e - name - len - 1;
77
91
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
78
92
VALUE p = RARRAY_PTR(load_path)[i];
79
93
const char *s = StringValuePtr(p);
80
94
long n = RSTRING_LEN(p);
82
if (vlen < n + len + 1) continue;
96
if (n != plen ) continue;
83
97
if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
84
if (strncmp(name + n + 1, feature, len)) continue;
85
if (name[n+len+1] && name[n+len+1] != '.') continue;
88
100
if (IS_DLEXT(&name[n+len+1])) return p;
289
305
th->mild_compile_error++;
290
306
node = (NODE *)rb_load_file(RSTRING_PTR(fname));
292
iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, fname, Qfalse);
308
iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse);
293
309
th->mild_compile_error--;
294
310
rb_iseq_eval(iseq);
417
* require(string) -> true or false
419
* Ruby tries to load the library named _string_, returning
420
* +true+ if successful. If the filename does not resolve to
421
* an absolute path, it will be searched for in the directories listed
422
* in <code>$:</code>. If the file has the extension ``.rb'', it is
423
* loaded as a source file; if the extension is ``.so'', ``.o'', or
424
* ``.dll'', or whatever the default shared library extension is on
425
* the current platform, Ruby loads the shared library as a Ruby
426
* extension. Otherwise, Ruby tries adding ``.rb'', ``.so'', and so on
427
* to the name. The name of the loaded feature is added to the array in
428
* <code>$"</code>. A feature will not be loaded if its name already
429
* appears in <code>$"</code>. The file name is converted to an absolute
430
* path, so ``<code>require 'a'; require './a'</code>'' will not load
431
* <code>a.rb</code> twice.
433
* require "my-library.rb"
434
* require "db-driver"
433
* require(name) -> true or false
435
* Loads the given +name+, returning +true+ if successful and +false+ if the
436
* feature is already loaded.
438
* If the filename does not resolve to an absolute path, it will be searched
439
* for in the directories listed in <code>$LOAD_PATH</code> (<code>$:</code>).
441
* If the filename has the extension ".rb", it is loaded as a source file; if
442
* the extension is ".so", ".o", or ".dll", or the default shared library
443
* extension on the current platform, Ruby loads the shared library as a
444
* Ruby extension. Otherwise, Ruby tries adding ".rb", ".so", and so on
445
* to the name until found. If the file named cannot be found, a LoadError
448
* For Ruby extensions the filename given may use any shared library
449
* extension. For example, on Linux the socket extension is "socket.so" and
450
* <code>require 'socket.dll'</code> will load the socket extension.
452
* The absolute path of the loaded file is added to
453
* <code>$LOADED_FEATURES</code> (<code>$"</code>). A file will not be
454
* loaded again if its path already appears in <code>$"</code>. For example,
455
* <code>require 'a'; require './a'</code> will not load <code>a.rb</code>
458
* require "my-library.rb"
459
* require "db-driver"
440
465
return rb_require_safe(fname, rb_safe_level());
470
* require_relative(string) -> true or false
472
* Ruby tries to load the library named _string_ relative to the requiring
473
* file's path. If the file's path cannot be determined a LoadError is raised.
474
* If a file is loaded +true+ is returned and false otherwise.
444
477
rb_f_require_relative(VALUE obj, VALUE fname)
446
VALUE rb_current_realfilepath(void);
447
479
VALUE base = rb_current_realfilepath();
448
480
if (NIL_P(base)) {
449
481
rb_raise(rb_eLoadError, "cannot infer basepath");