Comments (5)
This is a great issue for someone to work on! The current model is that Go owns all the data structures exposed by gopy, which continue to be managed by its GC etc, and are accessed exclusively by the (auto generated) handle. To do something more efficient, gopy could expose a method that returns an unsafe pointer and a length into any slice's raw memory (&slice[0]
), which then shows up as a python bytes
object, with whatever proper steps / warnings or whatever to ensure that this raw memory is copied immediately into the Python side of things and the dangling pointer is not kept around after this initial call, as it will become increasingly likely to become invalid. Presumably the python wrapper just does the copy immediately in the course of calling this method.
from gopy.
This could be achieved by using a string type presumably? The semantics of the []byte would be lost if it was not directly writable on the python side.
from gopy.
My understanding is that a string
type in Go would automatically map to an str
type in Python, which is defined as being composed only of UTF-8 bytes. Indeed, trying something similar out seems to return an error on the autogenerated Get
method:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
I suppose there's no way of forcing a Go string
to be handled as a bytes
type instead? My assumption here is that there's not (or that any conversion here would be of equivalent effort as the original ask, in GoPy itself), and it's also partially the reason why I specified bytes
rather than bytearray
-- I assume that mapping the mutating aspects of the Python bytearray
back to the Go []byte
may not be feasible, hence it might simply be worth adding a function that returns an immutable copy of the entire byte slice instead.
from gopy.
I'm not sufficiently up on the relevant standards in Python for how this all works, so I can't really judge, but it sounds like we might want to have it work in different ways depending on the use case.. We do have the ability to flag things with some kind of comment directive I believe, so that might be an option. I can't quite remember where this is used but I believe it determines how an interface{}
is treated or something to that effect.
from gopy.
Fixed by #342
from gopy.
Related Issues (20)
- Windows build broke without the sed hack
- Build constraints exclude all Go files in HOT 1
- "go": cannot run executable found relative to current directory HOT 3
- Best way to pass data chunks (bytes, bytearray)? HOT 1
- Panic when function returns a map of non-pointer structs HOT 2
- Build error on Windows10 HOT 2
- gopy: only one function signature arg allowed HOT 1
- cross-platform generation of Python bindings HOT 1
- Enhancement request: enable manylinux builds
- fmt.Stringer on the Go side didn't get called properly from __str__ on the Python side. HOT 1
- Add hacktoberfest topic
- No consts documentation is generated
- gopy doesn't ignore internal package HOT 2
- []byte Parameter Results in Unexpected Integer Type HOT 1
- Methods with two outputs are expected to return an error, methods aren't visible from python
- Can't return a slice of slices ([][]bool) HOT 3
- Type aliases points to the underlying type not the root one, this cause issues where the autogenerated go package does not build if it links to internal packages. HOT 4
- Invalid #cgo CFLAGS / Invalid #cgo LDFLAGS on Windows for path with space HOT 1
- cannot use _Ctype_long(size) (value of type _Ctype_long) as _Ctype_longlong value in argument to (_Cfunc_PyBytes_FromStringAndSize) HOT 3
- appveyor cannot find pybindgen HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gopy.