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
import cython as ct
from libc.string cimport strcpy
from dtype cimport C_param, C_datatype, getOne, display, change
np.import_array()
......@@ -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.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):
#&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.isingle = iv
strcpy(self.f_image_ptr.nickname, nn)
self.f_image_ptr.rsingle = rv
self.f_image_ptr.isingle = iv
......
......@@ -220,12 +220,12 @@ contains
type(c_ptr), value :: nn
!
character(kind=c_char,len=30), pointer :: nname
integer(kind=4) :: i
integer(kind=4) :: i, j
type(T_dt_link) , pointer :: dl
call c_f_pointer(cptr=nn,fptr=nname)
i = 0
do while( i <30 .and. nname(i+1:i+1) /= c_null_char )
i = 1
do while( i <30 .and. nname(i:i) /= c_null_char )
i = i + 1
end do
mydatas(id)%nickname(1:i) = nname(1:i)
......@@ -235,7 +235,7 @@ contains
mydatas(id)%isingle = iv
dl => Root
do i = 1, id-1
do j = 1, id-1
if( associated(dl%n) ) then
dl => dl%n
else
......@@ -243,6 +243,7 @@ contains
return
end if
end do
dl%d%nickname(1:i) = nname(1:i)
dl%d%nickname(i+1:) = ''
......
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