-
Notifications
You must be signed in to change notification settings - Fork 124
cffi: Support named type + Pass 'seq.go' test. #120
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
Conversation
05a8367
to
04f3705
Compare
@alclaude Ready for review :) |
bind/doc.go
Outdated
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
/* |
There was a problem hiding this comment.
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. | ||
|
||
*/ | ||
|
There was a problem hiding this comment.
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)
bind/gencffi_cdef.go
Outdated
"go/types" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Generate C definitions of Go struct. |
There was a problem hiding this comment.
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...]
)
bind/gencffi_cdef.go
Outdated
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. |
There was a problem hiding this comment.
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.
bind/gencffi_cdef.go
Outdated
func (g *cffiGen) genCdefType(sym *symbol) { | ||
g.wrapper.Printf("// C definitions of the %[1]s.%[2]s.\n", g.pkg.pkg.Name(), sym.id) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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)
)
bind/gencffi_type.go
Outdated
case sym.isSlice(): | ||
g.wrapper.Printf("if args:\n") | ||
g.wrapper.Indent() | ||
g.wrapper.Printf("if not isinstance(args[0], collections.Sequence):\n") |
There was a problem hiding this comment.
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.
bind/gencffi_type.go
Outdated
g.wrapper.Printf("\n") | ||
} | ||
|
||
// Generate Type converter between C and Python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc.
bind/gencffi_type.go
Outdated
g.wrapper.Printf("\n") | ||
} | ||
|
||
// Generate Type methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc.
bind/gencffi_type.go
Outdated
g.wrapper.Printf("\n") | ||
} | ||
|
||
// Generate Type __str__ method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc.
@sbinet Updated!! |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: Package bind package
bind/gencffi_cdef.go
Outdated
"go/types" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// genCdefStruct generate C definitions of Go struct. |
There was a problem hiding this comment.
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/
bind/gencffi_cdef.go
Outdated
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. |
There was a problem hiding this comment.
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/
bind/gencffi_cdef.go
Outdated
g.wrapper.Printf("\n") | ||
} | ||
|
||
// genTypeCdefInit generate cgo_func_XXXX_new() of Go type. |
There was a problem hiding this comment.
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/
bind/gencffi_cdef.go
Outdated
} | ||
} | ||
|
||
// genCdefFunc generates a C definition of Go function. |
There was a problem hiding this comment.
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/
bind/gencffi_cdef.go
Outdated
@@ -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. |
There was a problem hiding this comment.
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
.)
bind/gencffi_cdef.go
Outdated
@@ -116,6 +217,8 @@ func (g *cffiGen) genCdefStructMemberGetter(s Struct, i int, f types.Object) { | |||
} | |||
} | |||
|
|||
// genCdefStructMemberSetter generates | |||
// C defintion of Setter for Go struct. |
There was a problem hiding this comment.
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.
bind/gencffi_cdef.go
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
bind/gencffi_cdef.go
Outdated
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. |
There was a problem hiding this comment.
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.
bind/gencffi_type.go
Outdated
"go/types" | ||
) | ||
|
||
// genType generates Go type with Python wrapper class. |
There was a problem hiding this comment.
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.
@sbinet |
Updated |
Fix: #121