@@ -75,6 +75,11 @@ func (g *pyGen) genSliceInit(slc *symbol, extTypes, pyWrapOnly bool, slob *Slice
75
75
gocl = ""
76
76
}
77
77
78
+ pysnm := slc .id
79
+ if ! strings .Contains (pysnm , "Slice_" ) {
80
+ pysnm = strings .TrimPrefix (pysnm , pkgname + "_" )
81
+ }
82
+
78
83
if ! extTypes || pyWrapOnly {
79
84
g .pywrap .Printf ("def __init__(self, *args, **kwargs):\n " )
80
85
g .pywrap .Indent ()
@@ -154,6 +159,22 @@ otherwise parameter is a python list that we copy from
154
159
g .pywrap .Indent ()
155
160
g .pywrap .Printf ("if isinstance(key, slice):\n " )
156
161
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
+ }
157
178
g .pywrap .Printf ("return [self[ii] for ii in range(*key.indices(len(self)))]\n " )
158
179
g .pywrap .Outdent ()
159
180
g .pywrap .Printf ("elif isinstance(key, int):\n " )
@@ -294,6 +315,19 @@ otherwise parameter is a python list that we copy from
294
315
295
316
g .pybuild .Printf ("mod.add_function('%s_elem', retval('%s'), [param('%s', 'handle'), param('int', 'idx')])\n " , slNm , esym .cpyname , PyHandle )
296
317
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
+
297
331
g .gofile .Printf ("//export %s_set\n " , slNm )
298
332
g .gofile .Printf ("func %s_set(handle CGoHandle, _idx int, _vl %s) {\n " , slNm , esym .cgoname )
299
333
g .gofile .Indent ()
0 commit comments