# HG changeset patch
# User wstein@teragon.local
# Date 1224804554 25200
# Node ID 71595e484ae57ebe43e17e64463bdfa99a5a12d1
# Parent aad802b97a9923a945de2ddfa7d80278fce46f46
trac #4241 -- magma -- memory is never freed in the interface when MagmaElement's are deleted
diff -r aad802b97a99 -r 71595e484ae5 sage/interfaces/magma.py
a
|
b
|
|
232 | 232 | # local user startup configuration is not read. |
233 | 233 | |
234 | 234 | self.__seq = 0 |
| 235 | self.__available_var = [] |
235 | 236 | |
236 | 237 | def __reduce__(self): |
237 | 238 | """ |
… |
… |
|
504 | 505 | return Expect.__call__(self, x) |
505 | 506 | return self.objgens(x, gens) |
506 | 507 | |
507 | | #def clear(self, var): |
508 | | # """ |
509 | | # Clear the variable named var. |
510 | | # """ |
511 | | #self.eval("delete %s"%var) |
512 | | # self.eval("%s:=0"%var) |
| 508 | def clear(self, var): |
| 509 | """ |
| 510 | Clear the variable named var and make it available |
| 511 | to be used again. |
| 512 | |
| 513 | INPUT: |
| 514 | var -- a string |
| 515 | |
| 516 | |
| 517 | EXAMPLES: |
| 518 | sage: magma = Magma() # optional |
| 519 | sage: magma.clear('foo') # optional -- this sets foo to 0 in magma. |
| 520 | sage: magma.eval('foo') # optional |
| 521 | '0' |
| 522 | |
| 523 | Because we cleared foo, it is set to be used as a variable |
| 524 | name in the future: |
| 525 | sage: a = magma('10') # optional |
| 526 | sage: a.name() # optional |
| 527 | 'foo' |
| 528 | |
| 529 | The following tests that the whole variable clearlying and |
| 530 | freeing system is working correctly. |
| 531 | sage: magma = Magma() # optional |
| 532 | sage: a = magma('100') # optional |
| 533 | sage: a.name() # optional |
| 534 | '_sage_[1]' |
| 535 | sage: del a # optional |
| 536 | sage: b = magma('257') # optional |
| 537 | sage: b.name() # optional |
| 538 | '_sage_[1]' |
| 539 | sage: del b # optional |
| 540 | sage: magma('_sage_[1]') # optional |
| 541 | 0 |
| 542 | """ |
| 543 | self.__available_var.append(var) |
| 544 | self.eval("%s:=0"%var) |
513 | 545 | |
514 | 546 | def cputime(self, t=None): |
515 | 547 | """ |
… |
… |
|
660 | 692 | # this exception could happen if the MAGMA process |
661 | 693 | # was interrupted during startup / initialization. |
662 | 694 | self.eval('_sage_ := [* 0 : i in [1..%s] *];'%self.__seq) |
663 | | self.__seq += 1 |
664 | | return '_sage_[%s]'%self.__seq |
| 695 | if len(self.__available_var) > 0: |
| 696 | n = self.__available_var[0] |
| 697 | del self.__available_var[0] |
| 698 | return n |
| 699 | else: |
| 700 | self.__seq += 1 |
| 701 | return '_sage_[%s]'%self.__seq |
665 | 702 | |
666 | 703 | def function_call(self, function, args=[], params={}, nvals=1): |
667 | 704 | """ |