kakts-log

programming について調べたことを整理していきます

Node.js contribute: add test cases for validateOffsetLengthWrite.

github.com

I added some test cases for Node.js core module.

This fix was landed on Node.js v10.6.0.

node/CHANGELOG_V10.md at master · nodejs/node · GitHub

golang: failed to get golang.org/x/tools/cmd/oracle

preconditions

golang: 1.6

failed to get golang.org/x/tools/cmd/oracle

When I try to "go get golang.org/x/tools/cmd/oracle" in my golang project, it occures an error as wrote down below.

go get golang.org/x/tools/cmd/oracle
package golang.org/x/tools/cmd/oracle: cannot find package "golang.org/x/tools/cmd/oracle" in any of:
    /usr/local/Cellar/go/1.8/libexec/src/golang.org/x/tools/cmd/oracle (from $GOROOT)
    /Users/me/go_vendor/src/golang.org/x/tools/cmd/oracle (from $GOPATH)

The reason why this error occured

At the moment, this tool has been replaced to tools/cmd/guru godoc.org

So, you just get tools/cmd/guru, this problem can be solved.

go get golang.org/x/tools/cmd/oracle

go get golang.org/x/tools/cmd/oracle failed in v1.6.3 · Issue #18262 · golang/go · GitHub

Rust: occured error when using closure without type annotation.

I'm studying Rust and trying to write Rust code using closure.
I found some confusing error about Type Inference of Rust.
This post is just a memorandum of understanding for mechanism of Rust.

fn main() {
    // closure
    // argument x is set without type annotation.
    let closure = |x| x;

    // calling closure two times with different type argument.
    let a = closure(String::from("Hello")); // passing string.
    let b = closure(5); // passing integer

}

Without type annotation in closure script, Rust inferences the type of the argument.
In this case, the first String argument was passed to the closure, Rust inferences the "x" would be a String value.
But in the next line, integer(u32) value was passed, and then Rust thinks that the argument is a wrong type value, so it occurs an error, mentioned as below.

error[E0308]: mismatched types
  --> src/main.rs:14:29
   |
14 |     let n = example_closure(5);
   |                             ^
   |                             |
   |                             expected struct "std::string::String", found integral variable
   |                             help: try using a conversion method: "5.to_string()"
   |
   = note: expected type std::string::String
              found type "{integer}"    

Contributing to Node.js

Merged 2 PRs.

I found and fixed small typo and bug of the sample codes in the documentation of Node.js.

github.com

github.com

Both of them are landed on 10.2.0

node/CHANGELOG_V10.md at master · nodejs/node · GitHub

Rust: Error for copying String allocated memory to new variable.

When I write Rust code as below, it occurs error. I tried to print two same String by copying memory.

fn main() {
    let s1 = String::from("Hello");
    let s2 = s1;
    println!("{}, {}", s1, s2);
}
error[E0382]: use of moved value: `s1`
  --> src/main.rs:14:24
   |
13 |     let s2 = s1;
   |         -- value moved here
14 |     println!("{}, {}", s1, s2);
   |                        ^^ value used here after move
   |
   = note: move occurs because `s1` has type `std::string::String`, which does not implement the `Copy` trait

error: aborting due to previous error

error: Could not compile `owner`.

The reason of this is arisen from Rust's memory management. In The Rust code, String pointer is assigned to two variables s1, s2.
If s2 is tried tobe copied allocated memory value of s1, s1 variable goes out of scope, it no longer be valid.
This is one of the mechanism of Rust's memory management called move .

So in this case, s1 is already moved to s2, it is invalid to use s1 in println!() .

Installing node.js v8.11.1 to centos 6.5 server.

Recently, Node.js v8.11.1 was released.
From this version, minimum compiler requirement(gcc) for Node.js had been updated to 4.9.4.

https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V8.md#8.11.1

In the centOS 6.5 server, default gcc package version was too old, so I had to update gcc version over 4.9.4 .

Installing devtoolset-4

To use newer gcc and other packages, Software Collections provides devtoolset for CentOS servers. Devtoolset-4 — Software Collections

In April 2018, devtoolset-4 is already ended its support, but in this post, I'll try to introduce how to install devtoolset-4.
There is also devtoolset-2 repository, but in this devtoolset-2, the version of gcc is 4.9.2. It's not applicable to node.js v8.11.1.

scl-utils package

First, to install devtoolset-4, it requires scl-utils package version above "20120927-11".
I had to set up SCL repository for centOS. repository base url is http://vault.centos.org/6.5/SCL/x86_64/

I created repository setting file to /etc/yum.repos.d/centos-scl.repo . The content of the file is as below.

[centos-scl]

name=centos-scl
baseurl=http://vault.centos.org/6.5/SCL/$basearch/
gpgcheck=0
enabled=0

After create this file, install scl-utils pakcage.

$ sudo yum install scl-utils --enablerepo=centos-scl

devtoolset-4 package

Next, set up new yum repository. mirror.centos.org provides a yum repository for Software collection packages. http://mirror.centos.org/centos/6/sclo/x86_64/rh/
In this repository, there are some versions of devtoolset. You can choose the version of it as you like.

Same as the previous chapter, it needs to set up yum repository setting. I created it to /etc/yum.repos.d/centos-devtools.repo

[centos-devtools]
name=centos-devtools
baseurl=http://mirror.centos.org/centos/6/sclo/x86_64/rh/
gpgcheck=0
enabled=0

After that, I can install some devtools-4's gcc packages for building node.js v8.11.1's native module.

$ sudo yum install devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-binutils --enablerepo=centos-devtools

Finally, checking the scl list. If devtoolset-4 in the scl list, it's okay to use newer gcc.

$ scl -l

devtoolset-2
devtoolset-4

By enabling devtoolset-4, I was finally able to use newer gcc.

$ scl enable devtoolset-4 bash

$ gcc --version
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)

Copyright (C) 2015 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How to solve the yum ** http://mirror.centos.org/centos/6/SCL/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 ** error in Centos6.5 server.

After installing centos-release-SCL yum package in CentOS 6.5 server, installing other yum package was failed. Error message is same as below.

$ sudo yum install libcurl
http://mirror.centos.org/centos/6/SCL/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: scl. Please verify its path and try again

The reason of this is about new yum repo setting file in /etc/yum.repos.d/ . If I install centos-release-SCL package, CentOS-SCL.repo file was created in /etc/yum.repos.d/ .

# CentOS-SCL.repo
#
# The Software Collections  ( SCL ) repository contains rpms for newer 
# software that can be installed alongside default versions
#
# Look at http://wiki.centos.org/AdditionalResources/Repositories/SCL
# for more details about how this repository works

[scl]
name=CentOS-$releasever - SCL
baseurl=http://mirror.centos.org/centos/$releasever/SCL/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

In this file, baseurl is set to http://mirror.centos.org/centos/$releasever/SCL/$basearch/ . But this url might be already deprecated. For example, in this url. http://mirror.centos.org/centos/6.5/

There is only readme file in this repo.

To resolve this problem, I removed /etc/yum.repos.d/CentOS-SCL.repo

$ sudo rm /etc/yum.repos.d/CentOS-SCL.repo

And cleaned yum cache.

$ sudo yum clean all

After doing this, the probleam was resolved.