printrun-src/printrun/gcoder_line.pyx

changeset 46
cce0af6351f0
parent 15
0bbb006204fc
equal deleted inserted replaced
45:c82943fb205f 46:cce0af6351f0
1 # This file is copied from GCoder. 1 #cython: language_level=3
2 # 2 #
3 # GCoder is free software: you can redistribute it and/or modify 3 # This file is part of the Printrun suite.
4 #
5 # Printrun is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by 6 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or 7 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version. 8 # (at your option) any later version.
7 # 9 #
8 # GCoder is distributed in the hope that it will be useful, 10 # Printrun is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 13 # GNU General Public License for more details.
12 # 14 #
13 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 from libc.stdlib cimport malloc, free 18 from libc.stdlib cimport malloc, free
17 from libc.stdint cimport uint8_t, uint32_t 19 from libc.stdint cimport uint8_t, uint32_t
18 from libc.string cimport strlen, strncpy 20 from libc.string cimport strlen, strncpy
19 21
20 cdef char* copy_string(object value): 22 cdef char* copy_string(object value):
23 value = value.encode('utf-8')
21 cdef char* orig = value 24 cdef char* orig = value
22 str_len = len(orig) 25 str_len = len(orig)
23 cdef char* array = <char *>malloc(str_len + 1) 26 cdef char* array = <char *>malloc(str_len + 1)
24 strncpy(array, orig, str_len) 27 strncpy(array, orig, str_len)
25 array[str_len] = 0; 28 array[str_len] = 0;
190 def __set__(self, value): 193 def __set__(self, value):
191 self._gcview_end_vertex = value 194 self._gcview_end_vertex = value
192 self._status = set_has_var(self._status, pos_gcview_end_vertex) 195 self._status = set_has_var(self._status, pos_gcview_end_vertex)
193 property raw: 196 property raw:
194 def __get__(self): 197 def __get__(self):
195 if has_var(self._status, pos_raw): return self._raw 198 if has_var(self._status, pos_raw): return self._raw.decode('utf-8')
196 else: return None 199 else: return None
197 def __set__(self, value): 200 def __set__(self, value):
198 # WARNING: memory leak could happen here, as we don't do the following : 201 # WARNING: memory leak could happen here, as we don't do the following :
199 # if self._raw != NULL: free(self._raw) 202 # if self._raw != NULL: free(self._raw)
200 self._raw = copy_string(value) 203 self._raw = copy_string(value)
201 self._status = set_has_var(self._status, pos_raw) 204 self._status = set_has_var(self._status, pos_raw)
202 property command: 205 property command:
203 def __get__(self): 206 def __get__(self):
204 if has_var(self._status, pos_command): return self._command 207 if has_var(self._status, pos_command): return self._command.decode('utf-8')
205 else: return None 208 else: return None
206 def __set__(self, value): 209 def __set__(self, value):
207 # WARNING: memory leak could happen here, as we don't do the following : 210 # WARNING: memory leak could happen here, as we don't do the following :
208 # if self._command != NULL: free(self._command) 211 # if self._command != NULL: free(self._command)
209 self._command = copy_string(value) 212 self._command = copy_string(value)
229 if self._raw != NULL: free(self._raw) 232 if self._raw != NULL: free(self._raw)
230 if self._command != NULL: free(self._command) 233 if self._command != NULL: free(self._command)
231 234
232 property raw: 235 property raw:
233 def __get__(self): 236 def __get__(self):
234 if has_var(self._status, pos_raw): return self._raw 237 if has_var(self._status, pos_raw): return self._raw.decode('utf-8')
235 else: return None 238 else: return None
236 def __set__(self, value): 239 def __set__(self, value):
237 # WARNING: memory leak could happen here, as we don't do the following : 240 # WARNING: memory leak could happen here, as we don't do the following :
238 # if self._raw != NULL: free(self._raw) 241 # if self._raw != NULL: free(self._raw)
239 self._raw = copy_string(value) 242 self._raw = copy_string(value)
240 self._status = set_has_var(self._status, pos_raw) 243 self._status = set_has_var(self._status, pos_raw)
241 property command: 244 property command:
242 def __get__(self): 245 def __get__(self):
243 if has_var(self._status, pos_command): return self._command 246 if has_var(self._status, pos_command): return self._command.decode('utf-8')
244 else: return None 247 else: return None
245 def __set__(self, value): 248 def __set__(self, value):
246 # WARNING: memory leak could happen here, as we don't do the following : 249 # WARNING: memory leak could happen here, as we don't do the following :
247 # if self._command != NULL: free(self._command) 250 # if self._command != NULL: free(self._command)
248 self._command = copy_string(value) 251 self._command = copy_string(value)

mercurial