Skip to content

Conversation

corona10
Copy link
Collaborator

@corona10 corona10 commented Jul 15, 2017

  • Pass 'named.go' test.
  • Support to generate named type includes slice and array types.
  • Add doc.go for bind package.
  • Add comments.
  • Support iadd for Go slice types.
  • Add a 'seq.go' test for the CFFI engine.

Fix: #121

@corona10 corona10 force-pushed the gsoc-type branch 7 times, most recently from 05a8367 to 04f3705 Compare July 17, 2017 06:54
@corona10 corona10 changed the title [WIP] cffi: Generating named type. cffi: Generate named type. Jul 17, 2017
@corona10 corona10 changed the title cffi: Generate named type. cffi: Generate named types. Jul 17, 2017
@corona10
Copy link
Collaborator Author

@alclaude Ready for review :)

@corona10 corona10 changed the title cffi: Generate named types. cffi: Support named type + Pass 'seq.go' test. Jul 21, 2017
bind/doc.go Outdated
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*
Copy link
Member

Choose a reason for hiding this comment

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

Standard documentation for packages look like:

// Package bind provides tools to generate bindings to use Go from Python.
package bind

bind/doc.go Outdated
to call Go code and pass objects from Python.

*/

Copy link
Member

Choose a reason for hiding this comment

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

remove that empty line (otherwise the documentation isn't attached to the package)

"go/types"
"strconv"
"strings"
)

// Generate C definitions of Go struct.
Copy link
Member

Choose a reason for hiding this comment

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

the canonical way to document functions/methods is:

// genCdefStruct generates C definitions for a Go struct.
func (g *cffiGen) genCdefStruct(s Struct) {

(ie: // [method or function name] [verb] [stuff...])

func (g *cffiGen) genCdefStruct(s Struct) {
g.wrapper.Printf("// A type definition of the %[1]s.%[2]s for wrapping.\n", s.Package().Name(), s.sym.cgoname)
g.wrapper.Printf("typedef void* %s;\n", s.sym.cgoname)
g.wrapper.Printf("extern void* cgo_func_%s_new();\n", s.sym.id)
}

// Generate C definitions of Go type.
Copy link
Member

Choose a reason for hiding this comment

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

please use the canonical way to document functions/methods.

func (g *cffiGen) genCdefType(sym *symbol) {
g.wrapper.Printf("// C definitions of the %[1]s.%[2]s.\n", g.pkg.pkg.Name(), sym.id)
Copy link
Member

Choose a reason for hiding this comment

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

I would rephrase as:

"// C definitions for Go type %[1]s.%[2]s.\n"

case sym.isArray():
g.wrapper.Printf("if args:\n")
g.wrapper.Indent()
g.wrapper.Printf("if not isinstance(args[0], collections.Sequence):\n")
Copy link
Member

Choose a reason for hiding this comment

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

here, collections.Sequence is ok. (we need len(x))

case sym.isSlice():
g.wrapper.Printf("if args:\n")
g.wrapper.Indent()
g.wrapper.Printf("if not isinstance(args[0], collections.Sequence):\n")
Copy link
Member

Choose a reason for hiding this comment

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

but here, I would use collections.Iterable instead.

g.wrapper.Printf("\n")
}

// Generate Type converter between C and Python.
Copy link
Member

Choose a reason for hiding this comment

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

doc.

g.wrapper.Printf("\n")
}

// Generate Type methods.
Copy link
Member

Choose a reason for hiding this comment

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

doc.

g.wrapper.Printf("\n")
}

// Generate Type __str__ method.
Copy link
Member

Choose a reason for hiding this comment

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

doc.

@corona10 corona10 changed the title cffi: Support named type + Pass 'seq.go' test. [WIP] cffi: Support named type + Pass 'seq.go' test. Jul 31, 2017
@corona10 corona10 changed the title [WIP] cffi: Support named type + Pass 'seq.go' test. cffi: Support named type + Pass 'seq.go' test. Jul 31, 2017
@corona10
Copy link
Collaborator Author

@sbinet Updated!!

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

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

some more nitpicks.

bind/doc.go Outdated
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package bind package generates language bindings that make it possible
Copy link
Member

Choose a reason for hiding this comment

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

typo: Package bind package

"go/types"
"strconv"
"strings"
)

// genCdefStruct generate C definitions of Go struct.
Copy link
Member

Choose a reason for hiding this comment

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

s/generate/generates/
s/of Go/for a Go/

func (g *cffiGen) genCdefStruct(s Struct) {
g.wrapper.Printf("// A type definition of the %[1]s.%[2]s for wrapping.\n", s.Package().Name(), s.sym.cgoname)
g.wrapper.Printf("typedef void* %s;\n", s.sym.cgoname)
g.wrapper.Printf("extern void* cgo_func_%s_new();\n", s.sym.id)
}

// genCdefType generates C definitions of Go type.
Copy link
Member

Choose a reason for hiding this comment

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

s/of Go/for a Go/

g.wrapper.Printf("\n")
}

// genTypeCdefInit generate cgo_func_XXXX_new() of Go type.
Copy link
Member

Choose a reason for hiding this comment

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

s/generate/generates/
s/of Go/for a Go/

}
}

// genCdefFunc generates a C definition of Go function.
Copy link
Member

Choose a reason for hiding this comment

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

s/of Go/for a Go/

@@ -99,6 +198,8 @@ func (g *cffiGen) genCdefMethod(f Func) {
g.wrapper.Printf("extern %[1]s cgo_func_%[2]s(%[3]s);\n", cdef_ret, f.id, paramString)
}

// genCdefStructMemberGetter generates
// C definitions of Getter/Setter for Go struct.
Copy link
Member

Choose a reason for hiding this comment

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

s/for Go struct/for a Go struct/
also, please everything on one line (ie: no new line after generates.)

@@ -116,6 +217,8 @@ func (g *cffiGen) genCdefStructMemberGetter(s Struct, i int, f types.Object) {
}
}

// genCdefStructMemberSetter generates
// C defintion of Setter for Go struct.
Copy link
Member

Choose a reason for hiding this comment

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

s/for Go/for a Go/.
s/defintion/definition/
also: please everything on one line.

@@ -126,6 +229,14 @@ func (g *cffiGen) genCdefStructMemberSetter(s Struct, i int, f types.Object) {
g.wrapper.Printf("extern void cgo_func_%[1]s_setter_%[2]d(void* p0, %[3]s p1);\n", s.sym.id, i+1, cdef_value)
}

// genCdefStructTPStr generates
// C definitions of str method for Go struct.
Copy link
Member

Choose a reason for hiding this comment

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

s/for Go/for a Go/
also: please everything on one line.

func (g *cffiGen) genCdefStructTPStr(s Struct) {
g.wrapper.Printf("extern GoString cgo_func_%[1]s_str(void* p0);\n", s.sym.id)
}

// genCdefTypeTPStr generates
// C definitions of str method for Go type.
Copy link
Member

Choose a reason for hiding this comment

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

s/for Go/for a Go/
also: please everything on one line.

"go/types"
)

// genType generates Go type with Python wrapper class.
Copy link
Member

Choose a reason for hiding this comment

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

that doesn't read very well.
please replace with something along the lines of:

// genType generates a Python class wrapping the given Go type.

* Pass 'named.go' test.
* Support to generate named type includes slice and array types.
* Add doc.go for bind package.
* Add comments.
* Support __iadd__ for Go slice types.
* Add a 'seq.go' test for the CFFI engine.
@corona10
Copy link
Collaborator Author

corona10 commented Aug 2, 2017

@sbinet
Thank you for comment about all sentences.
The update was a little bit late due to unexpected event.

@corona10
Copy link
Collaborator Author

corona10 commented Aug 2, 2017

Updated

@sbinet sbinet merged commit c2676d7 into go-python:master Aug 3, 2017
@corona10 corona10 deleted the gsoc-type branch August 3, 2017 09:21
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.

2 participants