Changeset b7b08c in git for Singular/ring.cc
- Timestamp:
- Oct 14, 1999, 4:27:35 PM (25 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 548777d246af408b77296a71c16c980b2cef5b35
- Parents:
- e960943ba1dcfcb333014a2aee474750e8fafe10
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/ring.cc
re960943 rb7b08c 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: ring.cc,v 1. 69 1999-10-14 12:50:28 SingularExp $ */4 /* $Id: ring.cc,v 1.70 1999-10-14 14:27:28 obachman Exp $ */ 5 5 6 6 /* … … 11 11 #include <math.h> 12 12 #include "mod2.h" 13 #include "structs.h" 13 14 #include "mmemory.h" 14 15 #include "tok.h" … … 113 114 } 114 115 115 /*------------ set spolys ------------------------------------------*/ 116 /*------------ Garbage Collection -----------------------------------*/ 117 mmGarbageCollectHeaps(2); 116 118 } 117 119 } … … 203 205 /*r->P = 0; Alloc0 in idhdl::set, ipid.cc*/ 204 206 /*names*/ 205 r->names = (char **) Alloc(3 * sizeof(char *));207 r->names = (char **) Alloc(3 * sizeof(char_ptr)); 206 208 r->names[0] = mstrdup("x"); 207 209 r->names[1] = mstrdup("y"); 208 210 r->names[2] = mstrdup("z"); 209 211 /*weights: entries for 3 blocks: NULL*/ 210 r->wvhdl = (int **)Alloc0(3 * sizeof(int *));212 r->wvhdl = (int **)Alloc0(3 * sizeof(int_ptr)); 211 213 /*order: dp,C,0*/ 212 r->order = (int *) Alloc(3 * sizeof(int *));213 r->block0 = (int *)Alloc(3 * sizeof(int *));214 r->block1 = (int *)Alloc(3 * sizeof(int *));214 r->order = (int *) Alloc(3 * sizeof(int_ptr)); 215 r->block0 = (int *)Alloc(3 * sizeof(int_ptr)); 216 r->block1 = (int *)Alloc(3 * sizeof(int_ptr)); 215 217 /* ringorder dp for the first block: var 1..3 */ 216 218 r->order[0] = ringorder_dp; … … 321 323 R->block0=(int *)Alloc0(n*sizeof(int)); 322 324 R->block1=(int *)Alloc0(n*sizeof(int)); 323 R->wvhdl=(int**)Alloc0(n*sizeof(int *));325 R->wvhdl=(int**)Alloc0(n*sizeof(int_ptr)); 324 326 325 327 // init order, so that rBlocks works correctly … … 519 521 if ((pn->next==NULL) && complex_flag) 520 522 { 521 pn->next=(leftv)Alloc0 (sizeof(sleftv));523 pn->next=(leftv)Alloc0SizeOf(sleftv); 522 524 pn->next->name=mstrdup("i"); 523 525 } … … 572 574 } 573 575 // allocated ring and set ch 574 R = (ring) Alloc0 (sizeof(sip_sring));576 R = (ring) Alloc0SizeOf(sip_sring); 575 577 R->ch = ch; 576 578 if (ch == -1) … … 589 591 goto rInitError; 590 592 } 591 R->parameter=(char**)Alloc0(R->P*sizeof(char *));593 R->parameter=(char**)Alloc0(R->P*sizeof(char_ptr)); 592 594 if (rSleftvList2StringArray(pn, R->parameter)) 593 595 { … … 612 614 /* names and number of variables-------------------------------------*/ 613 615 R->N = rv->listLength(); 614 R->names = (char **)Alloc0(R->N * sizeof(char *));616 R->names = (char **)Alloc0(R->N * sizeof(char_ptr)); 615 617 if (rSleftvList2StringArray(rv, R->names)) 616 618 { … … 643 645 644 646 // try to enter the ring into the name list // 647 // need to clean up sleftv here, before this ring can be set to 648 // new currRing or currRing can be killed beacuse new ring has 649 // same name 650 if (pn != NULL) pn->CleanUp(); 651 if (rv != NULL) rv->CleanUp(); 652 if (ord != NULL) ord->CleanUp(); 645 653 if ((tmp = enterid(s, myynest, RING_CMD, &IDROOT))==NULL) 646 654 goto rInitError; … … 648 656 memcpy(IDRING(tmp),R,sizeof(*R)); 649 657 // set current ring 650 Free (R, sizeof(ip_sring));658 FreeSizeOf(R, ip_sring); 651 659 return tmp; 652 660 … … 654 662 rInitError: 655 663 if (R != NULL) rDelete(R); 664 if (pn != NULL) pn->CleanUp(); 665 if (rv != NULL) rv->CleanUp(); 666 if (ord != NULL) ord->CleanUp(); 656 667 return NULL; 657 668 } … … 691 702 mmTestP(r->block0,nblocks*sizeof(int)); 692 703 mmTestP(r->block1,nblocks*sizeof(int)); 693 mmTestP(r->wvhdl,nblocks*sizeof(int *));694 mmTestP(r->names,r->N*sizeof(char *));704 mmTestP(r->wvhdl,nblocks*sizeof(int_ptr)); 705 mmTestP(r->names,r->N*sizeof(char_ptr)); 695 706 696 707 nblocks--; … … 835 846 if (r->names[i] != NULL) FreeL((ADDRESS)r->names[i]); 836 847 } 837 Free((ADDRESS)r->names,r->N*sizeof(char *));848 Free((ADDRESS)r->names,r->N*sizeof(char_ptr)); 838 849 } 839 850 … … 849 860 j++; 850 861 } 851 Free((ADDRESS)r->parameter,rPar(r)*sizeof(char *));852 } 853 Free (r, sizeof(ip_sring));862 Free((ADDRESS)r->parameter,rPar(r)*sizeof(char_ptr)); 863 } 864 FreeSizeOf(r, ip_sring); 854 865 } 855 866 … … 1278 1289 if (strcmp(r1->parameter[0],r2->parameter[0])==0) /* 1 char */ 1279 1290 { 1280 tmpR.parameter=(char **)Alloc (sizeof(char *));1291 tmpR.parameter=(char **)AllocSizeOf(char_ptr); 1281 1292 tmpR.parameter[0]=mstrdup(r1->parameter[0]); 1282 1293 tmpR.P=1; … … 1299 1310 && naEqual(r1->minpoly,r2->minpoly)) 1300 1311 { 1301 tmpR.parameter=(char **)Alloc (sizeof(char *));1312 tmpR.parameter=(char **)AllocSizeOf(char_ptr); 1302 1313 tmpR.parameter[0]=mstrdup(r1->parameter[0]); 1303 1314 tmpR.minpoly=naCopy(r1->minpoly); … … 1317 1328 && (rPar(r2)==1)) 1318 1329 { 1319 tmpR.parameter=(char **)Alloc0 (sizeof(char *));1330 tmpR.parameter=(char **)Alloc0SizeOf(char_ptr); 1320 1331 tmpR.parameter[0]=mstrdup(r1->parameter[0]); 1321 1332 tmpR.P=1; … … 1338 1349 && (rPar(r1)==1)) 1339 1350 { 1340 tmpR.parameter=(char **)Alloc (sizeof(char *));1351 tmpR.parameter=(char **)AllocSizeOf(char_ptr); 1341 1352 tmpR.parameter[0]=mstrdup(r1->parameter[0]); 1342 1353 tmpR.P=1; … … 1354 1365 { 1355 1366 int len=rPar(r1)+rPar(r2); 1356 tmpR.parameter=(char **)Alloc(len*sizeof(char *));1367 tmpR.parameter=(char **)Alloc(len*sizeof(char_ptr)); 1357 1368 int i; 1358 1369 for (i=0;i<rPar(r1);i++) … … 1376 1387 if (i!=len) 1377 1388 { 1378 ReAlloc(tmpR.parameter,len*sizeof(char *),i*sizeof(char *));1389 ReAlloc(tmpR.parameter,len*sizeof(char_ptr),i*sizeof(char_ptr)); 1379 1390 } 1380 1391 } … … 1390 1401 { 1391 1402 tmpR.ch=rInternalChar(r1); 1392 tmpR.parameter=(char **)Alloc(rPar(r1)*sizeof(char *));1403 tmpR.parameter=(char **)Alloc(rPar(r1)*sizeof(char_ptr)); 1393 1404 tmpR.P=rPar(r1); 1394 memcpy(tmpR.parameter,r1->parameter,rPar(r1)*sizeof(char *));1405 memcpy(tmpR.parameter,r1->parameter,rPar(r1)*sizeof(char_ptr)); 1395 1406 if (r1->minpoly!=NULL) 1396 1407 { … … 1417 1428 tmpR.ch=rInternalChar(r2); 1418 1429 tmpR.P=rPar(r2); 1419 tmpR.parameter=(char **)Alloc(rPar(r2)*sizeof(char *));1420 memcpy(tmpR.parameter,r2->parameter,rPar(r2)*sizeof(char *));1430 tmpR.parameter=(char **)Alloc(rPar(r2)*sizeof(char_ptr)); 1431 memcpy(tmpR.parameter,r2->parameter,rPar(r2)*sizeof(char_ptr)); 1421 1432 if (r2->minpoly!=NULL) 1422 1433 { … … 1431 1442 if (r2->parameter!=NULL) 1432 1443 { 1433 tmpR.parameter=(char **)Alloc (sizeof(char *));1444 tmpR.parameter=(char **)AllocSizeOf(char_ptr); 1434 1445 tmpR.P=1; 1435 1446 tmpR.parameter[0]=mstrdup(r2->parameter[0]); … … 1448 1459 tmpR.ch=rInternalChar(r1); 1449 1460 tmpR.P=rPar(r1); 1450 tmpR.parameter=(char **)Alloc0(rPar(r1)*sizeof(char *));1461 tmpR.parameter=(char **)Alloc0(rPar(r1)*sizeof(char_ptr)); 1451 1462 int i; 1452 1463 for(i=0;i<rPar(r1);i++) … … 1477 1488 tmpR.ch=rInternalChar(r2); 1478 1489 tmpR.P=rPar(r2); 1479 tmpR.parameter=(char **)Alloc(rPar(r2)*sizeof(char *));1490 tmpR.parameter=(char **)Alloc(rPar(r2)*sizeof(char_ptr)); 1480 1491 int i; 1481 1492 for(i=0;i<rPar(r2);i++) … … 1500 1511 int i,j,k; 1501 1512 int l=r1->N+r2->N; 1502 char **names=(char **)Alloc0(l*sizeof(char *));1513 char **names=(char **)Alloc0(l*sizeof(char_ptr)); 1503 1514 k=0; 1504 1515 … … 1590 1601 tmpR.block0=(int*)Alloc(3*sizeof(int)); 1591 1602 tmpR.block1=(int*)Alloc(3*sizeof(int)); 1592 tmpR.wvhdl=(int**)Alloc0(3*sizeof(int *));1603 tmpR.wvhdl=(int**)Alloc0(3*sizeof(int_ptr)); 1593 1604 tmpR.order[0]=ringorder_unspec; 1594 1605 tmpR.order[1]=ringorder_C; … … 1623 1634 tmpR.block0=(int*)Alloc0(b*sizeof(int)); 1624 1635 tmpR.block1=(int*)Alloc0(b*sizeof(int)); 1625 tmpR.wvhdl=(int**)Alloc0(b*sizeof(int *));1636 tmpR.wvhdl=(int**)Alloc0(b*sizeof(int_ptr)); 1626 1637 /* weights not implemented yet ...*/ 1627 1638 if (rb!=NULL) … … 1687 1698 tmpR.block0=(int*)Alloc0(b*sizeof(int)); 1688 1699 tmpR.block1=(int*)Alloc0(b*sizeof(int)); 1689 tmpR.wvhdl=(int**)Alloc0(b*sizeof(int *));1700 tmpR.wvhdl=(int**)Alloc0(b*sizeof(int_ptr)); 1690 1701 /* weights not implemented yet ...*/ 1691 1702 for (i=0;i<b;i++) … … 1706 1717 { 1707 1718 for(i=0;i<k;i++) FreeL((ADDRESS)tmpR.names[i]); 1708 Free((ADDRESS)names,tmpR.N*sizeof(char *));1719 Free((ADDRESS)names,tmpR.N*sizeof(char_ptr)); 1709 1720 Werror("difficulties with variables: %d,%d -> %d",r1->N,r2->N,k); 1710 1721 return -1; 1711 1722 } 1712 sum=(ring)Alloc (sizeof(ip_sring));1723 sum=(ring)AllocSizeOf(ip_sring); 1713 1724 memcpy(sum,&tmpR,sizeof(ip_sring)); 1714 1725 rComplete(sum); … … 1727 1738 int i,j; 1728 1739 int *pi; 1729 ring res=(ring)Alloc (sizeof(ip_sring));1740 ring res=(ring)AllocSizeOf(ip_sring); 1730 1741 1731 1742 memcpy4(res,r,sizeof(ip_sring)); … … 1735 1746 res->minpoly=nCopy(r->minpoly); 1736 1747 int l=rPar(r); 1737 res->parameter=(char **)Alloc(l*sizeof(char *));1748 res->parameter=(char **)Alloc(l*sizeof(char_ptr)); 1738 1749 int i; 1739 1750 for(i=0;i<rPar(r);i++) … … 1742 1753 } 1743 1754 } 1744 res->names = (char **)Alloc(r->N * sizeof(char *));1755 res->names = (char **)Alloc(r->N * sizeof(char_ptr)); 1745 1756 i=1; 1746 1757 pi=r->order; 1747 1758 while ((*pi)!=0) { i++;pi++; } 1748 res->wvhdl = (int **)Alloc(i * sizeof(int *));1759 res->wvhdl = (int **)Alloc(i * sizeof(int_ptr)); 1749 1760 res->order = (int *) Alloc(i * sizeof(int)); 1750 1761 res->block0 = (int *) Alloc(i * sizeof(int)); … … 1968 1979 mmTestP(r->block0,i*sizeof(int)); 1969 1980 mmTestP(r->block1,i*sizeof(int)); 1970 mmTestP(r->wvhdl,i*sizeof(int *));1981 mmTestP(r->wvhdl,i*sizeof(int_ptr)); 1971 1982 #endif 1972 1983 if (r->VarOffset == NULL) … … 2459 2470 r->ExpLSize=j/(sizeof(long)/sizeof(Exponent_t)); 2460 2471 r->mm_specHeap = mmGetSpecHeap(POLYSIZE + (r->ExpLSize)*sizeof(long)); 2472 assume(r->m_specHeap != NULL); 2461 2473 2462 2474 // ---------------------------- … … 2921 2933 r->ExpLSize=j/(sizeof(long)/sizeof(Exponent_t)); 2922 2934 r->mm_specHeap = mmGetSpecHeap(POLYSIZE + (r->ExpLSize)*sizeof(long)); 2923 if (r->mm_specHeap == NULL) 2924 { 2925 // monomial too large, clean up 2926 Free((ADDRESS)tmp_ordsgn,(2*(n+r->N)*sizeof(long))); 2927 Free((ADDRESS)tmp_typ,(2*(n+r->N)*sizeof(sro_ord))); 2928 Free((ADDRESS)v,(r->N+1)*sizeof(int)); 2929 return TRUE; 2930 } 2931 2935 assume(r->mm_specHeap != NULL); 2932 2936 2933 2937 // ---------------------------- … … 3024 3028 void rUnComplete(ring r) 3025 3029 { 3030 if (r->mm_specHeap != NULL) 3031 mmUnGetSpecHeap(&(r->mm_specHeap)); 3026 3032 Free((ADDRESS)r->VarOffset, (r->N +1)*sizeof(int)); 3027 3033 if (r->OrdSize!=0) … … 3044 3050 int i,j; 3045 3051 int *pi; 3046 ring res=(ring)Alloc (sizeof(ip_sring));3052 ring res=(ring)AllocSizeOf(ip_sring); 3047 3053 3048 3054 memcpy4(res,r,sizeof(ip_sring)); … … 3052 3058 res->minpoly=nCopy(r->minpoly); 3053 3059 int l=rPar(r); 3054 res->parameter=(char **)Alloc(l*sizeof(char *));3060 res->parameter=(char **)Alloc(l*sizeof(char_ptr)); 3055 3061 int i; 3056 3062 for(i=0;i<r->P;i++) … … 3059 3065 } 3060 3066 } 3061 res->names = (char **)Alloc(r->N * sizeof(char *));3067 res->names = (char **)Alloc(r->N * sizeof(char_ptr)); 3062 3068 i=1; // ringorder_C -> ringorder_S 3063 3069 pi=r->order; 3064 3070 while ((*pi)!=0) { i++;pi++; } 3065 res->wvhdl = (int **)Alloc(i * sizeof(int *));3071 res->wvhdl = (int **)Alloc(i * sizeof(int_ptr)); 3066 3072 res->order = (int *) Alloc(i * sizeof(int)); 3067 3073 res->block0 = (int *) Alloc(i * sizeof(int));
Note: See TracChangeset
for help on using the changeset viewer.