summaryrefslogtreecommitdiffstats
path: root/generator.py
diff options
context:
space:
mode:
Diffstat (limited to 'generator.py')
-rwxr-xr-xgenerator.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/generator.py b/generator.py
index a98a894..ced7e41 100755
--- a/generator.py
+++ b/generator.py
@@ -259,8 +259,8 @@ py_types = {
'double': ('d', None, "double", "double"),
'unsigned int': ('i', None, "int", "int"),
'unsigned long': ('l', None, "long", "long"),
- 'long long': ('l', None, "longlong", "long long"),
- 'unsigned long long': ('l', None, "longlong", "long long"),
+ 'long long': ('L', None, "longlong", "long long"),
+ 'unsigned long long': ('L', None, "longlong", "long long"),
'unsigned char *': ('z', None, "charPtr", "char *"),
'char *': ('z', None, "charPtr", "char *"),
'const char *': ('z', None, "constcharPtr", "const char *"),
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
/* linkedlist.c
 * This file set implements a generic linked list object. It can be used
 * wherever a linke list is required.
 * 
 * NOTE: we do not currently provide a constructor and destructor for the
 * object itself as we assume it will always be part of another strucuture.
 * Having a pointer to it, I think, does not really make sense but costs
 * performance. Consequently, there is is llInit() and llDestroy() and they
 * do what a constructor and destructur do, except for creating the
 * linkedList_t structure itself.
 *
 * File begun on 2007-07-31 by RGerhards
 *
 * This file is part of rsyslog.
 *
 * Rsyslog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Rsyslog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Rsyslog.  If not, see <http://www.gnu.org/licenses/>.
 *
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
 */
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "rsyslog.h"
#include "linkedlist.h"


/* Initialize an existing linkedList_t structure
 * pKey destructor may be zero to take care of non-keyed lists.
 */
rsRetVal llInit(linkedList_t *pThis, rsRetVal (*pEltDestructor)(), rsRetVal (*pKeyDestructor)(void*), int (*pCmpOp)())
{
	assert(pThis != NULL);
	assert(pEltDestructor != NULL);

	pThis->pEltDestruct = pEltDestructor;
	pThis->pKeyDestruct = pKeyDestructor;
	pThis->cmpOp = pCmpOp;
	pThis->pKey = NULL;
	pThis->iNumElts = 0;
	pThis->pRoot = NULL;
	pThis->pLast = NULL;

	return RS_RET_OK;
};
	

/* llDestroyEltData - destroys a list element 
 * It is a separate function as the
 * functionality is needed in multiple code-pathes.
 */
static rsRetVal llDestroyElt(linkedList_t *pList, llElt_t *pElt)
{
	DEFiRet;

	assert(pList != NULL);
	assert(pElt != NULL);

	/* we ignore errors during destruction, as we need to try
	 * free the element in any case.
	 */
	if(pElt->pData != NULL)
		pList->pEltDestruct(pElt->pData);
	if(pElt->pKey != NULL)
		pList->pKeyDestruct(pElt->pKey);
	free(pElt);
	pList->iNumElts--; /* one less */

	RETiRet;
}


/* llDestroy - destroys a COMPLETE linkedList
 */
rsRetVal llDestroy(linkedList_t *pThis)
{
	DEFiRet;
	llElt_t *pElt;
	llElt_t *pEltPrev;

	assert(pThis != NULL);

	pElt = pThis->pRoot;
	while(pElt != NULL) {
		pEltPrev = pElt;
		pElt = pElt->pNext;
		/* we ignore errors during destruction, as we need to try
		 * finish the linked list in any case.
		 */
		llDestroyElt(pThis, pEltPrev);
	}
	/* now clean up the pointers */
	pThis->pRoot = NULL;
	pThis->pLast = NULL;

	RETiRet;
}

/* llDestroyRootElt - destroy the root element but otherwise
 * keeps this list intact.  -- rgerhards, 2007-08-03
 */
rsRetVal llDestroyRootElt(linkedList_t *pThis)
{
	DEFiRet;
	llElt_t *pPrev;
	
	if(pThis->pRoot == NULL) {
		ABORT_FINALIZE(RS_RET_EMPTY_LIST);
	}

	pPrev = pThis->pRoot;
	if(pPrev->pNext == NULL) {
		/* it was the only list element */
		pThis->pLast = NULL;
		pThis->pRoot = NULL;
	} else {
		/* there are other list elements */
		pThis->pRoot = pPrev->pNext;
	}

	CHKiRet(llDestroyElt(pThis, pPrev));

finalize_it:
	RETiRet;
}


/* get next user data element of a linked list. The caller must also
 * provide a "cookie" to the function. On initial call, it must be
 * NULL. Other than that, the caller is not allowed to to modify the
 * cookie. In the current implementation, the cookie is an actual
 * pointer to the current list element, but this is nothing that the
 * caller should rely on.
 */
rsRetVal llGetNextElt(linkedList_t *pThis, linkedListCookie_t *ppElt, void **ppUsr)
{
	llElt_t *pElt;
	DEFiRet;

	assert(pThis != NULL);
	assert(ppElt != NULL);
	assert(ppUsr != NULL);

	pElt = *ppElt;

	pElt = (pElt == NULL) ? pThis->pRoot : pElt->pNext;

	if(pElt == NULL) {
		iRet = RS_RET_END_OF_LINKEDLIST;
	} else {
		*ppUsr = pElt->pData;
	}

	*ppElt = pElt;

	RETiRet;
}


/* return the key of an Elt
 * rgerhards, 2007-09-11: note that ppDatea is actually a void**,
 * but I need to make it a void* to avoid lots of compiler warnings.
 * It will be converted later down in the code.
 */
rsRetVal llGetKey(llElt_t *pThis, void *ppData)
{
	assert(pThis != NULL);
	assert(ppData != NULL);

	*(void**) ppData = pThis->pKey;

	return RS_RET_OK;
}


/* construct a new llElt_t
 */
static rsRetVal llEltConstruct(llElt_t **ppThis, void *pKey, void *pData)
{
	DEFiRet;
	llElt_t *pThis;

	assert(ppThis != NULL);

	if((pThis = (llElt_t*) calloc(1, sizeof(llElt_t))) == NULL) {
		ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
	}

	pThis->pKey = pKey;
	pThis->pData = pData;

finalize_it:
	*ppThis = pThis;
	RETiRet;
}


/* append a user element to the end of the linked list. This includes setting a key. If no
 * key is desired, simply pass in a NULL pointer for it.
 */
rsRetVal llAppend(linkedList_t *pThis, void *pKey, void *pData)
{
	llElt_t *pElt;
	DEFiRet;
	
	CHKiRet(llEltConstruct(&pElt, pKey, pData));

	pThis->iNumElts++; /* one more */
	if(pThis->pLast == NULL) {
		pThis->pRoot = pElt;
	} else {
		pThis->pLast->pNext = pElt;
	}
	pThis->pLast = pElt;

finalize_it:
	RETiRet;
}


/* unlink a requested element. As we have singly-linked lists, the
 * caller also needs to pass in the previous element (or NULL, if it is the
 * root element).
 * rgerhards, 2007-11-21
 */
static rsRetVal llUnlinkElt(linkedList_t *pThis, llElt_t *pElt, llElt_t *pEltPrev)
{
	assert(pElt != NULL);

	if(pEltPrev == NULL) { /* root element? */
		pThis->pRoot = pElt->pNext;
	} else { /* regular element */
		pEltPrev->pNext = pElt->pNext;
	}

	if(pElt == pThis->pLast)
		pThis->pLast = pEltPrev;

	return RS_RET_OK;
}


/* unlinks and immediately deletes an element. Previous element must
 * be given (or zero if the root element is to be deleted).
 * rgerhards, 2007-11-21
 */
static rsRetVal llUnlinkAndDelteElt(linkedList_t *pThis, llElt_t *pElt, llElt_t *pEltPrev)
{
	DEFiRet;

	assert(pElt != NULL);

	CHKiRet(llUnlinkElt(pThis, pElt, pEltPrev));
	CHKiRet(llDestroyElt(pThis, pElt));

finalize_it:
	RETiRet;
}

/* find a user element based on the provided key - this is the
 * internal variant, which also tracks the last element pointer
 * before the found element. This is necessary to delete elements.
 * NULL means there is no element in front of it, aka the found elt
 * is the root elt.
 * rgerhards, 2007-11-21
 */
static rsRetVal llFindElt(linkedList_t *pThis, void *pKey, llElt_t **ppElt, llElt_t **ppEltPrev)
{
	DEFiRet;
	llElt_t *pElt;
	llElt_t *pEltPrev = NULL;
	int bFound = 0;

	assert(pThis != NULL);
	assert(pKey != NULL);
	assert(ppElt != NULL);
	assert(ppEltPrev != NULL);

	pElt = pThis->pRoot;