Giter Site home page Giter Site logo

cii's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cii's Issues

Question about using assert() inside of except.c

I am a bit stumped how Except_raise implementation can use assert when it is implemented in terms of Except_raise.

assert(e);

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.

Possible memory leak in Arena code

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

Undefined behaviour in text.c

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.

In chapter 9, Set_union(s,NULL) clones a set.Its member size is smaller than expected

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

Is that a typo?

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

memchk.c - sometimes malloc doesn't return aligned pointer

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

Is the Except lib tread safe ?

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

chan.o should be in $(THREADS), not in $(OBJS)

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

List Manipulation using pointer to pointers

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

Ch20's partition function may access invalid memory

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

Solutions

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.