ARSperl
view release on metacpan or search on metacpan
*/
#define __support_c_
#include "support.h"
#include "supportrev.h"
#if defined(ARSPERL_UNDEF_MALLOC) && defined(malloc)
#undef malloc
#undef calloc
#undef realloc
#undef free
#endif
int
compmem(MEMCAST * m1, MEMCAST * m2, int size)
{
if (m1 && m2 && (size > 0)) {
#ifndef BSD
return memcmp(m1, m2, size) ? 1 : 0;
#else
return bcmp(m1, m2, size) ? 1 : 0;
#endif
}
return -1;
}
/* copy from m2 to m1 */
int
copymem(MEMCAST * m1, MEMCAST * m2, int size)
{
if (m1 && m2 && (size > 0)) {
#ifndef BSD
(void) memcpy(m1, m2, size);
#else
(void) bcopy(m2, m1, size);
#endif
return 0;
}
return -1;
}
/* malloc that will never return null */
void *
mallocnn(int s)
{
void *m = malloc(s ? s : 1);
if (!m)
croak("can't malloc");
memset(m, 0, s ? s : 1);
return m;
}
void *
debug_mallocnn(int s, char *file, char *func, int line)
{
printf("mallocnn(%d) called from %s::%s(), line %d\n", s,
file ? file : "UNKNOWN",
func ? func : "UNKNOWN",
line);
return mallocnn(s);
}
void
debug_free(void *p, char *file, char *func, int line)
{
printf("free(0x%X) called from %s::%s(), line %d\n", (unsigned long) p,
file ? file : "UNKNOWN",
func ? func : "UNKNOWN",
line);
free(p);
}
FILE *tmp__log_file_ptr = NULL;
FILE*
get_logging_file_ptr()
{
SV *file_ptr;
file_ptr = get_sv( "ARS::logging_file_ptr", FALSE );
if( file_ptr != NULL ){
return (FILE*) SvIV(file_ptr);
}else{
return NULL;
}
}
void
set_logging_file_ptr( FILE* ptr )
{
SV *file_ptr;
file_ptr = get_sv( "ARS::logging_file_ptr", TRUE );
sv_setiv( file_ptr, (long)ptr );
}
/* ROUTINE
* ARError_add(type, num, text)
* ARError_reset()
*
* DESCRIPTION
* err_hash is a hash with the following keys:
* {numItems}
* {messageType} (array reference)
* {messageNum} (array reference)
* {messageText} (array reference)
* each of the array refs have exactly {numItems} elements in
* them. one for each error in the list.
*
* _add will add a new error onto the error hash/array and will
* incremement numItems appropriately.
*
* _reset will reset the error hash to 0 elements and clear out
* old entries.
*
* RETURN
* 0 on success
* negative int on failure
*/
int
ARError_reset()
* we should remove all entries from the array and delete it as well.
*/
if (hv_exists(err_hash, EH_TYPE, strlen(EH_TYPE) ))
t2 = hv_delete(err_hash, EH_TYPE, strlen(EH_TYPE) , 0);
if (hv_exists(err_hash, EH_NUM, strlen(EH_NUM) ))
t2 = hv_delete(err_hash, EH_NUM, strlen(EH_NUM) , 0);
if (hv_exists(err_hash, EH_TEXT, strlen(EH_TEXT) ))
t2 = hv_delete(err_hash, EH_TEXT, strlen(EH_TEXT) , 0);
/* create numItems key, set to zero */
ni = newSViv(0);
if (!ni)
return -2;
t1 = hv_store(err_hash, EH_COUNT, strlen(EH_COUNT) , ni, 0);
if (!t1)
return -3;
/* create array refs (with empty arrays) */
t3 = newAV();
if (!t3)
return -4;
t1 = hv_store(err_hash, EH_TYPE, strlen(EH_TYPE) , newRV_noinc((SV *) t3), 0);
if (!t1 || !*t1)
return -5;
t3 = newAV();
if (!t3)
return -6;
t1 = hv_store(err_hash, EH_NUM, strlen(EH_NUM) , newRV_noinc((SV *) t3), 0);
if (!t1 || !*t1)
return -7;
t3 = newAV();
if (!t3)
return -8;
t1 = hv_store(err_hash, EH_TEXT, strlen(EH_TEXT) , newRV_noinc((SV *) t3), 0);
if (!t1 || !*t1)
return -9;
return 0;
}
int
ARError_add(int type, long num, char *text)
{
SV **numItems, **messageType, **messageNum, **messageText;
AV *a;
SV *t2;
HV *err_hash = (HV *) NULL;
unsigned int ni, ret = 0;
#ifdef ARSPERL_DEBUG
printf("ARError_add(%d, %d, %s)\n", type, num, text ? text : "NULL");
#endif
/* this is used to insert 'traceback' (debugging) messages into the
* error hash. these can be filtered out by modifying the FETCH clause
* of the ARSERRSTR package in ARS.pm
*/
switch (type) {
case ARSPERL_TRACEBACK:
case AR_RETURN_OK:
case AR_RETURN_WARNING:
ret = 0;
break;
case AR_RETURN_ERROR:
case AR_RETURN_FATAL:
ret = -1;
break;
default:
return -1;
}
if (!text || !*text)
return -2;
/*
* fetch base hash and numItems reference, it should already exist
* because you should call ARError_reset before using this routine.
* if you forgot.. no big deal.. we'll do it for you.
*/
err_hash = perl_get_hv(ERRHASH, FALSE);
if (!err_hash) {
ret = ARError_reset();
if (ret != 0)
return -3;
}
numItems = hv_fetch(err_hash, "numItems", strlen("numItems") , FALSE);
if (!numItems)
return -4;
messageType = hv_fetch(err_hash, "messageType", strlen("messageType") , FALSE);
if (!messageType)
return -5;
messageNum = hv_fetch(err_hash, "messageNum", strlen("messageNum") , FALSE);
if (!messageNum)
return -6;
messageText = hv_fetch(err_hash, "messageText", strlen("messageText") , FALSE);
if (!messageText)
return -7;
/*
* add the num, type and text to the appropriate arrays and then
* increase the counter by 1 (one).
*/
if (!SvIOK(*numItems))
return -8;
ni = (int) SvIV(*numItems) + 1;
(void) sv_setiv(*numItems, ni);
/* push type, num, and text onto each of the arrays */
if (!SvROK(*messageType) || (SvTYPE(SvRV(*messageType)) != SVt_PVAV))
return -9;
( run in 0.729 second using v1.01-cache-2.11-cpan-39bf76dae61 )