From: <mie...@us...> - 2009-07-14 17:06:31
|
Revision: 4917 http://oorexx.svn.sourceforge.net/oorexx/?rev=4917&view=rev Author: miesfeld Date: 2009-07-14 17:06:26 +0000 (Tue, 14 Jul 2009) Log Message: ----------- [2821033] Incompatible event semaphore function results Modified Paths: -------------- main/trunk/extensions/rexxutil/platform/unix/rexxutil.cpp main/trunk/extensions/rexxutil/platform/windows/rexxutil.cpp Modified: main/trunk/extensions/rexxutil/platform/unix/rexxutil.cpp =================================================================== --- main/trunk/extensions/rexxutil/platform/unix/rexxutil.cpp 2009-07-14 14:51:39 UTC (rev 4916) +++ main/trunk/extensions/rexxutil/platform/unix/rexxutil.cpp 2009-07-14 17:06:26 UTC (rev 4917) @@ -2354,7 +2354,7 @@ * '' - Empty string in case of any error * *************************************************************************/ -RexxRoutine2(uintptr_t, SysCreateEventSem, OPTIONAL_CSTRING, name, OPTIONAL_CSTRING, reset) +RexxRoutine2(RexxObjectPtr, SysCreateEventSem, OPTIONAL_CSTRING, name, OPTIONAL_CSTRING, reset) { RXSEMDATA *semdata; int rc; @@ -2362,7 +2362,7 @@ // Note that the reset arg has no meaning on Unix/Linux and is unused. semdata = (RXSEMDATA *)malloc(sizeof(RXSEMDATA)); if (semdata == NULL) { - return 0; + return context->String(""); } if (name == NULL) { /* this is an unnamed semaphore */ @@ -2370,7 +2370,7 @@ rc = sem_init(semdata->handle, 0, 0); if (rc == -1) { free(semdata); - return 0; + return context->String(""); } semdata->named = false; } @@ -2380,11 +2380,11 @@ semdata->handle = sem_open(name, (O_CREAT | O_EXCL), (S_IRWXU | S_IRWXG), 0); if (semdata->handle == SEM_FAILED ) { free(semdata); - return 0; + return context->String(""); } semdata->named = true; } - return (uintptr_t)semdata; + return context->Uintptr(semdata); } @@ -2558,14 +2558,14 @@ * '' - Empty string in case of any error * *************************************************************************/ -RexxRoutine1(uintptr_t, SysCreateMutexSem, OPTIONAL_CSTRING, name) +RexxRoutine1(RexxObjectPtr, SysCreateMutexSem, OPTIONAL_CSTRING, name) { RXSEMDATA *semdata; int rc; semdata = (RXSEMDATA *)malloc(sizeof(RXSEMDATA)); if (semdata == NULL) { - return 0; + return context->String(""); } if (strlen(name) == 0) { /* this is an unnamed semaphore */ @@ -2573,7 +2573,7 @@ rc = sem_init(semdata->handle, 0, 0); if (rc == -1) { free(semdata); - return 0; + return context->String(""); } semdata->named = false; } @@ -2583,12 +2583,12 @@ semdata->handle = sem_open(name, (O_CREAT | O_EXCL), (S_IRWXU | S_IRWXG), 0); if (semdata->handle == SEM_FAILED ) { free(semdata); - return 0; + return context->String(""); } semdata->named = true; } rc = sem_post(semdata->handle); - return (uintptr_t)semdata; + return context->Uintptr(semdata); } Modified: main/trunk/extensions/rexxutil/platform/windows/rexxutil.cpp =================================================================== --- main/trunk/extensions/rexxutil/platform/windows/rexxutil.cpp 2009-07-14 14:51:39 UTC (rev 4916) +++ main/trunk/extensions/rexxutil/platform/windows/rexxutil.cpp 2009-07-14 17:06:26 UTC (rev 4917) @@ -3746,28 +3746,36 @@ size_t RexxEntry SysCreateMutexSem(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr) { - HANDLE handle; /* mutex handle */ - SECURITY_ATTRIBUTES sa={sizeof(SECURITY_ATTRIBUTES), NULL, true}; + HANDLE handle = 0; + SECURITY_ATTRIBUTES sa={sizeof(SECURITY_ATTRIBUTES), NULL, true}; - handle = 0; /* zero the handle */ - if (numargs == 1) { /* request for named sem */ - /* create it by name */ - handle = CreateMutex(&sa, FALSE, args[0].strptr); - if (!handle) /* may already be created */ - /* try to open it */ - handle = OpenMutex(MUTEX_ALL_ACCESS, TRUE, args[0].strptr); - } - else /* unnamed semaphore */ - handle = CreateMutex(&sa, FALSE, NULL); - if (!handle) /* failed? */ - retstr->strlength = 0; /* return null string */ - else { - /* format the result */ - sprintf(retstr->strptr, "%p", handle); - /* set the length */ - retstr->strlength = strlen(retstr->strptr); - } - return VALID_ROUTINE; /* good completion */ + if ( numargs == 1 ) + { + // Request for a named semaphore + handle = CreateMutex(&sa, FALSE, args[0].strptr); + if ( handle == NULL ) + { + // It may have been already created, so open it by name. + handle = OpenMutex(MUTEX_ALL_ACCESS, TRUE, args[0].strptr); + } + } + else + { + // Request for an unamed semaphore. + handle = CreateMutex(&sa, FALSE, NULL); + } + + if ( handle == NULL ) + { + // Failed, return the empty string. + retstr->strlength = 0; + } + else + { + // Good handle, format it as a pointer string. + retstr->strlength = sprintf(retstr->strptr, "%p", handle); + } + return VALID_ROUTINE; /* good completion */ } /************************************************************************* @@ -3782,17 +3790,22 @@ size_t RexxEntry SysOpenMutexSem(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr) { - HANDLE handle; /* mutex handle */ - SECURITY_ATTRIBUTES sa={sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; + HANDLE handle; - if (numargs != 1) /* Only one argument accepted */ - return INVALID_ROUTINE; /* raise error condition */ + // One and only one argument accepted. + if (numargs != 1) + { + return INVALID_ROUTINE; + } - /* get a binary handle */ - /* try to open it */ handle = OpenMutex(MUTEX_ALL_ACCESS, TRUE, args[0].strptr); - wsprintf(retstr->strptr, "%p", handle); /* format the return code */ - retstr->strlength = strlen(retstr->strptr); + if ( handle == NULL ) + { + RETVAL(0) + } + + // Good handle, format it as a pointer string. + retstr->strlength = wsprintf(retstr->strptr, "%p", handle); return VALID_ROUTINE; /* good completion */ } @@ -3900,37 +3913,50 @@ size_t RexxEntry SysCreateEventSem(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr) { - HANDLE handle; /* mutex handle */ - SECURITY_ATTRIBUTES sa={sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; - bool manual; + HANDLE handle = 0; + SECURITY_ATTRIBUTES sa={sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; + bool manual; - handle = 0; /* zero the handle */ - if (numargs > 2) - return INVALID_ROUTINE; /* raise error condition */ - else if (numargs == 2) - manual = true; - else manual = false; + if ( numargs > 2 ) + { + return INVALID_ROUTINE; + } + else if ( numargs == 2 ) + { + manual = true; + } + else + { + manual = false; + } - if ((numargs >= 1) && args[0].strptr != 0 && (strlen(args[0].strptr) > 0)) - { /* request for named sem */ - /* create it by name */ - handle = CreateEvent(&sa, manual, FALSE, args[0].strptr); - if (!handle) /* may already be created */ - /* try to open it */ - handle = OpenEvent(EVENT_ALL_ACCESS, TRUE, args[0].strptr); - } - else /* unnamed semaphore */ - handle = CreateEvent(&sa, manual, FALSE, NULL); - if (!handle) /* failed? */ - retstr->strlength = 0; /* return null string */ - else - { - /* format the result */ - sprintf(retstr->strptr, "%p", handle); - /* set the length */ - retstr->strlength = strlen(retstr->strptr); - } - return VALID_ROUTINE; /* good completion */ + if ( (numargs >= 1) && args[0].strptr != 0 && (strlen(args[0].strptr) > 0) ) + { + // Request for a named semaphore. + handle = CreateEvent(&sa, manual, FALSE, args[0].strptr); + if ( handle == NULL ) + { + // It may already exist, so try to open it. + handle = OpenEvent(EVENT_ALL_ACCESS, TRUE, args[0].strptr); + } + } + else + { + // Request for unamed semaphore. + handle = CreateEvent(&sa, manual, FALSE, NULL); + } + + if ( handle == NULL ) + { + // Failed, return null string. + retstr->strlength = 0; + } + else + { + // Format the result as a pointer string. + retstr->strlength = sprintf(retstr->strptr, "%p", handle); + } + return VALID_ROUTINE; /* good completion */ } /************************************************************************* @@ -3945,16 +3971,23 @@ size_t RexxEntry SysOpenEventSem(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr) { - HANDLE handle; /* mutex handle */ - SECURITY_ATTRIBUTES sa={sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; + HANDLE handle; - if (numargs != 1) /* Only one argument accepted */ - return INVALID_ROUTINE; /* raise error condition */ - /* get a binary handle */ - handle = OpenEvent(EVENT_ALL_ACCESS, TRUE, args[0].strptr); /* try to open it */ - wsprintf(retstr->strptr, "%p", handle); /* format the return code */ - retstr->strlength = strlen(retstr->strptr); - return VALID_ROUTINE; /* good completion */ + /* Only one argument accepted */ + if (numargs != 1) + { + return INVALID_ROUTINE; + } + + handle = OpenEvent(EVENT_ALL_ACCESS, TRUE, args[0].strptr); + if ( handle == NULL ) + { + RETVAL(0) + } + + // Good handle, format it as pointer string. + retstr->strlength = wsprintf(retstr->strptr, "%p", handle); + return VALID_ROUTINE; } /************************************************************************* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |