drh / cii Goto Github PK
View Code? Open in Web Editor NEWC Interfaces and Implementations
Home Page: http://drh.github.io/cii/
License: Other
C Interfaces and Implementations
Home Page: http://drh.github.io/cii/
License: Other
https://github.com/drh/cii/blob/master/src/xp.c#L192
should change to if (n >= m + s/8)
For example {0xFF, 0xFF}
shift left XP_lshift(3, z, 2, x, 20, 0)
should be {0, 0, 0}
, but is {0, 0xFF, 0xFF}.
Fix:
int i, j = n-1;
if (n >= m + s/8)
// +++------+++ m
// ============= n
i = m - 1;
else
// +++------+++ m
// ======= n < m + s/8
// ===== n < m
i = n - s/8 - 1;
I am a bit stumped how Except_raise
implementation can use assert
when it is implemented in terms of Except_raise
.
Line 19 in 9cb8b5f
Using gcc I got the following error:
except.c: In function ‘Except_raise’:
except.c:11:6: warning: infinite recursion detected [-Winfinite-recursion]
11 | void Except_raise(const T *e, const char *file, int line)
| ^~~~~~~~~~~~
In file included from except.c:3:
./except.h:35:18: note: recursive call
35 | #define RAISE(e) Except_raise(&(e), __FILE__, __LINE__)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./assert.h:10:33: note: in expansion of macro ‘RAISE’
10 | #define assert(e) ((void)((e)||(RAISE(Assert_Failed),0)))
| ^~~~~
except.c:15:3: note: in expansion of macro ‘assert’
15 | assert(e);
If I use <assert.h> I can resolve this but I am not sure that is what was intended since it won't raise an exception in the way the assert module does.
Should free the two tables and the set.
This is just a small issue. When I used the "-fsanitize=undefined" option to clang, it complained that performing arithmetic on a NULL pointer is undefined behaviour at L49 of text.c. The problem is that current->avail
is NULL at initialisation time, so the addition is undefined (nasal daemons, etc. :-) ). This patch fixes the warning.
Are any particular reason to use pointer to pointers for list manipulation?
For example, in the List interface
T List_append(T list, T tail){
T *p = &list;
while (*p)
p = &(*p)->rest;
*p = tail;
return list;
}
Writing this function using just pointers like:
T List_append(T list, T tail){
T p = list;
assert(p)
while (p->rest)
p = p->rest;
p->rest = tail;
return list;
}
Implementing those functions using pointer to pointers is more efficient or you
just choose that for showing an idiom.
Thanks
Original issue reported on code.google.com by [email protected]
on 31 May 2012 at 7:00
Line 16 in 9cb8b5f
setop
only use one of the sequal, snull, tnull
. But the other two variables don't get freed.
https://github.com/drh/cii/blob/master/src/ap.c#L361
Before AP_new(0)
, call AP_free(&z)
making code stricting, Does it ?
if (endp == p) { endp = (char *)str; z = AP_new(0); }
I'm trying to use the memchk.c library to check some of my code, but I was
getting an assertion error on FREE'ing because this test was failing:
((unsigned long)ptr) % (sizeof (union align)) != 0
Upon review, it looks like it is a result of malloc not returning a pointer
that is aligned according to `sizeof(union align)`. For example, I added the
following check to the `dalloc` function:
size_t alignment = sizeof(union align);
assert((alignment & (alignment - 1)) == 0); // make sure alignment is a power of 2
void *nptr = (void *)(((unsigned long)ptr + (alignment-1)) & ~ (size_t)(alignment-1));
assert(ptr == nptr);
And my code would fail, but I would expect that nptr should equal ptr? If the
code was modified to change:
avail->ptr = ptr;
to:
avail->ptr = (void *)(((unsigned long)ptr + (alignment-1)) & ~ (size_t)(alignment-1));
I don't think it would have any affect other than to assure that the memory is
aligned along the boundaries we believe it is.
Original issue reported on code.google.com by [email protected]
on 26 Jul 2011 at 4:22
Hi,
Is the Except lib tread safe ?
I have a multithreaded app, i really like your small Except lib but is it safe ?
Thanks,
Alex
Original issue reported on code.google.com by ealexs
on 14 Feb 2011 at 10:21
I do not want to post my issue without first discussing it by email with Dr. Hanson.
I think there's a memory leak in the Arena code.
Consider a scenario where:
* You create and release 3 arenas, each with a chunk of say 20KB of memory.
* You create a new arena, using one of those chunks; there are 2 chunks
left on the free list.
* You attempt to allocate a chunk of size 100KB.
If I read the code correctly, the loop in Arena_alloc() - p94 of the third
printing - invokes <get a new chunk 95>. Each time that is called, it
removes a chunk from the freelist, finds that it is not big enough, and
discards it, rather than restoring it to the freelist or releasing it.
--
Jonathan Leffler <[email protected]>
Original issue reported on code.google.com by [email protected]
on 29 Sep 2008 at 7:50
1, Optional return statement.
2, NDEBUG defined or not.
Original issue reported on code.google.com by [email protected]
on 15 Oct 2012 at 9:51
Attachments:
What steps will reproduce the problem?
1.
2.
3.
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 31 May 2012 at 12:49
From: Norman Ramsey <[email protected]>
Date: Sun, Nov 23, 2008 at 1:41 PM
chan.o should really be in $(THREADS), not in the main $(OBJS).
Without a threads package, I can't easily build a shared library for cii.
Also for some reason I was not able to get the custom.mk to work
as I expected, so I've left in a patch I used to build a shared
library on 64-bit RHEL 5. Presumably you could use something
similar to build a DLL on windows? Not sure.
Appended is a diff.
--- makefile 2008-11-23 14:33:30.623248000 -0500
+++ makefile.orig 2008-09-30 00:43:42.000000000 -0400
@@ -14,7 +14,7 @@
RM=rm -f
CUSTOM=custom.mk
EXTRAS=$(BUILDDIR)memcmp$O $(BUILDDIR)memmove$O $(BUILDDIR)strncmp$O
-THREADS=$(BUILDDIR)thread$O $(BUILDDIR)swtch$O $(BUILDDIR)chan$O
+THREADS=$(BUILDDIR)thread$O $(BUILDDIR)swtch$O
include $(CUSTOM)
B=$(BUILDDIR)
@@ -25,6 +25,7 @@
$Bassert$O \
$Batom$O \
$Bbit$O \
+ $Bchan$O \
$Bexcept$O \
$Bfmt$O \
$Blist$O \
@@ -61,9 +62,6 @@
$Blibcii$A:: $(OBJS) $(EXTRAS)
$(AR) $@ $(OBJS) $(EXTRAS); $(RANLIB) $@ || true
-$Blibcii$(SO).$(MAJORVERSION): $(OBJS) $(EXTRAS)
- $(CC) -shared -Wl,-soname,libcii.so.2 \
- -o $@ $(OBJS) $(EXTRAS)
$Bap$O: src/ap.c; $(CC) $(CFLAGS) -c -o $@ src/ap.c
$Barena$O: src/arena.c; $(CC) $(CFLAGS) -c -o $@ src/arena.c
Original issue reported on code.google.com by [email protected]
on 24 Nov 2008 at 6:58
AP_T x = AP_new(LONG_MIN);
long val = AP_toint(x); // The val is 0
AP_toint
turn LONG_MIN
to 0
. https://github.com/drh/cii/blob/master/src/ap.c#L323 can use without %
.
unsigned long u = XP_toint(x->ndigits, x->digits);
In Ch20, 20.2.1, Sorting concurrently, partition's implementation might access
the invalid memory.
1 int partition(int a[], int i, int j) {
2 int v, k, t;
3 j++;
4 k = i;
5 v = a[k];
6 while (i < j) {
7 i++; while (a[i] < v && i < j) i++;
8 j--; while (a[j] > v) j--;
9 if (i < j) { t = a[i]; a[i] = a[j]; a[j] = t; }
10 }
11 t = a[k]; a[k] = a[j]; a[j] = t;
12 return j;
13 }
For example:
int a[5] = {5,4,3,2,1};
partition(a,0,4);
line 3 increments j to 5, line 7's a[i] < v will access a[5], which is out of
the upper boundary of array.
Maybe, line 7 should be changed as
i++; while (i < j && a[i] < v) i++;
Original issue reported on code.google.com by [email protected]
on 9 Jul 2012 at 2:45
What steps will reproduce the problem?
In CII's chapter 9, Set_union(s,NULL) clones a set, but the cloned set's size
is smaller.
Here is test code:
Set_T s,t;
s = Set_new(1024,NULL,NULL);
t = Set_union(s,NULL);
printf("s:%d, t:%d\n", s->size,t->size);
output is:
s:1021, t:509
The problem seems related to Set_new's implementation:
static int primes[] = { 509, 509, 1021, 2053, 4093,
8191, 16381, 32771, 65521, INT_MAX };
assert(hint >= 0);
for (i = 1; primes[i] < hint; i++)
;
When giving it a hint, it searches the primes table and use the greatest one less than hint.
If the hint happens to be the number in primes, a much less value will be used.
What is the expected output? What do you see instead?
When clone a set, it's member size should be the same.
What version of the product are you using? On what operating system?
N/A
Please provide any additional information below.
N/A
Original issue reported on code.google.com by [email protected]
on 27 Jun 2012 at 12:46
have you posted the solutions to the examples(at the end of each chapter)
to somewhere that we can reach?
Thanks
Original issue reported on code.google.com by [email protected]
on 2 Jun 2012 at 10:12
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.