Skip to content

plain old C, to be called via ctypes #4

Description

@jsbueno

we can format this a sa pr later, but it is this thing:

unsigned long long count_double(char *str) {
    char *i, c1, c2;
    unsigned long long  count = 0;

    c1 = *str;
    c2 = *(str + 1);
    for(i = str+1; c2 = *i; i++) {
        count += (c1 == c2);
        c1 = c2;
    }
    return count;
}

Build with:
gcc -shared -o libblacount.so -fPIC blacount.c

And prepare to use from Python with:

import ctypes
blacount = ctypes.cdll.LoadLibrary("./libblacount.so")
blacount.count_double.argtypes = [ctypes.c_char_p]
blacount.count_double.restype = ctypes.c_uint64

(it counts byte-strings only)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions