richter 00/07/05 23:18:00
Modified: . Tag: Embperl2 epdom.c epdom.h epparse.c test.pl
Log:
Embperl 2 - Memory Management
Revision Changes Path
No revision
No revision
1.1.2.48 +92 -18 embperl/Attic/epdom.c
Index: epdom.c
===================================================================
RCS file: /home/cvs/embperl/Attic/epdom.c,v
retrieving revision 1.1.2.47
retrieving revision 1.1.2.48
diff -u -r1.1.2.47 -r1.1.2.48
--- epdom.c 2000/07/05 11:50:41 1.1.2.47
+++ epdom.c 2000/07/06 06:17:37 1.1.2.48
@@ -363,8 +363,9 @@
/* ------------------------------------------------------------------------ */
-tStringIndex String2Ndx (/*in*/ const char * sText,
- /*in*/ int nLen)
+tStringIndex String2NdxInc (/*in*/ const char * sText,
+ /*in*/ int nLen,
+ /*in*/ int bInc)
{
SV * * ppSV ;
@@ -383,7 +384,11 @@
/*lprintf (pCurrReq, "String2Ndx type=%d iok=%d flg=%x\n",
*ppSV?SvTYPE(*ppSV):-1, SvIOK (*ppSV), SvFLAGS(*ppSV)) ;*/
if (*ppSV != NULL && SvIOKp (*ppSV)) /* use SvIOKp to avoid problems with
tainting */
+ {
+ if (bInc)
+ SvREFCNT_inc (*ppSV) ;
return SvIVX (*ppSV) ;
+ }
}
@@ -394,9 +399,11 @@
pSVNdx = newSViv (nNdx) ;
SvTAINTED_off (pSVNdx) ;
- SvREFCNT_inc (pSVNdx) ;
+ if (bInc)
+ SvREFCNT_inc (pSVNdx) ;
pSVKey = newSVpv (nLen?(char *)sText:"", nLen) ;
pHEKey = hv_store_ent (pStringTableHash, pSVKey, pSVNdx, 0) ;
+ SvREFCNT_dec (pSVKey) ;
pStringTableArray[nNdx] = pHEKey ;
@@ -405,7 +412,34 @@
return nNdx ;
}
+/* ------------------------------------------------------------------------ */
+/* */
+/* NdxStringFree */
+/* */
+/* Free one reference to a string */
+/* */
+/* ------------------------------------------------------------------------ */
+
+void NdxStringFree (/*in*/ tStringIndex nNdx)
+
+ {
+ HE * pHE = pStringTableArray[nNdx] ;
+ SV * pSVNdx = HeVAL (pHE) ;
+
+ SvREFCNT_dec (pSVNdx) ;
+
+ if (SvREFCNT(pSVNdx) == 1)
+ {
+ lprintf (pCurrReq, "delete string %s (#%d)\n", Ndx2String (nNdx), nNdx) ;
+ hv_delete (pStringTableHash, HeKEY (pHE), HeKLEN(pHE), 0) ;
+ pStringTableArray[nNdx] = NULL ;
+
+ numStr-- ;
+ }
+ }
+
+
/* ------------------------------------------------------------------------ */
/* */
/* DomInit */
@@ -566,18 +600,23 @@
while (pNode)
{
- /* is it really save to leave out attr here????
- int n = pNewNode -> numAttr ;
- tAttrData * pAttr = Node_selfFirstAttr(pNewNode) ;
+ int n = pNode -> numAttr ;
+ tAttrData * pAttr = Node_selfFirstAttr(pNode) ;
while (n--)
{
pDomTree -> pLookup[pAttr -> xNdx] = NULL ;
+ if (pAttr -> xName)
+ NdxStringFree (pAttr -> xName) ;
+ if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
+ NdxStringFree (pAttr -> xValue) ;
pAttr++ ;
}
- */
lprintf (pCurrReq, "delete typ=%d Node xNdx=%d\n", pNode -> nType,
pNode -> xNdx) ;
pDomTree -> pLookup[pNode -> xNdx] = NULL ;
+ if (pNode -> nText)
+ NdxStringFree (pNode -> nText) ;
+
nOffset = sizeof (struct tNodeData) + sizeof (struct tAttrData) *
pNode -> numAttr ;
if (pPad -> nFill <= pNode -> nPadOffset + nOffset)
break ;
@@ -669,8 +708,10 @@
if (pDocument -> nType == ntypDocumentFraq)
{
+ tAttrData * pAttr;
pDocument = Node_selfCloneNode (pDomTree, pDocument, 1) ;
- Element_selfSetAttribut (pDomTree, pDocument, NULL, xDomTreeAttr, NULL,
pDomTree -> xNdx, 0) ;
+ pAttr = Element_selfSetAttribut (pDomTree, pDocument, NULL, xDomTreeAttr,
NULL, pDomTree -> xNdx, 0) ;
+ pAttr -> bFlags = aflgOK ; /* reset string value flag */
pDomTree -> xDocument = pDocument -> xNdx ;
}
@@ -1070,9 +1111,15 @@
int n = pNewNode -> numAttr ;
tAttrData * pAttr = Node_selfFirstAttr(pNewNode) ;
+ if (pNewNode -> nText)
+ NdxStringRefcntInc (pNewNode -> nText) ;
while (n--)
{
pLookup[pAttr -> xNdx] = pAttr ;
+ if (pAttr -> xName)
+ NdxStringRefcntInc (pAttr -> xName) ;
+ if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
+ NdxStringRefcntInc (pAttr -> xValue) ;
pAttr++ ;
}
@@ -1164,7 +1211,8 @@
xNdx = ArrayAdd (&pDomTree -> pLookup, 1) ;
pDomTree -> pLookup[xNdx] = (struct tNodeData *)pNew ;
- pNew -> xName = sText?String2Ndx (sText, nTextLen):nTextLen ;
+ pNew -> xName = sText?String2NdxNoInc (sText, nTextLen):nTextLen ;
+ NdxStringRefcntInc (pNew -> xName) ;
pNew -> xValue = 0 ;
pNew -> bFlags = aflgOK ;
pNew -> nType = nType ;
@@ -1176,7 +1224,7 @@
if (pCurrReq -> bDebug & dbgParse)
lprintf (pCurrReq, "[%d]PARSE: AddNode: +%02d %*s Attribut parent=%d
node=%d type=%d text=%*.*s (#%d)\n",
- pCurrReq -> nPid, nLevel, nLevel * 2, "",
xParent, xNdx, nType, nTextLen, nTextLen, sText?sText:Ndx2String (nTextLen),
sText?String2Ndx (sText, nTextLen):nTextLen) ;
+ pCurrReq -> nPid, nLevel, nLevel * 2, "",
xParent, xNdx, nType, nTextLen, nTextLen, sText?sText:Ndx2String (nTextLen),
sText?String2NdxNoInc (sText, nTextLen):nTextLen) ;
return xNdx ;
}
@@ -1221,9 +1269,10 @@
if (!bAddChild && !bForceAttrValue)
{
- pNew -> xValue = sText?String2Ndx (sText, nTextLen):nTextLen ;
+ pNew -> xValue = sText?String2NdxNoInc (sText, nTextLen):nTextLen ;
+ NdxStringRefcntInc (pNew -> xValue) ;
if (pCurrReq -> bDebug & dbgParse)
- lprintf (pCurrReq, "[%d]PARSE: AddNode: +%02d %*s AttributValue
parent=%d node=%d type=%d text=%*.*s (#%d)\n", pCurrReq -> nPid, nLevel, nLevel * 2,
"", xParent, pNew -> xNdx, nType, nTextLen, nTextLen, sText, sText?String2Ndx (sText,
+ lprintf (pCurrReq, "[%d]PARSE: AddNode: +%02d %*s AttributValue
parent=%d node=%d type=%d text=%*.*s (#%d)\n", pCurrReq -> nPid, nLevel, nLevel * 2,
"", xParent, pNew -> xNdx, nType, nTextLen, nTextLen, sText, sText?String2NdxNoInc
(sText,
nTextLen):-1) ;
pNew -> bFlags |= aflgAttrValue ;
@@ -1279,8 +1328,8 @@
pNew = NodePad_appendChild (pDomTree, &pChilds, nType, String2Ndx (sText,
nTextLen), nLinenumber) ;
if (pCurrReq -> bDebug & dbgParse)
- lprintf (pCurrReq, "[%d]PARSE: AddNode: +%02d %*s Element parent=%d
node=%d type=%d text=%*.*s (#%d)\n", pCurrReq -> nPid, nLevel, nLevel * 2, "",
xParent, pNew -> xNdx, nType, nTextLen, nTextLen, sText, sText?String2Ndx (sText,
nTextLen)
-:-1) ;
+ lprintf (pCurrReq, "[%d]PARSE: AddNode: +%02d %*s Element parent=%d
node=%d type=%d text=%*.*s (#%d)\n", pCurrReq -> nPid, nLevel, nLevel * 2, "",
xParent, pNew -> xNdx, nType, nTextLen, nTextLen, sText,
+
sText?String2NdxNoInc (sText, nTextLen):-1) ;
return pNew -> xNdx ;
}
@@ -1373,6 +1422,8 @@
pDomTree -> pLookup[xNewNode] = pNew ;
pNew -> xNdx = xNewNode ;
pNew -> nPadOffset = pPad -> nFill ;
+ if (pNew -> nText)
+ NdxStringRefcntInc (pNew -> nText) ;
pPad -> numChilds++ ;
pPad -> nFill += len ;
@@ -1390,6 +1441,10 @@
xNewNode = ArrayAdd (&pDomTree -> pLookup, 1) ;
pDomTree -> pLookup[xNewNode] = pAttr ;
pAttr -> xNdx = xNewNode ;
+ if (pAttr -> xName)
+ NdxStringRefcntInc (pAttr -> xName) ;
+ if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
+ NdxStringRefcntInc (pAttr -> xValue) ;
n-- ;
pAttr++ ;
}
@@ -1490,6 +1545,10 @@
while (n > 0)
{
pAttr -> bFlags = nflgDeleted ;
+ if (pAttr -> xName)
+ NdxStringFree (pAttr -> xName) ;
+ if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
+ NdxStringFree (pAttr -> xValue) ;
n-- ;
pAttr++ ;
}
@@ -1497,8 +1556,10 @@
}
if (pOldChild -> nType == ntypDocumentFraq)
- Element_selfSetAttribut (pOldChildDomTree, pOldChild, NULL, xDomTreeAttr,
NULL, pDomTree -> xNdx, 0) ;
-
+ {
+ tAttrData * pAttr = Element_selfSetAttribut (pOldChildDomTree, pOldChild,
NULL, xDomTreeAttr, NULL, pDomTree -> xNdx, 0) ;
+ pAttr -> bFlags = aflgOK ; /* reset string value flag */
+ }
DomTree_selfCheckpoint (pOldChildDomTree, xOrgChild, xOldChild) ;
@@ -1557,6 +1618,8 @@
else
pOldChild -> nType = ntypCDATA ;
+ if (pOldChild -> nText)
+ NdxStringFree (pOldChild -> nText) ;
pOldChild -> nText = String2Ndx(sText, nTextLen) ;
pOldChild -> xChilds = 0 ;
pOldChild -> bFlags |= bFlags ;
@@ -2142,7 +2205,7 @@
/*in*/ int nAttrNameLen)
{
- int nAttrName = sAttrName?String2Ndx (sAttrName, nAttrNameLen):nAttrNameLen ;
+ int nAttrName = sAttrName?String2NdxNoInc (sAttrName,
nAttrNameLen):nAttrNameLen ;
struct tAttrData * pAttr = (struct tAttrData * )(pNode + 1) ;
int n = pNode -> numAttr ;
@@ -2216,7 +2279,8 @@
if (pAttr)
{
- tIndex xValue = sNewValue?String2Ndx (sNewValue, nNewValueLen):nNewValueLen ;
+ tIndex xValue = sNewValue?String2NdxNoInc (sNewValue,
nNewValueLen):nNewValueLen ;
+ NdxStringRefcntInc (xValue) ;
if (bClone)
{
@@ -2233,6 +2297,9 @@
pNode -> bFlags |= nflgReturn | nflgModified ;
}
+ if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
+ NdxStringFree (pAttr -> xValue) ;
+
pAttr -> xValue = xValue ;
return pAttr ;
}
@@ -2298,7 +2365,14 @@
}
if (pAttr)
+ {
pAttr -> bFlags = 0 ;
+ if (pAttr -> xName)
+ NdxStringFree (pAttr -> xName) ;
+ if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
+ NdxStringFree (pAttr -> xValue) ;
+ }
+
/*
int nCopyAttr ;
1.1.2.31 +8 -2 embperl/Attic/epdom.h
Index: epdom.h
===================================================================
RCS file: /home/cvs/embperl/Attic/epdom.h,v
retrieving revision 1.1.2.30
retrieving revision 1.1.2.31
diff -u -r1.1.2.30 -r1.1.2.31
--- epdom.h 2000/07/04 21:37:31 1.1.2.30
+++ epdom.h 2000/07/06 06:17:40 1.1.2.31
@@ -184,14 +184,20 @@
extern tIndex xCheckpointCache[] ;
-tStringIndex String2Ndx (/*in*/ const char * sText,
- /*in*/ int nLen) ;
+tStringIndex String2NdxInc (/*in*/ const char * sText,
+ /*in*/ int nLen,
+ /*in*/ int bInc) ;
#define SV2String(pSV,l) (SvOK (pSV)?SvPV (pSV, l):(l=0,NULL))
+#define String2NdxNoInc(sText,nLen) String2NdxInc(sText,nLen,0)
+#define String2Ndx(sText,nLen) String2NdxInc(sText,nLen,1)
+
#define Ndx2String(nNdx) (HeKEY (pStringTableArray[nNdx]))
#define Ndx2StringLen(nNdx,sVal,nLen) { HE * pHE = pStringTableArray[nNdx] ;
nLen=HeKLEN(pHE) ; sVal = HeKEY (pHE) ; }
+
+#define NdxStringRefcntInc(nNdx) (SvREFCNT_inc (HeVAL (pStringTableArray[nNdx])))
int ArrayNew (/*in*/ const tArray * pArray,
1.1.2.29 +1 -1 embperl/Attic/epparse.c
Index: epparse.c
===================================================================
RCS file: /home/cvs/embperl/Attic/epparse.c,v
retrieving revision 1.1.2.28
retrieving revision 1.1.2.29
diff -u -r1.1.2.28 -r1.1.2.29
--- epparse.c 2000/07/04 21:37:34 1.1.2.28
+++ epparse.c 2000/07/06 06:17:41 1.1.2.29
@@ -302,7 +302,7 @@
p -> sNodeName = GetHashValueStrDup (pHash, "nodename", NULL) ;
p -> nNodeType = GetHashValueInt (pHash, "nodetype", ntypTag) ;
p -> bUnescape = GetHashValueInt (pHash, "unescape", 0) ;
- p -> nCDataType = GetHashValueInt (pHash, "cdatatype", -1) ;
+ p -> nCDataType = GetHashValueInt (pHash, "cdatatype", ntypCDATA) ;
p -> nForceType = GetHashValueInt (pHash, "forcetype", 0) ;
p -> pStartTag = (struct tToken *)GetHashValueStrDup (pHash, "starttag",
NULL) ;
p -> pEndTag = (struct tToken *)GetHashValueStrDup (pHash, "endtag",
NULL) ;
1.57.2.35 +2 -0 embperl/test.pl
Index: test.pl
===================================================================
RCS file: /home/cvs/embperl/test.pl,v
retrieving revision 1.57.2.34
retrieving revision 1.57.2.35
diff -u -r1.57.2.34 -r1.57.2.35
--- test.pl 2000/07/05 11:50:45 1.57.2.34
+++ test.pl 2000/07/06 06:17:42 1.57.2.35
@@ -480,6 +480,8 @@
my @status ;
+ return 0 if ($EPWIN32) ;
+
open FH, "/proc/$pid/status" or die "Cannot open /proc/$pid/status" ;
@status = <FH> ;
close FH ;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]