Commit aac09fda authored by Mozul Rémy's avatar Mozul Rémy

correction in string assignment

parent 68da62ce
...@@ -4,6 +4,7 @@ import numpy as np ...@@ -4,6 +4,7 @@ import numpy as np
import cython as ct import cython as ct
from libc.string cimport strcpy
from dtype cimport C_param, C_datatype, getOne, display, change from dtype cimport C_param, C_datatype, getOne, display, change
np.import_array() np.import_array()
...@@ -23,10 +24,21 @@ cdef class P_datatype(object): ...@@ -23,10 +24,21 @@ cdef class P_datatype(object):
self.rtab = np.PyArray_SimpleNewFromData(1, [self.f_image.itab[0]], np.NPY_DOUBLE, self.f_image.rtab) self.rtab = np.PyArray_SimpleNewFromData(1, [self.f_image.itab[0]], np.NPY_DOUBLE, self.f_image.rtab)
self.f_image_ptr = addOne(nn, rv, iv) self.f_image_ptr = addOne(nn, rv, iv)
# beurk
self.f_image.nickname[30] = '\0'
for i in range(self.f_image.itab[1]):
self.f_image.weird[i].field[30] = '\0'
self.f_image_ptr.nickname[30] = '\0'
for i in range(self.f_image_ptr.itab[1]):
self.f_image_ptr.weird[i].field[30] = '\0'
def cythonChange(self,nn,rv,iv): def cythonChange(self,nn,rv,iv):
#&self.f_image.nickname[0] = nn #this is not possible because char[30] is a non-lvalue
#self.f_image.nickname = nn
strcpy(self.f_image.nickname, nn)
self.f_image.rsingle = rv self.f_image.rsingle = rv
self.f_image.isingle = iv self.f_image.isingle = iv
strcpy(self.f_image_ptr.nickname, nn)
self.f_image_ptr.rsingle = rv self.f_image_ptr.rsingle = rv
self.f_image_ptr.isingle = iv self.f_image_ptr.isingle = iv
......
...@@ -220,12 +220,12 @@ contains ...@@ -220,12 +220,12 @@ contains
type(c_ptr), value :: nn type(c_ptr), value :: nn
! !
character(kind=c_char,len=30), pointer :: nname character(kind=c_char,len=30), pointer :: nname
integer(kind=4) :: i integer(kind=4) :: i, j
type(T_dt_link) , pointer :: dl type(T_dt_link) , pointer :: dl
call c_f_pointer(cptr=nn,fptr=nname) call c_f_pointer(cptr=nn,fptr=nname)
i = 0 i = 1
do while( i <30 .and. nname(i+1:i+1) /= c_null_char ) do while( i <30 .and. nname(i:i) /= c_null_char )
i = i + 1 i = i + 1
end do end do
mydatas(id)%nickname(1:i) = nname(1:i) mydatas(id)%nickname(1:i) = nname(1:i)
...@@ -235,7 +235,7 @@ contains ...@@ -235,7 +235,7 @@ contains
mydatas(id)%isingle = iv mydatas(id)%isingle = iv
dl => Root dl => Root
do i = 1, id-1 do j = 1, id-1
if( associated(dl%n) ) then if( associated(dl%n) ) then
dl => dl%n dl => dl%n
else else
...@@ -243,6 +243,7 @@ contains ...@@ -243,6 +243,7 @@ contains
return return
end if end if
end do end do
dl%d%nickname(1:i) = nname(1:i) dl%d%nickname(1:i) = nname(1:i)
dl%d%nickname(i+1:) = '' dl%d%nickname(i+1:) = ''
......
import dtype import dtype
dat = dtype.P_datatype(1, 'new from p', 12., 5) dat = dtype.P_datatype(1, 'new from p', 1., 1)
#dat.fortranChange('fortran change', 13.,6)
#dat.fortranContent()
#dat.cythonContent()
dat.cythonChange('cython change', 144., 12)
#dat.fortranContent()
dat.cythonContent()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment