Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented #2770 #6306

Merged
merged 4 commits into from Jul 3, 2018
Merged

Conversation

paulkass
Copy link
Contributor

@paulkass paulkass commented Jul 1, 2018

Implemented #2770.

Processed the hostname of the server in the OpenSSL Client with punycode to support non-ASCII characters in hostnames. I used punycode from #2543 and also used the same method he used for implementing this (addrinfo.cr).

First PR, feel free to rip it apart :).

@RX14 RX14 added this to the Next milestone Jul 1, 2018
@RX14
Copy link
Contributor

RX14 commented Jul 1, 2018

This actually breaks the build: @hostname : String was previously inferred from this method, now adding this method call breaks that inference. So the instance variable type restriction needs to be manually added.

@RX14 RX14 removed this from the Next milestone Jul 1, 2018
@paulkass
Copy link
Contributor Author

paulkass commented Jul 2, 2018

@asterite sorry habit :)

@paulkass
Copy link
Contributor Author

paulkass commented Jul 2, 2018

What's interesting is that the error that I get here happens even when I take out all of the changes that I made. After moving the file back to before my initial commit, the same error persisted on my local machine (running make std_spec gave an error about Undefined symbols for architecture x86_64).

@RX14
Copy link
Contributor

RX14 commented Jul 2, 2018

@paulkass can you please paste the error you get when you run make std_spec?

@paulkass
Copy link
Contributor Author

paulkass commented Jul 2, 2018

@RX14

Using /usr/local/bin/llvm-config [version=6.0.0]
./bin/crystal build  -o .build/std_spec spec/std_spec.cr
Undefined symbols for architecture x86_64:
  "_LLVMInitializeInstCombine", referenced from:
      _*LLVM::PassRegistry#initialize_inst_combine:Nil in L-L-V-M-5858P-assR-egistry.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc "${@}" -o '/Users/<name>/crystal-scripts/crystal/.build/std_spec'  -rdynamic  -lxml2 -lyaml -lreadline `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` /Users/<name>/crystal-scripts/crystal/src/llvm/ext/llvm_ext.o `/usr/local/bin/llvm-config --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lgmp -lz -lpcre -lgc -lpthread /Users/<name>/crystal-scripts/crystal/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`
make: *** [.build/std_spec] Error 1```

@RX14
Copy link
Contributor

RX14 commented Jul 2, 2018

make clean std_spec

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

@RX14 error persists after running that. Can it be that that's because my computer does not support the x86_64 architecture? Also, the Travis CI build is failing but it's failing in the compiler, and I didn't touch the compiler at all so I don't know what that issue is all about.

@asterite
Copy link
Member

asterite commented Jul 3, 2018

Re-run CI, now it passes. It was a hiccup.

@asterite
Copy link
Member

asterite commented Jul 3, 2018

@paulkass I think Crystal is not compatible with LLVM 6 yet, only LLVM 5.

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

oh nice! thanks @asterite! i guess i'll revert to an older version then.

@asterite
Copy link
Member

asterite commented Jul 3, 2018

@paulcsmith Please don't set the default value of "". Just set it in the only place that's needed. For example it's not needed in the method that uses punicode. If later we add another initialize it's easy to forget to initialize @hostname. So always before doing changes, please ask why :-)

@paulcsmith
Copy link
Contributor

@asterite I think you meant to ping @paulkass :)

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

@asterite I'm kind of confused about this as we need to initialize @hostname somewhere (otherwise we get a compile time error). So the definition of the instance variable seems like the most logical place to me. Without variable restrictions (which must be done at the class level) it won't compile as @RX14 said.

@asterite
Copy link
Member

asterite commented Jul 3, 2018

But if you initialize it there, the compiler won't detect when you don't initialize it later. In one of the methods it's initialized from the method argument, so putting first an empty string and then overwriting it is not the best thing to do. It's a minor thing, but the way you did it originally was better.

This can be merged as it is right now, but usually reviewers are more strict, I don't know why they are not in this particular case.

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

@asterite I've played around a bit, and it seems like "casting" (adding a .as(String)) will do the trick. Will that work better?

@asterite
Copy link
Member

asterite commented Jul 3, 2018

Casting? What do you mean?

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

More like "casting". Instead of declaring @hostname and it's type at the class level, we just assign it in the method with @hostname = hostname.as(String).

@asterite
Copy link
Member

asterite commented Jul 3, 2018

Yes, that's similar but probably less clear. I'd go with a type declaration.

@asterite
Copy link
Member

asterite commented Jul 3, 2018

Actually, a type declaration is better. If you use that cast, but in another method assign another type that the compiler can infer, it will result in a union. So please use a type declaration.

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

Yeah, I don't think I know a way to get a type declaration without some sort of initialization somewhere (at the class level or initializate method). I tried doing a type declaration in the method and at the class level without initialization, and they both gave errors.

@asterite
Copy link
Member

asterite commented Jul 3, 2018

@hostname : String

That should work

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

@asterite That gives me this error:

Error in src/openssl/ssl/context.cr:78: instance variable '@hostname' of 
\ OpenSSL::SSL::Context::Client was not initialized directly 
\ in all of the 'initialize' methods, rendering it nilable```

@asterite
Copy link
Member

asterite commented Jul 3, 2018

Exactly. Now to fix that initialize where hostname is not properly initialized ;-)

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

@asterite I dug through the docs (again) and I found the uninitialized keyword. It's marked as unsafe, so I'm not sure if this is what you're hinting at. :)

@jhass
Copy link
Member

jhass commented Jul 3, 2018

It's just to keep a reference, so just make it nilable

@asterite
Copy link
Member

asterite commented Jul 3, 2018

Oh, the hostname isn't always assigned? If so, an empty string is good.

@asterite
Copy link
Member

asterite commented Jul 3, 2018

Or, yeah, it can be nilable. I'll review this in a few hours...

@RX14
Copy link
Contributor

RX14 commented Jul 3, 2018

Crystal supports LLVM 6 just fine, it just needs a single bugfix patch applied which arch linux has kindly done. Someone accidentally unexported a symbol in a refactor commit. I was expecting LLVM to release 6.0.1 but they haven't for some reason despite an obvious regression. Someone should do the same for homebrew.

$ crystal -v
Crystal 0.25.1 (2018-06-29)

LLVM: 6.0.0
Default target: x86_64-pc-linux-gnu

@asterite
Copy link
Member

asterite commented Jul 3, 2018

I just checked this, and the current type of @hostname is String | Nil. So it's better to keep it that way.

@paulkass Please use this type annotation:

@hostname : String?

@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

@asterite alright there we go!

@paulkass paulkass closed this Jul 3, 2018
@paulkass paulkass reopened this Jul 3, 2018
@paulkass
Copy link
Contributor Author

paulkass commented Jul 3, 2018

oops sorry about closing this

@RX14 RX14 added this to the Next milestone Jul 3, 2018
@RX14 RX14 merged commit 735be7f into crystal-lang:master Jul 3, 2018
@paulkass paulkass deleted the adding-punycode-to-openssl branch July 4, 2018 07:12
@RX14 RX14 modified the milestones: Next, 0.26.0 Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants