Skip to content

Instantly share code, notes, and snippets.

@taf2
Created June 5, 2011 13:05
Show Gist options
  • Save taf2/1008945 to your computer and use it in GitHub Desktop.
Save taf2/1008945 to your computer and use it in GitHub Desktop.
Ruby 1.9.2-p180 require performance patch
--- a/load.c 2010-10-23 05:36:38.000000000 -0400
+++ b/patchload.c 2011-06-05 08:58:00.000000000 -0400
@@ -40,14 +40,6 @@
VALUE ary;
long i;
- for (i = 0; i < RARRAY_LEN(load_path); ++i) {
- VALUE str = rb_check_string_type(RARRAY_PTR(load_path)[i]);
- if (NIL_P(str) || !rb_is_absolute_path(RSTRING_PTR(str)))
- goto relative_path_found;
- }
- return load_path;
-
- relative_path_found:
ary = rb_ary_new2(RARRAY_LEN(load_path));
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
VALUE path = rb_file_expand_path(RARRAY_PTR(load_path)[i], Qnil);
@@ -81,16 +73,27 @@
int type, VALUE load_path)
{
long i;
+ long plen;
+ const char *e;
+ if(vlen < len) return 0;
+ if (!strncmp(name+(vlen-len),feature,len)){
+ plen = vlen - len - 1;
+ } else {
+ for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
+ if (*e!='.' ||
+ e-name < len ||
+ strncmp(e-len,feature,len) )
+ return 0;
+ plen = e - name - len - 1;
+ }
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
VALUE p = RARRAY_PTR(load_path)[i];
const char *s = StringValuePtr(p);
long n = RSTRING_LEN(p);
- if (vlen < n + len + 1) continue;
+ if (n != plen ) continue;
if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
- if (strncmp(name + n + 1, feature, len)) continue;
- if (name[n+len+1] && name[n+len+1] != '.') continue;
switch (type) {
case 's':
if (IS_DLEXT(&name[n+len+1])) return p;
--- a/load.c 2010-10-23 05:36:38.000000000 -0400
+++ b/patchload.c 2011-06-05 08:58:00.000000000 -0400
@@ -81,16 +73,27 @@
int type, VALUE load_path)
{
long i;
+ long plen;
+ const char *e;
+ if(vlen < len) return 0;
+ if (!strncmp(name+(vlen-len),feature,len)){
+ plen = vlen - len - 1;
+ } else {
+ for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
+ if (*e!='.' ||
+ e-name < len ||
+ strncmp(e-len,feature,len) )
+ return 0;
+ plen = e - name - len - 1;
+ }
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
VALUE p = RARRAY_PTR(load_path)[i];
const char *s = StringValuePtr(p);
long n = RSTRING_LEN(p);
- if (vlen < n + len + 1) continue;
+ if (n != plen ) continue;
if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
- if (strncmp(name + n + 1, feature, len)) continue;
- if (name[n+len+1] && name[n+len+1] != '.') continue;
switch (type) {
case 's':
if (IS_DLEXT(&name[n+len+1])) return p;
@dgm
Copy link

dgm commented Jun 5, 2011

[2011-06-05 09:32:21] patch -F25 -p1 -f <"/Users/dgm/workspace/load.patch"
missing header for unified diff at line 3 of patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

|--- load.c 2010-10-23 05:36:38.000000000 -0400

|+++ patchload.c 2011-06-05 08:58:00.000000000 -0400

No file to patch. Skipping patch.
2 out of 2 hunks ignored

@taf2
Copy link
Author

taf2 commented Jun 5, 2011

dgm, worked here... I created it as diff -u load.c loadpatch.c >load.patch... to apply manually, patch -p0 <load.patch

@taf2
Copy link
Author

taf2 commented Jun 5, 2011

Okay, I see, i updated the patch to be rvm friendly, prefixed a/ and b/

@dgm
Copy link

dgm commented Jun 6, 2011

Ok, the url changed. This appears to work:

curl https://gist.github.com/raw/1008945/7532898172cd9f03b4c0d0db145bc2440dcbb2f6/load.patch > load.patch
rvm install ruby-1.9.2-p180 --patch load.patch

@erickrause
Copy link

the url failed for me with a redirect to this
curl https://raw.github.com/gist/1008945/7532898172cd9f03b4c0d0db145bc2440dcbb2f6 > load.patch
rvm install ruby-1.9.2-p180 --patch load.patch

@taf2
Copy link
Author

taf2 commented Jun 8, 2011

Thought it might be worth pointing out there is a much faster way to apply this patch, assuming you already have 1.9.2 installed via rvm. It requires 1 extra step, but avoids a full recompile.

  1. download this patch: https://gist.github.com/1014298, it doesn't have the leading a/ and b/
  2. apply the patch: patch -p0 < path/to/load.patch
  3. make && make install

@Bregor
Copy link

Bregor commented Jun 9, 2011

After running

$ rvm install ruby-1.9.2-p180 --patch ./load.patch -n patched

I got following error:

ERROR: Error running 'make ', please read /Users/bregor/Developer/.rvm/log/ruby-1.9.2-p180-patched/make.log
ERROR: There has been an error while running make. Halting the installation.

Log:

$ cat /Users/bregor/Developer/.rvm/log/ruby-1.9.2-p180-patched/make.log

[2011-06-09 13:36:20] make 
gcc -I/Users/bregor/Developer/include -fno-common -pipe -I. -I.ext/include/x86_64-darwin10.7.4 -I./include -I. -DRUBY_EXPORT -I/Users/bregor/Developer/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -o load.o -c load.c
load.c: In function ‘get_loaded_features_hash’:
load.c:99: error: ‘rb_vm_t’ has no member named ‘loaded_features_hash’
load.c:102: error: ‘rb_vm_t’ has no member named ‘loaded_features_hash’
load.c: In function ‘get_filename_expansion_hash’:
load.c:112: error: ‘rb_vm_t’ has no member named ‘filename_expansion_hash’
load.c:115: error: ‘rb_vm_t’ has no member named ‘filename_expansion_hash’
load.c: In function ‘rb_feature_p’:
load.c:292: error: ‘loadable_ext’ undeclared (first use in this function)
load.c:292: error: (Each undeclared identifier is reported only once
load.c:292: error: for each function it appears in.)
load.c: In function ‘Init_load’:
load.c:773: error: ‘j’ undeclared (first use in this function)
make: *** [load.o] Error 1

Environment:

$ uname -a
Darwin marcuria 10.7.4 Darwin Kernel Version 10.7.4: Mon Apr 18 21:24:17 PDT 2011; root:xnu-1504.14.12~3/RELEASE_X86_64 x86_64

$ rvm --version                                              
rvm 1.6.20 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]

$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)

@taf2
Copy link
Author

taf2 commented Jun 14, 2011

@Bregor, you'll need to reapply the patch from a clean tree... I think rvm clean and then try the patch.

@Bregor
Copy link

Bregor commented Jun 14, 2011

@taf2 thank you! Works like a charm.

@Bregor
Copy link

Bregor commented Jul 15, 2011

@taf2, have you any plans to update this patch for 1.9.2-p290?

@taf2
Copy link
Author

taf2 commented Jul 15, 2011

@Bregor, I bet it works for p290? Have you tried it?

@Bregor
Copy link

Bregor commented Jul 15, 2011

@taf2:

Applying patch './load.patch' (located at /tmp/load.patch)
ERROR: Error running 'patch -F25 -p1 -f <"/tmp/load.patch"', please read /Users/bregor/Developer/.rvm/log/ruby-1.9.2-p290-patched/patch.apply.load.patch.log

log:

[2011-07-15 19:13:29] patch -F25 -p1 -f <"/tmp/load.patch"
patching file load.c
Hunk #1 FAILED at 40.
Hunk #2 succeeded at 65 (offset -8 lines).
1 out of 2 hunks FAILED -- saving rejects to file load.c.rej

@taf2
Copy link
Author

taf2 commented Jul 15, 2011

Alright, I'll take a look.

@taf2
Copy link
Author

taf2 commented Jul 16, 2011

@Bregor, i attached the updated patch it's actually much smaller: ruby-1.9.2p290.patch

@epinault
Copy link

The patch is failing for me using RVM and 1.9.2 . Did I get the wrong version? where do I find the ruby-1.9.2p290.patch?

[2011-10-27 15:40:24] patch -F25 -p1 -f <"/home/emmanuel/require.patch"
patching file load.c
Hunk #1 FAILED at 40.
Hunk #2 succeeded at 73 (offset -8 lines).
1 out of 2 hunks FAILED -- saving rejects to file load.c.rej
~

@aaronjensen
Copy link

@epinault-ttc I wouldn't recommend using any of these any more, these patchsets work great: https://github.com/skaes/rvm-patchsets

@epinault
Copy link

@aaronjensen: Thanks! seems to work now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment