diff --git a/qpms/qpms_c.pyx b/qpms/qpms_c.pyx index a6fb4e2..6f6c25f 100644 --- a/qpms/qpms_c.pyx +++ b/qpms/qpms_c.pyx @@ -1112,11 +1112,13 @@ cdef char *make_c_string(pythonstring): ''' bytestring = pythonstring.encode('UTF-8') cdef Py_ssize_t n = len(bytestring) + cdef Py_ssize_t i cdef char *s s = malloc(n+1) if not s: raise MemoryError - s[:] = bytestring + #s[:n] = bytestring # This segfaults; why? + for i in range(n): s[i] = bytestring[i] s[n] = 0 return s @@ -1138,7 +1140,8 @@ cdef class FinitePointGroup: cdef int order = len(permlist) permindices = {perm: i for i, perm in enumerate(permlist)} # 'invert' permlist identity = info.permgroup.identity - self.G = malloc(sizeof(qpms_finite_group_t)) + # We use calloc to avoid calling free to unitialized pointers + self.G = calloc(1,sizeof(qpms_finite_group_t)) if not self.G: raise MemoryError self.G[0].name = make_c_string(info.name) self.G[0].order = order @@ -1156,7 +1159,7 @@ cdef class FinitePointGroup: self.G[0].gens = malloc(sizeof(qpms_gmi_t) * self.G[0].ngens) if not self.G[0].gens: raise MemoryError for i in range(self.G[0].ngens): - self.G[0].gens[i] = permindices[info.groupgens[i]] + self.G[0].gens[i] = permindices[info.permgroupgens[i]] self.G[0].permrep = calloc(order, sizeof(char *)) if not self.G[0].permrep: raise MemoryError for i in range(order): @@ -1187,6 +1190,7 @@ cdef class FinitePointGroup: for row in range(dim): for col in range(dim): self.G[0].irreps[iri].m[i*dim*dim + row*dim + col] = irrep[permlist[i]][row,col] + self.G[0].elemlabels = 0 # Elem labels not yet implemented self.owns_data = True def __dealloc__(self):