diff options
author | Tim Potter <tpot@samba.org> | 2005-06-10 07:58:45 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:17:54 -0500 |
commit | a9258487043eb4862769ee8da02b3810db925295 (patch) | |
tree | 73c127469f8b162377ce695624b77b57b133d610 /source4/lib | |
parent | 302b4db004c51700dac7714d88ca27cdafe9612f (diff) | |
download | samba-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')
-rw-r--r-- | source4/lib/ejs/ejsParser.c | 1 | ||||
-rw-r--r-- | source4/lib/ejs/ejsProcs.c | 1 | ||||
-rw-r--r-- | source4/lib/ejs/var.c | 29 | ||||
-rw-r--r-- | source4/lib/ejs/var.h | 3 |
4 files changed, 34 insertions, 0 deletions
diff --git a/source4/lib/ejs/ejsParser.c b/source4/lib/ejs/ejsParser.c index 17fe0ce98a..8d0aa7ba2c 100644 --- a/source4/lib/ejs/ejsParser.c +++ b/source4/lib/ejs/ejsParser.c @@ -1659,6 +1659,7 @@ static int evalExpr(Ejs *ep, MprVar *lhs, int rel, MprVar *rhs) case MPR_TYPE_CFUNCTION: case MPR_TYPE_FUNCTION: case MPR_TYPE_OBJECT: + case MPR_TYPE_PTR: mprCopyVarValue(&ep->result, mprCreateBoolVar(0), 0); return 0; diff --git a/source4/lib/ejs/ejsProcs.c b/source4/lib/ejs/ejsProcs.c index b15985c8cf..e9932406ad 100644 --- a/source4/lib/ejs/ejsProcs.c +++ b/source4/lib/ejs/ejsProcs.c @@ -310,6 +310,7 @@ static int valueOfProc(EjsHandle eid, int argc, MprVar **argv) case MPR_TYPE_OBJECT: case MPR_TYPE_FUNCTION: case MPR_TYPE_STRING_CFUNCTION: + case MPR_TYPE_PTR: mprCopyVar(&ep->result, obj, MPR_SHALLOW_COPY); break; 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: diff --git a/source4/lib/ejs/var.h b/source4/lib/ejs/var.h index 3cb23cf461..c313e29544 100644 --- a/source4/lib/ejs/var.h +++ b/source4/lib/ejs/var.h @@ -92,6 +92,7 @@ typedef int MprType; #define MPR_TYPE_FUNCTION 8 /* JavaScript function */ #define MPR_TYPE_STRING 9 /* String (immutable) */ #define MPR_TYPE_STRING_CFUNCTION 10 /* C/C++ function with string args */ +#define MPR_TYPE_PTR 11 /* C pointer */ /* * Create a type for the default number type @@ -315,6 +316,7 @@ typedef struct MprVar { void *thisPtr; } cFunctionWithStrings; MprStr string; /* Allocated string */ + void *ptr; /* C pointer */ #if !BLD_DEBUG && !LINUX && !VXWORKS }; #endif @@ -351,6 +353,7 @@ extern MprVar mprCreateObjVar(const char *name, int hashSize); extern MprVar mprCreateBoolVar(bool value); extern MprVar mprCreateCFunctionVar(MprCFunction fn, void *thisPtr, int flags); +extern MprVar mprCreatePtrVar(void *ptr, const char *name); #if BLD_FEATURE_FLOATING_POINT extern MprVar mprCreateFloatVar(double value); #endif |