Skip to content

Add support for constructors, and integration tests. #332

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

Merged
merged 4 commits into from
Dec 13, 2016

Conversation

emilio
Copy link
Contributor

@emilio emilio commented Dec 13, 2016

r? @fitzgen

cc @vvuk

@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@vvuk
Copy link
Contributor

vvuk commented Dec 13, 2016

Works great with Skia, fwiw. Thanks!

I'll file a feature request -- would be nice to be able to rename the rust-side constructors based on their signature by passing in some kind of mapping file to bindgen, otherwise there's no guarantee that the function names will be stable (e.g. if upstream adds another constructor/overload).

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

LGTM! Just a couple comments that I am not sure require any code changes, just clarification for my benefit.

r=me when you're ready to land :)

Thanks!

@@ -0,0 +1,13 @@

class TestOverload {
// This one shouldnt' be generated.
Copy link
Member

Choose a reason for hiding this comment

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

Because it is private, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right.

TestOverload();
public:
TestOverload(int);
TestOverload(double);
Copy link
Member

Choose a reason for hiding this comment

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

Do we handle when the class already has a new method properly? Do we just treat the constructors or the new methods as overloads? Care to add a small test case?

Copy link
Member

Choose a reason for hiding this comment

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

Oh wait -- new is a keyword ofc -- nvm

@@ -147,6 +147,7 @@ impl FunctionSig {
};
let mut args: Vec<_> = match cursor.kind() {
CXCursor_FunctionDecl |
CXCursor_Constructor |
CXCursor_CXXMethod => {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this doesn't also match CXCursor_Destructor like the ClangSubItemParser impl further down does?

Is it handled elsewhere?

Copy link
Member

Choose a reason for hiding this comment

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

Ah -- are we not binding destructors yet? That's surprising I really thought we were.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we're not doing it. We can without too much trouble though.

When we do, there's no point in doing that, though (we could, I guess?). But destructors have no arguments.

let is_static = cursor.method_is_static();
let is_method = cursor.kind() == CXCursor_CXXMethod;

if is_method || cursor.kind() == CXCursor_Constructor {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto about dtors for this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, when we support them that check should be there. But we should also check for virtual destructors, etc.

@@ -1359,13 +1359,14 @@ impl MethodCodegen for Method {
let mut stmts = vec![];

// If it's a constructor, we need to insert an extra parameter with a
// variable called `tmp` we're going to create.
// variable called `__bindgen_tmp` we're going to create.
Copy link
Member

Choose a reason for hiding this comment

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

Great :)

@@ -1,6 +1,6 @@
#pragma once

class Test final {
Copy link
Member

Choose a reason for hiding this comment

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

Why no more final? We can't get at it with llvm_stable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The travis gcc was complaining, and I didn't want to fight that battle :)

@@ -38,7 +38,8 @@ script:
- cargo test --features "$BINDGEN_FEATURES"
- cargo test --release --features "$BINDGEN_FEATURES"
- cd ../bindgen-integration
- cargo test
- cargo test --features "$BINDGEN_FEATURES"
- cargo test --release --features "$BINDGEN_FEATURES"
Copy link
Member

Choose a reason for hiding this comment

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

I think this is getting big enough that we should pull it out into a ./ci/test script. In a follow up, of course.

@@ -466,6 +466,7 @@ impl CompInfo {
&self.methods
}

/// Get this type's set of constructors.
Copy link
Member

Choose a reason for hiding this comment

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

Gotcha ;)

@emilio
Copy link
Contributor Author

emilio commented Dec 13, 2016

@bors-servo r=fitzgen

@bors-servo
Copy link

📌 Commit 1daf989 has been approved by fitzgen

@bors-servo
Copy link

⚡ Test exempted - status

@bors-servo bors-servo merged commit 1daf989 into rust-lang:master Dec 13, 2016
bors-servo pushed a commit that referenced this pull request Dec 13, 2016
Add support for constructors, and integration tests.

r? @fitzgen

cc @vvuk
@bbigras bbigras mentioned this pull request Dec 15, 2016
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