@@ -75,6 +75,11 @@ func (g *pyGen) genSliceInit(slc *symbol, extTypes, pyWrapOnly bool, slob *Slice
7575 gocl = ""
7676 }
7777
78+ pysnm := slc .id
79+ if ! strings .Contains (pysnm , "Slice_" ) {
80+ pysnm = strings .TrimPrefix (pysnm , pkgname + "_" )
81+ }
82+
7883 if ! extTypes || pyWrapOnly {
7984 g .pywrap .Printf ("def __init__(self, *args, **kwargs):\n " )
8085 g .pywrap .Indent ()
@@ -154,6 +159,22 @@ otherwise parameter is a python list that we copy from
154159 g .pywrap .Indent ()
155160 g .pywrap .Printf ("if isinstance(key, slice):\n " )
156161 g .pywrap .Indent ()
162+ if slc .isSlice () {
163+ g .pywrap .Printf ("if key.step == None or key.step == 1:\n " )
164+ g .pywrap .Indent ()
165+ g .pywrap .Printf ("st = key.start\n " )
166+ g .pywrap .Printf ("ed = key.stop\n " )
167+ g .pywrap .Printf ("if st == None:\n " )
168+ g .pywrap .Indent ()
169+ g .pywrap .Printf ("st = 0\n " )
170+ g .pywrap .Outdent ()
171+ g .pywrap .Printf ("if ed == None:\n " )
172+ g .pywrap .Indent ()
173+ g .pywrap .Printf ("ed = _%s_len(self.handle)\n " , qNm )
174+ g .pywrap .Outdent ()
175+ g .pywrap .Printf ("return %s(handle=_%s_subslice(self.handle, st, ed))\n " , pysnm , qNm )
176+ g .pywrap .Outdent ()
177+ }
157178 g .pywrap .Printf ("return [self[ii] for ii in range(*key.indices(len(self)))]\n " )
158179 g .pywrap .Outdent ()
159180 g .pywrap .Printf ("elif isinstance(key, int):\n " )
@@ -270,7 +291,7 @@ otherwise parameter is a python list that we copy from
270291 g .gofile .Printf ("//export %s_len\n " , slNm )
271292 g .gofile .Printf ("func %s_len(handle CGoHandle) int {\n " , slNm )
272293 g .gofile .Indent ()
273- g .gofile .Printf ("return len(*ptrFromHandle_ %s(handle))\n " , slNm )
294+ g .gofile .Printf ("return len(deptrFromHandle_ %s(handle))\n " , slNm )
274295 g .gofile .Outdent ()
275296 g .gofile .Printf ("}\n \n " )
276297
@@ -279,9 +300,13 @@ otherwise parameter is a python list that we copy from
279300 g .gofile .Printf ("//export %s_elem\n " , slNm )
280301 g .gofile .Printf ("func %s_elem(handle CGoHandle, _idx int) %s {\n " , slNm , esym .cgoname )
281302 g .gofile .Indent ()
282- g .gofile .Printf ("s := *ptrFromHandle_ %s(handle)\n " , slNm )
303+ g .gofile .Printf ("s := deptrFromHandle_ %s(handle)\n " , slNm )
283304 if esym .go2py != "" {
284- g .gofile .Printf ("return %s(s[_idx])%s\n " , esym .go2py , esym .go2pyParenEx )
305+ if ! esym .isPointer () && esym .isStruct () {
306+ g .gofile .Printf ("return %s(&(s[_idx]))%s\n " , esym .go2py , esym .go2pyParenEx )
307+ } else {
308+ g .gofile .Printf ("return %s(s[_idx])%s\n " , esym .go2py , esym .go2pyParenEx )
309+ }
285310 } else {
286311 g .gofile .Printf ("return s[_idx]\n " )
287312 }
@@ -290,10 +315,23 @@ otherwise parameter is a python list that we copy from
290315
291316 g .pybuild .Printf ("mod.add_function('%s_elem', retval('%s'), [param('%s', 'handle'), param('int', 'idx')])\n " , slNm , esym .cpyname , PyHandle )
292317
318+ if slc .isSlice () {
319+ g .gofile .Printf ("//export %s_subslice\n " , slNm )
320+ g .gofile .Printf ("func %s_subslice(handle CGoHandle, _st, _ed int) CGoHandle {\n " , slNm )
321+ g .gofile .Indent ()
322+ g .gofile .Printf ("s := deptrFromHandle_%s(handle)\n " , slNm )
323+ g .gofile .Printf ("ss := s[_st:_ed]\n " )
324+ g .gofile .Printf ("return CGoHandle(handleFromPtr_%s(&ss))\n " , slNm )
325+ g .gofile .Outdent ()
326+ g .gofile .Printf ("}\n \n " )
327+
328+ g .pybuild .Printf ("mod.add_function('%s_subslice', retval('%s'), [param('%s', 'handle'), param('int', 'st'), param('int', 'ed')])\n " , slNm , PyHandle , PyHandle )
329+ }
330+
293331 g .gofile .Printf ("//export %s_set\n " , slNm )
294332 g .gofile .Printf ("func %s_set(handle CGoHandle, _idx int, _vl %s) {\n " , slNm , esym .cgoname )
295333 g .gofile .Indent ()
296- g .gofile .Printf ("s := *ptrFromHandle_ %s(handle)\n " , slNm )
334+ g .gofile .Printf ("s := deptrFromHandle_ %s(handle)\n " , slNm )
297335 if esym .py2go != "" {
298336 g .gofile .Printf ("s[_idx] = %s(_vl)%s\n " , esym .py2go , esym .py2goParenEx )
299337 } else {
0 commit comments