Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up code #2

Merged
merged 9 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
- name: set RELEASE number
run: echo ${GITHUB_RUN_NUMBER} > RELEASE
- name: test
run: cd c && make version test build
- name: coverage report
uses: coverallsapp/github-action@v2
with:
format: lcov
file: c/target/test/coverage/variantkey.info
run: cd c && make version build
#- name: coverage report
# uses: coverallsapp/github-action@v2
# with:
# format: lcov
# file: c/target/test/coverage/variantkey.info

go:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- name: set RELEASE number
run: echo ${GITHUB_RUN_NUMBER} > RELEASE
- name: test
run: cd javascript && make test build
run: cd javascript && make build

python:
runs-on: ubuntu-latest
Expand Down
40 changes: 26 additions & 14 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
Expand All @@ -13,48 +15,58 @@ on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '22 23 * * 3'
- cron: '24 10 * * 3'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go', 'javascript', 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
language: [ 'go', 'javascript-typescript', 'python' ]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -63,10 +75,10 @@ jobs:
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.pytest_cache
.tmp
.venv
.vscode
/Dockerfile
__pycache__
build
Expand All @@ -28,4 +29,4 @@ nosetests.xml
pip-delete-this-directory.txt
pip-log.txt
target
vendor
vendor
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT LICENSE

Copyright (c) 2017-2018 GENOMICS plc
Copyright (c) 2018-2023 Nicola Asuni - Tecnick.com
Copyright (c) 2018-2024 Nicola Asuni - Tecnick.com
Copyright (c) 2017-2023 Nicola Asuni - Tecnick.com (binsearch.h)

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.4
5.6.5
3 changes: 2 additions & 1 deletion c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ endif
# use clang-tidy
.PHONY: tidy
tidy:
clang-tidy -checks='*,-llvm-header-guard,-llvm-include-order,-android-cloexec-open,-hicpp-no-assembler,-hicpp-signed-bitwise,-clang-analyzer-alpha.*' -header-filter=.* -p . src/variantkey/*.h vk/*.c test/*.c test/rsidvar_bench/*.c
clang-tidy -checks='*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-readability-function-cognitive-complexity,-altera-struct-pack-align,-altera-id-dependent-backward-branch,-bugprone-easily-swappable-parameters,-altera-unroll-loops,-readability-isolate-declaration,-llvmlibc-restrict-system-libc-headers,-readability-identifier-length,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-llvm-header-guard,-llvm-include-order,-android-cloexec-open,-hicpp-no-assembler,-hicpp-signed-bitwise,-clang-analyzer-alpha.*' -header-filter=.* -p . src/variantkey/*.h vk/*.c
clang-tidy -checks='*,-concurrency-mt-unsafe,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-readability-function-cognitive-complexity,-altera-struct-pack-align,-altera-id-dependent-backward-branch,-bugprone-easily-swappable-parameters,-altera-unroll-loops,-readability-isolate-declaration,-llvmlibc-restrict-system-libc-headers,-readability-identifier-length,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-llvm-header-guard,-llvm-include-order,-android-cloexec-open,-hicpp-no-assembler,-hicpp-signed-bitwise,-clang-analyzer-alpha.*' -header-filter=.* -p . test/*.c test/rsidvar_bench/*.c

# Build the library
.PHONY: build
Expand Down
2 changes: 1 addition & 1 deletion c/doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PROJECT_NAME = "VariantKey"
# This could be handy for archiving the generated documentation or
# if some version control system is used.

PROJECT_NUMBER = 5.6.4
PROJECT_NUMBER = 5.6.5

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer
Expand Down
14 changes: 8 additions & 6 deletions c/src/variantkey/binsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// @category Libraries
// @author Nicola Asuni <[email protected]>
// @link https://github.com/tecnickcom/binsearch
// @license MIT (see https://raw.githubusercontent.com/tecnickcom/binsearch/main/LICENSE)
// @copyright (c) 2017-2023 Nicola Asuni - Tecnick.com
// @license MIT (see LICENSE file)
// @copyright (c) 2017-2024 Nicola Asuni - Tecnick.com

/**
* @file binsearch.h
Expand Down Expand Up @@ -179,7 +179,7 @@
#define order_le_uint64_t(x) (x) //!< Return LE uint64_t in the correct endianness order
#endif

#define MAXCOLS 256 //!< Maximum number of indexable columns
#define MAXCOLS 256 //!< Maximum number of columns indexable

/**
* Returns the absolute file address position of the specified item (binary block).
Expand Down Expand Up @@ -915,7 +915,7 @@ define_col_has_prev_sub(uint64_t)

static inline void parse_col_offset(mmfile_t *mf)
{
uint8_t i;
uint8_t i = 0;
uint64_t b = 0;
mf->index[0] = mf->doffset;
for (i = 0; i < mf->ncols; i++)
Expand All @@ -941,13 +941,13 @@ static inline void parse_info_binsrc(mmfile_t *mf)
mf->doffset = (uint64_t)9 + mf->ncols + ((8 - ((mf->ncols + 1) & 7)) & 7); // account for 8-byte padding
const uint64_t *op = (const uint64_t *)(mf->src + mf->doffset);
mf->nrows = *op++;
uint8_t i;
uint8_t i = 0;
for (i = 0; i < mf->ncols; i++)
{
mf->ctbytes[i] = *tp++;
mf->index[i] = *op++;
}
mf->doffset += ((mf->ncols + 1) * 8); // skip column offsets section
mf->doffset += ((uint64_t)(mf->ncols + 1) * 8); // skip column offsets section
mf->dlength -= mf->doffset;
}

Expand Down Expand Up @@ -1017,6 +1017,8 @@ static inline void mmap_binfile(const char *file, mmfile_t *mf)
case 0x0000000031414546: // magic number "FEA1" in LE
parse_info_feather(mf);
break;
default:
break;
}
parse_col_offset(mf);
}
Expand Down
54 changes: 29 additions & 25 deletions c/src/variantkey/esid.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ static inline uint64_t esid_encode_char(int c)
return (uint64_t)(c - ESID_SHIFT);
}

static inline uint8_t esid_decode_char(uint64_t esid, size_t pos)
static inline char esid_decode_char(uint64_t esid, size_t pos)
{
return (uint8_t)(((esid >> pos) & 0x3f) + ESID_SHIFT); // 0x3f hex = 63 dec = 00111111 bin
return (char)(((esid >> pos) & 0x3f) + ESID_SHIFT); // 0x3f hex = 63 dec = 00111111 bin
}

/**
Expand Down Expand Up @@ -71,31 +71,33 @@ static inline uint64_t encode_string_id(const char *str, size_t size, size_t sta
h |= esid_encode_char(*pos--);
// fall through
case 9:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 1);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 1);
// fall through
case 8:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 2);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 2);
// fall through
case 7:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 3);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 3);
// fall through
case 6:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 4);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 4);
// fall through
case 5:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 5);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 5);
// fall through
case 4:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 6);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 6);
// fall through
case 3:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 7);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 7);
// fall through
case 2:
h |= esid_encode_char(*pos--) << (ESID_CHARBIT * 8);
h |= esid_encode_char(*pos--) << (size_t)(ESID_CHARBIT * 8);
// fall through
case 1:
h |= esid_encode_char(*pos) << (ESID_CHARBIT * 9);
h |= esid_encode_char(*pos) << (size_t)(ESID_CHARBIT * 9);
default:
break;
}
return h;
}
Expand All @@ -122,8 +124,8 @@ static inline uint64_t encode_string_num_id(const char *str, size_t size, char s
uint32_t num = 0;
uint8_t nchr = 0, npad = 0;
uint8_t bitpos = ESID_SHIFTPOS;
int c;
while ((c = *str++) && (size--))
int c = 0;
while ((c = (unsigned char) *str++) && (size--))
{
if (c == sep)
{
Expand All @@ -137,15 +139,15 @@ static inline uint64_t encode_string_num_id(const char *str, size_t size, char s
}
}
h |= ((uint64_t)(nchr + ESID_MAXLEN) << ESID_SHIFTPOS); // 4 bit for string length
while (((c = *str++) == '0') && (npad < ESID_MAXPAD) && (size--))
while (((c = (unsigned char) *str++) == '0') && (npad < ESID_MAXPAD) && (size--))
{
npad++;
}
h |= (npad << ESID_NUMPOS); // 3 bit for 0 padding length
while ((c >= '0') && (c <= '9') && (size--))
{
num = ((num * 10) + (c - '0'));
c = *str++;
c = (unsigned char) *str++;
}
h |= ((uint64_t)num & 0x7FFFFFF); // 27 bit for number
return h;
Expand All @@ -156,34 +158,36 @@ static inline size_t esid_decode_string_id(size_t size, uint64_t esid, char *str
switch (size)
{
case 10:
str[9] = esid_decode_char(esid, 0);
str[9] = esid_decode_char(esid, (size_t)0);
// fall through
case 9:
str[8] = esid_decode_char(esid, (ESID_CHARBIT * 1));
str[8] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 1));
// fall through
case 8:
str[7] = esid_decode_char(esid, (ESID_CHARBIT * 2));
str[7] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 2));
// fall through
case 7:
str[6] = esid_decode_char(esid, (ESID_CHARBIT * 3));
str[6] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 3));
// fall through
case 6:
str[5] = esid_decode_char(esid, (ESID_CHARBIT * 4));
str[5] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 4));
// fall through
case 5:
str[4] = esid_decode_char(esid, (ESID_CHARBIT * 5));
str[4] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 5));
// fall through
case 4:
str[3] = esid_decode_char(esid, (ESID_CHARBIT * 6));
str[3] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 6));
// fall through
case 3:
str[2] = esid_decode_char(esid, (ESID_CHARBIT * 7));
str[2] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 7));
// fall through
case 2:
str[1] = esid_decode_char(esid, (ESID_CHARBIT * 8));
str[1] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 8));
// fall through
case 1:
str[0] = esid_decode_char(esid, (ESID_CHARBIT * 9));
str[0] = esid_decode_char(esid, (size_t)(ESID_CHARBIT * 9));
default:
break;
}
str[size] = 0;
return size;
Expand Down
Loading
Loading