summaryrefslogtreecommitdiff
path: root/source4/lib/ejs/var.c
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2005-06-10 07:58:45 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:17:54 -0500
commita9258487043eb4862769ee8da02b3810db925295 (patch)
tree73c127469f8b162377ce695624b77b57b133d610 /source4/lib/ejs/var.c
parent302b4db004c51700dac7714d88ca27cdafe9612f (diff)
downloadsamba-a9258487043eb4862769ee8da02b3810db925295.tar.gz
samba-a9258487043eb4862769ee8da02b3810db925295.tar.bz2
samba-a9258487043eb4862769ee8da02b3810db925295.zip
r7456: Add a simple type that represents a pointer. The ejs people may ask us
to change this later but that will be pretty easy. We can use this type to pass around pointers to handles in C. Talloc allows us to do type checking too. (This used to be commit b95c0bc9b0a18aeaa89f704e37669f01df2c2ad0)
Diffstat (limited to 'source4/lib/ejs/var.c')
-rw-r--r--source4/lib/ejs/var.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/source4/lib/ejs/var.c b/source4/lib/ejs/var.c
index ce771caa04..6ef1c4d3a3 100644
--- a/source4/lib/ejs/var.c
+++ b/source4/lib/ejs/var.c
@@ -1182,6 +1182,21 @@ MprVar mprCreateStringCFunctionVar(MprStringCFunction fn, void *thisPtr, int fla
return v;
}
+/*
+ * Initialize an opaque pointer.
+ */
+
+MprVar mprCreatePtrVar(void *ptr, const char *name)
+{
+ MprVar v;
+
+ memset(&v, 0x0, sizeof(v));
+ v.type = MPR_TYPE_PTR;
+ v.ptr = ptr;
+
+ return v;
+}
+
/******************************************************************************/
#if BLD_FEATURE_FLOATING_POINT
/*
@@ -1398,6 +1413,10 @@ static void copyVarCore(MprVar *dest, MprVar *src, int copyDepth)
dest->cFunctionWithStrings = src->cFunctionWithStrings;
break;
+ case MPR_TYPE_PTR:
+ dest->ptr = src->ptr;
+ break;
+
case MPR_TYPE_CFUNCTION:
dest->cFunction = src->cFunction;
break;
@@ -1645,6 +1664,10 @@ void mprVarToString(char** out, int size, char *fmt, MprVar *obj)
mprAllocSprintf(out, size, "[C StringFunction]");
break;
+ case MPR_TYPE_PTR:
+ mprAllocSprintf(out, size, "[C Pointer: %p]", obj->ptr);
+ break;
+
case MPR_TYPE_FUNCTION:
mprAllocSprintf(out, size, "[JavaScript Function]");
break;
@@ -1779,6 +1802,9 @@ bool mprVarToBool(MprVar *vp)
case MPR_TYPE_OBJECT:
return 0;
+ case MPR_TYPE_PTR:
+ return (vp->ptr != NULL);
+
case MPR_TYPE_BOOL:
return vp->boolean;
@@ -1821,6 +1847,7 @@ double mprVarToFloat(MprVar *vp)
case MPR_TYPE_CFUNCTION:
case MPR_TYPE_FUNCTION:
case MPR_TYPE_OBJECT:
+ case MPR_TYPE_PTR:
return 0;
case MPR_TYPE_BOOL:
@@ -1896,6 +1923,7 @@ int64 mprVarToInteger64(MprVar *vp)
case MPR_TYPE_CFUNCTION:
case MPR_TYPE_FUNCTION:
case MPR_TYPE_OBJECT:
+ case MPR_TYPE_PTR:
return 0;
case MPR_TYPE_BOOL:
@@ -2010,6 +2038,7 @@ int mprVarToInteger(MprVar *vp)
case MPR_TYPE_CFUNCTION:
case MPR_TYPE_FUNCTION:
case MPR_TYPE_OBJECT:
+ case MPR_TYPE_PTR:
return 0;
case MPR_TYPE_BOOL: