Skip to content

Commit

Permalink
Don't replace ENV twice on non Windows platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Nov 23, 2021
1 parent 481c271 commit 8dc86b7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bundler/lib/bundler/environment_preserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def initialize(env, keys)

# Replaces `ENV` with the bundler environment variables backed up
def replace_with_backup
ENV.replace(backup) unless Gem.win_platform?
unless Gem.win_platform?
ENV.replace(backup)
return
end

# Fallback logic for Windows below to workaround
# https://bugs.ruby-lang.org/issues/16798. Can be dropped once all
Expand Down
57 changes: 57 additions & 0 deletions bundler/spec/realworld/ffi_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

RSpec.describe "loading dinamically linked library on a bundle exec context", :realworld => true do
it "passes ENV right after argv in memory" do
create_file "foo.rb", <<~RUBY
require 'ffi'
module FOO
extend FFI::Library
ffi_lib './libfoo.so'
attach_function :Hello, [], :void
end
FOO.Hello()
RUBY

create_file "libfoo.c", <<~'C'
#include <stdio.h>
static int foo_init(int argc, char** argv, char** envp) {
if (argv[argc+1] == NULL) {
printf("FAIL\n");
} else {
printf("OK\n");
}
return 0;
}
#if defined(__APPLE__) && defined(__MACH__)
__attribute__((section("__DATA,__mod_init_func"), used, aligned(sizeof(void*))))
#else
__attribute__((section(".init_array")))
#endif
static void *ctr = &foo_init;
extern char** environ;
void Hello() {
return;
}
C

sys_exec "gcc -g -o libfoo.so -shared -fpic libfoo.c"

install_gemfile <<-G
source "https://rubygems.org"
gem 'ffi'
G

bundle "exec ruby foo.rb"

expect(out).to eq("OK")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
> GET /gems/ffi-1.15.4.gem
> accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
> accept: */*
> user-agent: Ruby
> connection: keep-alive
> keep-alive: 30
> host: rubygems.org
Binary file not shown.

0 comments on commit 8dc86b7

Please sign in to comment.