Giter Club home page Giter Club logo

cc's People

Contributors

fullaxx avatar gabewillen avatar hizuru3 avatar jacksonallan avatar

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

cc's Issues

Support for MSVC 19.39 (or later)

Thank you for the cool library and the nice article!

Recently, MSVC has finally started to support the __typeof__ operator (https://learn.microsoft.com/en-us/cpp/c-language/typeof-c?view=msvc-170). It would be good if CC library could be compiled with the newer version of MSVC. However, there are still some compatibility problems with the compiler:

  1. MSVC's <stddef.h> doesn't define max_align_t.

  2. __builtin_unreachable() is not available on MSVC.

  3. MSVC treats char and signed char as the same type so that they can't coexist in an association list of _Generic.
    (Probably, that doesn't conform the C standard)

  4. The old buggy preprocessor can't handle variadic macros properly.
    (It matters only in C++ since the "updated preprocessor" seems to be used in c11/c17/clatest mode by default.)

I'm writing a PR that resolves the issues listed above except 4. To manage the preprocessor problem, more work will be needed.

Thanks for reading.

Planned dynamic string API

As I'm currently in the process of adding the final planned container—dynamic, null-terminated strings—to CC, I've posted a call for public feedback on the API here. So if any current CC users have thoughts on the matter, please feel free to respond here or in the linked Reddit post. Much appreciated!

cc_insert() doesnt compile if compound literal doesnt wrapped up with extra braces.

Good morning.
Basically if i have a map with custom struct and try to insert to it and use compund literals without extra braces it doesnt compile.

cc_insert(&customValueMap, "Player", (Player){.id = 10, .name = "Player 10"}); // this line doesnt compile

if i wrap it up with extra braces it does compile:

cc_insert(&customValueMap, "Player", ((Player){.id = 10, .name = "Player 10"})); // this line compiles

I am a noob c guy. I dont know if it is a bug or not but looks like it is not intended to me.
I created a minimal program that demonstrates this. https://github.com/apilatosba/cc-issue-demo
i hope you a great day my friend.

A segmentation fault occurs when a map is cleared

I think the title describes the problem quite accurately. So, here is the minimal code example to reproduce the problem:

int main( void )
{
    // Declare a map with int keys and short elements.
    map( int, short ) our_map;
    init( &our_map );

    // Inserting elements.
    for( int i = 0; i < 10; ++i )
        if( !insert( &our_map, i, i + 1 ) )
        exit( 1 ); // Out of memory.

    for_each(&our_map, key, val)
        printf("%d : %d \n", *key, *val);

    for( int i = 0; i < 10; ++i )
        erase( &our_map, i);

    // UB. Usually segmentation fault 
    for_each(&our_map, key, val)
        printf("%d : %d \n", *key, *val);

    cleanup( &our_map );
}

Seems like the bug is in this function (in particular, because of 0):

// Returns a pointer-iterator to the first element, or end if the map is empty.
static inline void *cc_map_first(
  void *cntr,
  size_t el_size,
  uint64_t layout
)
{
  for( size_t i = 0; i < cc_map_hdr( cntr )->cap; ++i )
    if( *cc_map_probelen( cntr, i, el_size, layout ) )
      return cc_map_el( cntr, i, el_size, layout );

  return cc_map_end( cntr, 0 /* Dummy */, layout );
}

If change the last statement to

return cc_map_end( cntr, el_size /*0*/ /* Dummy */, layout );

then it seems working

Incomplete type analysis?

For the following program which is faulty (it gives an integer instead of a structure as argument of the map for the insert call),

#include <stdio.h>
#include <string.h>
#include "cc.h"

typedef struct { int x, y, z; } mp;
#define CC_CMPR mp, { return memcmp( &val_1, &val_2, sizeof (mp)); }
#define CC_HASH mp, { return val.x ^ val.y ^ val.z; }
#include "cc.h"

int main( void )
{
  map(mp, mp) map;
  init(&map);
  if (!insert(&map, 12, 12)) {
    abort();
  }
  cleanup(&map);
  return 0;
}

the compilation succeeds with some "missing braces around initializer [-Wmissing-braces]" warnings
whereas I was expecting a compilation failure or at least a warning about incompatible pointer.

Virus warning on Windows

Downloading CC-main.zip and extracting with 7zip, 7zip says: "Operation did not complete successfully because the file contains a virus of potentially unwanted software."
Windows Defender/Security blocks and reports threat as "Trojan:Script/Wacatac.H!ml"

https://go.microsoft.com/fwlink/?linkid=142185&name=Trojan:Script/Wacatac.H!ml&threatid=2147814524

CC-main.zip virus warning

Edition Windows 10 Home
Version 21H2
Installed on ‎29.‎06.‎2022
OS build 19044.2486
Experience Windows Feature Experience Pack 120.2212.4190.0

Memory usage for each instance

Thanks so much for this fascinating code!

I am suggesting a function that looks like this:

size_t memory_usage( <any container type> *cntr );

It would return the amount of (heap) memory associated with cntr.

Use case: when I am writing extension code for Ruby in C, the Ruby runtime likes to know how much memory is associated with a given object (although it doesn't insist on this knowledge). This helps with profiling and (I suspect) the Ruby garbage collector.

Custom maximum load factors for maps and sets not taking effect (now fixed)

Unfortunately, there was a bug in previous releases that prevented custom maximum load factors for maps and sets from taking effect when defined in isolation (i.e. when the user is not adding a custom hash, comparison, or destructor function at the same time).

Specifically, && !defined( CC_LOAD ) was missing from the line #if !defined( CC_DTOR ) && !defined( CC_CMPR ) && !defined( CC_HASH ), which selects between the primary header code and the code that adds a custom hash, comparison, or destructor function or hash table load factor based on whether the user has defined one or more of the customization macros.

I’ve just published a new release (v1.0.2) that corrects this bug. I’ll leave this GitHub issue open for a few days for visibility and then close it.

Feature: cc_tree / cc_graph

I’m working on a library that uses a tree structure for creating hierarchical models, and I’ve noticed significant overlap with the internal structures of CC. I’d like to propose incorporating this tree structure into the library. If you’re interested, I can open a PR with the API spec for your review. If you decide to move forward, I can quickly port my library code into the CC namespace and submit a PR with the implementation.

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.