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

Migration to N-API #189

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

MrKashlakov
Copy link

Hello!
I just did migration of this module to N-API. Please review this PR.
All tests passed!

Copy link

@gabrielschulhof gabrielschulhof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! I'm glad you were able to address the test failures after our N-API workshop 👍

@@ -0,0 +1,18 @@
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrKashlakov I don't believe this file should be part of the commit. You should probably remove it.

@@ -15,7 +15,8 @@
*/

#include "iconv.h"
#include "nan.h"
#include "napi.h"
#include "uv.h"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrKashlakov why do you need "uv.h"?

@@ -15,7 +15,8 @@
*/

#include "iconv.h"
#include "nan.h"
#include "napi.h"
#include "uv.h"
#include "node_buffer.h"
Copy link

@gabrielschulhof gabrielschulhof Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrKashlakov I believe you can remove this include, because node-addon-api provides access to node::Buffer via N-API.

Nan::New<FunctionTemplate>(Convert)->GetFunction());
Iconv::Init(env);
exports.Set(Napi::String::New(env, "make"),
Napi::Function::New(env, Make));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be indented so the Napi::... is in the same column as the line above.

exports.Set(Napi::String::New(env, "make"),
Napi::Function::New(env, Make));
exports.Set(Napi::String::New(env, "convert"),
Napi::Function::New(env, Convert));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here wrt. indentation.


using namespace Napi;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't actually need this line, because the code uses Napi::... explicitly everywhere – which is good.

}

// Forbid implicit copying.
Iconv(const Iconv&);
void operator=(const Iconv&);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new empty line is not needed.

@@ -6,7 +6,24 @@
'targets': [
{
'target_name': 'iconv',
'include_dirs': ['<!(node -e "require(\'nan\')")'],
'cflags!': [ '-fno-exceptions' ],
Copy link

@gabrielschulhof gabrielschulhof Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original version of node-iconv made sure there were no CPP exceptions. Thus, we should maintain that choice. This means that cflags! needs to be changed to cflags.

'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and this needs to be changed to 'NO'.

@@ -6,7 +6,24 @@
'targets': [
{
'target_name': 'iconv',
'include_dirs': ['<!(node -e "require(\'nan\')")'],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and cflags_cc! needs to be changed to cflags_cc.

@@ -18,7 +18,7 @@
"license": "ISC",
"readmeFilename": "README.md",
"dependencies": {
"nan": "^2.11.1",
"node-addon-api": "1.6.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ^1.6.0 so that, when node-addon-api@1.7.0 comes out this package will start using it.

Copy link
Owner

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, left some comments but mostly LGTM. I'll second Gabriel's comments.

'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this? It's incompatible with Node.js v6.x. node-iconv can just inherit it from node's common.gypi.

'support'
],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use single quotes for consistency?

},
'msvs_settings': {
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block should be removed.

Napi::ObjectWrap<Iconv>(info) {
conv_ = info[0].As<Napi::External<iconv_t>>().Data();
}
iconv_t conv_;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation, and can you move conv_ back to its old place again? Cheers.

size_t input_size = info[3].IsNumber() ? info[3].As<Napi::Number>().Uint32Value() : static_cast<uint32_t>(0);
char* output_buf = info[4].As<Napi::Buffer<char>>().Data();
size_t output_start = info[5].IsNumber() ? info[5].As<Napi::Number>().Uint32Value() : static_cast<uint32_t>(0);
size_t output_size = info[6].IsNumber() ? info[6].As<Napi::Number>().Uint32Value() : static_cast<uint32_t>(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the ternaries? The JS layer always passes up numbers.

@mhdawson
Copy link

@bnoordhuis is this something you'd be able to review/consider landing?

@mhdawson
Copy link

Just confirming you are waiting on responses to your comments and once they are addressed it might move forward as we are are talking about whether we need to find somebody else to take over the pr.

@MrKashlakov are you going to be able to get back to this in order to address the comments.

@bnoordhuis
Copy link
Owner

Just confirming you are waiting on responses to your comments and once they are addressed it might move forward

That's correct. This PR also needs a rebase now.

@NickNaso
Copy link

NickNaso commented Feb 4, 2019

Hi @MrKashlakov I hope that you have the time to finish this work, but in case if you are busy what do you think if I help you to accomplish at tasks requested in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants