Skip to content

Commit

Permalink
Update to version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HubTou authored Nov 11, 2022
1 parent e20018b commit f909042
Show file tree
Hide file tree
Showing 23 changed files with 859 additions and 124 deletions.
21 changes: 19 additions & 2 deletions pylists4c.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ typedef enum
{
ETYPE_UNDEFINED = -1,
// Empty elements:
ETYPE_NULL = 0, // Not implemented
ETYPE_NULL = 0,
ETYPE_CHAR = 1,
ETYPE_U_CHAR = 2,
ETYPE_SHORT = 3,
Expand Down Expand Up @@ -475,7 +475,24 @@ extern IMPORT void listSetFatalMallocErrors(BOOLEAN fatal);
extern IMPORT unsigned long listGetAllocatedMemory();

// Convenience type-oriented aliases:
// NB: values are not passed by address
// NB: values below are NOT passed by address
extern IMPORT STATUS listAppendNull(LIST** ppList);
#define listPushNull listAppendNull
#define listEnqueueNull listAppendNull
extern IMPORT STATUS listInsertFirstNull(LIST** ppList);
#define listPrependNull listInsertFirstNull
extern IMPORT STATUS listInsertNull(LIST** ppList, long n);
extern IMPORT STATUS listInsertSortedNull(LIST** ppList, BOOLEAN reversed, BOOLEAN caseInsensitive, BOOLEAN noDuplicates);
extern IMPORT STATUS listChangeNull(LIST* pList, long n);
extern IMPORT BOOLEAN listContainsNull(LIST* pList);
extern IMPORT long listCountNull(LIST* pList);
extern IMPORT long listIndexNull(LIST* pList);
extern IMPORT LIST* listIndexAllNull(LIST* pList);
#define listFindNull listIndexAllNull
#define listSearchNull listIndexAllNull
extern IMPORT void listRemoveNull(LIST** ppList);
extern IMPORT void listRemoveAllNull(LIST** ppList);

extern IMPORT STATUS listAppendChar(LIST** ppList, char value);
#define listPushChar listAppendChar
#define listEnqueueChar listAppendChar
Expand Down
3 changes: 2 additions & 1 deletion src/MakeWin.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ SET CFLAGS=-O3 -Wall -Wextra -pipe -I..
%CC% %CFLAGS% -c str.c -o str.o
%CC% %CFLAGS% -c toArray.c -o toArray.o
%CC% %CFLAGS% -c value.c -o value.o
%CC% %CFLAGS% -c types/Null.c -o types/Null.o
%CC% %CFLAGS% -c types/Char.c -o types/Char.o
%CC% %CFLAGS% -c types/UChar.c -o types/UChar.o
%CC% %CFLAGS% -c types/Short.c -o types/Short.o
Expand All @@ -110,7 +111,7 @@ SET CFLAGS=-O3 -Wall -Wextra -pipe -I..
@ECHO.
@ECHO.
@ECHO Building the Dynamic Link Library:
%CC% --shared append.o areEqual.o change.o changeSlice.o clear.o compareValues.o comprehension.o concat.o contains.o copy.o count.o createElement.o debug.o del.o delSlice.o extend.o filter.o fromArray.o get.o getAllocatedMemory.o getLast.o index.o indexAll.o insert.o insertFirst.o insertList.o insertSorted.o iterator.o join.o len.o list.o pop.o print.o remove.o removeAll.o removeDuplicates.o reverse.o reversed.o setDebugMessagesDisplay.o setFatalMallocErrors.o shuffle.o shuffled.o slice.o sort.o sorted.o sortedByInsertion.o sortedByQsort.o split.o stats.o statsPrint.o str.o toArray.o value.o types/Char.o types/UChar.o types/Short.o types/UShort.o types/Int.o types/UInt.o types/Long.o types/ULong.o types/LongLong.o types/ULongLong.o types/Float.o types/Double.o types/LongDouble.o types/String.o types/Struct.o -o ../pylists4c.dll >nul
%CC% --shared append.o areEqual.o change.o changeSlice.o clear.o compareValues.o comprehension.o concat.o contains.o copy.o count.o createElement.o debug.o del.o delSlice.o extend.o filter.o fromArray.o get.o getAllocatedMemory.o getLast.o index.o indexAll.o insert.o insertFirst.o insertList.o insertSorted.o iterator.o join.o len.o list.o pop.o print.o remove.o removeAll.o removeDuplicates.o reverse.o reversed.o setDebugMessagesDisplay.o setFatalMallocErrors.o shuffle.o shuffled.o slice.o sort.o sorted.o sortedByInsertion.o sortedByQsort.o split.o stats.o statsPrint.o str.o toArray.o value.o types/Null.o types/Char.o types/UChar.o types/Short.o types/UShort.o types/Int.o types/UInt.o types/Long.o types/ULong.o types/LongLong.o types/ULongLong.o types/Float.o types/Double.o types/LongDouble.o types/String.o types/Struct.o -o ../pylists4c.dll >nul
@ECHO.
@dir ..\pylists4c.*
@ECHO.
Expand Down
12 changes: 6 additions & 6 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
LIBRARY=pylists4c

MAJOR_VERSION=1
MINOR_VERSION=0
PATCH_VERSION=1
MINOR_VERSION=1
PATCH_VERSION=0

LIB=lib$(LIBRARY).a
SOLIB=lib$(LIBRARY).so

OBJECTS= \
append.o areEqual.o change.o changeSlice.o clear.o compareValues.o \
comprehension.o concat.o contains.o copy.o count.o createElement.o debug.o \
del.o delSlice.o extend.o filter.o fromArray.o get.o getAllocatedMemory.o \
del.o delSlice.o extend.o filter.o fromArray.o get.o getAllocatedMemory.o \
getLast.o index.o indexAll.o insert.o insertFirst.o insertList.o \
insertSorted.o iterator.o join.o len.o list.o pop.o print.o remove.o \
removeAll.o removeDuplicates.o reverse.o reversed.o \
setDebugMessagesDisplay.o setFatalMallocErrors.o shuffle.o shuffled.o \
slice.o sort.o sorted.o sortedByInsertion.o sortedByQsort.o split.o \
stats.o statsPrint.o str.o toArray.o value.o types/Char.o types/UChar.o \
types/Short.o types/UShort.o types/Int.o types/UInt.o types/Long.o \
types/ULong.o types/LongLong.o types/ULongLong.o types/Float.o \
stats.o statsPrint.o str.o toArray.o value.o types/Null.o types/Char.o \
types/UChar.o types/Short.o types/UShort.o types/Int.o types/UInt.o \
types/Long.o types/ULong.o types/LongLong.o types/ULongLong.o types/Float.o \
types/Double.o types/LongDouble.o types/String.o types/Struct.o
CFLAGS=-O3 -fPIC -Wall -Wextra -pipe -I.. # --std c99 is a minimum requirement
LOCALDIR=/usr/local
Expand Down
3 changes: 3 additions & 0 deletions src/areEqual.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ EXPORT BOOLEAN listAreEqual(LIST* pList1, LIST* pList2, BOOLEAN caseInsensitive)
if (pList1 -> type != pList2 -> type)
return FALSE;

if (pList1 -> type == ETYPE_NULL)
return TRUE;

if (pList1 -> type == ETYPE_STRING || pList1 -> type == ETYPE_STRUCT)
{
if (pList1 -> size != pList2 -> size)
Expand Down
8 changes: 4 additions & 4 deletions src/change.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
EXPORT STATUS listChange(LIST* pList, long n, void* pValue, ETYPE type, size_t size)
{
LIST* pElement = listGet(pList, n);
void* newValue;
void* newValue = NULL;

if (pElement == NULL)
return FAILURE;

// Allocate new space
if ((newValue = malloc(size)) == NULL)
if (size && (newValue = malloc(size)) == NULL)
{
if (listFatalMallocErrors)
{
Expand All @@ -47,7 +47,7 @@ EXPORT STATUS listChange(LIST* pList, long n, void* pValue, ETYPE type, size_t s
// Free the previous value
if (pElement -> type == ETYPE_LIST)
listClear((LIST **) &(pElement -> pValue));
else
else if (pElement -> type != ETYPE_NULL)
free(pElement -> pValue);

listAllocatedMemory -= pElement -> size;
Expand All @@ -69,7 +69,7 @@ EXPORT STATUS listChange(LIST* pList, long n, void* pValue, ETYPE type, size_t s
#endif
}
}
else
else if (size)
memset(newValue, 0, size);

// Modify the element
Expand Down
2 changes: 2 additions & 0 deletions src/contains.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ EXPORT BOOLEAN listContains(LIST* pList, void* pValue, ETYPE type, size_t size)
if (pElement -> size == size && ! memcmp(pElement -> pValue, pValue, size))
return TRUE;
}
else if (type == ETYPE_NULL)
return TRUE;
else if (! memcmp(pElement -> pValue, pValue, size))
return TRUE;
}
Expand Down
2 changes: 2 additions & 0 deletions src/count.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ EXPORT long listCount(LIST* pList, void* pValue, ETYPE type, size_t size)
if (listAreEqual(pElement -> pValue, pValue, FALSE))
count++;
}
else if (type == ETYPE_NULL)
count++;
else if (! memcmp(pElement -> pValue, pValue, size))
count++;
}
Expand Down
6 changes: 4 additions & 2 deletions src/createElement.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ EXPORT LIST* listCreateElement(void* pValue, ETYPE type, size_t size)
}
}

if ((pElement -> pValue = malloc(size)) == NULL)
if (size && (pElement -> pValue = malloc(size)) == NULL)
{
free(pElement);
if (listFatalMallocErrors)
Expand Down Expand Up @@ -70,8 +70,10 @@ EXPORT LIST* listCreateElement(void* pValue, ETYPE type, size_t size)
#endif
}
}
else
else if (size)
memset(pElement -> pValue, 0, size);
else
pElement -> pValue = NULL;
pElement -> size = size;
pElement -> type = type;
pElement -> pPrevious = NULL;
Expand Down
26 changes: 21 additions & 5 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,24 @@ EXPORT void listDebug(LIST* pList, STRING name)
switch (pElement -> type)
{
case ETYPE_NULL: fprintf(stderr, "(NULL, "); break;
case ETYPE_CHAR: fprintf(stderr, "%c (%s, ", *((char*) pElement -> pValue), "char"); break;
case ETYPE_U_CHAR: fprintf(stderr, "%c (%s, ", *((unsigned char*) pElement -> pValue), "unsigned char"); break;
case ETYPE_CHAR:
if (*((char*) pElement -> pValue) < 0)
fprintf(stderr, "%d (%s, ", (int) *((char*) pElement -> pValue), "char");
else if (*((char*) pElement -> pValue) == 127)
fprintf(stderr, "127 (%s, ", "char");
else if (*((char*) pElement -> pValue) < ' ')
fprintf(stderr, "%d or '^%c' (%s, ", (int) *((char*) pElement -> pValue), *((char*) pElement -> pValue) + '@', "char");
else
fprintf(stderr, "%d or '%c' (%s, ", (int) *((char*) pElement -> pValue), *((char*) pElement -> pValue), "char");
break;
case ETYPE_U_CHAR:
if (*((unsigned char*) pElement -> pValue) < ' ')
fprintf(stderr, "%d or '^%c' (%s, ", (int) *((unsigned char*) pElement -> pValue), *((unsigned char*) pElement -> pValue) + '@', "unsigned char");
else if (*((unsigned char*) pElement -> pValue) == 127)
fprintf(stderr, "127 (%s, ", "unsigned char");
else
fprintf(stderr, "%d or '%c' (%s, ", (int) *((unsigned char*) pElement -> pValue), *((unsigned char*) pElement -> pValue), "unsigned char");
break;
case ETYPE_SHORT: fprintf(stderr, "%hd (%s, ", *((short*) pElement -> pValue), "short"); break;
case ETYPE_U_SHORT: fprintf(stderr, "%hu (%s, ", *((unsigned short*) pElement -> pValue), "unsigned short"); break;
case ETYPE_INT: fprintf(stderr, "%d (%s, ", *((int*) pElement -> pValue), "int"); break;
Expand All @@ -43,9 +59,9 @@ EXPORT void listDebug(LIST* pList, STRING name)
case ETYPE_U_LONG: fprintf(stderr, "%lu (%s, ", *((unsigned long*) pElement -> pValue), "unsigned long"); break;
case ETYPE_LONG_LONG: fprintf(stderr, "%lld (%s, ", *((long long*) pElement -> pValue), "long long"); break;
case ETYPE_U_LONG_LONG: fprintf(stderr, "%llu (%s, ", *((unsigned long long*) pElement -> pValue), "unsigned long long"); break;
case ETYPE_FLOAT: fprintf(stderr, "%f (%s, ", *((float*) pElement -> pValue), "float"); break;
case ETYPE_DOUBLE: fprintf(stderr, "%lf (%s, ", *((double*) pElement -> pValue), "double"); break;
case ETYPE_LONG_DOUBLE: fprintf(stderr, "%Lf (%s, ", *((long double*) pElement -> pValue), "long double"); break;
case ETYPE_FLOAT: fprintf(stderr, "%g (%s, ", *((float*) pElement -> pValue), "float"); break;
case ETYPE_DOUBLE: fprintf(stderr, "%lg (%s, ", *((double*) pElement -> pValue), "double"); break;
case ETYPE_LONG_DOUBLE: fprintf(stderr, "%Lg (%s, ", *((long double*) pElement -> pValue), "long double"); break;
case ETYPE_STRING:
fprintf(stderr, "'");
for (pCharacter = (char*) pElement -> pValue; *pCharacter != 0; pCharacter++)
Expand Down
2 changes: 1 addition & 1 deletion src/del.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ EXPORT void listDelNth(LIST** ppList, long n)

if (pNthElement -> type == ETYPE_LIST)
listClear((LIST **) &(pNthElement -> pValue));
else
else if (pNthElement -> type != ETYPE_NULL)
free(pNthElement -> pValue);
free(pNthElement);

Expand Down
2 changes: 2 additions & 0 deletions src/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ EXPORT long listIndex(LIST* pList, void* pValue, ETYPE type, size_t size)
if (pElement -> size == size && ! memcmp(pElement -> pValue, pValue, size))
return i;
}
else if (type == ETYPE_NULL)
return i;
else if (! memcmp(pElement -> pValue, pValue, size))
return i;
}
Expand Down
2 changes: 1 addition & 1 deletion src/indexAll.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ EXPORT LIST* listIndexAll(LIST* pList, void* pValue, ETYPE type, size_t size)
return NULL;
}
}
else if (! memcmp(pElement -> pValue, pValue, size))
else if (type == ETYPE_NULL || ! memcmp(pElement -> pValue, pValue, size))
if (listAppendLong(&pIndexes, i) == FAILURE)
{
listClear(&pIndexes);
Expand Down
4 changes: 4 additions & 0 deletions src/insertSorted.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ EXPORT STATUS listInsertSorted(LIST** ppList, void* pValue, ETYPE type, size_t s

switch (pElement -> type)
{
case ETYPE_NULL:
foundPosition = TRUE;
break;

case ETYPE_SHORT:
if (*((short*) pValue) < *((short*) pElement -> pValue))
{
Expand Down
Loading

0 comments on commit f909042

Please sign in to comment.