@@ -72,9 +72,11 @@ cdef class Unit:
7272
7373 """
7474 cdef ut_unit * cunit
75+ cdef System system
7576
7677 def __cinit__ (self ):
7778 self .cunit = NULL
79+ self .system = None
7880
7981 def __dealloc__ (self ):
8082 ut_free(self .cunit)
@@ -116,11 +118,12 @@ cdef System wrap_system(ut_system* csystem):
116118 sytem.csystem = csystem
117119 return sytem
118120
119- cdef Unit wrap_unit(ut_unit* cunit):
121+ cdef Unit wrap_unit(System system, ut_unit* cunit):
120122 if cunit is NULL :
121123 _raise_error()
122124 cdef Unit unit = Unit()
123125 unit.cunit = cunit
126+ unit.system = system
124127 return unit
125128
126129cdef Converter wrap_converter(cv_converter* cconverter):
@@ -204,11 +207,11 @@ def read_xml(char* path=NULL):
204207
205208def get_unit_by_name (System system , char* name ):
206209 cdef ut_unit* cunit = ut_get_unit_by_name(system.csystem, name)
207- return wrap_unit(cunit)
210+ return wrap_unit(system, cunit)
208211
209212def clone (Unit unit ):
210213 cdef ut_unit* cunit = ut_clone(unit.cunit)
211- return wrap_unit(cunit)
214+ return wrap_unit(unit.system, cunit)
212215
213216def is_dimensionless (Unit unit ):
214217 return < bint> ut_is_dimensionless(unit.cunit)
@@ -225,43 +228,44 @@ def get_converter(Unit fr, Unit to):
225228
226229def scale (double factor , Unit unit ):
227230 cdef ut_unit* cunit = ut_scale(factor, unit.cunit)
228- return wrap_unit(cunit)
231+ return wrap_unit(unit.system, cunit)
229232
230233def offset (Unit unit , double offset ):
231234 cdef ut_unit* cunit = ut_offset(unit.cunit, offset)
232- return wrap_unit(cunit)
235+ return wrap_unit(unit.system, cunit)
233236
234237def offset_by_time (Unit unit , double origin ):
235238 cdef ut_unit* cunit = ut_offset_by_time(unit.cunit, origin)
236- return wrap_unit(cunit)
239+ return wrap_unit(unit.system, cunit)
237240
238241def multiply (Unit unit1 , Unit unit2 ):
239242 cdef ut_unit* cunit = ut_multiply(unit1.cunit, unit2.cunit)
240- return wrap_unit(cunit)
243+ return wrap_unit(unit1.system, cunit)
241244
242245def invert (Unit unit ):
243246 cdef ut_unit* cunit = ut_invert(unit.cunit)
244- return wrap_unit(cunit)
247+ return wrap_unit(unit.system, cunit)
245248
246249def divide (Unit numer , Unit denom ):
247250 cdef ut_unit* cunit = ut_divide(numer.cunit, denom.cunit)
248- return wrap_unit(cunit)
251+ return wrap_unit(numer.system, cunit)
249252
250253def raise_ (Unit unit , int power ):
251254 cdef ut_unit* cunit = ut_raise(unit.cunit, power)
252- return wrap_unit(cunit)
255+ return wrap_unit(unit.system, cunit)
253256
254257def root (Unit unit , int root ):
255258 cdef ut_unit* cunit = ut_root(unit.cunit, root)
256- return wrap_unit(cunit)
259+ return wrap_unit(unit.system, cunit)
257260
258261def log (double base , Unit reference ):
259262 cdef ut_unit* cunit = ut_log(base, reference.cunit)
260- return wrap_unit(cunit)
263+ return wrap_unit(reference.system, cunit)
264+
261265
262266def parse (System system , char* string , ut_encoding encoding ):
263267 cdef ut_unit* cunit = ut_parse(system.csystem, string, encoding)
264- return wrap_unit(cunit)
268+ return wrap_unit(system, cunit)
265269
266270def format (Unit unit , unsigned opts = 0 ):
267271 cdef bytearray buf = bytearray(_STRING_BUFFER_DEPTH)
0 commit comments