blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
4
721
content_id
stringlengths
40
40
detected_licenses
listlengths
0
57
license_type
stringclasses
2 values
repo_name
stringlengths
5
91
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
321 values
visit_date
timestamp[ns]date
2016-08-12 09:31:09
2023-09-06 10:45:07
revision_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
committer_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
github_id
int64
426
681M
star_events_count
int64
101
243k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
23 values
gha_event_created_at
timestamp[ns]date
2012-06-28 18:51:49
2023-09-14 21:59:16
gha_created_at
timestamp[ns]date
2008-02-11 22:55:26
2023-08-10 11:14:58
gha_language
stringclasses
147 values
src_encoding
stringclasses
26 values
language
stringclasses
2 values
is_vendor
bool
2 classes
is_generated
bool
2 classes
length_bytes
int64
6
10.2M
extension
stringclasses
115 values
filename
stringlengths
3
113
content
stringlengths
6
10.2M
0f06ee28026b8ebc43069fe879a55264f285dd0a
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/dev/fdt/pwm_fan.c
b67954bdf101c31067ad275c3c3fc21ca8c8d7ea
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
3,793
c
pwm_fan.c
/* $NetBSD: pwm_fan.c,v 1.2 2021/01/27 03:10:21 thorpej Exp $ */ /*- * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <sys/cdefs.h> __KERNEL_RCSID(0, "$NetBSD: pwm_fan.c,v 1.2 2021/01/27 03:10:21 thorpej Exp $"); #include <sys/param.h> #include <sys/bus.h> #include <sys/device.h> #include <sys/systm.h> #include <sys/sysctl.h> #include <sys/kmem.h> #include <sys/gpio.h> #include <dev/pwm/pwmvar.h> #include <dev/fdt/fdtvar.h> struct pwm_fan_softc { device_t sc_dev; pwm_tag_t sc_pwm; struct fdtbus_gpio_pin *sc_pin; u_int *sc_levels; u_int sc_nlevels; }; static int pwm_fan_match(device_t, cfdata_t, void *); static void pwm_fan_attach(device_t, device_t, void *); static void pwm_fan_set(struct pwm_fan_softc *, u_int); static const struct device_compatible_entry compat_data[] = { { .compat = "pwm-fan" }, DEVICE_COMPAT_EOL }; CFATTACH_DECL_NEW(pwmfan, sizeof(struct pwm_fan_softc), pwm_fan_match, pwm_fan_attach, NULL, NULL); static int pwm_fan_match(device_t parent, cfdata_t cf, void *aux) { struct fdt_attach_args * const faa = aux; return of_compatible_match(faa->faa_phandle, compat_data); } static void pwm_fan_attach(device_t parent, device_t self, void *aux) { struct pwm_fan_softc * const sc = device_private(self); struct fdt_attach_args * const faa = aux; const int phandle = faa->faa_phandle; const u_int *levels; u_int n; int len; sc->sc_dev = self; sc->sc_pwm = fdtbus_pwm_acquire(phandle, "pwms"); if (sc->sc_pwm == NULL) { aprint_error(": couldn't acquire pwm\n"); return; } levels = fdtbus_get_prop(phandle, "cooling-levels", &len); if (len < 4) { aprint_error(": couldn't get 'cooling-levels' property\n"); return; } sc->sc_levels = kmem_alloc(len, KM_SLEEP); sc->sc_nlevels = len / 4; for (n = 0; n < sc->sc_nlevels; n++) sc->sc_levels[n] = be32toh(levels[n]); aprint_naive("\n"); aprint_normal(": PWM Fan"); aprint_normal(" (levels"); for (n = 0; n < sc->sc_nlevels; n++) { aprint_normal(" %u%%", (sc->sc_levels[n] * 100) / 255); } aprint_normal(")\n"); /* Select the highest cooling level */ pwm_fan_set(sc, 255); } static void pwm_fan_set(struct pwm_fan_softc *sc, u_int level) { struct pwm_config conf; if (level > 255) level = 255; aprint_debug_dev(sc->sc_dev, "set duty cycle to %u%%\n", (level * 100) / 255); pwm_disable(sc->sc_pwm); pwm_get_config(sc->sc_pwm, &conf); conf.duty_cycle = (conf.period * level) / 255; pwm_set_config(sc->sc_pwm, &conf); pwm_enable(sc->sc_pwm); }
8989a202ecb85ddfd0947305fc8778c34ed191ef
c9bc99866cfab223c777cfb741083be3e9439d81
/product/rdfremont/module/mod_lcp_platform/src/mod_lcp_platform.c
8b5253c05ce4ebd811be799390ce7c2d7994fc5d
[ "BSD-3-Clause" ]
permissive
ARM-software/SCP-firmware
4738ca86ce42d82588ddafc2226a1f353ff2c797
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
refs/heads/master
2023-09-01T16:13:36.962036
2023-08-17T13:00:20
2023-08-31T07:43:37
134,399,880
211
165
NOASSERTION
2023-09-13T14:27:10
2018-05-22T10:35:56
C
UTF-8
C
false
false
1,434
c
mod_lcp_platform.c
/* * Arm SCP/MCP Software * Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #include <lcp_device.h> #include <fwk_id.h> #include <fwk_interrupt.h> #include <fwk_log.h> #include <fwk_module.h> #include <fwk_module_idx.h> #include <fwk_status.h> #define MOD_NAME "[LCP_PLATFORM] " #define LCP_TIMER_RELOAD 0xFFFFFU volatile struct { uint32_t counter; } lcp_platform_ctx; void timer_isr() { lcp_platform_ctx.counter++; /* clear interrupt flag */ LCP_TIMER_REG_S->INTSTATUS = 1U; } void mod_lcp_config_timer() { LCP_TIMER_REG_S->CTRL = CTRL_ENABLE_MASK | CTRL_INT_EN_MASK; LCP_TIMER_REG_S->RELOAD = LCP_TIMER_RELOAD; } static int mod_lcp_platform_init( fwk_id_t module_id, unsigned int element_count, const void *unused) { /* No elements support */ if (element_count > 0) { return FWK_E_DATA; } return FWK_SUCCESS; } static int mod_lcp_platform_start(fwk_id_t id) { fwk_interrupt_set_isr(TIMER_IRQ, timer_isr); fwk_interrupt_enable(TIMER_IRQ); mod_lcp_config_timer(); FWK_LOG_INFO(MOD_NAME "LCP RAM firmware initialized"); return FWK_SUCCESS; } const struct fwk_module module_lcp_platform = { .type = FWK_MODULE_TYPE_SERVICE, .init = mod_lcp_platform_init, .start = mod_lcp_platform_start, }; const struct fwk_module_config config_lcp_platform = { 0 };
eb4b893b32ee3f7763d4e64adcb2acc408af823a
e47e2263ca0b60d0c8327f74b4d4078deadea430
/tess-two/jni/com_googlecode_leptonica_android/src/prog/cctest1.c
135ee123140f4256ac720a6d61291dd267d5274e
[ "BSD-2-Clause", "Apache-2.0", "CC-BY-2.5" ]
permissive
rmtheis/tess-two
43ed1bdcceee88df696efdee7c3965572ff2121f
ab4cab1bd9794aacb74162aff339daa921a68c3f
refs/heads/master
2023-03-10T08:27:42.539055
2022-03-17T11:21:24
2022-03-17T11:21:24
2,581,357
3,632
1,331
Apache-2.0
2019-10-20T00:51:50
2011-10-15T11:14:00
C
UTF-8
C
false
false
4,466
c
cctest1.c
/*====================================================================* - Copyright (C) 2001 Leptonica. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials - provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *====================================================================*/ /* * cctest1.c * * This is a test of the following function: * * BOXA *pixConnComp(PIX *pixs, PIXA **ppixa, l_int32 connectivity) * * pixs: input pix * ppixa: &pixa (<optional> pixa of each c.c.) * connectivity (4 or 8) * boxa: returned array of boxes of c.c. * * Use NULL for &pixa if you don't want the pixa array. * * It also demonstrates a few display modes. */ #include "allheaders.h" #define NTIMES 2 l_int32 main(l_int32 argc, char **argv) { char *filein; l_int32 i, n, count; BOX *box; BOXA *boxa; PIX *pixs, *pixd; PIXA *pixa; PIXCMAP *cmap; static char mainName[] = "cctest1"; if (argc != 2) return ERROR_INT(" Syntax: cctest1 filein", mainName, 1); filein = argv[1]; if ((pixs = pixRead(filein)) == NULL) return ERROR_INT("pixs not made", mainName, 1); if (pixGetDepth(pixs) != 1) return ERROR_INT("pixs not 1 bpp", mainName, 1); /* Test speed of pixCountConnComp() */ startTimer(); for (i = 0; i < NTIMES; i++) pixCountConnComp(pixs, 4, &count); fprintf(stderr, "Time to compute 4-cc: %6.3f sec\n", stopTimer()/NTIMES); fprintf(stderr, "Number of 4-cc: %d\n", count); startTimer(); for (i = 0; i < NTIMES; i++) pixCountConnComp(pixs, 8, &count); fprintf(stderr, "Time to compute 8-cc: %6.3f sec\n", stopTimer()/NTIMES); fprintf(stderr, "Number of 8-cc: %d\n", count); /* Test speed of pixConnComp(), with only boxa output */ startTimer(); for (i = 0; i < NTIMES; i++) { boxa = pixConnComp(pixs, NULL, 4); boxaDestroy(&boxa); } fprintf(stderr, "Time to compute 4-cc: %6.3f sec\n", stopTimer()/NTIMES); startTimer(); for (i = 0; i < NTIMES; i++) { boxa = pixConnComp(pixs, NULL, 8); boxaDestroy(&boxa); } fprintf(stderr, "Time to compute 8-cc: %6.3f sec\n", stopTimer()/NTIMES); /* Draw outline of each c.c. box */ boxa = pixConnComp(pixs, NULL, 4); n = boxaGetCount(boxa); fprintf(stderr, "Num 4-cc boxes: %d\n", n); for (i = 0; i < n; i++) { box = boxaGetBox(boxa, i, L_CLONE); pixRenderBox(pixs, box, 3, L_FLIP_PIXELS); boxDestroy(&box); /* remember, clones need to be destroyed */ } boxaDestroy(&boxa); /* Display each component as a random color in cmapped 8 bpp. * Background is color 0; it is set to white. */ boxa = pixConnComp(pixs, &pixa, 4); pixd = pixaDisplayRandomCmap(pixa, pixGetWidth(pixs), pixGetHeight(pixs)); cmap = pixGetColormap(pixd); pixcmapResetColor(cmap, 0, 255, 255, 255); /* reset background to white */ pixDisplay(pixd, 100, 100); boxaDestroy(&boxa); pixDestroy(&pixd); pixaDestroy(&pixa); pixDestroy(&pixs); return 0; }
69014483201605ada01dfe16ebc9fed8278c057b
42ea124983b717e3f6a8acfaf16bb6f455e23d12
/src/lib/src/spi.c
1df58c50b356ce3a48ddd399a0e141bc76d16699
[ "BSD-2-Clause", "BSD-3-Clause", "MIT" ]
permissive
f32c/f32c
4a3f026c6a3e30089976c523861bf46c047bed1b
115c2d582296c8af6e9fc24e2355e5f31ff2f3b6
refs/heads/master
2023-09-01T19:32:24.288992
2023-08-17T19:32:17
2023-08-17T19:32:17
34,478,922
399
140
BSD-2-Clause
2023-04-28T17:13:20
2015-04-23T20:09:23
VHDL
UTF-8
C
false
false
2,592
c
spi.c
/*- * Copyright (c) 2013 Marko Zec, University of Zagreb * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id$ */ #include <dev/io.h> #include <dev/spi.h> #if (_BYTE_ORDER == _LITTLE_ENDIAN) #define SPI_READY_MASK (1 << 8) #else #define SPI_READY_MASK (1 << 16) #endif #define SPI_DATA 0 #define SPI_CONTROL 1 void spi_block_in(int port, void *buf, int len) { uint32_t *wp = (uint32_t *) buf; uint32_t w = 0; uint32_t c; if (len == 0) return; SB(0xff, SPI_DATA, port); do { LW(c, SPI_DATA, port); } while ((c & SPI_READY_MASK) == 0); for (len--; len != 0; len--) { SB(0xff, SPI_DATA, port); #if (_BYTE_ORDER == _LITTLE_ENDIAN) w = (w >> 8) | (c << 24); #else w = (w << 8) | (c >> 24); #endif if ((len & 3) == 0) *wp++ = w; do { LW(c, SPI_DATA, port); } while ((c & SPI_READY_MASK) == 0); } #if (_BYTE_ORDER == _LITTLE_ENDIAN) w = (w >> 8) | (c << 24); #else w = (w << 8) | (c >> 24); #endif *wp++ = w; } int spi_byte(int port, int out) { uint32_t in; SB(out, SPI_DATA, port); do { LW(in, SPI_DATA, port); } while ((in & SPI_READY_MASK) == 0); #if (_BYTE_ORDER == _LITTLE_ENDIAN) return (in & 0xff); #else return (in >> 24); #endif } void spi_start_transaction(int port) { uint32_t in; SB(0x80, SPI_CONTROL, port); do { LW(in, SPI_DATA, port); } while ((in & SPI_READY_MASK) == 0); }
c5e915c4abed173a492ba29bacc03827a6205ffa
2747df0b2fed96b7aed7c51169fe7e6b97ecf2af
/frozen.h
6445b770e480053252b9e3062e4b3ff68ce93e8a
[ "Apache-2.0" ]
permissive
cesanta/frozen
3727d9a8114d4baa5bd198b01d89f7213c2a7bbd
709ff5e891ff2b342043045b59422bebc4ca1d13
refs/heads/master
2023-09-01T04:49:28.303637
2023-08-29T12:15:44
2023-08-29T12:15:44
15,376,630
692
183
NOASSERTION
2023-08-29T12:15:45
2013-12-22T14:27:00
C
UTF-8
C
false
false
11,946
h
frozen.h
/* * Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com> * Copyright (c) 2018 Cesanta Software Limited * All rights reserved * * Licensed under the Apache License, Version 2.0 (the ""License""); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an ""AS IS"" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CS_FROZEN_FROZEN_H_ #define CS_FROZEN_FROZEN_H_ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #include <stdarg.h> #include <stddef.h> #include <stdio.h> #include <limits.h> #if defined(_WIN32) && _MSC_VER < 1700 typedef int bool; enum { false = 0, true = 1 }; #else #include <stdbool.h> #endif /* JSON token type */ enum json_token_type { JSON_TYPE_INVALID = 0, /* memsetting to 0 should create INVALID value */ JSON_TYPE_STRING, JSON_TYPE_NUMBER, JSON_TYPE_TRUE, JSON_TYPE_FALSE, JSON_TYPE_NULL, JSON_TYPE_OBJECT_START, JSON_TYPE_OBJECT_END, JSON_TYPE_ARRAY_START, JSON_TYPE_ARRAY_END, JSON_TYPES_CNT }; /* * Structure containing token type and value. Used in `json_walk()` and * `json_scanf()` with the format specifier `%T`. */ struct json_token { const char *ptr; /* Points to the beginning of the value */ int len; /* Value length */ enum json_token_type type; /* Type of the token, possible values are above */ }; #define JSON_INVALID_TOKEN \ { 0, 0, JSON_TYPE_INVALID } /* Error codes */ #define JSON_STRING_INVALID -1 #define JSON_STRING_INCOMPLETE -2 #define JSON_DEPTH_LIMIT -3 /* * Callback-based SAX-like API. * * Property name and length is given only if it's available: i.e. if current * event is an object's property. In other cases, `name` is `NULL`. For * example, name is never given: * - For the first value in the JSON string; * - For events JSON_TYPE_OBJECT_END and JSON_TYPE_ARRAY_END * * E.g. for the input `{ "foo": 123, "bar": [ 1, 2, { "baz": true } ] }`, * the sequence of callback invocations will be as follows: * * - type: JSON_TYPE_OBJECT_START, name: NULL, path: "", value: NULL * - type: JSON_TYPE_NUMBER, name: "foo", path: ".foo", value: "123" * - type: JSON_TYPE_ARRAY_START, name: "bar", path: ".bar", value: NULL * - type: JSON_TYPE_NUMBER, name: "0", path: ".bar[0]", value: "1" * - type: JSON_TYPE_NUMBER, name: "1", path: ".bar[1]", value: "2" * - type: JSON_TYPE_OBJECT_START, name: "2", path: ".bar[2]", value: NULL * - type: JSON_TYPE_TRUE, name: "baz", path: ".bar[2].baz", value: "true" * - type: JSON_TYPE_OBJECT_END, name: NULL, path: ".bar[2]", value: "{ \"baz\": *true }" * - type: JSON_TYPE_ARRAY_END, name: NULL, path: ".bar", value: "[ 1, 2, { *\"baz\": true } ]" * - type: JSON_TYPE_OBJECT_END, name: NULL, path: "", value: "{ \"foo\": 123, *\"bar\": [ 1, 2, { \"baz\": true } ] }" */ typedef void (*json_walk_callback_t)(void *callback_data, const char *name, size_t name_len, const char *path, const struct json_token *token); /* * Parse `json_string`, invoking `callback` in a way similar to SAX parsers; * see `json_walk_callback_t`. * Return number of processed bytes, or a negative error code. */ int json_walk(const char *json_string, int json_string_length, json_walk_callback_t callback, void *callback_data); /* * Extensible argument passing interface */ struct frozen_args { json_walk_callback_t callback; void *callback_data; int limit; }; int json_walk_args(const char *json_string, int json_string_length, const struct frozen_args *args); #define INIT_FROZEN_ARGS(ptr) do { \ memset((ptr), 0, sizeof(*(ptr))); \ (ptr)->limit = INT_MAX; \ } while(0) /* * JSON generation API. * struct json_out abstracts output, allowing alternative printing plugins. */ struct json_out { int (*printer)(struct json_out *, const char *str, size_t len); union { struct { char *buf; size_t size; size_t len; } buf; void *data; FILE *fp; } u; }; extern int json_printer_buf(struct json_out *, const char *, size_t); extern int json_printer_file(struct json_out *, const char *, size_t); #define JSON_OUT_BUF(buf, len) \ { \ json_printer_buf, { \ { buf, len, 0 } \ } \ } #define JSON_OUT_FILE(fp) \ { \ json_printer_file, { \ { (char *) fp, 0, 0 } \ } \ } typedef int (*json_printf_callback_t)(struct json_out *, va_list *ap); /* * Generate formatted output into a given sting buffer. * This is a superset of printf() function, with extra format specifiers: * - `%B` print json boolean, `true` or `false`. Accepts an `int`. * - `%Q` print quoted escaped string or `null`. Accepts a `const char *`. * - `%.*Q` same as `%Q`, but with length. Accepts `int`, `const char *` * - `%V` print quoted base64-encoded string. Accepts a `const char *`, `int`. * - `%H` print quoted hex-encoded string. Accepts a `int`, `const char *`. * - `%M` invokes a json_printf_callback_t function. That callback function * can consume more parameters. * * Return number of bytes printed. If the return value is bigger than the * supplied buffer, that is an indicator of overflow. In the overflow case, * overflown bytes are not printed. */ int json_printf(struct json_out *, const char *fmt, ...); int json_vprintf(struct json_out *, const char *fmt, va_list ap); /* * Same as json_printf, but prints to a file. * File is created if does not exist. File is truncated if already exists. */ int json_fprintf(const char *file_name, const char *fmt, ...); int json_vfprintf(const char *file_name, const char *fmt, va_list ap); /* * Print JSON into an allocated 0-terminated string. * Return allocated string, or NULL on error. * Example: * * ```c * char *str = json_asprintf("{a:%H}", 3, "abc"); * printf("%s\n", str); // Prints "616263" * free(str); * ``` */ char *json_asprintf(const char *fmt, ...); char *json_vasprintf(const char *fmt, va_list ap); /* * Helper %M callback that prints contiguous C arrays. * Consumes void *array_ptr, size_t array_size, size_t elem_size, char *fmt * Return number of bytes printed. */ int json_printf_array(struct json_out *, va_list *ap); /* * Scan JSON string `str`, performing scanf-like conversions according to `fmt`. * This is a `scanf()` - like function, with following differences: * * 1. Object keys in the format string may be not quoted, e.g. "{key: %d}" * 2. Order of keys in an object is irrelevant. * 3. Several extra format specifiers are supported: * - %B: consumes `int *` (or `char *`, if `sizeof(bool) == sizeof(char)`), * expects boolean `true` or `false`. * - %Q: consumes `char **`, expects quoted, JSON-encoded string. Scanned * string is malloc-ed, caller must free() the string. * - %V: consumes `char **`, `int *`. Expects base64-encoded string. * Result string is base64-decoded, malloced and NUL-terminated. * The length of result string is stored in `int *` placeholder. * Caller must free() the result. * - %H: consumes `int *`, `char **`. * Expects a hex-encoded string, e.g. "fa014f". * Result string is hex-decoded, malloced and NUL-terminated. * The length of the result string is stored in `int *` placeholder. * Caller must free() the result. * - %M: consumes custom scanning function pointer and * `void *user_data` parameter - see json_scanner_t definition. * - %T: consumes `struct json_token *`, fills it out with matched token. * * Return number of elements successfully scanned & converted. * Negative number means scan error. */ int json_scanf(const char *str, int str_len, const char *fmt, ...); int json_vscanf(const char *str, int str_len, const char *fmt, va_list ap); /* json_scanf's %M handler */ typedef void (*json_scanner_t)(const char *str, int len, void *user_data); /* * Helper function to scan array item with given path and index. * Fills `token` with the matched JSON token. * Return -1 if no array element found, otherwise non-negative token length. */ int json_scanf_array_elem(const char *s, int len, const char *path, int index, struct json_token *token); /* * Unescape JSON-encoded string src,slen into dst, dlen. * src and dst may overlap. * If destination buffer is too small (or zero-length), result string is not * written but the length is counted nevertheless (similar to snprintf). * Return the length of unescaped string in bytes. */ int json_unescape(const char *src, int slen, char *dst, int dlen); /* * Escape a string `str`, `str_len` into the printer `out`. * Return the number of bytes printed. */ int json_escape(struct json_out *out, const char *str, size_t str_len); /* * Read the whole file in memory. * Return malloc-ed file content, or NULL on error. The caller must free(). */ char *json_fread(const char *file_name); /* * Update given JSON string `s,len` by changing the value at given `json_path`. * The result is saved to `out`. If `json_fmt` == NULL, that deletes the key. * If path is not present, missing keys are added. Array path without an * index pushes a value to the end of an array. * Return 1 if the string was changed, 0 otherwise. * * Example: s is a JSON string { "a": 1, "b": [ 2 ] } * json_setf(s, len, out, ".a", "7"); // { "a": 7, "b": [ 2 ] } * json_setf(s, len, out, ".b", "7"); // { "a": 1, "b": 7 } * json_setf(s, len, out, ".b[]", "7"); // { "a": 1, "b": [ 2,7 ] } * json_setf(s, len, out, ".b", NULL); // { "a": 1 } */ int json_setf(const char *s, int len, struct json_out *out, const char *json_path, const char *json_fmt, ...); int json_vsetf(const char *s, int len, struct json_out *out, const char *json_path, const char *json_fmt, va_list ap); /* * Pretty-print JSON string `s,len` into `out`. * Return number of processed bytes in `s`. */ int json_prettify(const char *s, int len, struct json_out *out); /* * Prettify JSON file `file_name`. * Return number of processed bytes, or negative number of error. * On error, file content is not modified. */ int json_prettify_file(const char *file_name); /* * Iterate over an object at given JSON `path`. * On each iteration, fill the `key` and `val` tokens. It is OK to pass NULL * for `key`, or `val`, in which case they won't be populated. * Return an opaque value suitable for the next iteration, or NULL when done. * * Example: * * ```c * void *h = NULL; * struct json_token key, val; * while ((h = json_next_key(s, len, h, ".foo", &key, &val)) != NULL) { * printf("[%.*s] -> [%.*s]\n", key.len, key.ptr, val.len, val.ptr); * } * ``` */ void *json_next_key(const char *s, int len, void *handle, const char *path, struct json_token *key, struct json_token *val); /* * Iterate over an array at given JSON `path`. * Similar to `json_next_key`, but fills array index `idx` instead of `key`. */ void *json_next_elem(const char *s, int len, void *handle, const char *path, int *idx, struct json_token *val); #ifndef JSON_MAX_PATH_LEN #define JSON_MAX_PATH_LEN 256 #endif #ifndef JSON_MINIMAL #define JSON_MINIMAL 0 #endif #ifndef JSON_ENABLE_BASE64 #define JSON_ENABLE_BASE64 !JSON_MINIMAL #endif #ifndef JSON_ENABLE_HEX #define JSON_ENABLE_HEX !JSON_MINIMAL #endif #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* CS_FROZEN_FROZEN_H_ */
66a0546f0d366fd584a1d8dceaf5eaef71a59a14
3bbf88dc48d70e4c362e15589967c271f5ce844f
/tests/projects/windows/driver/kmdf/serial/log.h
eedcd08f39f64a2fb9f6c5dbd02020efc10c98db
[ "Apache-2.0", "LicenseRef-scancode-public-domain", "Unlicense", "MIT" ]
permissive
xmake-io/xmake
ed420a84d9dddd36946893e60799bd912ffd917d
025c5e8415b456bf5f24e37322731615bd5ddea1
refs/heads/master
2023-08-31T13:40:45.719615
2023-08-31T14:33:50
2023-08-31T14:33:50
34,431,834
6,914
618
Apache-2.0
2023-09-14T09:23:40
2015-04-23T03:37:31
Lua
UTF-8
C
false
false
425
h
log.h
/*++ Copyright (c) 1993 Microsoft Corporation :ts=4 Module Name: log.h Abstract: debug macros Environment: Kernel & user mode --*/ #ifndef __LOG_H__ #define __LOG_H__ #if !defined(EVENT_TRACING) VOID SerialDbgPrintEx ( IN ULONG DebugPrintLevel, IN ULONG DebugPrintFlag, IN PCCHAR DebugMessage, ... ); #endif #endif // __LOG_H__
075d961dd95e16c8c4a761fb5956beb1ab6752ab
f9cc38a7c78446b73747580aacae124bb2826a58
/cmd/demo/usbip/usbip-win/userspace/lib/usbip_forward.h
e23e45ac45ff7ce240725df8a5241ae57d95a9d8
[ "MIT", "GPL-2.0-only", "GPL-3.0-only" ]
permissive
bulwarkid/virtual-fido
dae4677d2051961c96d8f284cac7db9a8c5a45d3
c0256885902878809ea97dbe488d6937d75b5bc5
refs/heads/master
2023-08-09T22:09:58.891332
2023-07-24T22:08:36
2023-07-24T23:10:00
537,229,823
988
46
MIT
2023-07-17T21:08:29
2022-09-15T22:47:15
C
UTF-8
C
false
false
99
h
usbip_forward.h
#pragma #include <winsock2.h> void usbip_forward(HANDLE hdev_src, HANDLE hdev_dst, BOOL inbound);
c28f7de5fcf0682b7c917450e7f92774500d2a5f
07bbe7a0a829cfbc9789831d981aedf36e4e94d9
/source/lexbor/html/tree/insertion_mode/in_head_noscript.c
78e4c5919fe7d30a5f6892f3b0d7e2cdcc90a466
[ "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
lexbor/lexbor
0bf3a22898d8e295fa20cc1391e31a68502c458a
31e3d9d7f9032cd475d5afa788999de2d4b891dd
refs/heads/master
2023-08-31T23:25:49.903737
2023-08-30T08:25:12
2023-08-30T08:25:12
122,375,902
758
95
Apache-2.0
2023-08-30T08:25:13
2018-02-21T18:28:52
C
UTF-8
C
false
false
3,945
c
in_head_noscript.c
/* * Copyright (C) 2018-2020 Alexander Borisov * * Author: Alexander Borisov <borisov@lexbor.com> */ #include "lexbor/html/tree/insertion_mode.h" #include "lexbor/html/tree/open_elements.h" static bool lxb_html_tree_insertion_mode_in_head_noscript_open(lxb_html_tree_t *tree, lxb_html_token_t *token); static bool lxb_html_tree_insertion_mode_in_head_noscript_closed(lxb_html_tree_t *tree, lxb_html_token_t *token); bool lxb_html_tree_insertion_mode_in_head_noscript(lxb_html_tree_t *tree, lxb_html_token_t *token) { if (token->type & LXB_HTML_TOKEN_TYPE_CLOSE) { return lxb_html_tree_insertion_mode_in_head_noscript_closed(tree, token); } return lxb_html_tree_insertion_mode_in_head_noscript_open(tree, token); } lxb_inline bool lxb_html_tree_insertion_mode_in_head_noscript_anything_else(lxb_html_tree_t *tree, lxb_html_token_t *token); static bool lxb_html_tree_insertion_mode_in_head_noscript_open(lxb_html_tree_t *tree, lxb_html_token_t *token) { switch (token->tag_id) { case LXB_TAG__EM_DOCTYPE: lxb_html_tree_parse_error(tree, token, LXB_HTML_RULES_ERROR_DOTOINHENOMO); break; case LXB_TAG_HTML: return lxb_html_tree_insertion_mode_in_body(tree, token); case LXB_TAG__EM_COMMENT: case LXB_TAG_BASEFONT: case LXB_TAG_BGSOUND: case LXB_TAG_LINK: case LXB_TAG_META: case LXB_TAG_NOFRAMES: case LXB_TAG_STYLE: return lxb_html_tree_insertion_mode_in_head(tree, token); case LXB_TAG_HEAD: case LXB_TAG_NOSCRIPT: lxb_html_tree_parse_error(tree, token, LXB_HTML_RULES_ERROR_UNTO); break; /* CopyPast from "in head" insertion mode */ case LXB_TAG__TEXT: { lxb_html_token_t ws_token = {0}; tree->status = lxb_html_token_data_split_ws_begin(token, &ws_token); if (tree->status != LXB_STATUS_OK) { return lxb_html_tree_process_abort(tree); } if (ws_token.text_start != ws_token.text_end) { tree->status = lxb_html_tree_insert_character(tree, &ws_token, NULL); if (tree->status != LXB_STATUS_OK) { return lxb_html_tree_process_abort(tree); } } if (token->text_start == token->text_end) { return true; } } /* fall through */ default: return lxb_html_tree_insertion_mode_in_head_noscript_anything_else(tree, token); } return true; } static bool lxb_html_tree_insertion_mode_in_head_noscript_closed(lxb_html_tree_t *tree, lxb_html_token_t *token) { if(token->tag_id == LXB_TAG_BR) { return lxb_html_tree_insertion_mode_in_head_noscript_anything_else(tree, token); } lxb_html_tree_parse_error(tree, token, LXB_HTML_RULES_ERROR_UNTO); return true; } lxb_inline bool lxb_html_tree_insertion_mode_in_head_noscript_anything_else(lxb_html_tree_t *tree, lxb_html_token_t *token) { lxb_html_tree_parse_error(tree, token, LXB_HTML_RULES_ERROR_UNTO); lxb_html_tree_open_elements_pop(tree); tree->mode = lxb_html_tree_insertion_mode_in_head; return false; }
4eefe57af733c2f58983243b6fdb9322262b75ca
f268b50cfc676024734009a0678825d01fa78a57
/src/resource/postprocess.h
b6d2b2d074666a5b8d6e7e1ec6b5daaff0d1c2f4
[ "LicenseRef-scancode-warranty-disclaimer", "CC-BY-4.0", "LicenseRef-scancode-public-domain", "MIT" ]
permissive
taisei-project/taisei
90a1358567c77555eabfdb340bb6adeb913e2ced
f1c156cacdb579e66d4bc1776d4d1809e93014d2
refs/heads/master
2023-09-04T06:25:18.445412
2023-09-02T17:31:06
2023-09-02T17:31:06
977,986
785
87
NOASSERTION
2023-04-29T18:16:47
2010-10-11T07:31:32
C
UTF-8
C
false
false
1,565
h
postprocess.h
/* * This software is licensed under the terms of the MIT License. * See COPYING for further information. * --- * Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>. * Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>. */ #pragma once #include "taisei.h" #include "resource.h" #include "shader_program.h" #include "renderer/api.h" #include "util/graphics.h" typedef struct PostprocessShader PostprocessShader; typedef struct PostprocessShaderUniform PostprocessShaderUniform; typedef union PostprocessShaderUniformValue PostprocessShaderUniformValue; struct PostprocessShader { LIST_INTERFACE(PostprocessShader); PostprocessShaderUniform *uniforms; ShaderProgram *shader; }; union PostprocessShaderUniformValue { int i; float f; }; struct PostprocessShaderUniform { LIST_INTERFACE(PostprocessShaderUniform); Uniform *uniform; union { PostprocessShaderUniformValue *values; Texture *texture; }; uint elements; }; typedef void (*PostprocessDrawFuncPtr)(Framebuffer *fb, double w, double h); typedef void (*PostprocessPrepareFuncPtr)(Framebuffer *fb, ShaderProgram *prog, void *arg); PostprocessShader *postprocess_load(const char *path, ResourceFlags flags); void postprocess_unload(PostprocessShader **list); void postprocess(PostprocessShader *ppshaders, FBPair *fbos, PostprocessPrepareFuncPtr prepare, PostprocessDrawFuncPtr draw, double width, double height, void *arg); extern ResourceHandler postprocess_res_handler; DEFINE_OPTIONAL_RESOURCE_GETTER(PostprocessShader, res_postprocess, RES_POSTPROCESS)
8b7fcb4b1e70129957f9172429d24ac94da12a92
0a3c13015bb2511faacfe39b2e29bf36ee4b8022
/sys/lv2/atom/atom-test.c
5189d9dc7c153d83948e984afe912cd0c3df5a2d
[ "Apache-2.0", "MIT" ]
permissive
RustAudio/rust-lv2
b941a79050e44b4ee16766e518093631a215f22d
44aac000be49216ddd00f46aa7e8a05bde4a09f7
refs/heads/develop
2023-07-19T09:10:30.820681
2021-11-29T00:40:48
2021-11-29T00:40:48
183,491,078
154
28
Apache-2.0
2023-07-05T13:56:30
2019-04-25T18:43:10
Rust
UTF-8
C
false
false
13,534
c
atom-test.c
/* Copyright 2012-2015 David Robillard <http://drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "lv2/atom/atom-test-utils.c" #include "lv2/atom/atom.h" #include "lv2/atom/forge.h" #include "lv2/atom/util.h" #include "lv2/urid/urid.h" #include <stdint.h> #include <stdlib.h> int main(void) { LV2_URID_Map map = { NULL, urid_map }; LV2_Atom_Forge forge; lv2_atom_forge_init(&forge, &map); LV2_URID eg_Object = urid_map(NULL, "http://example.org/Object"); LV2_URID eg_one = urid_map(NULL, "http://example.org/one"); LV2_URID eg_two = urid_map(NULL, "http://example.org/two"); LV2_URID eg_three = urid_map(NULL, "http://example.org/three"); LV2_URID eg_four = urid_map(NULL, "http://example.org/four"); LV2_URID eg_true = urid_map(NULL, "http://example.org/true"); LV2_URID eg_false = urid_map(NULL, "http://example.org/false"); LV2_URID eg_path = urid_map(NULL, "http://example.org/path"); LV2_URID eg_uri = urid_map(NULL, "http://example.org/uri"); LV2_URID eg_urid = urid_map(NULL, "http://example.org/urid"); LV2_URID eg_string = urid_map(NULL, "http://example.org/string"); LV2_URID eg_literal = urid_map(NULL, "http://example.org/literal"); LV2_URID eg_tuple = urid_map(NULL, "http://example.org/tuple"); LV2_URID eg_vector = urid_map(NULL, "http://example.org/vector"); LV2_URID eg_vector2 = urid_map(NULL, "http://example.org/vector2"); LV2_URID eg_seq = urid_map(NULL, "http://example.org/seq"); #define BUF_SIZE 1024 #define NUM_PROPS 15 uint8_t buf[BUF_SIZE]; lv2_atom_forge_set_buffer(&forge, buf, BUF_SIZE); LV2_Atom_Forge_Frame obj_frame; LV2_Atom* obj = lv2_atom_forge_deref( &forge, lv2_atom_forge_object(&forge, &obj_frame, 0, eg_Object)); // eg_one = (Int)1 lv2_atom_forge_key(&forge, eg_one); LV2_Atom_Int* one = (LV2_Atom_Int*)lv2_atom_forge_deref( &forge, lv2_atom_forge_int(&forge, 1)); if (one->body != 1) { return test_fail("%d != 1\n", one->body); } // eg_two = (Long)2 lv2_atom_forge_key(&forge, eg_two); LV2_Atom_Long* two = (LV2_Atom_Long*)lv2_atom_forge_deref( &forge, lv2_atom_forge_long(&forge, 2)); if (two->body != 2) { return test_fail("%ld != 2\n", two->body); } // eg_three = (Float)3.0 lv2_atom_forge_key(&forge, eg_three); LV2_Atom_Float* three = (LV2_Atom_Float*)lv2_atom_forge_deref( &forge, lv2_atom_forge_float(&forge, 3.0f)); if (three->body != 3) { return test_fail("%f != 3\n", three->body); } // eg_four = (Double)4.0 lv2_atom_forge_key(&forge, eg_four); LV2_Atom_Double* four = (LV2_Atom_Double*)lv2_atom_forge_deref( &forge, lv2_atom_forge_double(&forge, 4.0)); if (four->body != 4) { return test_fail("%ld != 4\n", four->body); } // eg_true = (Bool)1 lv2_atom_forge_key(&forge, eg_true); LV2_Atom_Bool* t = (LV2_Atom_Bool*)lv2_atom_forge_deref( &forge, lv2_atom_forge_bool(&forge, true)); if (t->body != 1) { return test_fail("%ld != 1 (true)\n", t->body); } // eg_false = (Bool)0 lv2_atom_forge_key(&forge, eg_false); LV2_Atom_Bool* f = (LV2_Atom_Bool*)lv2_atom_forge_deref( &forge, lv2_atom_forge_bool(&forge, false)); if (f->body != 0) { return test_fail("%ld != 0 (false)\n", f->body); } // eg_path = (Path)"/foo/bar" const char* pstr = "/foo/bar"; const uint32_t pstr_len = (uint32_t)strlen(pstr); lv2_atom_forge_key(&forge, eg_path); LV2_Atom_String* path = (LV2_Atom_String*)lv2_atom_forge_deref( &forge, lv2_atom_forge_uri(&forge, pstr, pstr_len)); char* pbody = (char*)LV2_ATOM_BODY(path); if (strcmp(pbody, pstr)) { return test_fail("%s != \"%s\"\n", pbody, pstr); } // eg_uri = (URI)"http://example.org/value" const char* ustr = "http://example.org/value"; const uint32_t ustr_len = (uint32_t)strlen(ustr); lv2_atom_forge_key(&forge, eg_uri); LV2_Atom_String* uri = (LV2_Atom_String*)lv2_atom_forge_deref( &forge, lv2_atom_forge_uri(&forge, ustr, ustr_len)); char* ubody = (char*)LV2_ATOM_BODY(uri); if (strcmp(ubody, ustr)) { return test_fail("%s != \"%s\"\n", ubody, ustr); } // eg_urid = (URID)"http://example.org/value" LV2_URID eg_value = urid_map(NULL, "http://example.org/value"); lv2_atom_forge_key(&forge, eg_urid); LV2_Atom_URID* urid = (LV2_Atom_URID*)lv2_atom_forge_deref( &forge, lv2_atom_forge_urid(&forge, eg_value)); if (urid->body != eg_value) { return test_fail("%u != %u\n", urid->body, eg_value); } // eg_string = (String)"hello" lv2_atom_forge_key(&forge, eg_string); LV2_Atom_String* string = (LV2_Atom_String*)lv2_atom_forge_deref( &forge, lv2_atom_forge_string( &forge, "hello", strlen("hello"))); char* sbody = (char*)LV2_ATOM_BODY(string); if (strcmp(sbody, "hello")) { return test_fail("%s != \"hello\"\n", sbody); } // eg_literal = (Literal)"hello"@fr lv2_atom_forge_key(&forge, eg_literal); LV2_Atom_Literal* literal = (LV2_Atom_Literal*)lv2_atom_forge_deref( &forge, lv2_atom_forge_literal( &forge, "bonjour", strlen("bonjour"), 0, urid_map(NULL, "http://lexvo.org/id/term/fr"))); char* lbody = (char*)LV2_ATOM_CONTENTS(LV2_Atom_Literal, literal); if (strcmp(lbody, "bonjour")) { return test_fail("%s != \"bonjour\"\n", lbody); } // eg_tuple = "foo",true lv2_atom_forge_key(&forge, eg_tuple); LV2_Atom_Forge_Frame tuple_frame; LV2_Atom_Tuple* tuple = (LV2_Atom_Tuple*)lv2_atom_forge_deref( &forge, lv2_atom_forge_tuple(&forge, &tuple_frame)); LV2_Atom_String* tup0 = (LV2_Atom_String*)lv2_atom_forge_deref( &forge, lv2_atom_forge_string( &forge, "foo", strlen("foo"))); LV2_Atom_Bool* tup1 = (LV2_Atom_Bool*)lv2_atom_forge_deref( &forge, lv2_atom_forge_bool(&forge, true)); lv2_atom_forge_pop(&forge, &tuple_frame); LV2_Atom* i = lv2_atom_tuple_begin(tuple); if (lv2_atom_tuple_is_end(LV2_ATOM_BODY(tuple), tuple->atom.size, i)) { return test_fail("Tuple iterator is empty\n"); } LV2_Atom* tup0i = i; if (!lv2_atom_equals((LV2_Atom*)tup0, tup0i)) { return test_fail("Corrupt tuple element 0\n"); } i = lv2_atom_tuple_next(i); if (lv2_atom_tuple_is_end(LV2_ATOM_BODY(tuple), tuple->atom.size, i)) { return test_fail("Premature end of tuple iterator\n"); } LV2_Atom* tup1i = i; if (!lv2_atom_equals((LV2_Atom*)tup1, tup1i)) { return test_fail("Corrupt tuple element 1\n"); } i = lv2_atom_tuple_next(i); if (!lv2_atom_tuple_is_end(LV2_ATOM_BODY(tuple), tuple->atom.size, i)) { return test_fail("Tuple iter is not at end\n"); } // eg_vector = (Vector<Int>)1,2,3,4 lv2_atom_forge_key(&forge, eg_vector); int32_t elems[] = { 1, 2, 3, 4 }; LV2_Atom_Vector* vector = (LV2_Atom_Vector*)lv2_atom_forge_deref( &forge, lv2_atom_forge_vector( &forge, sizeof(int32_t), forge.Int, 4, elems)); void* vec_body = LV2_ATOM_CONTENTS(LV2_Atom_Vector, vector); if (memcmp(elems, vec_body, sizeof(elems))) { return test_fail("Corrupt vector\n"); } // eg_vector2 = (Vector<Int>)1,2,3,4 lv2_atom_forge_key(&forge, eg_vector2); LV2_Atom_Forge_Frame vec_frame; LV2_Atom_Vector* vector2 = (LV2_Atom_Vector*)lv2_atom_forge_deref( &forge, lv2_atom_forge_vector_head( &forge, &vec_frame, sizeof(int32_t), forge.Int)); for (unsigned e = 0; e < sizeof(elems) / sizeof(int32_t); ++e) { lv2_atom_forge_int(&forge, elems[e]); } lv2_atom_forge_pop(&forge, &vec_frame); if (!lv2_atom_equals(&vector->atom, &vector2->atom)) { return test_fail("Vector != Vector2\n"); } // eg_seq = (Sequence)1, 2 lv2_atom_forge_key(&forge, eg_seq); LV2_Atom_Forge_Frame seq_frame; LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)lv2_atom_forge_deref( &forge, lv2_atom_forge_sequence_head(&forge, &seq_frame, 0)); lv2_atom_forge_frame_time(&forge, 0); lv2_atom_forge_int(&forge, 1); lv2_atom_forge_frame_time(&forge, 1); lv2_atom_forge_int(&forge, 2); lv2_atom_forge_pop(&forge, &seq_frame); lv2_atom_forge_pop(&forge, &obj_frame); // Test equality LV2_Atom_Int itwo = { { forge.Int, sizeof(int32_t) }, 2 }; if (lv2_atom_equals((LV2_Atom*)one, (LV2_Atom*)two)) { return test_fail("1 == 2.0\n"); } else if (lv2_atom_equals((LV2_Atom*)one, (LV2_Atom*)&itwo)) { return test_fail("1 == 2\n"); } else if (!lv2_atom_equals((LV2_Atom*)one, (LV2_Atom*)one)) { return test_fail("1 != 1\n"); } unsigned n_events = 0; LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { if (ev->time.frames != n_events) { return test_fail("Corrupt event %u has bad time\n", n_events); } else if (ev->body.type != forge.Int) { return test_fail("Corrupt event %u has bad type\n", n_events); } else if (((LV2_Atom_Int*)&ev->body)->body != (int)n_events + 1) { return test_fail("Event %u != %d\n", n_events, n_events + 1); } ++n_events; } int n_props = 0; LV2_ATOM_OBJECT_FOREACH((LV2_Atom_Object*)obj, prop) { if (!prop->key) { return test_fail("Corrupt property %u has no key\n", n_props); } else if (prop->context) { return test_fail("Corrupt property %u has context\n", n_props); } ++n_props; } if (n_props != NUM_PROPS) { return test_fail("Corrupt object has %u properties != %u\n", n_props, NUM_PROPS); } struct { const LV2_Atom* one; const LV2_Atom* two; const LV2_Atom* three; const LV2_Atom* four; const LV2_Atom* affirmative; const LV2_Atom* negative; const LV2_Atom* path; const LV2_Atom* uri; const LV2_Atom* urid; const LV2_Atom* string; const LV2_Atom* literal; const LV2_Atom* tuple; const LV2_Atom* vector; const LV2_Atom* vector2; const LV2_Atom* seq; } matches; memset(&matches, 0, sizeof(matches)); LV2_Atom_Object_Query q[] = { { eg_one, &matches.one }, { eg_two, &matches.two }, { eg_three, &matches.three }, { eg_four, &matches.four }, { eg_true, &matches.affirmative }, { eg_false, &matches.negative }, { eg_path, &matches.path }, { eg_uri, &matches.uri }, { eg_urid, &matches.urid }, { eg_string, &matches.string }, { eg_literal, &matches.literal }, { eg_tuple, &matches.tuple }, { eg_vector, &matches.vector }, { eg_vector2, &matches.vector2 }, { eg_seq, &matches.seq }, LV2_ATOM_OBJECT_QUERY_END }; int n_matches = lv2_atom_object_query((LV2_Atom_Object*)obj, q); for (int n = 0; n < 2; ++n) { if (n_matches != n_props) { return test_fail("Query failed, %u matches != %u\n", n_matches, n_props); } else if (!lv2_atom_equals((LV2_Atom*)one, matches.one)) { return test_fail("Bad match one\n"); } else if (!lv2_atom_equals((LV2_Atom*)two, matches.two)) { return test_fail("Bad match two\n"); } else if (!lv2_atom_equals((LV2_Atom*)three, matches.three)) { return test_fail("Bad match three\n"); } else if (!lv2_atom_equals((LV2_Atom*)four, matches.four)) { return test_fail("Bad match four\n"); } else if (!lv2_atom_equals((LV2_Atom*)t, matches.affirmative)) { return test_fail("Bad match true\n"); } else if (!lv2_atom_equals((LV2_Atom*)f, matches.negative)) { return test_fail("Bad match false\n"); } else if (!lv2_atom_equals((LV2_Atom*)path, matches.path)) { return test_fail("Bad match path\n"); } else if (!lv2_atom_equals((LV2_Atom*)uri, matches.uri)) { return test_fail("Bad match URI\n"); } else if (!lv2_atom_equals((LV2_Atom*)string, matches.string)) { return test_fail("Bad match string\n"); } else if (!lv2_atom_equals((LV2_Atom*)literal, matches.literal)) { return test_fail("Bad match literal\n"); } else if (!lv2_atom_equals((LV2_Atom*)tuple, matches.tuple)) { return test_fail("Bad match tuple\n"); } else if (!lv2_atom_equals((LV2_Atom*)vector, matches.vector)) { return test_fail("Bad match vector\n"); } else if (!lv2_atom_equals((LV2_Atom*)vector, matches.vector2)) { return test_fail("Bad match vector2\n"); } else if (!lv2_atom_equals((LV2_Atom*)seq, matches.seq)) { return test_fail("Bad match sequence\n"); } memset(&matches, 0, sizeof(matches)); n_matches = lv2_atom_object_get((LV2_Atom_Object*)obj, eg_one, &matches.one, eg_two, &matches.two, eg_three, &matches.three, eg_four, &matches.four, eg_true, &matches.affirmative, eg_false, &matches.negative, eg_path, &matches.path, eg_uri, &matches.uri, eg_urid, &matches.urid, eg_string, &matches.string, eg_literal, &matches.literal, eg_tuple, &matches.tuple, eg_vector, &matches.vector, eg_vector2, &matches.vector2, eg_seq, &matches.seq, 0); } free_urid_map(); return 0; }
f6d4d0ee2f641a6c35f3d92ef48af0aa13ad4dbd
e73547787354afd9b717ea57fe8dd0695d161821
/src/world/area_kkj/kkj_28/kkj_28_0_header.c
fb9959282ad921104f35b68c1cc22d2660bd2314
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
246
c
kkj_28_0_header.c
#include "kkj_28.h" EntryList N(Entrances) = { [kkj_28_ENTRY_0] { 325.0, 0.0, -30.0, 270.0 }, }; MapSettings N(settings) = { .main = &N(EVS_Main), .entryList = &N(Entrances), .entryCount = ENTRY_COUNT(N(Entrances)), };
b2e3cfb0daf203529415dbdce134b78752eed986
e16ebe774e710b19e78006bc45276161a26b40d9
/BLACS/SRC/BI_dvvamn.c
d28c071abbafcc07123d3fe641acc44b4071e29d
[ "BSD-3-Clause-Open-MPI" ]
permissive
Reference-ScaLAPACK/scalapack
1f06618119a19c2b0af51ad7cdee61aee84d835d
2072b8602f0a5a84d77a712121f7715c58a2e80d
refs/heads/master
2022-12-02T05:15:46.251774
2022-11-23T14:16:15
2022-11-23T14:16:15
139,287,059
108
56
NOASSERTION
2022-11-23T14:16:16
2018-06-30T23:24:28
Fortran
UTF-8
C
false
false
674
c
BI_dvvamn.c
#include "Bdef.h" void BI_dvvamn(Int N, char *vec1, char *vec2) { double *v1=(double*)vec1, *v2=(double*)vec2; double diff; BI_DistType *dist1, *dist2; Int i, k; k = N * sizeof(double); i = k % sizeof(BI_DistType); if (i) k += sizeof(BI_DistType) - i; dist1 = (BI_DistType *) &vec1[k]; dist2 = (BI_DistType *) &vec2[k]; for (k=0; k < N; k++) { diff = Rabs(v1[k]) - Rabs(v2[k]); if (diff > 0) { v1[k] = v2[k]; dist1[k] = dist2[k]; } else if (diff == 0) { if (dist1[k] > dist2[k]) { v1[k] = v2[k]; dist1[k] = dist2[k]; } } } }
2f25adcbec6af8533d4bcc9591dd57627729fba4
20e1c2f5cfac01f6b007124fa7792dd69751a6bb
/src/ut-stubs/osapi-common-stubs.c
d3e85afb63f5d134031f12f3131fa617dddb05c2
[ "Apache-2.0" ]
permissive
nasa/osal
71f159b767ba4a8c39df48f238b4f296cc571ac8
99e3b4007da51031b521d90390526e123ff740b4
refs/heads/main
2023-09-01T06:33:53.932829
2023-08-18T14:27:02
2023-08-18T14:27:02
4,814,601
493
229
Apache-2.0
2023-09-13T13:57:40
2012-06-27T23:10:37
C
UTF-8
C
false
false
3,418
c
osapi-common-stubs.c
/************************************************************************ * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” * * Copyright (c) 2020 United States Government as represented by the * Administrator of the National Aeronautics and Space Administration. * All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ************************************************************************/ /** * @file * * Auto-Generated stub implementations for functions defined in osapi-common header */ #include "osapi-common.h" #include "utgenstub.h" /* * ---------------------------------------------------- * Generated stub function for OS_API_Init() * ---------------------------------------------------- */ int32 OS_API_Init(void) { UT_GenStub_SetupReturnBuffer(OS_API_Init, int32); UT_GenStub_Execute(OS_API_Init, Basic, NULL); return UT_GenStub_GetReturnValue(OS_API_Init, int32); } /* * ---------------------------------------------------- * Generated stub function for OS_API_Teardown() * ---------------------------------------------------- */ void OS_API_Teardown(void) { UT_GenStub_Execute(OS_API_Teardown, Basic, NULL); } /* * ---------------------------------------------------- * Generated stub function for OS_ApplicationExit() * ---------------------------------------------------- */ void OS_ApplicationExit(int32 Status) { UT_GenStub_AddParam(OS_ApplicationExit, int32, Status); UT_GenStub_Execute(OS_ApplicationExit, Basic, NULL); } /* * ---------------------------------------------------- * Generated stub function for OS_ApplicationShutdown() * ---------------------------------------------------- */ void OS_ApplicationShutdown(uint8 flag) { UT_GenStub_AddParam(OS_ApplicationShutdown, uint8, flag); UT_GenStub_Execute(OS_ApplicationShutdown, Basic, NULL); } /* * ---------------------------------------------------- * Generated stub function for OS_DeleteAllObjects() * ---------------------------------------------------- */ void OS_DeleteAllObjects(void) { UT_GenStub_Execute(OS_DeleteAllObjects, Basic, NULL); } /* * ---------------------------------------------------- * Generated stub function for OS_IdleLoop() * ---------------------------------------------------- */ void OS_IdleLoop(void) { UT_GenStub_Execute(OS_IdleLoop, Basic, NULL); } /* * ---------------------------------------------------- * Generated stub function for OS_RegisterEventHandler() * ---------------------------------------------------- */ int32 OS_RegisterEventHandler(OS_EventHandler_t handler) { UT_GenStub_SetupReturnBuffer(OS_RegisterEventHandler, int32); UT_GenStub_AddParam(OS_RegisterEventHandler, OS_EventHandler_t, handler); UT_GenStub_Execute(OS_RegisterEventHandler, Basic, NULL); return UT_GenStub_GetReturnValue(OS_RegisterEventHandler, int32); }
fc8ae7a0719e6fa4e91bf3ae2a857d05f101bdee
2f5ecc2614a199f6793264799e725ed6d005cf59
/TextDemo/main/main.c
e3ffa422968580d069453289b339d1e06238e1a4
[ "MIT" ]
permissive
nopnop2002/esp-idf-ssd1306
37180a5376bdf40a24c5c1ed1447bbe4dc1ebeaa
d79054b91068f7011ae3971b5a4b747736b85e9f
refs/heads/master
2023-08-04T06:23:58.430096
2023-07-24T21:21:29
2023-07-24T21:21:29
181,906,267
184
61
MIT
2022-10-01T08:03:11
2019-04-17T14:15:50
C
UTF-8
C
false
false
6,289
c
main.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "ssd1306.h" #include "font8x8_basic.h" /* You have to set this config value with menuconfig CONFIG_INTERFACE for i2c CONFIG_MODEL CONFIG_SDA_GPIO CONFIG_SCL_GPIO CONFIG_RESET_GPIO for SPI CONFIG_CS_GPIO CONFIG_DC_GPIO CONFIG_RESET_GPIO */ #define tag "SSD1306" void app_main(void) { SSD1306_t dev; int center, top, bottom; char lineChar[20]; #if CONFIG_I2C_INTERFACE ESP_LOGI(tag, "INTERFACE is i2c"); ESP_LOGI(tag, "CONFIG_SDA_GPIO=%d",CONFIG_SDA_GPIO); ESP_LOGI(tag, "CONFIG_SCL_GPIO=%d",CONFIG_SCL_GPIO); ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); i2c_master_init(&dev, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO, CONFIG_RESET_GPIO); #endif // CONFIG_I2C_INTERFACE #if CONFIG_SPI_INTERFACE ESP_LOGI(tag, "INTERFACE is SPI"); ESP_LOGI(tag, "CONFIG_MOSI_GPIO=%d",CONFIG_MOSI_GPIO); ESP_LOGI(tag, "CONFIG_SCLK_GPIO=%d",CONFIG_SCLK_GPIO); ESP_LOGI(tag, "CONFIG_CS_GPIO=%d",CONFIG_CS_GPIO); ESP_LOGI(tag, "CONFIG_DC_GPIO=%d",CONFIG_DC_GPIO); ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO); #endif // CONFIG_SPI_INTERFACE #if CONFIG_FLIP dev._flip = true; ESP_LOGW(tag, "Flip upside down"); #endif #if CONFIG_SSD1306_128x64 ESP_LOGI(tag, "Panel is 128x64"); ssd1306_init(&dev, 128, 64); #endif // CONFIG_SSD1306_128x64 #if CONFIG_SSD1306_128x32 ESP_LOGI(tag, "Panel is 128x32"); ssd1306_init(&dev, 128, 32); #endif // CONFIG_SSD1306_128x32 ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); ssd1306_display_text_x3(&dev, 0, "Hello", 5, false); vTaskDelay(3000 / portTICK_PERIOD_MS); #if CONFIG_SSD1306_128x64 top = 2; center = 3; bottom = 8; ssd1306_display_text(&dev, 0, "SSD1306 128x64", 14, false); ssd1306_display_text(&dev, 1, "ABCDEFGHIJKLMNOP", 16, false); ssd1306_display_text(&dev, 2, "abcdefghijklmnop",16, false); ssd1306_display_text(&dev, 3, "Hello World!!", 13, false); //ssd1306_clear_line(&dev, 4, true); //ssd1306_clear_line(&dev, 5, true); //ssd1306_clear_line(&dev, 6, true); //ssd1306_clear_line(&dev, 7, true); ssd1306_display_text(&dev, 4, "SSD1306 128x64", 14, true); ssd1306_display_text(&dev, 5, "ABCDEFGHIJKLMNOP", 16, true); ssd1306_display_text(&dev, 6, "abcdefghijklmnop",16, true); ssd1306_display_text(&dev, 7, "Hello World!!", 13, true); #endif // CONFIG_SSD1306_128x64 #if CONFIG_SSD1306_128x32 top = 1; center = 1; bottom = 4; ssd1306_display_text(&dev, 0, "SSD1306 128x32", 14, false); ssd1306_display_text(&dev, 1, "Hello World!!", 13, false); //ssd1306_clear_line(&dev, 2, true); //ssd1306_clear_line(&dev, 3, true); ssd1306_display_text(&dev, 2, "SSD1306 128x32", 14, true); ssd1306_display_text(&dev, 3, "Hello World!!", 13, true); #endif // CONFIG_SSD1306_128x32 vTaskDelay(3000 / portTICK_PERIOD_MS); // Display Count Down uint8_t image[24]; memset(image, 0, sizeof(image)); ssd1306_display_image(&dev, top, (6*8-1), image, sizeof(image)); ssd1306_display_image(&dev, top+1, (6*8-1), image, sizeof(image)); ssd1306_display_image(&dev, top+2, (6*8-1), image, sizeof(image)); for(int font=0x39;font>0x30;font--) { memset(image, 0, sizeof(image)); ssd1306_display_image(&dev, top+1, (7*8-1), image, 8); memcpy(image, font8x8_basic_tr[font], 8); if (dev._flip) ssd1306_flip(image, 8); ssd1306_display_image(&dev, top+1, (7*8-1), image, 8); vTaskDelay(1000 / portTICK_PERIOD_MS); } // Scroll Up ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); ssd1306_display_text(&dev, 0, "---Scroll UP---", 16, true); //ssd1306_software_scroll(&dev, 7, 1); ssd1306_software_scroll(&dev, (dev._pages - 1), 1); for (int line=0;line<bottom+10;line++) { lineChar[0] = 0x01; sprintf(&lineChar[1], " Line %02d", line); ssd1306_scroll_text(&dev, lineChar, strlen(lineChar), false); vTaskDelay(500 / portTICK_PERIOD_MS); } vTaskDelay(3000 / portTICK_PERIOD_MS); // Scroll Down ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); ssd1306_display_text(&dev, 0, "--Scroll DOWN--", 16, true); //ssd1306_software_scroll(&dev, 1, 7); ssd1306_software_scroll(&dev, 1, (dev._pages - 1) ); for (int line=0;line<bottom+10;line++) { lineChar[0] = 0x02; sprintf(&lineChar[1], " Line %02d", line); ssd1306_scroll_text(&dev, lineChar, strlen(lineChar), false); vTaskDelay(500 / portTICK_PERIOD_MS); } vTaskDelay(3000 / portTICK_PERIOD_MS); // Page Down ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); ssd1306_display_text(&dev, 0, "---Page DOWN---", 16, true); ssd1306_software_scroll(&dev, 1, (dev._pages-1) ); for (int line=0;line<bottom+10;line++) { //if ( (line % 7) == 0) ssd1306_scroll_clear(&dev); if ( (line % (dev._pages-1)) == 0) ssd1306_scroll_clear(&dev); lineChar[0] = 0x02; sprintf(&lineChar[1], " Line %02d", line); ssd1306_scroll_text(&dev, lineChar, strlen(lineChar), false); vTaskDelay(500 / portTICK_PERIOD_MS); } vTaskDelay(3000 / portTICK_PERIOD_MS); // Horizontal Scroll ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); ssd1306_display_text(&dev, center, "Horizontal", 10, false); ssd1306_hardware_scroll(&dev, SCROLL_RIGHT); vTaskDelay(5000 / portTICK_PERIOD_MS); ssd1306_hardware_scroll(&dev, SCROLL_LEFT); vTaskDelay(5000 / portTICK_PERIOD_MS); ssd1306_hardware_scroll(&dev, SCROLL_STOP); // Vertical Scroll ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); ssd1306_display_text(&dev, center, "Vertical", 8, false); ssd1306_hardware_scroll(&dev, SCROLL_DOWN); vTaskDelay(5000 / portTICK_PERIOD_MS); ssd1306_hardware_scroll(&dev, SCROLL_UP); vTaskDelay(5000 / portTICK_PERIOD_MS); ssd1306_hardware_scroll(&dev, SCROLL_STOP); // Invert ssd1306_clear_screen(&dev, true); ssd1306_contrast(&dev, 0xff); ssd1306_display_text(&dev, center, " Good Bye!!", 12, true); vTaskDelay(5000 / portTICK_PERIOD_MS); // Fade Out ssd1306_fadeout(&dev); #if 0 // Fade Out for(int contrast=0xff;contrast>0;contrast=contrast-0x20) { ssd1306_contrast(&dev, contrast); vTaskDelay(40); } #endif // Restart module esp_restart(); }
27c2e1e4a928de8b0fdd231a65a8ac321aa40407
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/mips/mti-malta/malta-memory.c
1f73d63e92a765d3ab1d829244a19e57dab8bd8e
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
3,329
c
malta-memory.c
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * PROM library functions for acquiring/using memory descriptors given to * us from the YAMON. * * Copyright (C) 1999,2000,2012 MIPS Technologies, Inc. * All rights reserved. * Authors: Carsten Langgaard <carstenl@mips.com> * Steven J. Hill <sjhill@mips.com> */ #include <linux/init.h> #include <linux/bootmem.h> #include <linux/string.h> #include <asm/bootinfo.h> #include <asm/sections.h> #include <asm/fw/fw.h> static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS]; /* determined physical memory size, not overridden by command line args */ unsigned long physical_memsize = 0L; fw_memblock_t * __init fw_getmdesc(void) { char *memsize_str, *ptr; unsigned int memsize; static char cmdline[COMMAND_LINE_SIZE] __initdata; long val; int tmp; /* otherwise look in the environment */ memsize_str = fw_getenv("memsize"); if (!memsize_str) { pr_warn("memsize not set in YAMON, set to default (32Mb)\n"); physical_memsize = 0x02000000; } else { tmp = kstrtol(memsize_str, 0, &val); physical_memsize = (unsigned long)val; } #ifdef CONFIG_CPU_BIG_ENDIAN /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last word of physical memory */ physical_memsize -= PAGE_SIZE; #endif /* Check the command line for a memsize directive that overrides the physical/default amount */ strcpy(cmdline, arcs_cmdline); ptr = strstr(cmdline, "memsize="); if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' ')) ptr = strstr(ptr, " memsize="); if (ptr) memsize = memparse(ptr + 8, &ptr); else memsize = physical_memsize; memset(mdesc, 0, sizeof(mdesc)); mdesc[0].type = fw_dontuse; mdesc[0].base = 0x00000000; mdesc[0].size = 0x00001000; mdesc[1].type = fw_code; mdesc[1].base = 0x00001000; mdesc[1].size = 0x000ef000; /* * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the * south bridge and PCI access always forwarded to the ISA Bus and * BIOSCS# is always generated. * This mean that this area can't be used as DMA memory for PCI * devices. */ mdesc[2].type = fw_dontuse; mdesc[2].base = 0x000f0000; mdesc[2].size = 0x00010000; mdesc[3].type = fw_dontuse; mdesc[3].base = 0x00100000; mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base; mdesc[4].type = fw_free; mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end)); mdesc[4].size = memsize - mdesc[4].base; return &mdesc[0]; } static int __init fw_memtype_classify(unsigned int type) { switch (type) { case fw_free: return BOOT_MEM_RAM; case fw_code: return BOOT_MEM_ROM_DATA; default: return BOOT_MEM_RESERVED; } } void __init fw_meminit(void) { fw_memblock_t *p; p = fw_getmdesc(); while (p->size) { long type; unsigned long base, size; type = fw_memtype_classify(p->type); base = p->base; size = p->size; add_memory_region(base, size, type); p++; } } void __init prom_free_prom_memory(void) { unsigned long addr; int i; for (i = 0; i < boot_mem_map.nr_map; i++) { if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) continue; addr = boot_mem_map.map[i].addr; free_init_pages("YAMON memory", addr, addr + boot_mem_map.map[i].size); } }
3cfb7cb8142db6d8ab28348f1d38056b41e733ff
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/fs/xfs/xfs_dir2.c
b26a50f9921db60e746d43946b644415ba24ca6a
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
16,367
c
xfs_dir2.c
/* * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. * All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "xfs.h" #include "xfs_fs.h" #include "xfs_types.h" #include "xfs_log.h" #include "xfs_inum.h" #include "xfs_trans.h" #include "xfs_sb.h" #include "xfs_ag.h" #include "xfs_mount.h" #include "xfs_da_btree.h" #include "xfs_bmap_btree.h" #include "xfs_alloc_btree.h" #include "xfs_dinode.h" #include "xfs_inode.h" #include "xfs_inode_item.h" #include "xfs_bmap.h" #include "xfs_dir2.h" #include "xfs_dir2_format.h" #include "xfs_dir2_priv.h" #include "xfs_error.h" #include "xfs_vnodeops.h" #include "xfs_trace.h" struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2}; /* * ASCII case-insensitive (ie. A-Z) support for directories that was * used in IRIX. */ STATIC xfs_dahash_t xfs_ascii_ci_hashname( struct xfs_name *name) { xfs_dahash_t hash; int i; for (i = 0, hash = 0; i < name->len; i++) hash = tolower(name->name[i]) ^ rol32(hash, 7); return hash; } STATIC enum xfs_dacmp xfs_ascii_ci_compname( struct xfs_da_args *args, const unsigned char *name, int len) { enum xfs_dacmp result; int i; if (args->namelen != len) return XFS_CMP_DIFFERENT; result = XFS_CMP_EXACT; for (i = 0; i < len; i++) { if (args->name[i] == name[i]) continue; if (tolower(args->name[i]) != tolower(name[i])) return XFS_CMP_DIFFERENT; result = XFS_CMP_CASE; } return result; } static struct xfs_nameops xfs_ascii_ci_nameops = { .hashname = xfs_ascii_ci_hashname, .compname = xfs_ascii_ci_compname, }; void xfs_dir_mount( xfs_mount_t *mp) { ASSERT(xfs_sb_version_hasdirv2(&mp->m_sb)); ASSERT((1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog)) <= XFS_MAX_BLOCKSIZE); mp->m_dirblksize = 1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog); mp->m_dirblkfsbs = 1 << mp->m_sb.sb_dirblklog; mp->m_dirdatablk = xfs_dir2_db_to_da(mp, XFS_DIR2_DATA_FIRSTDB(mp)); mp->m_dirleafblk = xfs_dir2_db_to_da(mp, XFS_DIR2_LEAF_FIRSTDB(mp)); mp->m_dirfreeblk = xfs_dir2_db_to_da(mp, XFS_DIR2_FREE_FIRSTDB(mp)); mp->m_attr_node_ents = (mp->m_sb.sb_blocksize - (uint)sizeof(xfs_da_node_hdr_t)) / (uint)sizeof(xfs_da_node_entry_t); mp->m_dir_node_ents = (mp->m_dirblksize - (uint)sizeof(xfs_da_node_hdr_t)) / (uint)sizeof(xfs_da_node_entry_t); mp->m_dir_magicpct = (mp->m_dirblksize * 37) / 100; if (xfs_sb_version_hasasciici(&mp->m_sb)) mp->m_dirnameops = &xfs_ascii_ci_nameops; else mp->m_dirnameops = &xfs_default_nameops; } /* * Return 1 if directory contains only "." and "..". */ int xfs_dir_isempty( xfs_inode_t *dp) { xfs_dir2_sf_hdr_t *sfp; ASSERT(S_ISDIR(dp->i_d.di_mode)); if (dp->i_d.di_size == 0) /* might happen during shutdown. */ return 1; if (dp->i_d.di_size > XFS_IFORK_DSIZE(dp)) return 0; sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; return !sfp->count; } /* * Validate a given inode number. */ int xfs_dir_ino_validate( xfs_mount_t *mp, xfs_ino_t ino) { xfs_agblock_t agblkno; xfs_agino_t agino; xfs_agnumber_t agno; int ino_ok; int ioff; agno = XFS_INO_TO_AGNO(mp, ino); agblkno = XFS_INO_TO_AGBNO(mp, ino); ioff = XFS_INO_TO_OFFSET(mp, ino); agino = XFS_OFFBNO_TO_AGINO(mp, agblkno, ioff); ino_ok = agno < mp->m_sb.sb_agcount && agblkno < mp->m_sb.sb_agblocks && agblkno != 0 && ioff < (1 << mp->m_sb.sb_inopblog) && XFS_AGINO_TO_INO(mp, agno, agino) == ino; if (unlikely(XFS_TEST_ERROR(!ino_ok, mp, XFS_ERRTAG_DIR_INO_VALIDATE, XFS_RANDOM_DIR_INO_VALIDATE))) { xfs_warn(mp, "Invalid inode number 0x%Lx", (unsigned long long) ino); XFS_ERROR_REPORT("xfs_dir_ino_validate", XFS_ERRLEVEL_LOW, mp); return XFS_ERROR(EFSCORRUPTED); } return 0; } /* * Initialize a directory with its "." and ".." entries. */ int xfs_dir_init( xfs_trans_t *tp, xfs_inode_t *dp, xfs_inode_t *pdp) { xfs_da_args_t args; int error; memset((char *)&args, 0, sizeof(args)); args.dp = dp; args.trans = tp; ASSERT(S_ISDIR(dp->i_d.di_mode)); if ((error = xfs_dir_ino_validate(tp->t_mountp, pdp->i_ino))) return error; return xfs_dir2_sf_create(&args, pdp->i_ino); } /* Enter a name in a directory. */ int xfs_dir_createname( xfs_trans_t *tp, xfs_inode_t *dp, struct xfs_name *name, xfs_ino_t inum, /* new entry inode number */ xfs_fsblock_t *first, /* bmap's firstblock */ xfs_bmap_free_t *flist, /* bmap's freeblock list */ xfs_extlen_t total) /* bmap's total block count */ { xfs_da_args_t args; int rval; int v; /* type-checking value */ ASSERT(S_ISDIR(dp->i_d.di_mode)); if ((rval = xfs_dir_ino_validate(tp->t_mountp, inum))) return rval; XFS_STATS_INC(xs_dir_create); memset(&args, 0, sizeof(xfs_da_args_t)); args.name = name->name; args.namelen = name->len; args.hashval = dp->i_mount->m_dirnameops->hashname(name); args.inumber = inum; args.dp = dp; args.firstblock = first; args.flist = flist; args.total = total; args.whichfork = XFS_DATA_FORK; args.trans = tp; args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) rval = xfs_dir2_sf_addname(&args); else if ((rval = xfs_dir2_isblock(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_block_addname(&args); else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_leaf_addname(&args); else rval = xfs_dir2_node_addname(&args); return rval; } /* * If doing a CI lookup and case-insensitive match, dup actual name into * args.value. Return EEXIST for success (ie. name found) or an error. */ int xfs_dir_cilookup_result( struct xfs_da_args *args, const unsigned char *name, int len) { if (args->cmpresult == XFS_CMP_DIFFERENT) return ENOENT; if (args->cmpresult != XFS_CMP_CASE || !(args->op_flags & XFS_DA_OP_CILOOKUP)) return EEXIST; args->value = kmem_alloc(len, KM_NOFS | KM_MAYFAIL); if (!args->value) return ENOMEM; memcpy(args->value, name, len); args->valuelen = len; return EEXIST; } /* * Lookup a name in a directory, give back the inode number. * If ci_name is not NULL, returns the actual name in ci_name if it differs * to name, or ci_name->name is set to NULL for an exact match. */ int xfs_dir_lookup( xfs_trans_t *tp, xfs_inode_t *dp, struct xfs_name *name, xfs_ino_t *inum, /* out: inode number */ struct xfs_name *ci_name) /* out: actual name if CI match */ { xfs_da_args_t args; int rval; int v; /* type-checking value */ ASSERT(S_ISDIR(dp->i_d.di_mode)); XFS_STATS_INC(xs_dir_lookup); memset(&args, 0, sizeof(xfs_da_args_t)); args.name = name->name; args.namelen = name->len; args.hashval = dp->i_mount->m_dirnameops->hashname(name); args.dp = dp; args.whichfork = XFS_DATA_FORK; args.trans = tp; args.op_flags = XFS_DA_OP_OKNOENT; if (ci_name) args.op_flags |= XFS_DA_OP_CILOOKUP; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) rval = xfs_dir2_sf_lookup(&args); else if ((rval = xfs_dir2_isblock(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_block_lookup(&args); else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_leaf_lookup(&args); else rval = xfs_dir2_node_lookup(&args); if (rval == EEXIST) rval = 0; if (!rval) { *inum = args.inumber; if (ci_name) { ci_name->name = args.value; ci_name->len = args.valuelen; } } return rval; } /* * Remove an entry from a directory. */ int xfs_dir_removename( xfs_trans_t *tp, xfs_inode_t *dp, struct xfs_name *name, xfs_ino_t ino, xfs_fsblock_t *first, /* bmap's firstblock */ xfs_bmap_free_t *flist, /* bmap's freeblock list */ xfs_extlen_t total) /* bmap's total block count */ { xfs_da_args_t args; int rval; int v; /* type-checking value */ ASSERT(S_ISDIR(dp->i_d.di_mode)); XFS_STATS_INC(xs_dir_remove); memset(&args, 0, sizeof(xfs_da_args_t)); args.name = name->name; args.namelen = name->len; args.hashval = dp->i_mount->m_dirnameops->hashname(name); args.inumber = ino; args.dp = dp; args.firstblock = first; args.flist = flist; args.total = total; args.whichfork = XFS_DATA_FORK; args.trans = tp; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) rval = xfs_dir2_sf_removename(&args); else if ((rval = xfs_dir2_isblock(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_block_removename(&args); else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_leaf_removename(&args); else rval = xfs_dir2_node_removename(&args); return rval; } /* * Read a directory. */ int xfs_readdir( xfs_inode_t *dp, void *dirent, size_t bufsize, xfs_off_t *offset, filldir_t filldir) { int rval; /* return value */ int v; /* type-checking value */ trace_xfs_readdir(dp); if (XFS_FORCED_SHUTDOWN(dp->i_mount)) return XFS_ERROR(EIO); ASSERT(S_ISDIR(dp->i_d.di_mode)); XFS_STATS_INC(xs_dir_getdents); if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) rval = xfs_dir2_sf_getdents(dp, dirent, offset, filldir); else if ((rval = xfs_dir2_isblock(NULL, dp, &v))) ; else if (v) rval = xfs_dir2_block_getdents(dp, dirent, offset, filldir); else rval = xfs_dir2_leaf_getdents(dp, dirent, bufsize, offset, filldir); return rval; } /* * Replace the inode number of a directory entry. */ int xfs_dir_replace( xfs_trans_t *tp, xfs_inode_t *dp, struct xfs_name *name, /* name of entry to replace */ xfs_ino_t inum, /* new inode number */ xfs_fsblock_t *first, /* bmap's firstblock */ xfs_bmap_free_t *flist, /* bmap's freeblock list */ xfs_extlen_t total) /* bmap's total block count */ { xfs_da_args_t args; int rval; int v; /* type-checking value */ ASSERT(S_ISDIR(dp->i_d.di_mode)); if ((rval = xfs_dir_ino_validate(tp->t_mountp, inum))) return rval; memset(&args, 0, sizeof(xfs_da_args_t)); args.name = name->name; args.namelen = name->len; args.hashval = dp->i_mount->m_dirnameops->hashname(name); args.inumber = inum; args.dp = dp; args.firstblock = first; args.flist = flist; args.total = total; args.whichfork = XFS_DATA_FORK; args.trans = tp; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) rval = xfs_dir2_sf_replace(&args); else if ((rval = xfs_dir2_isblock(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_block_replace(&args); else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_leaf_replace(&args); else rval = xfs_dir2_node_replace(&args); return rval; } /* * See if this entry can be added to the directory without allocating space. * First checks that the caller couldn't reserve enough space (resblks = 0). */ int xfs_dir_canenter( xfs_trans_t *tp, xfs_inode_t *dp, struct xfs_name *name, /* name of entry to add */ uint resblks) { xfs_da_args_t args; int rval; int v; /* type-checking value */ if (resblks) return 0; ASSERT(S_ISDIR(dp->i_d.di_mode)); memset(&args, 0, sizeof(xfs_da_args_t)); args.name = name->name; args.namelen = name->len; args.hashval = dp->i_mount->m_dirnameops->hashname(name); args.dp = dp; args.whichfork = XFS_DATA_FORK; args.trans = tp; args.op_flags = XFS_DA_OP_JUSTCHECK | XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) rval = xfs_dir2_sf_addname(&args); else if ((rval = xfs_dir2_isblock(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_block_addname(&args); else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) return rval; else if (v) rval = xfs_dir2_leaf_addname(&args); else rval = xfs_dir2_node_addname(&args); return rval; } /* * Utility routines. */ /* * Add a block to the directory. * * This routine is for data and free blocks, not leaf/node blocks which are * handled by xfs_da_grow_inode. */ int xfs_dir2_grow_inode( struct xfs_da_args *args, int space, /* v2 dir's space XFS_DIR2_xxx_SPACE */ xfs_dir2_db_t *dbp) /* out: block number added */ { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; xfs_fileoff_t bno; /* directory offset of new block */ int count; /* count of filesystem blocks */ int error; trace_xfs_dir2_grow_inode(args, space); /* * Set lowest possible block in the space requested. */ bno = XFS_B_TO_FSBT(mp, space * XFS_DIR2_SPACE_SIZE); count = mp->m_dirblkfsbs; error = xfs_da_grow_inode_int(args, &bno, count); if (error) return error; *dbp = xfs_dir2_da_to_db(mp, (xfs_dablk_t)bno); /* * Update file's size if this is the data space and it grew. */ if (space == XFS_DIR2_DATA_SPACE) { xfs_fsize_t size; /* directory file (data) size */ size = XFS_FSB_TO_B(mp, bno + count); if (size > dp->i_d.di_size) { dp->i_d.di_size = size; xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE); } } return 0; } /* * See if the directory is a single-block form directory. */ int xfs_dir2_isblock( xfs_trans_t *tp, xfs_inode_t *dp, int *vp) /* out: 1 is block, 0 is not block */ { xfs_fileoff_t last; /* last file offset */ xfs_mount_t *mp; int rval; mp = dp->i_mount; if ((rval = xfs_bmap_last_offset(tp, dp, &last, XFS_DATA_FORK))) return rval; rval = XFS_FSB_TO_B(mp, last) == mp->m_dirblksize; ASSERT(rval == 0 || dp->i_d.di_size == mp->m_dirblksize); *vp = rval; return 0; } /* * See if the directory is a single-leaf form directory. */ int xfs_dir2_isleaf( xfs_trans_t *tp, xfs_inode_t *dp, int *vp) /* out: 1 is leaf, 0 is not leaf */ { xfs_fileoff_t last; /* last file offset */ xfs_mount_t *mp; int rval; mp = dp->i_mount; if ((rval = xfs_bmap_last_offset(tp, dp, &last, XFS_DATA_FORK))) return rval; *vp = last == mp->m_dirleafblk + (1 << mp->m_sb.sb_dirblklog); return 0; } /* * Remove the given block from the directory. * This routine is used for data and free blocks, leaf/node are done * by xfs_da_shrink_inode. */ int xfs_dir2_shrink_inode( xfs_da_args_t *args, xfs_dir2_db_t db, struct xfs_buf *bp) { xfs_fileoff_t bno; /* directory file offset */ xfs_dablk_t da; /* directory file offset */ int done; /* bunmap is finished */ xfs_inode_t *dp; int error; xfs_mount_t *mp; xfs_trans_t *tp; trace_xfs_dir2_shrink_inode(args, db); dp = args->dp; mp = dp->i_mount; tp = args->trans; da = xfs_dir2_db_to_da(mp, db); /* * Unmap the fsblock(s). */ if ((error = xfs_bunmapi(tp, dp, da, mp->m_dirblkfsbs, XFS_BMAPI_METADATA, 0, args->firstblock, args->flist, &done))) { /* * ENOSPC actually can happen if we're in a removename with * no space reservation, and the resulting block removal * would cause a bmap btree split or conversion from extents * to btree. This can only happen for un-fragmented * directory blocks, since you need to be punching out * the middle of an extent. * In this case we need to leave the block in the file, * and not binval it. * So the block has to be in a consistent empty state * and appropriately logged. * We don't free up the buffer, the caller can tell it * hasn't happened since it got an error back. */ return error; } ASSERT(done); /* * Invalidate the buffer from the transaction. */ xfs_trans_binval(tp, bp); /* * If it's not a data block, we're done. */ if (db >= XFS_DIR2_LEAF_FIRSTDB(mp)) return 0; /* * If the block isn't the last one in the directory, we're done. */ if (dp->i_d.di_size > xfs_dir2_db_off_to_byte(mp, db + 1, 0)) return 0; bno = da; if ((error = xfs_bmap_last_before(tp, dp, &bno, XFS_DATA_FORK))) { /* * This can't really happen unless there's kernel corruption. */ return error; } if (db == mp->m_dirdatablk) ASSERT(bno == 0); else ASSERT(bno > 0); /* * Set the size to the new last block. */ dp->i_d.di_size = XFS_FSB_TO_B(mp, bno); xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); return 0; }
ef9d185322ac6bc51b11de1a3fd7ad407fd4831e
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/compat/common/sysv_ipc_50.c
a8f6b980e0130286a8e705521a623cc9fbd722a5
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
5,190
c
sysv_ipc_50.c
/* $NetBSD: sysv_ipc_50.c,v 1.6 2019/01/27 02:08:39 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Charles M. Hannum. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> __KERNEL_RCSID(0, "$NetBSD: sysv_ipc_50.c,v 1.6 2019/01/27 02:08:39 pgoyette Exp $"); #ifdef _KERNEL_OPT #include "opt_sysv.h" #include "opt_compat_netbsd.h" #endif #include <sys/param.h> #include <sys/kernel.h> #include <sys/proc.h> #include <sys/ipc.h> #ifdef SYSVMSG #include <sys/msg.h> #endif #ifdef SYSVSEM #include <sys/sem.h> #endif #ifdef SYSVSHM #include <sys/shm.h> #endif #include <sys/systm.h> #include <sys/malloc.h> #include <sys/mount.h> #include <sys/vnode.h> #include <sys/stat.h> #include <sys/sysctl.h> #include <sys/kauth.h> #include <compat/sys/ipc.h> #ifdef SYSVMSG #include <compat/sys/msg.h> #endif #ifdef SYSVSEM #include <compat/sys/sem.h> #endif #ifdef SYSVSHM #include <compat/sys/shm.h> #endif /* * Check for ipc permission */ int sysctl_kern_sysvipc50(SYSCTLFN_ARGS) { void *where = oldp; size_t *sizep = oldlenp; #ifdef SYSVMSG struct msg_sysctl_info50 *msgsi = NULL; #endif #ifdef SYSVSEM struct sem_sysctl_info50 *semsi = NULL; #endif #ifdef SYSVSHM struct shm_sysctl_info50 *shmsi = NULL; #endif size_t infosize, dssize, tsize, buflen; void *bf = NULL; char *start; int32_t nds; int i, error, ret; if (namelen != 1) return EINVAL; start = where; buflen = *sizep; switch (*name) { case KERN_SYSVIPC_OMSG_INFO: #ifdef SYSVMSG infosize = sizeof(msgsi->msginfo); nds = msginfo.msgmni; dssize = sizeof(msgsi->msgids[0]); break; #else return EINVAL; #endif case KERN_SYSVIPC_OSEM_INFO: #ifdef SYSVSEM infosize = sizeof(semsi->seminfo); nds = seminfo.semmni; dssize = sizeof(semsi->semids[0]); break; #else return EINVAL; #endif case KERN_SYSVIPC_OSHM_INFO: #ifdef SYSVSHM infosize = sizeof(shmsi->shminfo); nds = shminfo.shmmni; dssize = sizeof(shmsi->shmids[0]); break; #else return EINVAL; #endif default: return EPASSTHROUGH; } /* * Round infosize to 64 bit boundary if requesting more than just * the info structure or getting the total data size. */ if (where == NULL || *sizep > infosize) infosize = roundup(infosize, sizeof(quad_t)); tsize = infosize + nds * dssize; /* Return just the total size required. */ if (where == NULL) { *sizep = tsize; return 0; } /* Not enough room for even the info struct. */ if (buflen < infosize) { *sizep = 0; return ENOMEM; } bf = malloc(uimin(tsize, buflen), M_TEMP, M_WAITOK | M_ZERO); switch (*name) { #ifdef SYSVMSG case KERN_SYSVIPC_OMSG_INFO: msgsi = (struct msg_sysctl_info50 *)bf; msgsi->msginfo = msginfo; break; #endif #ifdef SYSVSEM case KERN_SYSVIPC_OSEM_INFO: semsi = (struct sem_sysctl_info50 *)bf; semsi->seminfo = seminfo; break; #endif #ifdef SYSVSHM case KERN_SYSVIPC_OSHM_INFO: shmsi = (struct shm_sysctl_info50 *)bf; shmsi->shminfo = shminfo; break; #endif } buflen -= infosize; ret = 0; if (buflen > 0) { /* Fill in the IPC data structures. */ for (i = 0; i < nds; i++) { if (buflen < dssize) { ret = ENOMEM; break; } switch (*name) { #ifdef SYSVMSG case KERN_SYSVIPC_OMSG_INFO: mutex_enter(&msgmutex); SYSCTL_FILL_MSG(msqs[i].msq_u, msgsi->msgids[i]); mutex_exit(&msgmutex); break; #endif #ifdef SYSVSEM case KERN_SYSVIPC_OSEM_INFO: SYSCTL_FILL_SEM(sema[i], semsi->semids[i]); break; #endif #ifdef SYSVSHM case KERN_SYSVIPC_OSHM_INFO: SYSCTL_FILL_SHM(shmsegs[i], shmsi->shmids[i]); break; #endif } buflen -= dssize; } } *sizep -= buflen; error = copyout(bf, start, *sizep); /* If copyout succeeded, use return code set earlier. */ if (error == 0) error = ret; if (bf) free(bf, M_TEMP); return error; }
b6d384f93486e102cda4186c4bdd5fc400ba6276
3d74f759ee48d383aa82eeff0a55864a93a001ba
/shell/platform/linux/fl_method_codec_private.h
8912093adc29c9cbc3595948be1a36e35c3f76f9
[ "BSD-3-Clause" ]
permissive
flutter/engine
78be5418a9b2f7730dda9ca9fcb25b7055f3da85
902ece7f89d7730cc69f35e098b223cbbf4e25f1
refs/heads/main
2023-09-04T06:12:34.462953
2023-09-04T05:33:32
2023-09-04T05:33:32
39,211,337
7,090
6,862
BSD-3-Clause
2023-09-14T21:58:17
2015-07-16T17:39:56
C++
UTF-8
C
false
false
3,857
h
fl_method_codec_private.h
// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_CODEC_PRIVATE_H_ #define FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_CODEC_PRIVATE_H_ #include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h" #include "flutter/shell/platform/linux/public/flutter_linux/fl_method_response.h" G_BEGIN_DECLS /** * fl_method_codec_encode_method_call: * @codec: an #FlMethodCodec. * @name: method name. * @args: (allow-none): method arguments, or %NULL. * @error: (allow-none): #GError location to store the error occurring, or * %NULL. * * Encodes a method call. * * Returns: (transfer full): a binary encoding of this method call or %NULL if * not able to encode. */ GBytes* fl_method_codec_encode_method_call(FlMethodCodec* codec, const gchar* name, FlValue* args, GError** error); /** * fl_method_codec_decode_method_call: * @codec: an #FlMethodCodec. * @message: message to decode. * @name: (transfer full): location to write method name or %NULL if not * required. * @args: (transfer full): location to write method arguments, or %NULL if not * required. * @error: (allow-none): #GError location to store the error occurring, or * %NULL. * * Decodes a method call. * * Returns: %TRUE if successfully decoded. */ gboolean fl_method_codec_decode_method_call(FlMethodCodec* codec, GBytes* message, gchar** name, FlValue** args, GError** error); /** * fl_method_codec_encode_success_envelope: * @codec: an #FlMethodCodec. * @result: (allow-none): method result, or %NULL. * @error: (allow-none): #GError location to store the error occurring, or * %NULL. * * Encodes a successful response to a method call. * * Returns: (transfer full): a binary encoding of this response or %NULL if not * able to encode. */ GBytes* fl_method_codec_encode_success_envelope(FlMethodCodec* codec, FlValue* result, GError** error); /** * fl_method_codec_encode_error_envelope: * @codec: an #FlMethodCodec. * @code: an error code. * @message: (allow-none): an error message or %NULL. * @details: (allow-none): error details, or %NULL. * @error: (allow-none): #GError location to store the error occurring, or * %NULL. * * Encodes an error response to a method call. * * Returns: (transfer full): a binary encoding of this response or %NULL if not * able to encode. */ GBytes* fl_method_codec_encode_error_envelope(FlMethodCodec* codec, const gchar* code, const gchar* message, FlValue* details, GError** error); /** * fl_method_codec_decode_response: * @codec: an #FlMethodCodec. * @message: message to decode. * @error: (allow-none): #GError location to store the error occurring, or * %NULL. * * Decodes a response to a method call. If the call resulted in an error then * @error_code is set, otherwise it is %NULL. * * Returns: a new #FlMethodResponse or %NULL on error. */ FlMethodResponse* fl_method_codec_decode_response(FlMethodCodec* codec, GBytes* message, GError** error); G_END_DECLS #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_CODEC_PRIVATE_H_
2024904f37773af0277e154865429b206d9460fb
9ceacf33fd96913cac7ef15492c126d96cae6911
/lib/libc/arch/mips64/gdtoa/arith.h
ee44109ae503f3a9c405a495418dcf711f2fb963
[]
no_license
openbsd/src
ab97ef834fd2d5a7f6729814665e9782b586c130
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
refs/heads/master
2023-09-02T18:54:56.624627
2023-09-02T15:16:12
2023-09-02T15:16:12
66,966,208
3,394
1,235
null
2023-08-08T02:42:25
2016-08-30T18:18:25
C
UTF-8
C
false
false
184
h
arith.h
#ifdef __MIPSEB__ #define IEEE_MC68k #else #define IEEE_8087 #endif #define Arith_Kind_ASL 2 #define Long int #define Intcast (int)(long) #define Double_Align #define X64_bit_pointers
86099162c5e6ec4bfab5d7104658653af5ab9d9c
f21ddc1d9fcec88bf844bcc2c67b287b06156530
/baresip/modules/recorder/wavfile.h
4152d773989502fdaedf487c2237d80704bd8fa7
[ "BSD-3-Clause" ]
permissive
tomek-o/tSIP
69a6c4fa7b971fc37af97ab4a7e24c34f3bf273c
dd5d23316a819ad659e32d7bb70b8092946e73c5
refs/heads/master
2023-09-03T19:43:36.499392
2023-09-03T13:09:44
2023-09-03T13:09:44
148,903,107
110
32
null
2023-08-15T12:23:03
2018-09-15T13:11:01
C
UTF-8
C
false
false
192
h
wavfile.h
#ifndef WavFileH #define WavFileH #include <stdio.h> FILE * wavfile_open(const char *filename, unsigned int channels, unsigned int samples_per_sec); void wavfile_close(FILE * file); #endif
c145fc6f7a6cd0cb24d151701f6f25edcc84cfcc
ba1d7083ec292aca6db37d4ba8286cce5e400eb3
/src/pkcs7.c
5f070a3272c5cac72f08f9a6ee7db523e709b5c5
[ "LicenseRef-scancode-openssl", "OpenSSL", "MIT" ]
permissive
zhaozg/lua-openssl
e93c40ad1140e28e75ed52eed0b22266ebcc7902
289529260fd8b6c045644ccd68f9ec810bca7d46
refs/heads/master
2023-09-01T09:46:38.919932
2023-08-16T13:27:19
2023-08-17T14:36:41
1,987,363
269
121
NOASSERTION
2023-09-10T07:40:21
2011-07-02T11:15:48
C
UTF-8
C
false
false
14,347
c
pkcs7.c
/*** pkcs7 module to create and process PKCS#7 files. That only understands PKCS#7 v 1.5 as specified in IETF RFC 2315, and not currently parse CMS as described in IETF RFC 2630. @module pkcs7 @usage pkcs7 = require('openssl').pkcs7 */ #include "openssl.h" #include <openssl/pkcs7.h> #include "private.h" #if (OPENSSL_VERSION_NUMBER < 0x10100000L) \ || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2090000fL) #define OPENSSL_USE_M_ASN1 #endif /*** read string or bio object, which include pkcs7 content @function read @tparam bio|string input @tparam[opt='auto'] format allow 'auto','der','pem','smime' auto will only try 'der' or 'pem' @treturn pkcs7 object or nil @treturn string content exist only smime format */ static LUA_FUNCTION(openssl_pkcs7_read) { BIO* bio = load_bio_object(L, 1); int fmt = luaL_checkoption(L, 2, "auto", format); PKCS7 *p7 = NULL; BIO* ctx = NULL; int ret = 0; if (fmt == FORMAT_AUTO) fmt = bio_is_der(bio) ? FORMAT_DER : FORMAT_PEM; if (fmt == FORMAT_DER) { p7 = d2i_PKCS7_bio(bio, NULL); BIO_reset(bio); } else if (fmt == FORMAT_PEM) { p7 = PEM_read_bio_PKCS7(bio, NULL, NULL, NULL); BIO_reset(bio); } else if (fmt == FORMAT_SMIME) { p7 = SMIME_read_PKCS7(bio, &ctx); } BIO_free(bio); if (p7) { PUSH_OBJECT(p7, "openssl.pkcs7"); ret = 1; if (ctx) { BUF_MEM* mem; BIO_get_mem_ptr(ctx, &mem); lua_pushlstring(L, mem->data, mem->length); BIO_free(ctx); ret = 2; } } return ret; } #if OPENSSL_VERSION_NUMBER > 0x10000000L /*** create new empty pkcs7 object, which support flexble sign methods. @function new @tparam[opt=NID_pkcs7_signed] int oid given pkcs7 type @tparam[opt=NID_pkcs7_data] int content given pkcs7 content type @treturn pkcs7 object */ static LUA_FUNCTION(openssl_pkcs7_new) { int type = luaL_optint(L, 1, NID_pkcs7_signed); int content_nid = luaL_optint(L, 2, NID_pkcs7_data); int ret = 0; PKCS7 *p7 = PKCS7_new(); if (p7) { if (PKCS7_set_type(p7, type)) { if (PKCS7_content_new(p7, content_nid)) { PUSH_OBJECT(p7, "openssl.pkcs7"); ret = 1; } } if (ret==0) PKCS7_free(p7); } return ret; } static LUA_FUNCTION(openssl_pkcs7_add) { PKCS7 *p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7"); int n = lua_gettop(L); int i, ret = 1; luaL_argcheck(L, lua_isuserdata(L, 2), 2, "must supply certificate or crl object"); for (i = 2; i <= n; i++) { luaL_argcheck(L, auxiliar_getclassudata(L, "openssl.x509", i) || auxiliar_getclassudata(L, "openssl.x509_crl", i), i, "must supply certificate or crl object"); if (auxiliar_getclassudata(L, "openssl.x509", i)) { X509* x = CHECK_OBJECT(i, X509, "openssl.x509"); ret = PKCS7_add_certificate(p7, x); } else { X509_CRL *crl = CHECK_OBJECT(i, X509_CRL, "openssl.x509_crl"); ret = PKCS7_add_crl(p7, crl); } luaL_argcheck(L, ret, i, "add to pkcs7 fail"); } return openssl_pushresult(L, ret); } #endif /*** sign message with signcert and signpkey to create pkcs7 object @function sign @tparam string|bio msg @tparam x509 signcert @tparam evp_pkey signkey @tparam[opt] stack_of_x509 cacerts @tparam[opt=0] number flags @treturn pkcs7 object */ static LUA_FUNCTION(openssl_pkcs7_sign) { int ret = 0; BIO *in = load_bio_object(L, 1); X509 *cert = CHECK_OBJECT(2, X509, "openssl.x509"); EVP_PKEY *privkey = CHECK_OBJECT(3, EVP_PKEY, "openssl.evp_pkey"); STACK_OF(X509) *others = lua_isnoneornil(L, 4) ? 0 : openssl_sk_x509_fromtable(L, 4); long flags = luaL_optint(L, 5, 0); PKCS7 *p7 = NULL; luaL_argcheck(L, X509_check_private_key(cert, privkey), 3, "sigcert and private key not match"); p7 = PKCS7_sign(cert, privkey, others, in, flags); BIO_free(in); if (others) sk_X509_pop_free(others, X509_free); if (p7) { PUSH_OBJECT(p7, "openssl.pkcs7"); ret = 1; } return ret; } /*** verify pkcs7 object, and return msg content or verify result @function verify @tparam pkcs7 in @tparam[opt] stack_of_x509 signercerts @tparam[opt] x509_store cacerts @tparam[opt] string|bio msg @tparam[opt=0] number flags @treturn[1] string content @treturn[1] boolean result */ static LUA_FUNCTION(openssl_pkcs7_verify) { int ret = 0; PKCS7 *p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7"); STACK_OF(X509) *signers = lua_isnoneornil(L, 2) ? NULL : openssl_sk_x509_fromtable(L, 2); X509_STORE *store = lua_isnoneornil(L, 3) ? NULL : CHECK_OBJECT(3, X509_STORE, "openssl.x509_store"); BIO* in = lua_isnoneornil(L, 4) ? NULL : load_bio_object(L, 4); long flags = luaL_optint(L, 5, 0); BIO* out = NULL; if ((flags & PKCS7_DETACHED) == 0) out = BIO_new(BIO_s_mem()); if (PKCS7_verify(p7, signers, store, in, out, flags) == 1) { if (out) { BUF_MEM *bio_buf; BIO_get_mem_ptr(out, &bio_buf); lua_pushlstring(L, bio_buf->data, bio_buf->length); } else lua_pushboolean(L, 1); ret = 1; } if (signers) sk_X509_pop_free(signers, X509_free); if (out) BIO_free(out); if (in) BIO_free(in); return ret; } /*** encrypt message with recipcerts certificates return encrypted pkcs7 object @function encrypt @tparam string|bio msg @tparam stack_of_x509 recipcerts @tparam[opt='aes-128-cbc'] string|evp_cipher cipher @tparam[opt] number flags */ static LUA_FUNCTION(openssl_pkcs7_encrypt) { int ret = 0; PKCS7 * p7 = NULL; BIO *in = load_bio_object(L, 1); STACK_OF(X509) *recipcerts = openssl_sk_x509_fromtable(L, 2); const EVP_CIPHER *cipher = get_cipher(L, 3, "aes-128-cbc"); long flags = luaL_optint(L, 4, 0); p7 = PKCS7_encrypt(recipcerts, in, cipher, flags); BIO_free(in); sk_X509_pop_free(recipcerts, X509_free); if (p7) { PUSH_OBJECT(p7, "openssl.pkcs7"); ret = 1; } return ret; } /*** decrypt encrypted pkcs7 message @function decrypt @tparam pkcs7 input @tparam x509 recipcert @tparam evp_pkey recipkey @treturn string decrypt message */ static LUA_FUNCTION(openssl_pkcs7_decrypt) { int ret = 0; PKCS7 *p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7"); X509 *cert = CHECK_OBJECT(2, X509, "openssl.x509"); EVP_PKEY *key = CHECK_OBJECT(3, EVP_PKEY, "openssl.evp_pkey"); long flags = luaL_optint(L, 4, 0); BIO *out = BIO_new(BIO_s_mem()); if (PKCS7_decrypt(p7, key, cert, out, flags)) { BUF_MEM* mem; BIO_get_mem_ptr(out, &mem); lua_pushlstring(L, mem->data, mem->length); ret = 1; } BIO_free(out); return ret; } /*** openssl.pkcs7 object @type pkcs7 */ static LUA_FUNCTION(openssl_pkcs7_gc) { PKCS7* p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7"); PKCS7_free(p7); return 0; } /*** export pkcs7 as string @function export @tparam[opt='pem'] string support export as 'pem' or 'der' format, default is 'pem' @treturn string */ static LUA_FUNCTION(openssl_pkcs7_export) { int ret = 0; PKCS7 * p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7"); int fmt = luaL_checkoption(L, 2, "pem", format); BIO* bio_out = NULL; luaL_argcheck(L, fmt == FORMAT_PEM || fmt == FORMAT_DER || fmt == FORMAT_SMIME, 2, "only accept pem, der or smime, default is pem"); bio_out = BIO_new(BIO_s_mem()); if (fmt == FORMAT_PEM) ret = PEM_write_bio_PKCS7(bio_out, p7); else if(fmt == FORMAT_DER) ret = i2d_PKCS7_bio(bio_out, p7); else if(fmt == FORMAT_SMIME) ret = SMIME_write_PKCS7(bio_out, p7, NULL, 0); if (ret==1) { BUF_MEM *bio_buf; BIO_get_mem_ptr(bio_out, &bio_buf); lua_pushlstring(L, bio_buf->data, bio_buf->length); ret = 1; } BIO_free(bio_out); return ret == 1 ? 1 : openssl_pushresult(L, ret); } static int openssl_push_pkcs7_signer_info(lua_State *L, PKCS7_SIGNER_INFO *info) { lua_newtable(L); AUXILIAR_SET(L, -1, "version", ASN1_INTEGER_get(info->version), integer); if (info->issuer_and_serial != NULL) { X509_NAME *i = X509_NAME_dup(info->issuer_and_serial->issuer); ASN1_INTEGER *s = ASN1_INTEGER_dup(info->issuer_and_serial->serial); if (info->issuer_and_serial->issuer) AUXILIAR_SETOBJECT(L, i, "openssl.x509_name", -1, "issuer"); if (info->issuer_and_serial->serial) AUXILIAR_SETOBJECT(L, s, "openssl.asn1_integer", -1, "serial"); } if (info->digest_alg) { X509_ALGOR *dup = X509_ALGOR_dup(info->digest_alg); AUXILIAR_SETOBJECT(L, dup, "openssl.x509_algor", -1, "digest_alg"); } if (info->digest_enc_alg) { X509_ALGOR *dup = X509_ALGOR_dup(info->digest_alg); AUXILIAR_SETOBJECT(L, dup, "openssl.x509_algor", -1, "digest_enc_alg"); } if (info->enc_digest) { ASN1_STRING *dup = ASN1_STRING_dup(info->enc_digest); AUXILIAR_SETOBJECT(L, dup, "openssl.asn1_string", -1, "enc_digest"); } if (info->pkey) { EVP_PKEY_up_ref(info->pkey); AUXILIAR_SETOBJECT(L, info->pkey, "openssl.evp_pkey", -1, "pkey"); } if (info->auth_attr) { openssl_sk_x509_attribute_totable(L, info->auth_attr); lua_setfield(L, -2, "auth_attr"); } if (info->unauth_attr) { openssl_sk_x509_attribute_totable(L, info->unauth_attr); lua_setfield(L, -2, "unauth_attr"); } return 1; } static LUA_FUNCTION(openssl_pkcs7_type) { PKCS7 * p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7"); int i = OBJ_obj2nid(p7->type); lua_pushstring(L, OBJ_nid2sn(i)); lua_pushstring(L, OBJ_nid2ln(i)); return 2; } /*** export pkcs7 as a string @function parse @treturn table a table has pkcs7 infomation, include type,and other things relate to types */ static LUA_FUNCTION(openssl_pkcs7_parse) { PKCS7 * p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7"); STACK_OF(X509) *certs = NULL; STACK_OF(X509_CRL) *crls = NULL; int i = OBJ_obj2nid(p7->type); lua_newtable(L); AUXILIAR_SET(L, -1, "type", OBJ_nid2ln(i), string); switch (i) { case NID_pkcs7_signed: { PKCS7_SIGNED *sign = p7->d.sign; certs = sign->cert ? sign->cert : NULL; crls = sign->crl ? sign->crl : NULL; AUXILIAR_SET(L, -1, "version", ASN1_INTEGER_get(sign->version), integer); AUXILIAR_SET(L, -1, "detached", PKCS7_is_detached(p7), boolean); lua_pushstring(L, "md_algs"); openssl_sk_x509_algor_totable(L, sign->md_algs); lua_rawset(L, -3); if (sign->signer_info) { int j, n; n = sk_PKCS7_SIGNER_INFO_num(sign->signer_info); lua_pushstring(L, "signer_info"); lua_newtable(L); for (j = 0; j < n; j++) { PKCS7_SIGNER_INFO *info = sk_PKCS7_SIGNER_INFO_value(sign->signer_info, j); lua_pushinteger(L, j + 1); openssl_push_pkcs7_signer_info(L, info); lua_rawset(L, -3); } lua_rawset(L, -3); } if (!PKCS7_is_detached(p7)) { PKCS7* c = sign->contents; c = PKCS7_dup(c); AUXILIAR_SETOBJECT(L, c, "openssl.pkcs7", -1, "contents"); } } break; case NID_pkcs7_signedAndEnveloped: certs = p7->d.signed_and_enveloped->cert; crls = p7->d.signed_and_enveloped->crl; break; case NID_pkcs7_enveloped: { /* BIO * mem = BIO_new(BIO_s_mem()); BIO * v_p7bio = PKCS7_dataDecode(p7,pkey,NULL,NULL); BUF_MEM *bptr = NULL; unsigned char src[4096]; int len; while((len = BIO_read(v_p7bio,src,4096))>0){ BIO_write(mem, src, len); } BIO_free(v_p7bio); BIO_get_mem_ptr(mem, &bptr); if((int)*puiDataLen < bptr->length) { *puiDataLen = bptr->length; ret = SAR_MemoryErr; }else{ *puiDataLen = bptr->length; memcpy(pucData,bptr->data, bptr->length); } */ } break; case NID_pkcs7_digest: { PKCS7_DIGEST* d = p7->d.digest; PUSH_ASN1_OCTET_STRING(L, d->digest); lua_setfield(L, -2, "digest"); } break; case NID_pkcs7_data: { PUSH_ASN1_OCTET_STRING(L, p7->d.data); lua_setfield(L, -2, "data"); } break; default: break; } /* NID_pkcs7_signed or NID_pkcs7_signedAndEnveloped */ if (certs != NULL) { lua_pushstring(L, "certs"); openssl_sk_x509_totable(L, certs); lua_rawset(L, -3); } if (crls != NULL) { lua_pushstring(L, "crls"); openssl_sk_x509_crl_totable(L, crls); lua_rawset(L, -3); } return 1; } /*** verify pkcs7 object, and return msg content or verify result @function verify @tparam[opt] stack_of_x509 signercerts @tparam[opt] x509_store cacerts @tparam[opt] string|bio msg @tparam[opt=0] number flags @treturn[1] string content @treturn[1] boolean result */ /*** decrypt encrypted pkcs7 message @function decrypt @tparam x509 recipcert @tparam evp_pkey recipkey @treturn string decrypt message */ static luaL_Reg pkcs7_funcs[] = { {"type", openssl_pkcs7_type}, {"parse", openssl_pkcs7_parse}, {"export", openssl_pkcs7_export}, {"decrypt", openssl_pkcs7_decrypt}, {"verify", openssl_pkcs7_verify}, #if OPENSSL_VERSION_NUMBER > 0x10000000L {"add", openssl_pkcs7_add}, #endif {"__gc", openssl_pkcs7_gc}, {"__tostring", auxiliar_tostring}, {NULL, NULL} }; static const luaL_Reg R[] = { #if OPENSSL_VERSION_NUMBER > 0x10000000L {"new", openssl_pkcs7_new}, #endif {"read", openssl_pkcs7_read}, {"sign", openssl_pkcs7_sign}, {"verify", openssl_pkcs7_verify}, {"encrypt", openssl_pkcs7_encrypt}, {"decrypt", openssl_pkcs7_decrypt}, {NULL, NULL} }; static LuaL_Enumeration pkcs7_const[] = { {"TEXT", PKCS7_TEXT}, {"NOCERTS", PKCS7_NOCERTS}, {"NOSIGS", PKCS7_NOSIGS}, {"NOCHAIN", PKCS7_NOCHAIN}, {"NOINTERN", PKCS7_NOINTERN}, {"NOVERIFY", PKCS7_NOVERIFY}, {"DETACHED", PKCS7_DETACHED}, {"BINARY", PKCS7_BINARY}, {"NOATTR", PKCS7_NOATTR}, {"NOSMIMECAP", PKCS7_NOSMIMECAP}, {"NOOLDMIMETYPE", PKCS7_NOOLDMIMETYPE}, {"CRLFEOL", PKCS7_CRLFEOL}, {"STREAM", PKCS7_STREAM}, {"NOCRL", PKCS7_NOCRL}, {"PARTIAL", PKCS7_PARTIAL}, {"REUSE_DIGEST", PKCS7_REUSE_DIGEST}, {NULL, 0} }; int luaopen_pkcs7(lua_State *L) { auxiliar_newclass(L, "openssl.pkcs7", pkcs7_funcs); lua_newtable(L); luaL_setfuncs(L, R, 0); auxiliar_enumerate(L, -1, pkcs7_const); return 1; }
6e644db179e8be4d460215d0a116c8c64f24c963
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
/AKWF-c/AKWF_hdrawn/AKWF_hdrawn_0026.h
b018a833cc9ce66c0bd1a86db8e4abfb40cd7daa
[ "CC0-1.0" ]
permissive
KristofferKarlAxelEkstrand/AKWF-FREE
b2defa1a2d389d309be6dd2e9f968923daf80d1b
cf8171df36e9fec25416b5f568b72a6e2cb69194
refs/heads/master
2023-07-23T18:22:36.939705
2023-07-10T17:14:40
2023-07-10T17:14:40
145,817,187
359
59
CC0-1.0
2023-07-10T17:14:41
2018-08-23T07:26:56
null
UTF-8
C
false
false
4,686
h
AKWF_hdrawn_0026.h
/* Adventure Kid Waveforms (AKWF) converted for use with Teensy Audio Library * * Adventure Kid Waveforms(AKWF) Open waveforms library * https://www.adventurekid.se/akrt/waveforms/adventure-kid-waveforms/ * * This code is in the public domain, CC0 1.0 Universal (CC0 1.0) * https://creativecommons.org/publicdomain/zero/1.0/ * * Converted by Brad Roy, https://github.com/prosper00 */ /* AKWF_hdrawn_0026 256 samples +-----------------------------------------------------------------------------------------------------------------+ |* * | |* * | |* * | |* * | |* * | |* * | |* * | | ************************************************************************************************ ******| | * * | | * * | | * * | | * * | | * * | | * * | | * * | +-----------------------------------------------------------------------------------------------------------------+ */ const uint16_t AKWF_hdrawn_0026 [] = { 56340, 58879, 59526, 65535, 63301, 65535, 64239, 65535, 64792, 65535, 65373, 65273, 65535, 43554, 30278, 34190, 31801, 33466, 32258, 33137, 32512, 32931, 32680, 32793, 32793, 32703, 32866, 32647, 32907, 32620, 32961, 32681, 33034, 32762, 33095, 32853, 33147, 32951, 33194, 33052, 33239, 33147, 33281, 33238, 33327, 33327, 33378, 33411, 33431, 33489, 33490, 33577, 33590, 33691, 33699, 33802, 33810, 33908, 33879, 33914, 33881, 33911, 33885, 33906, 33902, 33958, 33981, 34028, 34056, 34100, 34132, 34171, 34207, 34245, 34275, 34273, 34276, 34272, 34276, 34272, 34276, 34273, 34275, 34274, 34275, 34273, 34275, 34273, 34274, 34274, 34274, 34274, 34275, 34274, 34274, 34274, 34274, 34274, 34274, 34274, 34273, 34274, 34274, 34274, 34274, 34274, 34273, 34275, 34275, 34274, 34274, 34273, 34274, 34274, 34274, 34274, 34274, 34275, 34274, 34274, 34274, 34274, 34275, 34274, 34274, 34274, 34274, 34274, 34273, 34274, 34274, 34273, 34275, 34273, 34274, 34274, 34274, 34274, 34274, 34273, 34274, 34274, 34275, 34274, 34274, 34273, 34274, 34274, 34274, 34274, 34274, 34274, 34274, 34275, 34273, 34275, 34274, 34274, 34272, 34275, 34273, 34275, 34272, 34275, 34273, 34275, 34273, 34276, 34253, 34174, 34106, 34026, 33959, 33881, 33838, 33769, 33729, 33656, 33620, 33543, 33529, 33512, 33530, 33512, 33528, 33515, 33526, 33519, 33520, 33526, 33512, 33534, 33504, 33545, 33493, 33555, 33481, 33566, 33470, 33577, 33462, 33584, 33456, 33586, 33456, 33583, 33464, 33565, 33420, 33437, 33336, 33295, 33265, 33138, 33217, 33042, 33280, 32971, 33360, 32882, 33441, 32647, 33406, 32290, 33493, 31779, 34439, 23702, 3072, 3190, 2955, 2990, 3092, 2903, 3142, 2884, 3132, 2925, 3053, 3057, 2861, 6768, 12212, 28638, 35918, 33347, 34779, 33550, 34372, 33540, 34062, 33476, 33789, 33382, 33474, 33171, };
ee54e197661778c6bb475f3d23cb5e45d83c22b9
a54c4b51556ab2358702ab014f8bff427c1f597d
/plugins/loader/kernel.c
49c0135ceeb7cbc4ebefe279aa1c1355851f4f71
[ "MIT" ]
permissive
SKGleba/enso_ex
678d0db7c9fba6bc903549e7cefe37ce8b9f31f9
0145b1c0f66eca827df3719b1ca222f931db506e
refs/heads/master
2023-07-20T06:46:56.583083
2023-07-08T08:02:57
2023-07-08T08:02:57
151,975,350
178
18
MIT
2023-07-08T08:02:20
2018-10-07T19:03:16
C
UTF-8
C
false
false
7,194
c
kernel.c
/* custom psp2bootconfig reimplementation * * Copyright (C) 2020-2023 skgleba * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ #include <string.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <vitasdkkern.h> #include "../plugins.h" #include "../../core/ex_defs.h" #define LIST_A_MODULE_COUNT 13 #define LIST_B_MODULE_COUNT 15 #define LIST_C_MODULE_COUNT E2X_MAX_EPATCHES_N #define LIST_D_MODULE_COUNT 5 #define CUSTOM_BOOT_LIST "os0:ex/boot_list.txt" #define CUSTOM_BOOT_LIST_MAGIC 'LXE#' // #EXL static int bootlist_mb_id = -1; static patch_args_struct patch_args; static int mlist_uid_a[LIST_A_MODULE_COUNT], mlist_uid_b[LIST_B_MODULE_COUNT], mlist_uid_d[LIST_D_MODULE_COUNT], clist_uid[LIST_C_MODULE_COUNT]; static int use_devmods = 0, use_clist = 0; static char* clist_str[LIST_C_MODULE_COUNT]; static char *mlist_str_a[] = { "sysmem.skprx", "excpmgr.skprx", "intrmgr.skprx", "buserror.skprx", "systimer.skprx", "acmgr.skprx", "threadmgr.skprx", "dmacmgr.skprx", "smsc_proxy.skprx", "authmgr.skprx", "processmgr.skprx", "iofilemgr.skprx", "modulemgr.skprx" }; static char *mlist_str_b[] = { "lowio.skprx", "syscon.skprx", "oled.skprx", NULL, "display.skprx", "sm_comm.skprx", "ss_mgr.skprx", "sdif.skprx", "msif.skprx", "gcauthmgr.skprx", "sdstor.skprx", "rtc.skprx", "exfatfs.skprx", "bsod.skprx", "sysstatemgr.skprx" }; static char *mlist_str_d[] = { "sdbgsdio.skprx", "deci4p_sdfmgr.skprx", "deci4p_sttyp.skprx", "deci4p_sdbgp.skprx", "deci4p_sdrfp.skprx" }; char* find_endline(char* start, char* end) { for (char* ret = start; ret < end; ret++) { if (*(uint16_t*)ret == 0x0A0D || *(uint8_t*)ret == 0x0A) return ret; } return end; } char* find_nextline(char* current_line_end, char* end) { for (char* next_line = current_line_end; next_line < end; next_line++) { if (*(uint8_t*)next_line != 0x0D && *(uint8_t*)next_line != 0x0A && *(uint8_t*)next_line != 0x00) return next_line; } return NULL; } void parse_bootlist(void* data_start, int data_size) { char* startlist = data_start; char* endlist = startlist + data_size; char* current_line = startlist; char* end_line = startlist; while (current_line < endlist) { end_line = find_endline(current_line, endlist); if (current_line[0] != '#' && current_line != end_line) { for (int i = 0; i < (end_line - current_line); i++) { if (current_line[i] == ' ' || current_line[i] == '#') { *(uint8_t*)(current_line + i) = 0; break; } } end_line[0] = 0; clist_str[use_clist++] = current_line; } current_line = find_nextline(end_line, endlist); if (!current_line || use_clist >= LIST_C_MODULE_COUNT) break; } return; } static void prepare_modlists(char** module_dir_s) { char dispmodel[16]; // get enso_ex funcs & useful data patchedHwcfgStruct *cfg = &patch_args; cfg->get_ex_ports = E2X_MAGIC; if (KblGetHwConfig(cfg) == E2X_MAGIC) { // core version check // module directory string paddr *module_dir_s = cfg->ex_ports.module_dir; // setup arg that will be given to patchers patch_args.uids_a = mlist_uid_a; // set default list part 1 patch_args.uids_b = mlist_uid_b; // set default list part 2 patch_args.uids_d = NULL; // 0 unless devkit (later check) // custom if (CTRL_BUTTON_HELD(patch_args.ex_ctrl, E2X_EPATCHES_SKIP)) { clist_str[0] = "e2xrecovr.skprx"; // recovery script clist_str[1] = "e2xhfwmod.skprx"; // always run the hfw-compat script use_clist = 2; } else { int bootlist_size = (int)patch_args.ex_get_file(CUSTOM_BOOT_LIST, NULL, 0, 0); void *bootlist = (bootlist_size > 0) ? patch_args.ex_load_exe(CUSTOM_BOOT_LIST, "boot_list", 0, (uint32_t)bootlist_size, E2X_LX_NO_XREMAP | E2X_LX_NO_CCACHE, &bootlist_mb_id) : NULL; if (bootlist && *(uint32_t*)bootlist == CUSTOM_BOOT_LIST_MAGIC) { // ensure we dont use the old list if (bootlist_size & 0xFFF) *(uint8_t*)(bootlist + bootlist_size) = 0; else *(uint8_t*)(bootlist + bootlist_size - 1) = 0; // possibly cut last entry parse_bootlist(bootlist, bootlist_size); } else { clist_str[0] = "e2xhencfg.skprx"; clist_str[1] = "e2xculogo.skprx"; clist_str[2] = "e2xhfwmod.skprx"; use_clist = 3; } } } else use_clist = 0; // devkit int iVar1 = KblCheckDipsw(0xc1); if ((((iVar1 != 0) && (iVar1 = KblIsCex(), iVar1 == 0)) && (iVar1 = KblIsModelx102(), iVar1 == 0)) && (iVar1 = KblIsDoubleModel(), iVar1 == 0)) { use_devmods = 5; iVar1 = KblParamx2dAnd1(); if (iVar1 == 0) { use_devmods = 3; mlist_str_d[3] = NULL; mlist_str_d[4] = NULL; } patch_args.uids_d = mlist_uid_d; } else use_devmods = 0; // can bsod if (KblIsCex()) mlist_str_b[13] = NULL; // display type iVar1 = KblIsGenuineDolce(); if (iVar1 == 0) { KblGetHwConfig(&dispmodel); if ((dispmodel[0] & 9) != 0) mlist_str_b[2] = "lcd.skprx"; } else mlist_str_b[2] = NULL; // has hdmi iVar1 = KblIsNotDolce(); if ((iVar1 == 0) || ((iVar1 = KblIsCex(), iVar1 == 0 && (iVar1 = KblIsModelx102(), iVar1 == 0)))) mlist_str_b[3] = "hdmi.skprx"; } void _start() __attribute__ ((weak, alias ("module_start"))); int module_start(SceSize argc, void* args) { char* module_dir = NULL; // prepare all the module lists prepare_modlists(&module_dir); // load default modules KblLoadModulesFromList(mlist_str_a, mlist_uid_a, LIST_A_MODULE_COUNT, 0); if (use_devmods > 0) // devkit modules KblLoadModulesFromList(mlist_str_d, mlist_uid_d, use_devmods, KblCheckDipsw(0xd2) ? 1 : 0); KblLoadModulesFromList(mlist_str_b, mlist_uid_b, LIST_B_MODULE_COUNT, 0); // change moddir to os0:ex/ and load custom modules from there if (use_clist > 0 && module_dir) { module_dir[0] = 'e'; module_dir[1] = 'x'; KblLoadModulesFromList(clist_str, clist_uid, use_clist, 0); } // cleanup KblDeinitStorageHandlers(); KblStopKASM(); return 0; } void _stop() __attribute__ ((weak, alias ("module_bootstart"))); int module_bootstart(SceSize argc, void *args) { // set some sysroot stuff uint32_t tmpr = 0; KblDisableIrq(); *(uint32_t *)(args + 0x2fc) = 0; *(uint32_t *)(args + 0x300) = 0; tmpr = KblGetDevRegs(); *(uint32_t *)(args + 0x304) = tmpr; tmpr = KblGetDipsw204And205Stat(); *(uint32_t *)(args + 0x308) = tmpr; // start the custom modules patch_args.this_version = PATCH_ARGS_VERSION; // loader's this struct version patch_args.defarg = args; if (use_clist > 0) { KblStartModulesFromList(clist_uid, use_clist, 4, &patch_args); if (bootlist_mb_id != -1) patch_args.kbl_free_memblock(bootlist_mb_id); } // start default modules part 1 KblStartModulesFromList(mlist_uid_a, LIST_A_MODULE_COUNT, 4, args); if (use_devmods > 0) KblStartModulesFromList(mlist_uid_d, (use_devmods == 3) ? 3 : 4, 0, 0); // cleanup, prepare for sysstatemgr boot handoff KblExecSysrootx2d4(); KblWriteModStartRegs(); KblExecSysrootx360x20(); KblExecSysrootx2d8(); // start default modules part 2 if (use_devmods == 5) KblStartModulesFromList(&mlist_uid_d[4], 1, 0, 0); KblStartModulesFromList(mlist_uid_b, LIST_B_MODULE_COUNT, 4, args); return 0; }
568e535d1e3cdb4f3addd647db023894db0a3879
d169de4c5c6b281984df35536430dcc931a957a9
/source/component/crypto/hash/crc/vsf_crc.c
b36f8591d8449c1a91cd1e015e85aff6c6ef658f
[ "LGPL-2.1-only", "Apache-2.0" ]
permissive
vsfteam/vsf
2ba968ba2ef53b036668019c6c6746149a63c38a
522a52ff2ee4ed149b52789a5bd366f80c08c458
refs/heads/master
2023-08-27T07:32:08.339123
2023-08-26T17:46:07
2023-08-26T17:46:07
181,911,464
273
83
Apache-2.0
2023-08-29T03:08:36
2019-04-17T14:43:42
C
UTF-8
C
false
false
2,656
c
vsf_crc.c
/***************************************************************************** * Copyright(C)2009-2022 by VSF Team * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * * * ****************************************************************************/ /*============================ INCLUDES ======================================*/ #include "./vsf_crc.h" #if VSF_HASH_USE_CRC == ENABLED /*============================ MACROS ========================================*/ /*============================ MACROFIED FUNCTIONS ===========================*/ /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ const vsf_crc_t vsf_crc8_ccitt = { .bitlen = 8, .poly = 0x07, }; /*============================ LOCAL VARIABLES ===============================*/ /*============================ PROTOTYPES ====================================*/ /*============================ IMPLEMENTATION ================================*/ uint_fast32_t vsf_crc(const vsf_crc_t *crc, uint_fast32_t initial, uint8_t *buff, uint_fast32_t bytesize) { uint_fast8_t shift = crc->bitlen - 8; uint_fast32_t msb = 1UL << (crc->bitlen - 1); while (bytesize--) { initial ^= *buff++ << shift; for (uint_fast8_t i = 0; i < 8; i++) { if (initial & msb) { initial = (initial << 1) ^ crc->poly; } else { initial <<= 1; } } } return initial & ((1UL << crc->bitlen) - 1); } #endif /* EOF */
106f830271354db259d6c04d890d7e634a95c9d4
3d144a23e67c839a4df1c073c6a2c842508f16b2
/test/ClangImporter/Inputs/custom-modules/IndirectFrameworkImporter.h
7d0c93d955c12f47ec1af98bd887682bec92215b
[ "Apache-2.0", "Swift-exception" ]
permissive
apple/swift
c2724e388959f6623cf6e4ad6dc1cdd875fd0592
98ada1b200a43d090311b72eb45fe8ecebc97f81
refs/heads/main
2023-08-16T10:48:25.985330
2023-08-16T09:00:42
2023-08-16T09:00:42
44,838,949
78,897
15,074
Apache-2.0
2023-09-14T21:19:23
2015-10-23T21:15:07
C++
UTF-8
C
false
false
27
h
IndirectFrameworkImporter.h
@import IndirectFramework;
df57f42e8b20ea412c4daadf2579fc6740f28b55
fb0f9abad373cd635c2635bbdf491ea0f32da5ff
/src/native/external/libunwind/src/x86/offsets.h
e5aec7f588849fef582118f496ef485cd1488829
[ "MIT" ]
permissive
dotnet/runtime
f6fd23936752e202f8e4d6d94f3a4f3b0e77f58f
47bb554d298e1e34c4e3895d7731e18ad1c47d02
refs/heads/main
2023-09-03T15:35:46.493337
2023-09-03T08:13:23
2023-09-03T08:13:23
210,716,005
13,765
5,179
MIT
2023-09-14T21:58:52
2019-09-24T23:36:39
C#
UTF-8
C
false
false
5,481
h
offsets.h
/* Linux-specific definitions: */ /* Define various structure offsets to simplify cross-compilation. */ /* Offsets for x86 Linux "ucontext_t": */ #define LINUX_UC_FLAGS_OFF 0x00 #define LINUX_UC_LINK_OFF 0x04 #define LINUX_UC_STACK_OFF 0x08 #define LINUX_UC_MCONTEXT_OFF 0x14 #define LINUX_UC_SIGMASK_OFF 0x6c #define LINUX_UC_FPREGS_MEM_OFF 0xec /* The struct sigcontext is located at an offset of 4 from the stack pointer in the signal frame. */ /* Offsets for x86 Linux "struct sigcontext": */ #define LINUX_SC_GS_OFF 0x00 #define LINUX_SC_GSH_OFF 0x02 #define LINUX_SC_FS_OFF 0x04 #define LINUX_SC_FSH_OFF 0x06 #define LINUX_SC_ES_OFF 0x08 #define LINUX_SC_ESH_OFF 0x0a #define LINUX_SC_DS_OFF 0x0c #define LINUX_SC_DSH_OFF 0x0e #define LINUX_SC_EDI_OFF 0x10 #define LINUX_SC_ESI_OFF 0x14 #define LINUX_SC_EBP_OFF 0x18 #define LINUX_SC_ESP_OFF 0x1c #define LINUX_SC_EBX_OFF 0x20 #define LINUX_SC_EDX_OFF 0x24 #define LINUX_SC_ECX_OFF 0x28 #define LINUX_SC_EAX_OFF 0x2c #define LINUX_SC_TRAPNO_OFF 0x30 #define LINUX_SC_ERR_OFF 0x34 #define LINUX_SC_EIP_OFF 0x38 #define LINUX_SC_CS_OFF 0x3c #define LINUX_SC_CSH_OFF 0x3e #define LINUX_SC_EFLAGS_OFF 0x40 #define LINUX_SC_ESP_AT_SIGNAL_OFF 0x44 #define LINUX_SC_SS_OFF 0x48 #define LINUX_SC_SSH_OFF 0x4a #define LINUX_SC_FPSTATE_OFF 0x4c #define LINUX_SC_OLDMASK_OFF 0x50 #define LINUX_SC_CR2_OFF 0x54 /* Offsets for x86 Linux "struct _fpstate": */ #define LINUX_FPSTATE_CW_OFF 0x000 #define LINUX_FPSTATE_SW_OFF 0x004 #define LINUX_FPSTATE_TAG_OFF 0x008 #define LINUX_FPSTATE_IPOFF_OFF 0x00c #define LINUX_FPSTATE_CSSEL_OFF 0x010 #define LINUX_FPSTATE_DATAOFF_OFF 0x014 #define LINUX_FPSTATE_DATASEL_OFF 0x018 #define LINUX_FPSTATE_ST0_OFF 0x01c #define LINUX_FPSTATE_ST1_OFF 0x026 #define LINUX_FPSTATE_ST2_OFF 0x030 #define LINUX_FPSTATE_ST3_OFF 0x03a #define LINUX_FPSTATE_ST4_OFF 0x044 #define LINUX_FPSTATE_ST5_OFF 0x04e #define LINUX_FPSTATE_ST6_OFF 0x058 #define LINUX_FPSTATE_ST7_OFF 0x062 #define LINUX_FPSTATE_STATUS_OFF 0x06c #define LINUX_FPSTATE_MAGIC_OFF 0x06e #define LINUX_FPSTATE_FXSR_ENV_OFF 0x070 #define LINUX_FPSTATE_MXCSR_OFF 0x088 #define LINUX_FPSTATE_FXSR_ST0_OFF 0x090 #define LINUX_FPSTATE_FXSR_ST1_OFF 0x0a0 #define LINUX_FPSTATE_FXSR_ST2_OFF 0x0b0 #define LINUX_FPSTATE_FXSR_ST3_OFF 0x0c0 #define LINUX_FPSTATE_FXSR_ST4_OFF 0x0d0 #define LINUX_FPSTATE_FXSR_ST5_OFF 0x0e0 #define LINUX_FPSTATE_FXSR_ST6_OFF 0x0f0 #define LINUX_FPSTATE_FXSR_ST7_OFF 0x100 #define LINUX_FPSTATE_XMM0_OFF 0x110 #define LINUX_FPSTATE_XMM1_OFF 0x120 #define LINUX_FPSTATE_XMM2_OFF 0x130 #define LINUX_FPSTATE_XMM3_OFF 0x140 #define LINUX_FPSTATE_XMM4_OFF 0x150 #define LINUX_FPSTATE_XMM5_OFF 0x160 #define LINUX_FPSTATE_XMM6_OFF 0x170 #define LINUX_FPSTATE_XMM7_OFF 0x180 /* FreeBSD-specific definitions: */ #define FREEBSD_SC_UCONTEXT_OFF 0x20 #define FREEBSD_UC_MCONTEXT_OFF 0x10 #define FREEBSD_UC_MCONTEXT_GS_OFF 0x14 #define FREEBSD_UC_MCONTEXT_FS_OFF 0x18 #define FREEBSD_UC_MCONTEXT_ES_OFF 0x1c #define FREEBSD_UC_MCONTEXT_DS_OFF 0x20 #define FREEBSD_UC_MCONTEXT_EDI_OFF 0x24 #define FREEBSD_UC_MCONTEXT_ESI_OFF 0x28 #define FREEBSD_UC_MCONTEXT_EBP_OFF 0x2c #define FREEBSD_UC_MCONTEXT_EBX_OFF 0x34 #define FREEBSD_UC_MCONTEXT_EDX_OFF 0x38 #define FREEBSD_UC_MCONTEXT_ECX_OFF 0x3c #define FREEBSD_UC_MCONTEXT_EAX_OFF 0x40 #define FREEBSD_UC_MCONTEXT_TRAPNO_OFF 0x44 #define FREEBSD_UC_MCONTEXT_EIP_OFF 0x4c #define FREEBSD_UC_MCONTEXT_ESP_OFF 0x58 #define FREEBSD_UC_MCONTEXT_CS_OFF 0x50 #define FREEBSD_UC_MCONTEXT_EFLAGS_OFF 0x54 #define FREEBSD_UC_MCONTEXT_SS_OFF 0x5c #define FREEBSD_UC_MCONTEXT_MC_LEN_OFF 0x60 #define FREEBSD_UC_MCONTEXT_FPFORMAT_OFF 0x64 #define FREEBSD_UC_MCONTEXT_OWNEDFP_OFF 0x68 #define FREEBSD_UC_MCONTEXT_FPSTATE_OFF 0x70 #define FREEBSD_UC_MCONTEXT_CW_OFF 0x70 #define FREEBSD_UC_MCONTEXT_SW_OFF 0x74 #define FREEBSD_UC_MCONTEXT_TAG_OFF 0x78 #define FREEBSD_UC_MCONTEXT_IPOFF_OFF 0x7c #define FREEBSD_UC_MCONTEXT_CSSEL_OFF 0x80 #define FREEBSD_UC_MCONTEXT_DATAOFF_OFF 0x84 #define FREEBSD_US_MCONTEXT_DATASEL_OFF 0x88 #define FREEBSD_UC_MCONTEXT_ST0_OFF 0x8c #define FREEBSD_UC_MCONTEXT_CW_XMM_OFF 0x70 #define FREEBSD_UC_MCONTEXT_SW_XMM_OFF 0x72 #define FREEBSD_UC_MCONTEXT_TAG_XMM_OFF 0x74 #define FREEBSD_UC_MCONTEXT_IPOFF_XMM_OFF 0x78 #define FREEBSD_UC_MCONTEXT_CSSEL_XMM_OFF 0x7c #define FREEBSD_UC_MCONTEXT_DATAOFF_XMM_OFF 0x80 #define FREEBSD_US_MCONTEXT_DATASEL_XMM_OFF 0x84 #define FREEBSD_UC_MCONTEXT_MXCSR_XMM_OFF 0x88 #define FREEBSD_UC_MCONTEXT_ST0_XMM_OFF 0x90 #define FREEBSD_UC_MCONTEXT_XMM0_OFF 0x110 #define FREEBSD_UC_MCONTEXT_MC_LEN_VAL 0x280 #define FREEBSD_UC_MCONTEXT_FPFMT_NODEV 0x10000 #define FREEBSD_UC_MCONTEXT_FPFMT_387 0x10001 #define FREEBSD_UC_MCONTEXT_FPFMT_XMM 0x10002 #define FREEBSD_UC_MCONTEXT_FPOWNED_NONE 0x20000 #define FREEBSD_UC_MCONTEXT_FPOWNED_FPU 0x20001 #define FREEBSD_UC_MCONTEXT_FPOWNED_PCB 0x20002
9d33952e120d210b6f530799d297f4f850a66861
35ece1a78314060ee6f815745db24f85012a6c77
/texlive/texk/xdvik/browser.c
59a1d2273774da663c1820df1f7a87f136866746
[ "LicenseRef-scancode-other-permissive" ]
permissive
clerkma/ptex-ng
dabc12a3df48aef6107efd1b4555f0141f858e12
a646d1cfe835712601b7edcfa96ad90c2549778b
refs/heads/master
2023-08-16T23:10:11.143532
2023-08-13T06:52:31
2023-08-13T06:52:31
24,095,177
260
46
null
2022-06-22T04:57:30
2014-09-16T10:25:01
C
UTF-8
C
false
false
7,998
c
browser.c
/* routines for launching a browser to retrieve remote documents. * Copyright(C) 2002-2004 the xdvik development team. */ /* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "xdvi-config.h" #include "xdvi.h" #include <ctype.h> #include "kpathsea/c-fopen.h" #include "kpathsea/c-stat.h" #include <sys/types.h> #include <sys/wait.h> /* for waitpid(), WEXITSTATUS */ #include "util.h" #include "message-window.h" #include "events.h" #include "browser.h" #include "string-utils.h" #include "statusline.h" static const char *const default_browser_cmd = "xdg-open %s" ":htmlview %s" ":firefox -remote \"openURL(%s,new-window)\"" ":mozilla -remote \"openURL(%s,new-window)\"" ":netscape -remote \"openURL(%s,new-window)\"" ":xterm -e w3m %s" ":xterm -e lynx %s" ":xterm -e wget %s"; static Boolean do_fork_browser(char *argv[]) { pid_t pid; switch(pid = vfork()) { case -1: /* forking error */ perror("fork"); return False; case 0: /* child */ execvp(argv[0], argv); /* arrive here only if execvp failed */ XDVI_ERROR((stderr, "Execution of %s failed: %s", argv[0], strerror(errno))); _exit(EXIT_FAILURE); return False; /* notreached - make compiler happy */ default: /* parent */ { int timeout; for (timeout = 0; timeout < 15; timeout++) { int status; if (waitpid(pid, &status, WNOHANG)) { TRACE_HTEX((stderr, "waiting for %d: %d", (int)pid, status)); if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) { fprintf(stderr, "Command `%s' exited with error status %d\n", argv[0], WEXITSTATUS(status)); return False; } else { TRACE_HTEX((stderr, "Child exited OK.")); return True; } } else { /* when do we arrive here?? */ sleep(1); } } else { /* waiting for child to finish */ sleep(1); } } return True; /* child not finished in time */ } } } static Boolean fork_browser(const char *browser, const char *url) { char *cmd, *orig_cmd, *last_arg; char **argv = NULL; int argv_len = 0; int i = 0, j = 0; int match = 0; int retval; cmd = xmalloc(strlen(browser) + strlen(url) + 1); orig_cmd = cmd; /* for freeing it later */ last_arg = cmd; /* skip over leading space */ while (isspace((int)browser[i])) i++; while (browser[i] != '\0') { while (j >= argv_len) { argv_len += 10; argv = xrealloc(argv, argv_len * sizeof *argv); } /* chop into separate arguments at spaces */ if (isspace((int)browser[i])) { *cmd++ = '\0'; argv[j++] = format_arg(last_arg, url, &match); last_arg = cmd; /* skip over multiple spaces */ while (isspace((int)browser[i])) i++; } /* remove quotes around arguments containing spaces */ else if (browser[i] == '\'' || browser[i] == '"') { int len = 0; /* normalize %% and replace %s by URL */ argv[j++] = unquote_arg(browser+i, url, &match, &len); if (len == 0) { /* excess quote at end of arg; try to recover: */ j--; break; } i += len + 1; } else { *cmd++ = browser[i++]; } } *cmd = browser[i]; /* null-teminate */ /* append last, unless it contained only skipped spaces */ if (strlen(last_arg) > 0) { argv[j++] = format_arg(last_arg, url, &match); } if (match == 0) argv[j++] = xstrdup(url); argv[j++] = NULL; for (i = 0; argv[i] != NULL; i++) { TRACE_HTEX((stderr, "arg[%d]: |%s|", i, argv[i])); } /* This will wait for child exits: */ retval = do_fork_browser(argv); for (i = 0; argv[i] != NULL; i++) free(argv[i]); free(orig_cmd); free(argv); return retval; } void launch_browser(const char *filename) { const char *browser; int pid; struct xchild *my_child; struct xio *my_io; int err_pipe[2]; /* try to set it from possible resources: First command-line argument or X resource, then environment variables, then default_browser_cmd */ for (;;) { if ((browser = resource.browser) != NULL) break; if ((browser = getenv("BROWSER")) != NULL) break; if ((browser = getenv("WWWBROWSER")) != NULL) break; XDVI_INFO((stderr, "Browser not set (xdvi.wwwBrowser, -browser or $BROWSER environment variable).")); XDVI_INFO((stderr, "Using built-in default: `%s'", default_browser_cmd)); browser = default_browser_cmd; break; } /* fork first time so that we can wait for children, without freezing the GUI. FIXME: this copies stuff from fork_process for the inter-process communication stuff - it would be better to have this in one function. */ my_child = xmalloc(sizeof *my_child); my_io = xmalloc(sizeof *my_io); statusline_info(STATUS_MEDIUM, "Trying to launch browser ..."); /* flush output buffers to avoid double buffering (i.e. data waiting in the output buffer being written twice, by the parent and the child) */ fflush(stdout); fflush(stderr); if (pipe(err_pipe) < 0) { perror("pipe"); _exit(-1); } switch (pid = fork()) { case -1: /* forking error */ perror("fork"); close(err_pipe[0]); close(err_pipe[1]); return; case 0: /* child */ { char *tmp_browser = xstrdup(browser); close(err_pipe[0]); /* no reading from stderr */ /* make stderr of child go to err_pipe[1] */ if (dup2(err_pipe[1], STDERR_FILENO) != STDERR_FILENO) { perror("dup2 for stderr"); _exit(EXIT_FAILURE); return; /* make compiler happy */ } /* BROWSER is a colon-separated list of commands, in decreasing preference; use the first that can be forked successfully. Note that the return value of the command isn't used at all (with GUI programs, xdvi shouldn't hang until they terminate!) */ while (tmp_browser != NULL) { char *next = strchr(tmp_browser, ':'); if (next != NULL) { *next++ = '\0'; } TRACE_HTEX((stderr, "trying browser |%s|", tmp_browser)); /* fork a second time to start the browser */ if (fork_browser(tmp_browser, filename)) { /* foking worked */ _exit(EXIT_SUCCESS); } tmp_browser = next; } /* child arrives here only if none of the commands worked */ XDVI_WARNING((stderr, "None of the browser commands in the `browser' resource (%s) worked\n", browser)); free(tmp_browser); _exit(EXIT_FAILURE); } default: /* parent */ close(err_pipe[1]); /* no writing to stderr */ my_io->next = NULL; my_io->fd = err_pipe[0]; my_io->xio_events = XIO_IN; #if HAVE_POLL my_io->pfd = NULL; #endif my_io->read_proc = read_child_error; my_io->write_proc = NULL; my_io->data = NULL; my_child->next = NULL; my_child->pid = pid; my_child->name = NULL; my_child->proc = handle_child_exit; my_child->data = NULL; my_child->io = my_io; set_chld(my_child); statusline_info(STATUS_MEDIUM, "Trying to launch browser ... done."); } }
37fe614ba93d251288d4d319d8be2976398c6fc1
0744dcc5394cebf57ebcba343747af6871b67017
/os/board/rtl8720e/src/component/soc/amebalite/cmsis-dsp/Source/TransformFunctions/arm_cfft_q31.c
71e9a57833bacb700a7c580180bf50e04c0446c1
[ "GPL-1.0-or-later", "BSD-3-Clause", "ISC", "MIT", "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-other-permissive", "Apache-2.0" ]
permissive
Samsung/TizenRT
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
refs/heads/master
2023-08-31T08:59:33.327998
2023-08-08T06:09:20
2023-08-31T04:38:20
82,517,252
590
719
Apache-2.0
2023-09-14T06:54:49
2017-02-20T04:38:30
C
UTF-8
C
false
false
20,556
c
arm_cfft_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_cfft_q31.c * Description: Combined Radix Decimation in Frequency CFFT fixed point processing function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" #if defined(ARM_MATH_MVEI) #include "arm_vec_fft.h" static void arm_bitreversal_32_inpl_mve( uint32_t *pSrc, const uint16_t bitRevLen, const uint16_t *pBitRevTab) { uint64_t *src = (uint64_t *) pSrc; uint32_t blkCnt; /* loop counters */ uint32x4_t bitRevTabOff; uint32x4_t one = vdupq_n_u32(1); blkCnt = (bitRevLen / 2) / 2; while (blkCnt > 0U) { bitRevTabOff = vldrhq_u32(pBitRevTab); pBitRevTab += 4; uint64x2_t bitRevOff1 = vmullbq_int_u32(bitRevTabOff, one); uint64x2_t bitRevOff2 = vmulltq_int_u32(bitRevTabOff, one); uint64x2_t in1 = vldrdq_gather_offset_u64(src, bitRevOff1); uint64x2_t in2 = vldrdq_gather_offset_u64(src, bitRevOff2); vstrdq_scatter_offset_u64(src, bitRevOff1, in2); vstrdq_scatter_offset_u64(src, bitRevOff2, in1); /* * Decrement the blockSize loop counter */ blkCnt--; } } static void _arm_radix4_butterfly_q31_mve( const arm_cfft_instance_q31 *S, q31_t *pSrc, uint32_t fftLen) { q31x4_t vecTmp0, vecTmp1; q31x4_t vecSum0, vecDiff0, vecSum1, vecDiff1; q31x4_t vecA, vecB, vecC, vecD; q31x4_t vecW; uint32_t blkCnt; uint32_t n1, n2; uint32_t stage = 0; int32_t iter = 1; static const uint32_t strides[4] = { (0 - 16) *sizeof(q31_t *), (1 - 16) *sizeof(q31_t *), (8 - 16) *sizeof(q31_t *), (9 - 16) *sizeof(q31_t *) }; /* * Process first stages * Each stage in middle stages provides two down scaling of the input */ n2 = fftLen; n1 = n2; n2 >>= 2u; for (int k = fftLen / 4u; k > 1; k >>= 2u) { for (int i = 0; i < iter; i++) { q31_t const *p_rearranged_twiddle_tab_stride2 = &S->rearranged_twiddle_stride2[ S->rearranged_twiddle_tab_stride2_arr[stage]]; q31_t const *p_rearranged_twiddle_tab_stride3 = &S->rearranged_twiddle_stride3[ S->rearranged_twiddle_tab_stride3_arr[stage]]; q31_t const *p_rearranged_twiddle_tab_stride1 = &S->rearranged_twiddle_stride1[ S->rearranged_twiddle_tab_stride1_arr[stage]]; q31_t const *pW1, *pW2, *pW3; q31_t *inA = pSrc + CMPLX_DIM * i * n1; q31_t *inB = inA + n2 * CMPLX_DIM; q31_t *inC = inB + n2 * CMPLX_DIM; q31_t *inD = inC + n2 * CMPLX_DIM; pW1 = p_rearranged_twiddle_tab_stride1; pW2 = p_rearranged_twiddle_tab_stride2; pW3 = p_rearranged_twiddle_tab_stride3; blkCnt = n2 / 2; /* * load 2 x q31 complex pair */ vecA = vldrwq_s32(inA); vecC = vldrwq_s32(inC); while (blkCnt > 0U) { vecB = vldrwq_s32(inB); vecD = vldrwq_s32(inD); vecSum0 = vhaddq(vecA, vecC); vecDiff0 = vhsubq(vecA, vecC); vecSum1 = vhaddq(vecB, vecD); vecDiff1 = vhsubq(vecB, vecD); /* * [ 1 1 1 1 ] * [ A B C D ]' .* 1 */ vecTmp0 = vhaddq(vecSum0, vecSum1); vst1q(inA, vecTmp0); inA += 4; /* * [ 1 -1 1 -1 ] * [ A B C D ]' */ vecTmp0 = vhsubq(vecSum0, vecSum1); /* * [ 1 -1 1 -1 ] * [ A B C D ]'.* W2 */ vecW = vld1q(pW2); pW2 += 4; vecTmp1 = MVE_CMPLX_MULT_FX_AxB(vecW, vecTmp0); vst1q(inB, vecTmp1); inB += 4; /* * [ 1 -i -1 +i ] * [ A B C D ]' */ vecTmp0 = MVE_CMPLX_SUB_FX_A_ixB(vecDiff0, vecDiff1); /* * [ 1 -i -1 +i ] * [ A B C D ]'.* W1 */ vecW = vld1q(pW1); pW1 += 4; vecTmp1 = MVE_CMPLX_MULT_FX_AxB(vecW, vecTmp0); vst1q(inC, vecTmp1); inC += 4; /* * [ 1 +i -1 -i ] * [ A B C D ]' */ vecTmp0 = MVE_CMPLX_ADD_FX_A_ixB(vecDiff0, vecDiff1); /* * [ 1 +i -1 -i ] * [ A B C D ]'.* W3 */ vecW = vld1q(pW3); pW3 += 4; vecTmp1 = MVE_CMPLX_MULT_FX_AxB(vecW, vecTmp0); vst1q(inD, vecTmp1); inD += 4; vecA = vldrwq_s32(inA); vecC = vldrwq_s32(inC); blkCnt--; } } n1 = n2; n2 >>= 2u; iter = iter << 2; stage++; } /* * End of 1st stages process * data is in 11.21(q21) format for the 1024 point as there are 3 middle stages * data is in 9.23(q23) format for the 256 point as there are 2 middle stages * data is in 7.25(q25) format for the 64 point as there are 1 middle stage * data is in 5.27(q27) format for the 16 point as there are no middle stages */ /* * start of Last stage process */ // uint32x4_t vecScGathAddr = *(uint32x4_t *) strides; uint32x4_t vecScGathAddr = vld1q_u32(strides); vecScGathAddr = vecScGathAddr + (uint32_t) pSrc; /* * load scheduling */ vecA = vldrwq_gather_base_wb_s32(&vecScGathAddr, 64); vecC = vldrwq_gather_base_s32(vecScGathAddr, 16); blkCnt = (fftLen >> 3); while (blkCnt > 0U) { vecSum0 = vhaddq(vecA, vecC); vecDiff0 = vhsubq(vecA, vecC); vecB = vldrwq_gather_base_s32(vecScGathAddr, 8); vecD = vldrwq_gather_base_s32(vecScGathAddr, 24); vecSum1 = vhaddq(vecB, vecD); vecDiff1 = vhsubq(vecB, vecD); /* * pre-load for next iteration */ vecA = vldrwq_gather_base_wb_s32(&vecScGathAddr, 64); vecC = vldrwq_gather_base_s32(vecScGathAddr, 16); vecTmp0 = vhaddq(vecSum0, vecSum1); vstrwq_scatter_base_s32(vecScGathAddr, -64, vecTmp0); vecTmp0 = vhsubq(vecSum0, vecSum1); vstrwq_scatter_base_s32(vecScGathAddr, -64 + 8, vecTmp0); vecTmp0 = MVE_CMPLX_SUB_FX_A_ixB(vecDiff0, vecDiff1); vstrwq_scatter_base_s32(vecScGathAddr, -64 + 16, vecTmp0); vecTmp0 = MVE_CMPLX_ADD_FX_A_ixB(vecDiff0, vecDiff1); vstrwq_scatter_base_s32(vecScGathAddr, -64 + 24, vecTmp0); blkCnt--; } /* * output is in 11.21(q21) format for the 1024 point * output is in 9.23(q23) format for the 256 point * output is in 7.25(q25) format for the 64 point * output is in 5.27(q27) format for the 16 point */ } static void arm_cfft_radix4by2_q31_mve(const arm_cfft_instance_q31 *S, q31_t *pSrc, uint32_t fftLen) { uint32_t n2; q31_t *pIn0; q31_t *pIn1; const q31_t *pCoef = S->pTwiddle; uint32_t blkCnt; q31x4_t vecIn0, vecIn1, vecSum, vecDiff; q31x4_t vecCmplxTmp, vecTw; n2 = fftLen >> 1; pIn0 = pSrc; pIn1 = pSrc + fftLen; blkCnt = n2 / 2; while (blkCnt > 0U) { vecIn0 = vld1q_s32(pIn0); vecIn1 = vld1q_s32(pIn1); vecIn0 = vecIn0 >> 1; vecIn1 = vecIn1 >> 1; vecSum = vhaddq(vecIn0, vecIn1); vst1q(pIn0, vecSum); pIn0 += 4; vecTw = vld1q_s32(pCoef); pCoef += 4; vecDiff = vhsubq(vecIn0, vecIn1); vecCmplxTmp = MVE_CMPLX_MULT_FX_AxConjB(vecDiff, vecTw); vst1q(pIn1, vecCmplxTmp); pIn1 += 4; blkCnt--; } _arm_radix4_butterfly_q31_mve(S, pSrc, n2); _arm_radix4_butterfly_q31_mve(S, pSrc + fftLen, n2); pIn0 = pSrc; blkCnt = (fftLen << 1) >> 2; while (blkCnt > 0U) { vecIn0 = vld1q_s32(pIn0); vecIn0 = vecIn0 << 1; vst1q(pIn0, vecIn0); pIn0 += 4; blkCnt--; } /* * tail * (will be merged thru tail predication) */ blkCnt = (fftLen << 1) & 3; if (blkCnt > 0U) { mve_pred16_t p0 = vctp32q(blkCnt); vecIn0 = vld1q_s32(pIn0); vecIn0 = vecIn0 << 1; vstrwq_p(pIn0, vecIn0, p0); } } static void _arm_radix4_butterfly_inverse_q31_mve( const arm_cfft_instance_q31 *S, q31_t *pSrc, uint32_t fftLen) { q31x4_t vecTmp0, vecTmp1; q31x4_t vecSum0, vecDiff0, vecSum1, vecDiff1; q31x4_t vecA, vecB, vecC, vecD; q31x4_t vecW; uint32_t blkCnt; uint32_t n1, n2; uint32_t stage = 0; int32_t iter = 1; static const uint32_t strides[4] = { (0 - 16) *sizeof(q31_t *), (1 - 16) *sizeof(q31_t *), (8 - 16) *sizeof(q31_t *), (9 - 16) *sizeof(q31_t *) }; /* * Process first stages * Each stage in middle stages provides two down scaling of the input */ n2 = fftLen; n1 = n2; n2 >>= 2u; for (int k = fftLen / 4u; k > 1; k >>= 2u) { for (int i = 0; i < iter; i++) { q31_t const *p_rearranged_twiddle_tab_stride2 = &S->rearranged_twiddle_stride2[ S->rearranged_twiddle_tab_stride2_arr[stage]]; q31_t const *p_rearranged_twiddle_tab_stride3 = &S->rearranged_twiddle_stride3[ S->rearranged_twiddle_tab_stride3_arr[stage]]; q31_t const *p_rearranged_twiddle_tab_stride1 = &S->rearranged_twiddle_stride1[ S->rearranged_twiddle_tab_stride1_arr[stage]]; q31_t const *pW1, *pW2, *pW3; q31_t *inA = pSrc + CMPLX_DIM * i * n1; q31_t *inB = inA + n2 * CMPLX_DIM; q31_t *inC = inB + n2 * CMPLX_DIM; q31_t *inD = inC + n2 * CMPLX_DIM; pW1 = p_rearranged_twiddle_tab_stride1; pW2 = p_rearranged_twiddle_tab_stride2; pW3 = p_rearranged_twiddle_tab_stride3; blkCnt = n2 / 2; /* * load 2 x q31 complex pair */ vecA = vldrwq_s32(inA); vecC = vldrwq_s32(inC); while (blkCnt > 0U) { vecB = vldrwq_s32(inB); vecD = vldrwq_s32(inD); vecSum0 = vhaddq(vecA, vecC); vecDiff0 = vhsubq(vecA, vecC); vecSum1 = vhaddq(vecB, vecD); vecDiff1 = vhsubq(vecB, vecD); /* * [ 1 1 1 1 ] * [ A B C D ]' .* 1 */ vecTmp0 = vhaddq(vecSum0, vecSum1); vst1q(inA, vecTmp0); inA += 4; /* * [ 1 -1 1 -1 ] * [ A B C D ]' */ vecTmp0 = vhsubq(vecSum0, vecSum1); /* * [ 1 -1 1 -1 ] * [ A B C D ]'.* W2 */ vecW = vld1q(pW2); pW2 += 4; vecTmp1 = MVE_CMPLX_MULT_FX_AxConjB(vecTmp0, vecW); vst1q(inB, vecTmp1); inB += 4; /* * [ 1 -i -1 +i ] * [ A B C D ]' */ vecTmp0 = MVE_CMPLX_ADD_FX_A_ixB(vecDiff0, vecDiff1); /* * [ 1 -i -1 +i ] * [ A B C D ]'.* W1 */ vecW = vld1q(pW1); pW1 += 4; vecTmp1 = MVE_CMPLX_MULT_FX_AxConjB(vecTmp0, vecW); vst1q(inC, vecTmp1); inC += 4; /* * [ 1 +i -1 -i ] * [ A B C D ]' */ vecTmp0 = MVE_CMPLX_SUB_FX_A_ixB(vecDiff0, vecDiff1); /* * [ 1 +i -1 -i ] * [ A B C D ]'.* W3 */ vecW = vld1q(pW3); pW3 += 4; vecTmp1 = MVE_CMPLX_MULT_FX_AxConjB(vecTmp0, vecW); vst1q(inD, vecTmp1); inD += 4; vecA = vldrwq_s32(inA); vecC = vldrwq_s32(inC); blkCnt--; } } n1 = n2; n2 >>= 2u; iter = iter << 2; stage++; } /* * End of 1st stages process * data is in 11.21(q21) format for the 1024 point as there are 3 middle stages * data is in 9.23(q23) format for the 256 point as there are 2 middle stages * data is in 7.25(q25) format for the 64 point as there are 1 middle stage * data is in 5.27(q27) format for the 16 point as there are no middle stages */ /* * start of Last stage process */ // uint32x4_t vecScGathAddr = *(uint32x4_t *) strides; uint32x4_t vecScGathAddr = vld1q_u32(strides); vecScGathAddr = vecScGathAddr + (uint32_t) pSrc; /* * load scheduling */ vecA = vldrwq_gather_base_wb_s32(&vecScGathAddr, 64); vecC = vldrwq_gather_base_s32(vecScGathAddr, 16); blkCnt = (fftLen >> 3); while (blkCnt > 0U) { vecSum0 = vhaddq(vecA, vecC); vecDiff0 = vhsubq(vecA, vecC); vecB = vldrwq_gather_base_s32(vecScGathAddr, 8); vecD = vldrwq_gather_base_s32(vecScGathAddr, 24); vecSum1 = vhaddq(vecB, vecD); vecDiff1 = vhsubq(vecB, vecD); /* * pre-load for next iteration */ vecA = vldrwq_gather_base_wb_s32(&vecScGathAddr, 64); vecC = vldrwq_gather_base_s32(vecScGathAddr, 16); vecTmp0 = vhaddq(vecSum0, vecSum1); vstrwq_scatter_base_s32(vecScGathAddr, -64, vecTmp0); vecTmp0 = vhsubq(vecSum0, vecSum1); vstrwq_scatter_base_s32(vecScGathAddr, -64 + 8, vecTmp0); vecTmp0 = MVE_CMPLX_ADD_FX_A_ixB(vecDiff0, vecDiff1); vstrwq_scatter_base_s32(vecScGathAddr, -64 + 16, vecTmp0); vecTmp0 = MVE_CMPLX_SUB_FX_A_ixB(vecDiff0, vecDiff1); vstrwq_scatter_base_s32(vecScGathAddr, -64 + 24, vecTmp0); blkCnt--; } /* * output is in 11.21(q21) format for the 1024 point * output is in 9.23(q23) format for the 256 point * output is in 7.25(q25) format for the 64 point * output is in 5.27(q27) format for the 16 point */ } static void arm_cfft_radix4by2_inverse_q31_mve(const arm_cfft_instance_q31 *S, q31_t *pSrc, uint32_t fftLen) { uint32_t n2; q31_t *pIn0; q31_t *pIn1; const q31_t *pCoef = S->pTwiddle; //uint16_t twidCoefModifier = arm_cfft_radix2_twiddle_factor(S->fftLen); //q31_t twidIncr = (2 * twidCoefModifier * sizeof(q31_t)); uint32_t blkCnt; //uint64x2_t vecOffs; q31x4_t vecIn0, vecIn1, vecSum, vecDiff; q31x4_t vecCmplxTmp, vecTw; n2 = fftLen >> 1; pIn0 = pSrc; pIn1 = pSrc + fftLen; //vecOffs[0] = 0; //vecOffs[1] = (uint64_t) twidIncr; blkCnt = n2 / 2; while (blkCnt > 0U) { vecIn0 = vld1q_s32(pIn0); vecIn1 = vld1q_s32(pIn1); vecIn0 = vecIn0 >> 1; vecIn1 = vecIn1 >> 1; vecSum = vhaddq(vecIn0, vecIn1); vst1q(pIn0, vecSum); pIn0 += 4; //vecTw = (q31x4_t) vldrdq_gather_offset_s64(pCoef, vecOffs); vecTw = vld1q_s32(pCoef); pCoef += 4; vecDiff = vhsubq(vecIn0, vecIn1); vecCmplxTmp = MVE_CMPLX_MULT_FX_AxB(vecDiff, vecTw); vst1q(pIn1, vecCmplxTmp); pIn1 += 4; //vecOffs = vaddq((q31x4_t) vecOffs, 2 * twidIncr); blkCnt--; } _arm_radix4_butterfly_inverse_q31_mve(S, pSrc, n2); _arm_radix4_butterfly_inverse_q31_mve(S, pSrc + fftLen, n2); pIn0 = pSrc; blkCnt = (fftLen << 1) >> 2; while (blkCnt > 0U) { vecIn0 = vld1q_s32(pIn0); vecIn0 = vecIn0 << 1; vst1q(pIn0, vecIn0); pIn0 += 4; blkCnt--; } /* * tail * (will be merged thru tail predication) */ blkCnt = (fftLen << 1) & 3; if (blkCnt > 0U) { mve_pred16_t p0 = vctp32q(blkCnt); vecIn0 = vld1q_s32(pIn0); vecIn0 = vecIn0 << 1; vstrwq_p(pIn0, vecIn0, p0); } } /** @ingroup groupTransforms */ /** @addtogroup ComplexFFT @{ */ /** @brief Processing function for the Q31 complex FFT. @param[in] S points to an instance of the fixed-point CFFT structure @param[in,out] p1 points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place @param[in] ifftFlag flag that selects transform direction - value = 0: forward transform - value = 1: inverse transform @param[in] bitReverseFlag flag that enables / disables bit reversal of output - value = 0: disables bit reversal of output - value = 1: enables bit reversal of output @return none */ void arm_cfft_q31( const arm_cfft_instance_q31 *S, q31_t *pSrc, uint8_t ifftFlag, uint8_t bitReverseFlag) { uint32_t fftLen = S->fftLen; if (ifftFlag == 1U) { switch (fftLen) { case 16: case 64: case 256: case 1024: case 4096: _arm_radix4_butterfly_inverse_q31_mve(S, pSrc, fftLen); break; case 32: case 128: case 512: case 2048: arm_cfft_radix4by2_inverse_q31_mve(S, pSrc, fftLen); break; } } else { switch (fftLen) { case 16: case 64: case 256: case 1024: case 4096: _arm_radix4_butterfly_q31_mve(S, pSrc, fftLen); break; case 32: case 128: case 512: case 2048: arm_cfft_radix4by2_q31_mve(S, pSrc, fftLen); break; } } if (bitReverseFlag) { arm_bitreversal_32_inpl_mve((uint32_t *)pSrc, S->bitRevLength, S->pBitRevTable); } } #else extern void arm_radix4_butterfly_q31( q31_t *pSrc, uint32_t fftLen, const q31_t *pCoef, uint32_t twidCoefModifier); extern void arm_radix4_butterfly_inverse_q31( q31_t *pSrc, uint32_t fftLen, const q31_t *pCoef, uint32_t twidCoefModifier); extern void arm_bitreversal_32( uint32_t *pSrc, const uint16_t bitRevLen, const uint16_t *pBitRevTable); void arm_cfft_radix4by2_q31( q31_t *pSrc, uint32_t fftLen, const q31_t *pCoef); void arm_cfft_radix4by2_inverse_q31( q31_t *pSrc, uint32_t fftLen, const q31_t *pCoef); /** @ingroup groupTransforms */ /** @addtogroup ComplexFFT @{ */ /** @brief Processing function for the Q31 complex FFT. @param[in] S points to an instance of the fixed-point CFFT structure @param[in,out] p1 points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place @param[in] ifftFlag flag that selects transform direction - value = 0: forward transform - value = 1: inverse transform @param[in] bitReverseFlag flag that enables / disables bit reversal of output - value = 0: disables bit reversal of output - value = 1: enables bit reversal of output @return none */ void arm_cfft_q31( const arm_cfft_instance_q31 *S, q31_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag) { uint32_t L = S->fftLen; if (ifftFlag == 1U) { switch (L) { case 16: case 64: case 256: case 1024: case 4096: arm_radix4_butterfly_inverse_q31(p1, L, (q31_t *)S->pTwiddle, 1); break; case 32: case 128: case 512: case 2048: arm_cfft_radix4by2_inverse_q31(p1, L, S->pTwiddle); break; } } else { switch (L) { case 16: case 64: case 256: case 1024: case 4096: arm_radix4_butterfly_q31(p1, L, (q31_t *)S->pTwiddle, 1); break; case 32: case 128: case 512: case 2048: arm_cfft_radix4by2_q31(p1, L, S->pTwiddle); break; } } if (bitReverseFlag) { arm_bitreversal_32((uint32_t *) p1, S->bitRevLength, S->pBitRevTable); } } /** @} end of ComplexFFT group */ void arm_cfft_radix4by2_q31( q31_t *pSrc, uint32_t fftLen, const q31_t *pCoef) { uint32_t i, l; uint32_t n2; q31_t xt, yt, cosVal, sinVal; q31_t p0, p1; n2 = fftLen >> 1U; for (i = 0; i < n2; i++) { cosVal = pCoef[2 * i]; sinVal = pCoef[2 * i + 1]; l = i + n2; xt = (pSrc[2 * i] >> 2U) - (pSrc[2 * l] >> 2U); pSrc[2 * i] = (pSrc[2 * i] >> 2U) + (pSrc[2 * l] >> 2U); yt = (pSrc[2 * i + 1] >> 2U) - (pSrc[2 * l + 1] >> 2U); pSrc[2 * i + 1] = (pSrc[2 * l + 1] >> 2U) + (pSrc[2 * i + 1] >> 2U); mult_32x32_keep32_R(p0, xt, cosVal); mult_32x32_keep32_R(p1, yt, cosVal); multAcc_32x32_keep32_R(p0, yt, sinVal); multSub_32x32_keep32_R(p1, xt, sinVal); pSrc[2 * l] = p0 << 1; pSrc[2 * l + 1] = p1 << 1; } /* first col */ arm_radix4_butterfly_q31(pSrc, n2, (q31_t *)pCoef, 2U); /* second col */ arm_radix4_butterfly_q31(pSrc + fftLen, n2, (q31_t *)pCoef, 2U); n2 = fftLen >> 1U; for (i = 0; i < n2; i++) { p0 = pSrc[4 * i + 0]; p1 = pSrc[4 * i + 1]; xt = pSrc[4 * i + 2]; yt = pSrc[4 * i + 3]; p0 <<= 1U; p1 <<= 1U; xt <<= 1U; yt <<= 1U; pSrc[4 * i + 0] = p0; pSrc[4 * i + 1] = p1; pSrc[4 * i + 2] = xt; pSrc[4 * i + 3] = yt; } } void arm_cfft_radix4by2_inverse_q31( q31_t *pSrc, uint32_t fftLen, const q31_t *pCoef) { uint32_t i, l; uint32_t n2; q31_t xt, yt, cosVal, sinVal; q31_t p0, p1; n2 = fftLen >> 1U; for (i = 0; i < n2; i++) { cosVal = pCoef[2 * i]; sinVal = pCoef[2 * i + 1]; l = i + n2; xt = (pSrc[2 * i] >> 2U) - (pSrc[2 * l] >> 2U); pSrc[2 * i] = (pSrc[2 * i] >> 2U) + (pSrc[2 * l] >> 2U); yt = (pSrc[2 * i + 1] >> 2U) - (pSrc[2 * l + 1] >> 2U); pSrc[2 * i + 1] = (pSrc[2 * l + 1] >> 2U) + (pSrc[2 * i + 1] >> 2U); mult_32x32_keep32_R(p0, xt, cosVal); mult_32x32_keep32_R(p1, yt, cosVal); multSub_32x32_keep32_R(p0, yt, sinVal); multAcc_32x32_keep32_R(p1, xt, sinVal); pSrc[2 * l] = p0 << 1U; pSrc[2 * l + 1] = p1 << 1U; } /* first col */ arm_radix4_butterfly_inverse_q31(pSrc, n2, (q31_t *)pCoef, 2U); /* second col */ arm_radix4_butterfly_inverse_q31(pSrc + fftLen, n2, (q31_t *)pCoef, 2U); n2 = fftLen >> 1U; for (i = 0; i < n2; i++) { p0 = pSrc[4 * i + 0]; p1 = pSrc[4 * i + 1]; xt = pSrc[4 * i + 2]; yt = pSrc[4 * i + 3]; p0 <<= 1U; p1 <<= 1U; xt <<= 1U; yt <<= 1U; pSrc[4 * i + 0] = p0; pSrc[4 * i + 1] = p1; pSrc[4 * i + 2] = xt; pSrc[4 * i + 3] = yt; } } #endif /* defined(ARM_MATH_MVEI) */
f16550296901a67de6d807a5ad19d136d01b960d
5655a9fa1371274fb9d61bbb652e13eec0595468
/runtime/Python3/tests/c.c
f4ada7a8d2ae853123c92d4ccc92c8e3d6cc2e58
[ "BSD-3-Clause" ]
permissive
antlr/antlr4
68f3cbb13eefa1638569fe9f4f2f96e048255cd1
e0df58f5185cb3c9148eab724a11394050c565ca
refs/heads/dev
2023-08-29T14:07:51.178320
2023-08-28T15:29:08
2023-08-28T16:46:56
501,687
15,379
3,965
BSD-3-Clause
2023-09-09T22:21:56
2010-02-04T01:36:28
Java
UTF-8
C
false
false
9,558
c
c.c
void main() { int a=0; if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ a++; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } else if( 3 > 4){ ; } }
8117b06024b49ca65723f1fc756f9fccaaa1065c
f79dec3c4033ca3cbb55d8a51a748cc7b8b6fbab
/graphics/evas/patches/patch-src_lib_engines_common_evas__font__load.c
812653ecfdb79c059ef0e584c23686c84346011a
[]
no_license
jsonn/pkgsrc
fb34c4a6a2d350e8e415f3c4955d4989fcd86881
c1514b5f4a3726d90e30aa16b0c209adbc276d17
refs/heads/trunk
2021-01-24T09:10:01.038867
2017-07-07T15:49:43
2017-07-07T15:49:43
2,095,004
106
47
null
2016-09-19T09:26:01
2011-07-23T23:49:04
Makefile
UTF-8
C
false
false
613
c
patch-src_lib_engines_common_evas__font__load.c
$NetBSD: patch-src_lib_engines_common_evas__font__load.c,v 1.1 2014/03/22 20:15:20 spz Exp $ make it deal gracefully with both freetype 2.4.* and 2.5.* --- src/lib/engines/common/evas_font_load.c.orig 2013-04-04 18:00:09.000000000 +0000 +++ src/lib/engines/common/evas_font_load.c @@ -5,7 +5,8 @@ #include "evas_font_private.h" /* for Frame-Queuing support */ #include "evas_font_ot.h" -#include <freetype/tttables.h> /* Freetype2 OS/2 font table. */ +#include <ft2build.h> +#include FT_TRUETYPE_TABLES_H /* Freetype2 OS/2 font table. */ #ifdef EVAS_CSERVE2 # include "../../cserve2/evas_cs2_private.h"
f032915111f8ce963996ebb97d449754760cd0be
c9bc99866cfab223c777cfb741083be3e9439d81
/unit_test/unity_mocks/mocks/Mockfwk_status.h
d75b6c808d2e5115cc44d8538b463d7643b02f2d
[ "BSD-3-Clause" ]
permissive
ARM-software/SCP-firmware
4738ca86ce42d82588ddafc2226a1f353ff2c797
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
refs/heads/master
2023-09-01T16:13:36.962036
2023-08-17T13:00:20
2023-08-31T07:43:37
134,399,880
211
165
NOASSERTION
2023-09-13T14:27:10
2018-05-22T10:35:56
C
UTF-8
C
false
false
2,180
h
Mockfwk_status.h
/* AUTOGENERATED FILE. DO NOT EDIT. */ #ifndef _MOCKFWK_STATUS_H #define _MOCKFWK_STATUS_H #include "unity.h" #include "fwk_status.h" /* Ignore the following warnings, since we are copying code */ #if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__) #if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0))) #pragma GCC diagnostic push #endif #if !defined(__clang__) #pragma GCC diagnostic ignored "-Wpragmas" #endif #pragma GCC diagnostic ignored "-Wunknown-pragmas" #pragma GCC diagnostic ignored "-Wduplicate-decl-specifier" #endif void Mockfwk_status_Init(void); void Mockfwk_status_Destroy(void); void Mockfwk_status_Verify(void); #define fwk_status_str_IgnoreAndReturn(cmock_retval) fwk_status_str_CMockIgnoreAndReturn(__LINE__, cmock_retval) void fwk_status_str_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return); #define fwk_status_str_StopIgnore() fwk_status_str_CMockStopIgnore() void fwk_status_str_CMockStopIgnore(void); #define fwk_status_str_ExpectAnyArgsAndReturn(cmock_retval) fwk_status_str_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval) void fwk_status_str_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return); #define fwk_status_str_ExpectAndReturn(status, cmock_retval) fwk_status_str_CMockExpectAndReturn(__LINE__, status, cmock_retval) void fwk_status_str_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int status, const char* cmock_to_return); typedef const char* (* CMOCK_fwk_status_str_CALLBACK)(int status, int cmock_num_calls); void fwk_status_str_AddCallback(CMOCK_fwk_status_str_CALLBACK Callback); void fwk_status_str_Stub(CMOCK_fwk_status_str_CALLBACK Callback); #define fwk_status_str_StubWithCallback fwk_status_str_Stub #define fwk_status_str_IgnoreArg_status() fwk_status_str_CMockIgnoreArg_status(__LINE__) void fwk_status_str_CMockIgnoreArg_status(UNITY_LINE_TYPE cmock_line); #if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__) #if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0))) #pragma GCC diagnostic pop #endif #endif #endif
fca9287ed53268ad89ea0c752c90673e5f62b75f
8380b5eb12e24692e97480bfa8939a199d067bce
/Trochilus/base/include/udpserver/UdpServerData.h
5236e7d8cd5399a68f91f8e5375c4c08ba79e91c
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
RamadhanAmizudin/malware
788ee745b5bb23b980005c2af08f6cb8763981c2
62d0035db6bc9aa279b7c60250d439825ae65e41
refs/heads/master
2023-02-05T13:37:18.909646
2023-01-26T08:43:18
2023-01-26T08:43:18
53,407,812
873
291
null
2023-01-26T08:43:19
2016-03-08T11:44:21
C++
UTF-8
C
false
false
142
h
UdpServerData.h
#pragma once typedef void (*FnUdpMsgHandler)(SOCKADDR_IN addr, SOCKET listenSock, const LPBYTE pData, DWORD dwDataSize, LPVOID lpParameter);
486b586ac25e8e9fa8c56baf1b18192db211ca4c
5e4913b3d7b6dfd9f35d9e5f24486bb6b6145125
/src/plugins/specload/testdata.h
2a310e8a9ef56c95503ae7b9981714df0aca7fd9
[ "BSD-3-Clause" ]
permissive
ElektraInitiative/libelektra
ff5d5cfc4bf91d704f58405b14ea694aad3a2edd
dbbe4ae4f669c322a8f95f59112d3f5fc370bbd9
refs/heads/master
2023-08-05T14:54:48.081359
2023-08-04T12:40:00
2023-08-04T12:40:00
21,063,580
215
170
BSD-3-Clause
2023-09-07T13:34:30
2014-06-21T08:01:04
C
UTF-8
C
false
false
1,027
h
testdata.h
/** * @file * * @brief Tests for specload plugin * * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) * */ #ifndef ELEKTRA_SPECLOAD_TESTDATA_H #define ELEKTRA_SPECLOAD_TESTDATA_H #define PARENT_KEY "spec:/tests/specload" #define DEFAULT_SPEC ksNew (50, keyNew (PARENT_KEY "/mykey", KEY_META, "default", "7", KEY_END), KS_END) unsigned char default_spec_expected[] = { 0x45, 0x4b, 0x44, 0x42, 0x00, 0x00, 0x00, 0x03, 0x0B, 0x6d, 0x79, 0x6b, 0x65, 0x79, 0x73, 0x01, 0x6d, 0x0F, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x03, 0x37, 0x00 }; unsigned int default_spec_expected_size = 28; #define NOPARENT_SPEC ksNew (50, keyNew ("/mykey", KEY_META, "default", "7", KEY_END), KS_END) unsigned char noparent_spec_expected[] = { 0x45, 0x4b, 0x44, 0x42, 0x00, 0x00, 0x00, 0x03, 0x0B, 0x6d, 0x79, 0x6b, 0x65, 0x79, 0x73, 0x01, 0x6d, 0x0F, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x03, 0x37, 0x00 }; unsigned int noparent_spec_expected_size = 28; #endif // ELEKTRA_SPECLOAD_TESTDATA_H
07eb12262c667777902cc13f6e91746bbf7f79e6
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
/security/sectok/files/patch-cyberflex.c
30bfa6e6f29cd93faa40fdcdeeaf33553d84723f
[ "BSD-2-Clause" ]
permissive
freebsd/freebsd-ports
86f2e89d43913412c4f6b2be3e255bc0945eac12
605a2983f245ac63f5420e023e7dce56898ad801
refs/heads/main
2023-08-30T21:46:28.720924
2023-08-30T19:33:44
2023-08-30T19:33:44
1,803,961
916
918
NOASSERTION
2023-09-08T04:06:26
2011-05-26T11:15:35
null
UTF-8
C
false
false
1,865
c
patch-cyberflex.c
--- cyberflex.c.orig 2003-06-20 00:37:35.000000000 +0200 +++ cyberflex.c 2015-02-28 15:57:55.093727371 +0100 @@ -48,7 +48,13 @@ #define SHA1Init SHA1_Init #define SHA1Update SHA1_Update #define SHA1Final SHA1_Final -#else /* __linux */ +#elif defined(__FreeBSD__) +#define SHA1_CTX SHA_CTX +#define SHA1Init SHA1_Init +#define SHA1Update SHA1_Update +#define SHA1Final SHA1_Final +#include <openssl/sha.h> +#else #include <sha1.h> #endif #else @@ -69,7 +75,7 @@ #include "sc.h" #ifdef __sun -#define des_set_key(key, schedule) des_key_sched(key, schedule) +#define DES_set_key(key, &schedule) DES_key_sched(key, &schedule) #endif #define JDIRSIZE 40 @@ -91,7 +97,7 @@ #ifndef __palmos__ /* default signed applet key of Cyberflex Access */ -static des_cblock app_key = {0x6A, 0x21, 0x36, 0xF5, 0xD8, 0x0C, 0x47, 0x83}; +static DES_cblock app_key = {0x6A, 0x21, 0x36, 0xF5, 0xD8, 0x0C, 0x47, 0x83}; #endif static int @@ -663,8 +669,8 @@ unsigned char aid[16], app_data[MAX_APP_SIZE], data[MAX_BUF_SIZE]; int i, j, vflag = 0, gotprog = 0, gotcont = 0, fd_app, size, aidlen = 0, sw; int cont_size = 1152, inst_size = 1024; - des_cblock tmp; - des_key_schedule schedule; + DES_cblock tmp; + DES_key_schedule schedule; static unsigned char acl[] = {0x81, 0, 0, 0xff, 0, 0, 0, 0}; optind = optreset = 1; @@ -777,12 +783,12 @@ /* chain. DES encrypt one block, XOR the cyphertext with the next block, ... continues until the end of the buffer */ - des_set_key (&app_key, schedule); + DES_set_key (&app_key, &schedule); for (i = 0; i < size/BLOCK_SIZE; i++) { for (j = 0; j < BLOCK_SIZE; j++) tmp[j] = tmp[j] ^ app_data[i*BLOCK_SIZE + j]; - des_ecb_encrypt (&tmp, &tmp, schedule, DES_ENCRYPT); + DES_ecb_encrypt (&tmp, &tmp, &schedule, DES_ENCRYPT); } if (vflag) {
8595a91977af77e1f1033c2f62f94c0d352b5d37
2ec013c79d75d56e602f835c831ffbb5f9187bec
/kernel/daoGC.c
2cd3b45152d39d49cb5d4c70491b68ae3fa0714f
[ "BSD-2-Clause" ]
permissive
daokoder/dao
2127890ab90e79604c9597a581fc1e9f85d4d3be
cdb18f9fcacf64692ec88f64f2d373e83b74e08b
refs/heads/master
2022-09-17T01:54:22.363773
2022-09-01T14:47:35
2022-09-01T14:47:35
4,697,082
180
22
NOASSERTION
2018-10-29T06:53:19
2012-06-18T04:04:19
C
UTF-8
C
false
false
75,071
c
daoGC.c
/* // Dao Virtual Machine // http://daoscript.org // // Copyright (c) 2006-2017, Limin Fu // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. */ #include<assert.h> #include<string.h> #include<math.h> #include<time.h> #include"daoGC.h" #include"daoMap.h" #include"daoClass.h" #include"daoObject.h" #include"daoNumtype.h" #include"daoProcess.h" #include"daoRoutine.h" #include"daoNamespace.h" #include"daoVmspace.h" #include"daoThread.h" #include"daoValue.h" #if defined(DEBUG) && defined(UNIX) #if 0 #define DEBUG_TRACE #endif #endif #ifdef DEBUG_TRACE #include <execinfo.h> void print_trace( const char *info ) { void *array[100]; daoint i, size = backtrace (array, 100); char **strings = backtrace_symbols (array, size); FILE *debug = fopen( "debug.txt", "w+" ); fprintf (debug, "===========================================\n"); fprintf (debug, "Obtained %" DAO_I64 " stack frames.\n", size); printf ("=====================%s======================\n", info); printf ("Obtained %" DAO_I64 " stack frames.\n", size); for (i = 0; i < size; i++){ printf ("%s\n", strings[i]); fprintf (debug,"%s\n", strings[i]); } /* comment this to cause leaking, so that valgrind will print the trace with line numbers */ //free (strings); fflush( debug ); fclose( debug ); fflush( stdout ); } #endif #ifdef DAO_TRACE_ADDRESS #define DAO_TRACE_ADDRESS ((DaoValue*)0x102e4fad0) void DaoGC_TraceValue( DaoValue *value ) { //if( value == DAO_TRACE_ADDRESS || value == (DaoValue*) 0x10038b300 ) { int uninitialized; /* for valgrind; */ uninitialized += time(NULL); //if( uninitialized % 1000 == 0 ) printf( "%i\n", uninitialized ); //printf( "DaoGC_TraceValue: %i %i\n", value->type, value->xBase.refCount ); char buffer[60]; sprintf( buffer, "tracing %p", value ); print_trace( buffer ); } } #endif #if DEBUG static void DaoGC_PrintValueInfo( DaoValue *value ) { switch( value->type ){ case DAO_TYPE : printf( "type: %s %i %p\t", value->xType.name->chars, value->xType.tid, value ); break; case DAO_CSTRUCT : case DAO_CDATA : printf( "cdata: %s\t", value->xCdata.ctype->name->chars ); break; case DAO_CLASS : printf( "class: %s\t", value->xClass.className->chars ); break; case DAO_TYPEKERNEL : //printf( "tkernal: %s\t", ((DaoTypeKernel*)value)->abtype->name->chars ); break; case DAO_ROUTINE : printf( "rout: %s %s\n", value->xRoutine.routName->chars, value->xRoutine.routType->name->chars ); break; case DAO_OBJECT : printf( "object: %s\n", value->xObject.defClass->className->chars ); break; case DAO_NAMESPACE : printf( "namespace: %s\n", value->xNamespace.name->chars ); break; } printf( "%16p %2i %i %i\n", value, value->type, value->xGC.refCount, value->xGC.cycRefCount ); } #else #define DaoGC_PrintValueInfo( value ) #endif static void DaoValue_Delete( DaoValue *self ); static int DaoGC_DecRC2( DaoValue *p ); static void DaoGC_CycRefCountDecrements( DaoValue **values, daoint size ); static void DaoGC_CycRefCountIncrements( DaoValue **values, daoint size ); static void DaoGC_RefCountDecrements( DaoValue **values, daoint size ); static void cycRefCountDecrement( DaoValue *value ); static void cycRefCountIncrement( DaoValue *value ); static void cycRefCountDecrements( DList *values ); static void cycRefCountIncrements( DList *values ); static void directRefCountDecrement( DaoValue **value ); static void directRefCountDecrements( DList *values ); static int DaoGC_CycRefCountDecScan( DaoValue *value ); static int DaoGC_CycRefCountIncScan( DaoValue *value ); static int DaoGC_RefCountDecScan( DaoValue *value ); static void DaoGC_PrepareCandidates(); static void DaoCGC_FreeGarbage(); static void DaoCGC_CycRefCountDecScan(); static void DaoCGC_CycRefCountIncScan(); static void DaoCGC_DeregisterModules(); static int DaoCGC_AliveObjectScan(); static void DaoCGC_RefCountDecScan(); static void DaoCGC_Finish(); static void DaoIGC_FreeGarbage(); static void DaoIGC_CycRefCountDecScan(); static void DaoIGC_DeregisterModules(); static void DaoIGC_CycRefCountIncScan(); static int DaoIGC_AliveObjectScan(); static void DaoIGC_RefCountDecScan(); static void DaoIGC_Finish(); static void DaoIGC_TryInvoke(); static void DaoGC_Init(); #ifdef DAO_WITH_THREAD static void DaoCGC_Recycle( void * ); static void DaoCGC_TryBlock(); #endif #ifdef DAO_USE_GC_LOGGER typedef struct DaoObjectLogger DaoObjectLogger; struct DaoObjectLogger { DMap *allObjects; daoint *newCounts; daoint *delCounts; daoint allCounts[END_EXTRA_TYPES]; daoint newCounts1[END_EXTRA_TYPES]; daoint newCounts2[END_EXTRA_TYPES]; daoint delCounts1[END_EXTRA_TYPES]; daoint delCounts2[END_EXTRA_TYPES]; DList *cstructValues; DList *cstructLists; DList *cstructMaps; DList *objects; DMutex mutex; }; DaoObjectLogger dao_object_logger = { NULL, NULL, NULL }; void DaoObjectLogger_SwitchBuffer(); void DaoObjectLogger_Init() { DMutex_Init( & dao_object_logger.mutex ); dao_object_logger.allObjects = DHash_New(0,0); DaoObjectLogger_SwitchBuffer(); } void DaoObjectLogger_LogNew( DaoValue *object ) { if( dao_object_logger.allObjects == NULL ) return; DMutex_Lock( & dao_object_logger.mutex ); dao_object_logger.newCounts[ object->type ] += 1; DMap_Insert( dao_object_logger.allObjects, object, object ); DMutex_Unlock( & dao_object_logger.mutex ); } void DaoObjectLogger_LogDelete( DaoValue *object ) { if( dao_object_logger.allObjects == NULL ) return; DMutex_Lock( & dao_object_logger.mutex ); dao_object_logger.delCounts[ object->type ] += 1; DMap_Erase( dao_object_logger.allObjects, object ); DMutex_Unlock( & dao_object_logger.mutex ); } #ifdef WIN32 const char *format = "Type = %9Ii; Newed = %9Ii; Deleted = %9Ii; All = %9Ii\n"; #else const char *format = "Type = %9ti; Newed = %9ti; Deleted = %9ti; All = %9ti\n"; #endif void DaoObjectLogger_PrintProfile() { int i; printf("=======================================\n"); for(i=0; i<END_EXTRA_TYPES; ++i){ daoint N = dao_object_logger.newCounts[i]; daoint D = dao_object_logger.delCounts[i]; daoint A = dao_object_logger.allCounts[i] + N - D; dao_object_logger.allCounts[i] = A; if( N != 0 || D != 0 || A != 0 ) printf( format, i, N, D, A ); } } void DaoObjectLogger_SwitchBuffer() { DMutex_Lock( & dao_object_logger.mutex ); if( dao_object_logger.newCounts != NULL ) DaoObjectLogger_PrintProfile(); if( dao_object_logger.newCounts == dao_object_logger.newCounts1 ){ dao_object_logger.newCounts = dao_object_logger.newCounts2; dao_object_logger.delCounts = dao_object_logger.delCounts2; }else{ dao_object_logger.newCounts = dao_object_logger.newCounts1; dao_object_logger.delCounts = dao_object_logger.delCounts1; } memset( dao_object_logger.newCounts, 0, END_EXTRA_TYPES*sizeof(daoint) ); memset( dao_object_logger.delCounts, 0, END_EXTRA_TYPES*sizeof(daoint) ); DMutex_Unlock( & dao_object_logger.mutex ); } static void DaoObjectLogger_ScanValue( DaoValue *object ) { DMap *objmap = dao_object_logger.allObjects; DNode *it = DMap_Find( objmap, object ); if( object == NULL || object == dao_none_value ) return; object->xBase.refCount --; if( it != NULL ) return; DList_Append( dao_object_logger.objects, object ); } static void DaoObjectLogger_ScanValues( DaoValue **values, daoint size ) { DMap *objmap = dao_object_logger.allObjects; daoint i; for(i=0; i<size; ++i) DaoObjectLogger_ScanValue( values[i] ); } static void DaoObjectLogger_ScanArray2( DList *list ) { if( list == NULL ) return; DaoObjectLogger_ScanValues( list->items.pValue, list->size ); } static void DaoObjectLogger_ScanArray( DList *list ) { if( list == NULL || list->type != DAO_DATA_VALUE ) return; DaoObjectLogger_ScanValues( list->items.pValue, list->size ); } static void DaoObjectLogger_ScanMap( DMap *map, int gckey, int gcval ) { DMap *objmap = dao_object_logger.allObjects; DNode *it; if( map == NULL || map->size == 0 ) return; gckey &= map->keytype == DAO_DATA_VALUE; gcval &= map->valtype == DAO_DATA_VALUE; for(it = DMap_First(map); it != NULL; it = DMap_Next(map, it) ){ if( gckey ) DaoObjectLogger_ScanValue( it->key.pValue ); if( gcval ) DaoObjectLogger_ScanValue( it->value.pValue ); } } static void DaoObjectLogger_ScanCstruct( DaoCstruct *cstruct ) { DaoTypeCore *core = cstruct->ctype ? cstruct->ctype->core : NULL; DList *cvalues = dao_object_logger.cstructValues; DList *clists = dao_object_logger.cstructLists; DList *cmaps = dao_object_logger.cstructMaps; daoint i, n; if( cstruct->subtype == DAO_CDATA_PTR ) return; if( core == NULL || core->HandleGC == NULL ) return; cvalues->size = clists->size = cmaps->size = 0; core->HandleGC( (DaoValue*) cstruct, cvalues, clists, cmaps, 0 ); DaoObjectLogger_ScanArray2( cvalues ); for(i=0,n=clists->size; i<n; i++) DaoObjectLogger_ScanArray( clists->items.pList[i] ); for(i=0,n=cmaps->size; i<n; i++) DaoObjectLogger_ScanMap( cmaps->items.pMap[i], 1, 1 ); } void DaoObjectLogger_Quit() { daoint i; DNode *it; DMap *objmap = dao_object_logger.allObjects; DList *objects = DList_New(0); DList *cvalues = DList_New(0); DList *clists = DList_New(0); DList *cmaps = DList_New(0); dao_object_logger.objects = objects; dao_object_logger.cstructValues = cvalues; dao_object_logger.cstructLists = clists; dao_object_logger.cstructMaps = cmaps; DaoObjectLogger_PrintProfile(); for(it=DMap_First(objmap); it; it=DMap_Next(objmap, it)){ DaoValue *object = it->key.pValue; DList_Append( objects, object ); } for(i=0; i<objects->size; ++i){ DaoValue *value = objects->items.pValue[i]; switch( value->type ){ case DAO_ENUM : { DaoEnum *en = (DaoEnum*) value; DaoObjectLogger_ScanValue( (DaoValue*) en->etype ); break; } case DAO_CONSTANT : { DaoObjectLogger_ScanValue( value->xConst.value ); break; } case DAO_VARIABLE : { DaoObjectLogger_ScanValue( value->xVar.value ); DaoObjectLogger_ScanValue( (DaoValue*) value->xVar.dtype ); break; } case DAO_PAR_NAMED : { DaoObjectLogger_ScanValue( value->xNameValue.value ); DaoObjectLogger_ScanValue( (DaoValue*) value->xNameValue.ctype ); break; } #ifdef DAO_WITH_NUMARRAY case DAO_ARRAY : { DaoArray *array = (DaoArray*) value; DaoObjectLogger_ScanValue( (DaoValue*) array->original ); break; } #endif case DAO_TUPLE : { DaoTuple *tuple = (DaoTuple*) value; DaoObjectLogger_ScanValue( (DaoValue*) tuple->ctype ); DaoObjectLogger_ScanValues( tuple->values, tuple->size ); break; } case DAO_LIST : { DaoList *list = (DaoList*) value; DaoObjectLogger_ScanValue( (DaoValue*) list->ctype ); DaoObjectLogger_ScanArray( list->value ); break; } case DAO_MAP : { DaoMap *map = (DaoMap*) value; DaoObjectLogger_ScanValue( (DaoValue*) map->ctype ); DaoObjectLogger_ScanMap( map->value, 1, 1 ); break; } case DAO_OBJECT : { DaoObject *obj = (DaoObject*) value; if( obj->isRoot ){ DaoObjectLogger_ScanValues( obj->objValues, obj->valueCount ); } DaoObjectLogger_ScanValue( (DaoValue*) obj->parent ); DaoObjectLogger_ScanValue( (DaoValue*) obj->rootObject ); DaoObjectLogger_ScanValue( (DaoValue*) obj->defClass ); break; } case DAO_CTYPE : { DaoCtype *ctype = (DaoCtype*) value; DaoObjectLogger_ScanValue( (DaoValue*) ctype->nameSpace ); DaoObjectLogger_ScanValue( (DaoValue*) ctype->classType ); DaoObjectLogger_ScanValue( (DaoValue*) ctype->valueType ); break; } case DAO_CSTRUCT : case DAO_CDATA : { DaoCstruct *cstruct = (DaoCstruct*) value; DaoObjectLogger_ScanValue( (DaoValue*) cstruct->object ); DaoObjectLogger_ScanValue( (DaoValue*) cstruct->ctype ); DaoObjectLogger_ScanCstruct( cstruct ); break; } case DAO_ROUTINE : { DaoRoutine *rout = (DaoRoutine*)value; DaoObjectLogger_ScanValue( (DaoValue*) rout->routType ); DaoObjectLogger_ScanValue( (DaoValue*) rout->routHost ); DaoObjectLogger_ScanValue( (DaoValue*) rout->nameSpace ); DaoObjectLogger_ScanValue( (DaoValue*) rout->original ); DaoObjectLogger_ScanValue( (DaoValue*) rout->routConsts ); DaoObjectLogger_ScanValue( (DaoValue*) rout->body ); DaoObjectLogger_ScanArray( rout->variables ); if( rout->overloads ) DaoObjectLogger_ScanArray( rout->overloads->array ); if( rout->specialized ) DaoObjectLogger_ScanArray( rout->specialized->array ); break; } case DAO_ROUTBODY : { DaoRoutineBody *rout = (DaoRoutineBody*)value; DaoObjectLogger_ScanArray( rout->regType ); break; } case DAO_CLASS : { DaoClass *klass = (DaoClass*)value; DaoObjectLogger_ScanValue( (DaoValue*) klass->nameSpace ); DaoObjectLogger_ScanValue( (DaoValue*) klass->outerClass ); DaoObjectLogger_ScanValue( (DaoValue*) klass->clsType ); DaoObjectLogger_ScanValue( (DaoValue*) klass->initRoutine ); DaoObjectLogger_ScanArray( klass->constants ); DaoObjectLogger_ScanArray( klass->variables ); DaoObjectLogger_ScanArray( klass->instvars ); DaoObjectLogger_ScanArray( klass->allBases ); DaoObjectLogger_ScanArray( klass->auxData ); break; } case DAO_INTERFACE : { DaoInterface *inter = (DaoInterface*)value; DaoObjectLogger_ScanArray( inter->bases ); DaoObjectLogger_ScanValue( (DaoValue*) inter->outerClass ); DaoObjectLogger_ScanValue( (DaoValue*) inter->nameSpace ); DaoObjectLogger_ScanValue( (DaoValue*) inter->abtype ); DaoObjectLogger_ScanMap( inter->concretes, 0, 1 ); DaoObjectLogger_ScanMap( inter->methods, 0, 1 ); break; } case DAO_CINTYPE : { DaoCinType *cintype = (DaoCinType*)value; DaoObjectLogger_ScanArray( cintype->bases ); DaoObjectLogger_ScanValue( (DaoValue*) cintype->outerClass ); DaoObjectLogger_ScanValue( (DaoValue*) cintype->citype ); DaoObjectLogger_ScanValue( (DaoValue*) cintype->vatype ); DaoObjectLogger_ScanValue( (DaoValue*) cintype->target ); DaoObjectLogger_ScanValue( (DaoValue*) cintype->abstract ); DaoObjectLogger_ScanMap( cintype->methods, 0, 1 ); break; } case DAO_CINVALUE : { DaoObjectLogger_ScanValue( value->xCinValue.value ); DaoObjectLogger_ScanValue( (DaoValue*) value->xCinValue.cintype ); break; } case DAO_NAMESPACE : { DaoNamespace *ns = (DaoNamespace*) value; DaoObjectLogger_ScanArray( ns->constants ); DaoObjectLogger_ScanArray( ns->variables ); DaoObjectLogger_ScanArray( ns->auxData ); DaoObjectLogger_ScanMap( ns->abstypes, 0, 1 ); break; } case DAO_TYPE : { DaoType *type = (DaoType*) value; DaoObjectLogger_ScanValue( type->aux ); DaoObjectLogger_ScanValue( type->value ); DaoObjectLogger_ScanValue( (DaoValue*) type->kernel ); DaoObjectLogger_ScanValue( (DaoValue*) type->cbtype ); DaoObjectLogger_ScanValue( (DaoValue*) type->quadtype ); DaoObjectLogger_ScanValue( (DaoValue*) type->nameSpace ); DaoObjectLogger_ScanArray( type->args ); DaoObjectLogger_ScanArray( type->bases ); DaoObjectLogger_ScanMap( type->interfaces, 1, 1 ); break; } case DAO_TYPEKERNEL : { DaoTypeKernel *kernel = (DaoTypeKernel*) value; DaoObjectLogger_ScanValue( (DaoValue*) kernel->abtype ); DaoObjectLogger_ScanValue( (DaoValue*) kernel->nspace ); DaoObjectLogger_ScanValue( (DaoValue*) kernel->initRoutines ); DaoObjectLogger_ScanMap( kernel->values, 0, 1 ); DaoObjectLogger_ScanMap( kernel->methods, 0, 1 ); if( kernel->sptree ){ DaoObjectLogger_ScanArray( kernel->sptree->holders ); DaoObjectLogger_ScanArray( kernel->sptree->defaults ); DaoObjectLogger_ScanArray( kernel->sptree->sptypes ); } break; } case DAO_PROCESS : { DaoProcess *vmp = (DaoProcess*) value; DaoStackFrame *frame = vmp->firstFrame; DaoObjectLogger_ScanValue( (DaoValue*) vmp->future ); DaoObjectLogger_ScanValue( (DaoValue*) vmp->stdioStream ); DaoObjectLogger_ScanArray( vmp->exceptions ); DaoObjectLogger_ScanArray( vmp->defers ); DaoObjectLogger_ScanArray( vmp->factory ); DaoObjectLogger_ScanValues( vmp->stackValues, vmp->stackSize ); while( frame ){ DaoObjectLogger_ScanValue( (DaoValue*) frame->routine ); DaoObjectLogger_ScanValue( (DaoValue*) frame->object ); DaoObjectLogger_ScanValue( (DaoValue*) frame->retype ); frame = frame->next; } break; } default: break; } } for(i=0; i<objects->size; ++i){ DaoValue *value = objects->items.pValue[i]; if( value->xBase.refCount != 0 ){ DaoGC_PrintValueInfo( value ); } } DMutex_Destroy( & dao_object_logger.mutex ); DMap_Delete( dao_object_logger.allObjects ); DList_Delete( objects ); DList_Delete( cvalues ); DList_Delete( clists ); DList_Delete( cmaps ); } #else void DaoObjectLogger_PrintProfile(){} void DaoObjectLogger_SwitchBuffer(){} #endif typedef struct DaoGarbageCollector DaoGarbageCollector; struct DaoGarbageCollector { DList *idleList; /* List of new garbage candidates; */ DList *workList; /* List of working candidates; */ DList *idleList2; /* List of new garbage candidates (primitive types); */ DList *workList2; /* List of working candidates (primitive types); */ DList *delayList; /* List of delayed candidates; */ DList *freeList; /* List of garbage objects as determined by the GC; */ DList *auxList; /* Auxiliary list for GC; */ DList *auxList2; /* Auxiliary list for GC; */ DList *nsList; /* List of namespaces; */ DList *cstructValues; /* Value buffer for scanning wrapped objects; */ DList *cstructLists; /* List buffer for scanning wrapped objects; */ DList *cstructMaps; /* Map buffer for scanning wrapped objects; */ DList *temporary; /* Temporary list; */ uchar_t fullgc; uchar_t finalizing; uchar_t delayMask; daoint gcMin, gcMax; daoint ii, jj, kk; daoint cycle; daoint mdelete; short busy; short locked; short workType; short concurrent; #ifdef DAO_WITH_THREAD DThread thread; DMutex mutex_idle_list; DMutex mutex_start_gc; DMutex mutex_block_mutator; DMutex data_lock; DMutex generic_lock; DCondVar condv_start_gc; DCondVar condv_block_mutator; #endif }; static DaoGarbageCollector gcWorker = { NULL, NULL, NULL }; int DaoGC_IsConcurrent() { return gcWorker.concurrent; } int DaoGC_Min( int n ) { int prev = gcWorker.gcMin; if( n >= 0 ) gcWorker.gcMin = n; return prev; } int DaoGC_Max( int n ) { int prev = gcWorker.gcMax; if( n >= 0 ) gcWorker.gcMax = n; return prev; } daoint DaoGC_GetCycleIndex() { return gcWorker.cycle; } void DaoGC_SetMode( int fullgc, int finalizing ) { gcWorker.fullgc = fullgc; gcWorker.finalizing = finalizing; } void DaoGC_Init() { if( gcWorker.idleList != NULL ) return; gcWorker.idleList = DList_New(0); gcWorker.workList = DList_New(0); gcWorker.idleList2 = DList_New(0); gcWorker.workList2 = DList_New(0); gcWorker.delayList = DList_New(0); gcWorker.freeList = DList_New(0); gcWorker.auxList = DList_New(0); gcWorker.auxList2 = DList_New(0); gcWorker.nsList = DList_New(0); gcWorker.cstructValues = DList_New(0); gcWorker.cstructLists = DList_New(0); gcWorker.cstructMaps = DList_New(0); gcWorker.temporary = DList_New(0); gcWorker.delayMask = DAO_VALUE_DELAYGC; gcWorker.fullgc = 0; gcWorker.finalizing = 0; gcWorker.cycle = 0; gcWorker.mdelete = 0; gcWorker.gcMin = 1000; gcWorker.gcMax = 100 * gcWorker.gcMin; gcWorker.workType = 0; gcWorker.ii = 0; gcWorker.jj = 0; gcWorker.kk = 0; gcWorker.busy = 0; gcWorker.locked = 0; gcWorker.concurrent = 0; } void DaoGC_Start() { DaoGC_Init(); } void DaoCGC_Start() { daoint min = gcWorker.gcMin; if( gcWorker.concurrent ) return; #ifdef DAO_WITH_THREAD DThread_Init( & gcWorker.thread ); DMutex_Init( & gcWorker.data_lock ); DMutex_Init( & gcWorker.generic_lock ); DMutex_Init( & gcWorker.mutex_idle_list ); DMutex_Init( & gcWorker.mutex_start_gc ); DMutex_Init( & gcWorker.mutex_block_mutator ); DCondVar_Init( & gcWorker.condv_start_gc ); DCondVar_Init( & gcWorker.condv_block_mutator ); DaoIGC_Finish(); gcWorker.gcMin = min; gcWorker.concurrent = 1; gcWorker.finalizing = 0; gcWorker.fullgc = 0; gcWorker.cycle = 0; if( DThread_Start( & gcWorker.thread, DaoCGC_Recycle, NULL ) == 0 ){ dao_abort( "failed to create the GC thread" ); } #endif } static void DaoGC_DeleteSimpleData( DaoValue *value ) { if( value == NULL || value->xGC.refCount ) return; switch( value->type ){ case DAO_NONE : case DAO_BOOLEAN : case DAO_INTEGER : case DAO_FLOAT : case DAO_COMPLEX : #ifdef DAO_USE_GC_LOGGER DaoObjectLogger_LogDelete( value ); #endif dao_free( value ); break; case DAO_STRING : DaoString_Delete( & value->xString ); break; default: break; } } static void DaoValue_Delete( DaoValue *self ) { switch( self->type ){ default : if( self->type < DAO_ENUM ){ DaoGC_DeleteSimpleData( self ); }else{ DaoTypeCore *core = DaoValue_GetTypeCore( self ); core->Delete( self ); } break; case DAO_CDATA : DaoCdata_Delete( (DaoCdata*) self ); break; case DAO_CTYPE : DaoCtype_Delete( (DaoCtype*) self ); break; case DAO_ROUTBODY : DaoRoutineBody_Delete( (DaoRoutineBody*) self ); break; case DAO_CONSTANT : DaoConstant_Delete( (DaoConstant*) self); break; case DAO_VARIABLE : DaoVariable_Delete( (DaoVariable*) self); break; case DAO_VMSPACE : DaoVmSpace_Delete( (DaoVmSpace*) self ); break; } } void DList_PushBack2( DList *self, void *val ) { if( (daoint)(self->size + 1) >= self->bufsize ){ void **buf = self->items.pVoid; self->bufsize += self->bufsize/5 + 5; self->items.pVoid = (void**) dao_realloc( buf, (self->bufsize+1)*sizeof(void*) ); } self->items.pVoid[ self->size ] = val; self->size++; } static int DaoGC_DecRC2( DaoValue *p ) { daoint i, n; p->xGC.refCount --; #ifdef DAO_TRACE_ADDRESS DaoGC_TraceValue( p ); #endif if( p->xGC.refCount == 0 ){ switch( p->xGC.type ){ case DAO_NONE : case DAO_BOOLEAN: case DAO_INTEGER : case DAO_FLOAT : case DAO_COMPLEX : case DAO_STRING : #if 0 if( gcWorker.concurrent ){ DList_PushBack2( gcWorker.idleList2, p ); }else{ DaoGC_DeleteSimpleData( p ); } #else DaoGC_DeleteSimpleData( p ); #endif return 0; #ifdef DAO_WITH_NUMARRAY case DAO_ARRAY : DaoArray_ResizeVector( & p->xArray, 0 ); break; #endif case DAO_TUPLE : if( p->xTuple.ctype && p->xTuple.ctype->noncyclic ){ DaoTuple *tuple = & p->xTuple; for(i=0,n=tuple->size; i<n; i++){ if( tuple->values[i] ){ DaoGC_DecRC2( tuple->values[i] ); tuple->values[i] = NULL; } } tuple->size = 0; } break; case DAO_LIST : // TODO same for map if( p->xList.ctype && p->xList.ctype->noncyclic ){ DList *array = p->xList.value; DaoValue **items = array->items.pValue; for(i=0,n=array->size; i<n; i++) if( items[i] ) DaoGC_DecRC2( items[i] ); array->size = 0; array->type = 0; /* To avoid locking in DList_Clear(); */ DList_Clear( array ); } break; default : /* No safe way to delete other types of objects here, since they might be * being concurrently scanned by the GC! */ break; } } /* never push simple data types into GC queue, * because they cannot form cyclic referencing structure: */ if( p->type < DAO_ENUM ) return 0; if( p->xGC.delay ) return 0; DList_PushBack2( gcWorker.idleList, p ); return 1; } void DaoGC_Finish() { daoint i; if( gcWorker.concurrent ){ #ifdef DAO_WITH_THREAD DaoCGC_Finish(); #endif }else{ DaoIGC_Finish(); } DaoObjectLogger_SwitchBuffer(); #ifdef DAO_WITH_THREAD if( gcWorker.concurrent ){ DThread_Destroy( & gcWorker.thread ); DMutex_Destroy( & gcWorker.data_lock ); DMutex_Destroy( & gcWorker.generic_lock ); DMutex_Destroy( & gcWorker.mutex_idle_list ); DMutex_Destroy( & gcWorker.mutex_start_gc ); DMutex_Destroy( & gcWorker.mutex_block_mutator ); DCondVar_Destroy( & gcWorker.condv_start_gc ); DCondVar_Destroy( & gcWorker.condv_block_mutator ); } #endif DList_Delete( gcWorker.idleList ); DList_Delete( gcWorker.workList ); DList_Delete( gcWorker.idleList2 ); DList_Delete( gcWorker.workList2 ); DList_Delete( gcWorker.delayList ); DList_Delete( gcWorker.freeList ); DList_Delete( gcWorker.auxList ); DList_Delete( gcWorker.auxList2 ); DList_Delete( gcWorker.nsList ); DList_Delete( gcWorker.cstructValues ); DList_Delete( gcWorker.cstructLists ); DList_Delete( gcWorker.cstructMaps ); DList_Delete( gcWorker.temporary ); gcWorker.idleList = NULL; } #ifdef DAO_WITH_THREAD void DaoGC_IncCycRC( DaoValue *value ) { if( value == NULL ) return; if( gcWorker.concurrent ){ DMutex_Lock( & gcWorker.mutex_idle_list ); if( value->type >= DAO_ENUM ) value->xGC.cycRefCount ++; DMutex_Unlock( & gcWorker.mutex_idle_list ); return; } if( value->type >= DAO_ENUM ) value->xGC.cycRefCount ++; } void DaoGC_IncRC( DaoValue *value ) { if( value == NULL ) return; if( gcWorker.concurrent ){ DMutex_Lock( & gcWorker.mutex_idle_list ); if( value->type >= DAO_ENUM ) value->xGC.cycRefCount ++; value->xGC.refCount ++; DMutex_Unlock( & gcWorker.mutex_idle_list ); #ifdef DAO_TRACE_ADDRESS DaoGC_TraceValue( value ); #endif return; } if( value->type >= DAO_ENUM ) value->xGC.cycRefCount ++; value->xGC.refCount ++; #ifdef DAO_TRACE_ADDRESS DaoGC_TraceValue( value ); #endif } void DaoGC_DecRC( DaoValue *value ) { if( value == NULL ) return; if( gcWorker.concurrent ){ int bl; DMutex_Lock( & gcWorker.mutex_idle_list ); bl = DaoGC_DecRC2( value ); DMutex_Unlock( & gcWorker.mutex_idle_list ); if( bl ) DaoCGC_TryBlock(); return; } DaoGC_DecRC2( value ); } void DaoGC_Assign( DaoValue **dest, DaoValue *src ) { DaoValue *value = *dest; if( src == value ) return; if( gcWorker.concurrent ){ int bl; DMutex_Lock( & gcWorker.mutex_idle_list ); if( src ){ if( src->type >= DAO_ENUM ) src->xGC.cycRefCount ++; src->xGC.refCount ++; } #ifdef DAO_TRACE_ADDRESS DaoGC_TraceValue( src ); #endif bl = value ? DaoGC_DecRC2( value ) : 0; *dest = src; DMutex_Unlock( & gcWorker.mutex_idle_list ); if( bl ) DaoCGC_TryBlock(); return; } if( src ){ if( src->type >= DAO_ENUM ) src->xGC.cycRefCount ++; src->xGC.refCount ++; } #ifdef DAO_TRACE_ADDRESS DaoGC_TraceValue( src ); #endif *dest = src; if( value ) DaoGC_DecRC2( value ); } void DaoGC_Assign2( DaoValue **dest, DaoValue *src ) { DaoValue *value = *dest; if( src == value ) return; if( gcWorker.concurrent ){ DMutex_Lock( & gcWorker.mutex_idle_list ); *dest = src; DMutex_Unlock( & gcWorker.mutex_idle_list ); return; } *dest = src; } void DaoGC_TryInvoke() { if( gcWorker.concurrent ){ DaoCGC_TryBlock(); return; } DaoIGC_TryInvoke(); } #else void DaoGC_IncCycRC( DaoValue *value ) { if( value && value->type >= DAO_ENUM ) value->xGC.cycRefCount ++; } void DaoGC_IncRC( DaoValue *value ) { if( value ){ value->xGC.refCount ++; if( value->type >= DAO_ENUM ) value->xGC.cycRefCount ++; } #ifdef DAO_TRACE_ADDRESS DaoGC_TraceValue( value ); #endif } void DaoGC_DecRC( DaoValue *value ) { if( value ) DaoGC_DecRC2( value ); } void DaoGC_Assign( DaoValue **dest, DaoValue *src ) { DaoValue *value = *dest; if( src == value ) return; if( src ){ src->xGC.refCount ++; if( src->type >= DAO_ENUM ) src->xGC.cycRefCount ++; } #ifdef DAO_TRACE_ADDRESS DaoGC_TraceValue( src ); #endif *dest = src; if( value ) DaoGC_DecRC2( value ); } void DaoGC_Assign2( DaoValue **dest, DaoValue *src ) { DaoValue *value = *dest; if( src == value ) return; *dest = src; } void DaoGC_TryInvoke() { DaoIGC_TryInvoke(); } #endif void DaoGC_TryDelete( DaoValue *value ) { GC_IncRC( value ); GC_DecRC( value ); } static void DaoGC_FreeSimple() { DaoValue *value; DList *workList2 = gcWorker.workList2; daoint i, k = 0; for(i=0,k=0; i<workList2->size; i++){ value = workList2->items.pValue[i]; if( value->xGC.work ) continue; value->xGC.work = 1; workList2->items.pValue[k++] = value; } for(i=0; i<k; i++) DaoValue_Delete( workList2->items.pValue[i] ); workList2->size = 0; } #define DAO_FULL_GC_SCAN_CYCLE 16 /* // Notes: // -- The implementation makes sure the GC flags are modified only by the GC thread; // -- The "work" flag is set to true only for objects that is in the workList buffer; // -- The "delay" flag is set to true only for objects that is in the delayList buffer; // -- The "dead" flag is set to true only for objects that is in the freeList buffer; // -- The "delay" flag is set/unset when an object enters/leaves the delayList buffer; */ void DaoGC_PrepareCandidates() { DaoValue *value; DList *workList = gcWorker.workList; DList *freeList = gcWorker.freeList; DList *delayList = gcWorker.delayList; DList *types = gcWorker.temporary; uchar_t cycle = (++gcWorker.cycle) % DAO_FULL_GC_SCAN_CYCLE; uchar_t delay = cycle && gcWorker.fullgc == 0 ? DAO_VALUE_DELAYGC : 0; daoint i, k = 0; int delay2; gcWorker.delayMask = delay; /* Damping to avoid "delay2" changing too dramatically: */ gcWorker.mdelete = 0.5*gcWorker.mdelete + 0.5*freeList->size; delay2 = gcWorker.cycle % (1 + 100 / (1 + gcWorker.mdelete)); if( gcWorker.fullgc ) delay2 = 0; if( delay == 0 ){ /* Push delayed objects into the working list for full GC scan: */ for(i=0; i<delayList->size; ++i){ value = delayList->items.pValue[i]; value->xGC.delay = 0; if( value->xGC.dead ) continue; DList_PushBack2( workList, value ); } delayList->size = 0; }else if( freeList->size ){ /* // It is ok to have redundant items in delayList, // because the redundancy will be removed after // they are pushed into workList. */ for(i=0,k=0; i<delayList->size; ++i){ value = delayList->items.pValue[i]; if( value->xGC.dead ) continue; delayList->items.pValue[k++] = value; } delayList->size = k; } for(i=0,k=0; i<workList->size; ++i){ value = workList->items.pValue[i]; if( value->xGC.work ){ DaoGC_PrintValueInfo( value ); } } /* Remove possible redundant items: */ for(i=0,k=0; i<workList->size; ++i){ value = workList->items.pValue[i]; if( value->xGC.work | value->xGC.delay | value->xGC.dead ) continue; if( (value->xBase.trait & delay) || (delay2 && value->xBase.refCount) ){ /* // for non full scan cycles, delay scanning on objects with DAO_VALUE_DELAYGC trait; // and delay scanning on objects with reference count >= 1: */ value->xGC.delay = 1; DList_PushBack2( delayList, value ); continue; }else if( value->type == DAO_PROCESS && value->xProcess.status > DAO_PROCESS_ABORTED ){ if( gcWorker.fullgc == 0 ){ value->xGC.delay = 1; DList_PushBack2( delayList, value ); continue; } } workList->items.pValue[k++] = value; value->xGC.cycRefCount = value->xGC.refCount; value->xGC.work = 1; value->xGC.alive = 0; } #if 0 printf( "%9i %6i %9i %9i\n", gcWorker.cycle, delay, workList->size, k ); #endif workList->size = k; types->size = 0; for(i=0; i<freeList->size; i++){ if( freeList->items.pValue[i]->type == DAO_TYPE ){ /* // DaoType should be freed after DaoCdata, because // the function pointers for free the wrapped data // is stored in association with DaoType; */ DList_PushBack2( types, freeList->items.pValue[i] ); continue; } DaoValue_Delete( freeList->items.pValue[i] ); } freeList->size = 0; for(i=0; i<types->size; ++i) DaoValue_Delete( types->items.pValue[i] ); } enum DaoGCActions{ DAO_GC_DEC, DAO_GC_INC, DAO_GC_BREAK }; void DaoGC_LockRefCount() { if( gcWorker.concurrent == 0 ) return; #ifdef DAO_WITH_THREAD DMutex_Lock( & gcWorker.mutex_idle_list ); #endif } void DaoGC_UnlockRefCount() { if( gcWorker.concurrent == 0 ) return; #ifdef DAO_WITH_THREAD DMutex_Unlock( & gcWorker.mutex_idle_list ); #endif } void DaoGC_LockData() { if( gcWorker.concurrent == 0 ) return; #ifdef DAO_WITH_THREAD DMutex_Lock( & gcWorker.data_lock ); gcWorker.locked = 1; #endif } void DaoGC_UnlockData() { #ifdef DAO_WITH_THREAD if( gcWorker.locked == 0 ) return; gcWorker.locked = 0; DMutex_Unlock( & gcWorker.data_lock ); #endif } static void DaoGC_ScanArray( DList *array, int action, int valueArrayOnly ) { if( array == NULL || array->size == 0 ) return; if( valueArrayOnly && array->type != DAO_DATA_VALUE ) return; switch( action ){ case DAO_GC_DEC : cycRefCountDecrements( array ); break; case DAO_GC_INC : cycRefCountIncrements( array ); break; case DAO_GC_BREAK : directRefCountDecrements( array ); array->size = 0; break; } } static void DaoGC_ScanValue( DaoValue **value, int action ) { switch( action ){ case DAO_GC_DEC : cycRefCountDecrement( *value ); break; case DAO_GC_INC : cycRefCountIncrement( *value ); break; case DAO_GC_BREAK : directRefCountDecrement( value ); break; } } static int DaoGC_ScanMap( DMap *map, int action, int gckey, int gcvalue ) { int count = 0; DNode *it; if( map == NULL || map->size == 0 ) return 0; gckey &= map->keytype == DAO_DATA_VALUE; gcvalue &= map->valtype == DAO_DATA_VALUE; if( action != DAO_GC_BREAK ){ /* if action == DAO_GC_BREAK, no mutator can access this map: */ DaoGC_LockData(); } for(it = DMap_First( map ); it != NULL; it = DMap_Next( map, it ) ){ if( gckey ) DaoGC_ScanValue( & it->key.pValue, action ); if( gcvalue ) DaoGC_ScanValue( & it->value.pValue, action ); count += gckey + gcvalue; } if( action == DAO_GC_BREAK ){ if( map->keytype == DAO_DATA_VALUE ) map->keytype = 0; if( map->valtype == DAO_DATA_VALUE ) map->valtype = 0; DMap_Clear( map ); }else{ DaoGC_UnlockData(); } return count; } static void DaoGC_ScanCstruct( DaoCstruct *cstruct, int action ) { DaoTypeCore *core = cstruct->ctype ? cstruct->ctype->core : NULL; DList *cvalues = gcWorker.cstructValues; DList *clists = gcWorker.cstructLists; DList *cmaps = gcWorker.cstructMaps; daoint i, n; if( cstruct->subtype == DAO_CDATA_PTR ) return; if( core == NULL || core->HandleGC == NULL ) return; cvalues->size = clists->size = cmaps->size = 0; core->HandleGC( (DaoValue*) cstruct, cvalues, clists, cmaps, action == DAO_GC_BREAK ); DaoGC_ScanArray( cvalues, action, 0 ); for(i=0,n=clists->size; i<n; i++) DaoGC_ScanArray( clists->items.pList[i], action, 0 ); for(i=0,n=cmaps->size; i<n; i++) DaoGC_ScanMap( cmaps->items.pMap[i], action, 1, 1 ); } #ifdef DAO_WITH_THREAD /* Concurrent Garbage Collector */ void DaoCGC_Finish() { gcWorker.gcMin = 0; gcWorker.fullgc = 1; gcWorker.finalizing = 1; DThread_Join( & gcWorker.thread ); } void DaoCGC_TryBlock() { if( gcWorker.idleList->size >= gcWorker.gcMax ){ DThread *thread = DThread_GetCurrent(); if( thread && ! (thread->state & DTHREAD_NO_PAUSE) ){ DMutex_Lock( & gcWorker.mutex_block_mutator ); DCondVar_TimedWait( & gcWorker.condv_block_mutator, & gcWorker.mutex_block_mutator, 0.001 ); DMutex_Unlock( & gcWorker.mutex_block_mutator ); } } } void DaoCGC_Recycle( void *p ) { DList *works = gcWorker.workList; DList *idles = gcWorker.idleList; DList *works2 = gcWorker.workList2; DList *idles2 = gcWorker.idleList2; DList *frees = gcWorker.freeList; DList *delays = gcWorker.delayList; daoint N; while(1){ N = idles->size + works->size + idles2->size + works2->size + frees->size + delays->size; if( gcWorker.finalizing && N == 0 ) break; gcWorker.busy = 0; while( ! gcWorker.fullgc && (idles->size + idles->size) < gcWorker.gcMin ){ daoint gcount = idles->size + idles2->size; double wtime = 3.0 * gcount / (double)gcWorker.gcMin; wtime = 0.01 * exp( - wtime * wtime ); DMutex_Lock( & gcWorker.mutex_start_gc ); DCondVar_TimedWait( & gcWorker.condv_start_gc, & gcWorker.mutex_start_gc, wtime ); DMutex_Unlock( & gcWorker.mutex_start_gc ); if( idles2->size > 10 ){ DMutex_Lock( & gcWorker.mutex_idle_list ); DList_Swap( idles2, works2 ); DMutex_Unlock( & gcWorker.mutex_idle_list ); DaoGC_FreeSimple(); } } gcWorker.busy = 1; DMutex_Lock( & gcWorker.mutex_idle_list ); DList_Swap( idles, works ); DList_Swap( idles2, works2 ); DMutex_Unlock( & gcWorker.mutex_idle_list ); DaoGC_FreeSimple(); gcWorker.kk = 0; DaoGC_PrepareCandidates(); DaoCGC_CycRefCountDecScan(); DaoCGC_CycRefCountIncScan(); DaoCGC_DeregisterModules(); DaoCGC_CycRefCountIncScan(); DaoCGC_RefCountDecScan(); DaoCGC_FreeGarbage(); } DThread_Exit( & gcWorker.thread ); } void DaoCGC_CycRefCountDecScan() { DList *workList = gcWorker.workList; uchar_t delay = gcWorker.delayMask; daoint i, k; for(i=0; i<workList->size; i++){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.delay ) continue; DaoGC_CycRefCountDecScan( value ); } } void DaoCGC_DeregisterModules() { daoint i; DList *workList = gcWorker.workList; for( i=0; i<workList->size; i++ ){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.alive ) continue; if( value->type == DAO_NAMESPACE ){ DaoNamespace *NS = (DaoNamespace*) value; DaoVmSpace_Lock( NS->vmSpace ); if( NS->cycRefCount == 0 ) DMap_Erase( NS->vmSpace->nsModules, NS->name ); DaoVmSpace_Unlock( NS->vmSpace ); } } } void DaoCGC_CycRefCountIncScan() { daoint i; DList *workList = gcWorker.workList; DList *auxList = gcWorker.auxList; #if 0 if( gcWorker.fullgc ){ for( i=0; i<workList->size; i++ ){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.cycRefCount > 0 ) DaoGC_PrintValueInfo( value ); } } #endif for( i=0; i<workList->size; i++ ){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.alive ) continue; if( value->xGC.cycRefCount > 0 ){ auxList->size = 0; value->xGC.alive = 1; DList_PushBack2( auxList, value ); DaoCGC_AliveObjectScan(); } } } int DaoCGC_AliveObjectScan() { DList *auxList = gcWorker.auxList; uchar_t delay = gcWorker.delayMask; daoint i, k; for( i=0; i<auxList->size; i++){ DaoValue *value = auxList->items.pValue[i]; if( value->xGC.delay ) continue; DaoGC_CycRefCountIncScan( value ); } return auxList->size; } void DaoCGC_RefCountDecScan() { DList *workList = gcWorker.workList; uchar_t delay = gcWorker.delayMask; daoint i, k; for( i=0; i<workList->size; i++ ){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.cycRefCount && value->xGC.refCount ) continue; if( value->xGC.delay ) continue; DaoGC_RefCountDecScan( value ); } } static void DaoCGC_FreeGarbage() { DList *idleList = gcWorker.idleList; DList *workList = gcWorker.workList; uchar_t delay = gcWorker.delayMask; daoint i, n = 0; for(i=0; i<gcWorker.auxList2->size; i++) gcWorker.auxList2->items.pValue[i]->xGC.alive = 0; gcWorker.auxList2->size = 0; for(i=0; i<workList->size; i++){ DaoValue *value = workList->items.pValue[i]; value->xGC.work = value->xGC.alive = 0; if( value->xGC.cycRefCount && value->xGC.refCount ) continue; if( value->xGC.refCount ){ /* This is possible since Cyclic RefCount is not updated atomically: */ #ifdef DEBUG_TRACE printf("RefCount not zero %p %i: %i %i\n", value, value->type, value->xGC.refCount, value->xGC.cycRefCount ); DaoGC_PrintValueInfo( value ); #endif value->xGC.delay = 1; DList_PushBack2( gcWorker.delayList, value ); continue; }else if( value->xGC.cycRefCount ){ /* To allow postponing GC by increasing the cyclic RefCount: */ value->xGC.delay = 1; DList_PushBack2( gcWorker.delayList, value ); continue; } value->xGC.dead = 1; DList_PushBack2( gcWorker.freeList, value ); } DaoObjectLogger_SwitchBuffer(); workList->size = 0; } #endif /* Incremental Garbage Collector */ enum DaoGCWorkType { GC_RESET_RC , GC_DEC_RC , GC_INC_RC , GC_DEREG , GC_INC_RC2 , GC_DIR_DEC_RC , GC_FREE }; static void DaoIGC_Switch(); static void DaoIGC_Continue(); static void DaoIGC_RefCountDecScan(); static int counts = 1000; static void DaoIGC_TryInvoke() { if( gcWorker.busy ) return; if( gcWorker.fullgc == 0 && gcWorker.gcMin > 0 ){ if( --counts ) return; if( gcWorker.idleList->size < gcWorker.gcMax ){ counts = 1000; }else{ counts = 100; } } if( gcWorker.workList->size ){ DaoIGC_Continue(); }else if( gcWorker.fullgc || gcWorker.idleList->size >= gcWorker.gcMin ){ DaoIGC_Switch(); } } void DaoIGC_Switch() { if( gcWorker.busy ) return; DList_Swap( gcWorker.idleList, gcWorker.workList ); gcWorker.workType = 0; gcWorker.ii = 0; gcWorker.jj = 0; gcWorker.kk = 0; DaoIGC_Continue(); } void DaoIGC_Continue() { if( gcWorker.busy ) return; //printf( "DaoIGC_Continue: %i\n", gcWorker.workType ); gcWorker.busy = 1; switch( gcWorker.workType ){ case GC_RESET_RC : DaoGC_PrepareCandidates(); gcWorker.workType = GC_DEC_RC; gcWorker.ii = 0; break; case GC_DEC_RC : DaoIGC_CycRefCountDecScan(); #if 0 if( gcWorker.fullgc && gcWorker.workType == GC_INC_RC ){ daoint i; for( i=0; i<gcWorker.workList->size; i++ ){ DaoValue *value = gcWorker.workList->items.pValue[i]; if( value->xGC.cycRefCount > 0 ) DaoGC_PrintValueInfo( value ); } } #endif break; case GC_DEREG : DaoIGC_DeregisterModules(); break; case GC_INC_RC : case GC_INC_RC2 : DaoIGC_CycRefCountIncScan(); break; case GC_DIR_DEC_RC : DaoIGC_RefCountDecScan(); break; case GC_FREE : DaoIGC_FreeGarbage(); break; default : break; } gcWorker.busy = 0; } void DaoIGC_Finish() { DList *works = gcWorker.workList; DList *idles = gcWorker.idleList; DList *works2 = gcWorker.workList2; DList *idles2 = gcWorker.idleList2; DList *frees = gcWorker.freeList; DList *delays = gcWorker.delayList; gcWorker.gcMin = 0; gcWorker.fullgc = 1; gcWorker.finalizing = 1; while( idles->size + works->size + idles2->size + works2->size + frees->size + delays->size ){ while( works->size ) DaoIGC_Continue(); DaoIGC_Switch(); } } void DaoIGC_CycRefCountDecScan() { DList *workList = gcWorker.workList; uchar_t delay = gcWorker.delayMask; daoint min = workList->size >> 2; daoint i = gcWorker.ii; daoint j = 0, k; if( min < gcWorker.gcMin ) min = gcWorker.gcMin; for( ; i<workList->size; i++ ){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.delay ) continue; j += DaoGC_CycRefCountDecScan( value ); if( (++j) >= min ) break; } if( i >= workList->size ){ gcWorker.ii = 0; gcWorker.workType = GC_INC_RC; }else{ gcWorker.ii = i+1; } } void DaoIGC_DeregisterModules() { DList *workList = gcWorker.workList; daoint min = workList->size >> 2; daoint i = gcWorker.ii; daoint k = 0; if( min < gcWorker.gcMin ) min = gcWorker.gcMin; for( ; i<workList->size; i++ ){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.alive ) continue; if( value->type == DAO_NAMESPACE ){ DaoNamespace *NS = (DaoNamespace*) value; DaoVmSpace_Lock( NS->vmSpace ); if( NS->cycRefCount == 0 ) DMap_Erase( NS->vmSpace->nsModules, NS->name ); DaoVmSpace_Unlock( NS->vmSpace ); } } if( i >= workList->size ){ gcWorker.ii = 0; gcWorker.workType ++; }else{ gcWorker.ii = i+1; } } void DaoIGC_CycRefCountIncScan() { DList *workList = gcWorker.workList; DList *auxList = gcWorker.auxList; daoint min = workList->size >> 2; daoint i = gcWorker.ii; daoint k = 0; if( min < gcWorker.gcMin ) min = gcWorker.gcMin; if( gcWorker.jj ){ k += DaoIGC_AliveObjectScan(); if( gcWorker.jj ) return; } for( ; i<workList->size; i++ ){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.alive ) continue; if( value->xGC.cycRefCount > 0 ){ auxList->size = 0; value->xGC.alive = 1; DList_PushBack2( auxList, value ); k += DaoIGC_AliveObjectScan(); if( gcWorker.jj || k >= min ) break; } } if( i >= workList->size ){ gcWorker.ii = 0; gcWorker.workType ++; }else{ gcWorker.ii = i+1; } } int DaoIGC_AliveObjectScan() { daoint i, k = 9; daoint j = gcWorker.jj; daoint min = gcWorker.workList->size >> 2; uchar_t delay = gcWorker.delayMask; DList *auxList = gcWorker.auxList; if( min < gcWorker.gcMin ) min = gcWorker.gcMin; for( ; j<auxList->size; j++){ DaoValue *value = auxList->items.pValue[j]; if( value->xGC.delay ) continue; k += DaoGC_CycRefCountIncScan( value ); if( (++k) >= min ) break; } if( j >= auxList->size ){ gcWorker.jj = 0; }else{ gcWorker.jj = j+1; } return k; } void DaoIGC_RefCountDecScan() { DList *workList = gcWorker.workList; uchar_t delay = gcWorker.delayMask; daoint min = workList->size >> 2; daoint i = gcWorker.ii; daoint j = 0, k; if( min < gcWorker.gcMin ) min = gcWorker.gcMin; for(; i<workList->size; i++, j++){ DaoValue *value = workList->items.pValue[i]; if( value->xGC.cycRefCount && value->xGC.refCount ) continue; if( value->xGC.delay ) continue; j += DaoGC_RefCountDecScan( value ); if( j >= min ) break; } if( i >= workList->size ){ gcWorker.ii = 0; gcWorker.workType = GC_FREE; }else{ gcWorker.ii = i+1; } } void DaoIGC_FreeGarbage() { DList *idleList = gcWorker.idleList; DList *workList = gcWorker.workList; daoint min = workList->size >> 2; daoint i = gcWorker.ii; daoint j = 0; if( min < gcWorker.gcMin ) min = gcWorker.gcMin; for(; i<workList->size; i++, j++){ DaoValue *value = workList->items.pValue[i]; value->xGC.work = value->xGC.alive = 0; if( value->xGC.cycRefCount && value->xGC.refCount ) continue; if( value->xGC.refCount ){ /* This is possible since Cyclic RefCount is not updated atomically: */ #ifdef DEBUG_TRACE printf("RefCount not zero %p %i: %i %i\n", value, value->type, value->xGC.refCount, value->xGC.cycRefCount ); DaoGC_PrintValueInfo( value ); #endif value->xGC.delay = 1; DList_PushBack2( gcWorker.delayList, value ); continue; }else if( value->xGC.cycRefCount ){ /* To allow postponing GC by increasing the cyclic RefCount: */ value->xGC.delay = 1; DList_PushBack2( gcWorker.delayList, value ); continue; } value->xGC.dead = 1; DList_PushBack2( gcWorker.freeList, value ); if( j >= min ) break; } if( i >= workList->size ){ gcWorker.ii = 0; gcWorker.workType = GC_RESET_RC; workList->size = 0; }else{ gcWorker.ii = i+1; } for(i=0; i<gcWorker.auxList2->size; i++) gcWorker.auxList2->items.pValue[i]->xGC.alive = 0; gcWorker.auxList2->size = 0; DaoObjectLogger_SwitchBuffer(); } void cycRefCountDecrement( DaoValue *value ) { if( value == NULL ) return; /* Do not scan simple data types, as they cannot from cyclic structure: */ if( value->type < DAO_ENUM ) return; if( value->xGC.delay ) return; if( (value->xBase.trait & gcWorker.delayMask) && value->xGC.delay == 0 ){ DList_PushBack2( gcWorker.delayList, value ); value->xGC.cycRefCount = value->xGC.refCount; value->xGC.delay = 1; return; }else if( ! value->xGC.work ){ DList_PushBack2( gcWorker.workList, value ); value->xGC.cycRefCount = value->xGC.refCount; value->xGC.work = 1; } value->xGC.cycRefCount --; /* // Cyclic RefCount could become negative if it is initialized right after // its RefCount reaches zero. This could be avoided if the operation on // Cyclic RefCount is atomic. However, locks are currently used to ensure // atomicity of such operations, and it is computationally expensive to // use locking on Cyclic RefCount, so race condition is allowed on Cyclic // RefCount. // // Please note that the GC works correctly even if Cyclic RefCount is not // updated atomically. Because the GC performs two rounds of increment step // for Cyclic RefCount, which can guarantee that Cyclic RefCount will become // positive for alive objects. */ if( value->xGC.cycRefCount < 0 ){ /* // Always reset the Cyclic RefCount to zero when it falls below zero. // It will stay zero if it is true garbage object, otherwise, the increment // steps will increase it to a positive value. It is necessary to reset // it to zero, because at the end of the GC cycle, only objects with zero // Cyclic RefCount will be considered as garbages. */ value->xGC.cycRefCount = 0; #ifdef DEBUG_TRACE printf( "CycRefCount become negative: %2i %p %i %i %i\n", value->type, value ); DaoGC_PrintValueInfo( value ); #endif } } void cycRefCountIncrement( DaoValue *value ) { if( value == NULL ) return; /* do not scan simple data types, as they cannot from cyclic structure: */ if( value->type < DAO_ENUM ) return; value->xGC.cycRefCount ++; if( ! value->xGC.alive ){ value->xGC.alive = 1; DList_PushBack2( gcWorker.auxList, value ); DList_PushBack2( gcWorker.auxList2, value ); } } void DaoGC_CycRefCountDecrements( DaoValue **values, daoint size ) { daoint i; for(i=0; i<size; i++) cycRefCountDecrement( values[i] ); } void DaoGC_CycRefCountIncrements( DaoValue **values, daoint size ) { daoint i; for(i=0; i<size; i++) cycRefCountIncrement( values[i] ); } void DaoGC_RefCountDecrements( DaoValue **values, daoint size ) { daoint i; if( gcWorker.concurrent ) DMutex_Lock( & gcWorker.mutex_idle_list ); for(i=0; i<size; i++){ DaoValue *p = values[i]; if( p == NULL ) continue; p->xGC.refCount --; if( p->xGC.refCount == 0 && p->type < DAO_ENUM ) DaoGC_DeleteSimpleData( p ); values[i] = 0; } if( gcWorker.concurrent ) DMutex_Unlock( & gcWorker.mutex_idle_list ); } void cycRefCountDecrements( DList *list ) { if( list == NULL ) return; DaoGC_LockData(); DaoGC_CycRefCountDecrements( list->items.pValue, list->size ); DaoGC_UnlockData(); } void cycRefCountIncrements( DList *list ) { if( list == NULL ) return; DaoGC_LockData(); DaoGC_CycRefCountIncrements( list->items.pValue, list->size ); DaoGC_UnlockData(); } void directRefCountDecrement( DaoValue **value ) { DaoValue *p = *value; if( p == NULL ) return; if( gcWorker.concurrent ) DMutex_Lock( & gcWorker.mutex_idle_list ); p->xGC.refCount --; *value = NULL; if( p->xGC.refCount == 0 && p->type < DAO_ENUM ) DaoGC_DeleteSimpleData( p ); if( gcWorker.concurrent ) DMutex_Unlock( & gcWorker.mutex_idle_list ); } void directRefCountDecrements( DList *list ) { if( list == NULL ) return; DaoGC_LockData(); DaoGC_RefCountDecrements( list->items.pValue, list->size ); list->size = 0; DaoGC_UnlockData(); } static int DaoGC_CycRefCountDecScan( DaoValue *value ) { int count = 1; if( value->xGC.delay ) return 0; switch( value->type ){ case DAO_ENUM : { DaoEnum *en = (DaoEnum*) value; cycRefCountDecrement( (DaoValue*) en->etype ); break; } case DAO_CONSTANT : { cycRefCountDecrement( value->xConst.value ); break; } case DAO_VARIABLE : { cycRefCountDecrement( value->xVar.value ); cycRefCountDecrement( (DaoValue*) value->xVar.dtype ); break; } case DAO_PAR_NAMED : { cycRefCountDecrement( value->xNameValue.value ); cycRefCountDecrement( (DaoValue*) value->xNameValue.ctype ); break; } #ifdef DAO_WITH_NUMARRAY case DAO_ARRAY : { DaoArray *array = (DaoArray*) value; cycRefCountDecrement( (DaoValue*) array->original ); break; } #endif case DAO_TUPLE : { DaoTuple *tuple = (DaoTuple*) value; cycRefCountDecrement( (DaoValue*) tuple->ctype ); if( tuple->ctype == NULL || tuple->ctype->noncyclic ==0 ){ DaoGC_CycRefCountDecrements( tuple->values, tuple->size ); count += tuple->size; } break; } case DAO_LIST : { DaoList *list = (DaoList*) value; cycRefCountDecrement( (DaoValue*) list->ctype ); if( list->ctype == NULL || list->ctype->noncyclic ==0 ){ cycRefCountDecrements( list->value ); count += list->value->size; } break; } case DAO_MAP : { DaoMap *map = (DaoMap*) value; cycRefCountDecrement( (DaoValue*) map->ctype ); count += DaoGC_ScanMap( map->value, DAO_GC_DEC, 1, 1 ); break; } case DAO_OBJECT : { DaoObject *obj = (DaoObject*) value; if( obj->isRoot ){ DaoGC_CycRefCountDecrements( obj->objValues, obj->valueCount ); count += obj->valueCount; } cycRefCountDecrement( (DaoValue*) obj->parent ); cycRefCountDecrement( (DaoValue*) obj->rootObject ); cycRefCountDecrement( (DaoValue*) obj->defClass ); break; } case DAO_CTYPE : { DaoCtype *ctype = (DaoCtype*) value; cycRefCountDecrement( (DaoValue*) ctype->nameSpace ); cycRefCountDecrement( (DaoValue*) ctype->classType ); cycRefCountDecrement( (DaoValue*) ctype->valueType ); break; } case DAO_CSTRUCT : case DAO_CDATA : { DaoCstruct *cstruct = (DaoCstruct*) value; cycRefCountDecrement( (DaoValue*) cstruct->object ); cycRefCountDecrement( (DaoValue*) cstruct->ctype ); DaoGC_ScanCstruct( cstruct, DAO_GC_DEC ); break; } case DAO_ROUTINE : { DaoRoutine *rout = (DaoRoutine*)value; count += rout->variables ? rout->variables->size : 0; cycRefCountDecrement( (DaoValue*) rout->routType ); cycRefCountDecrement( (DaoValue*) rout->routHost ); cycRefCountDecrement( (DaoValue*) rout->nameSpace ); cycRefCountDecrement( (DaoValue*) rout->original ); cycRefCountDecrement( (DaoValue*) rout->routConsts ); cycRefCountDecrement( (DaoValue*) rout->body ); cycRefCountDecrements( rout->variables ); if( rout->overloads ) cycRefCountDecrements( rout->overloads->array ); if( rout->specialized ) cycRefCountDecrements( rout->specialized->array ); break; } case DAO_ROUTBODY : { DaoRoutineBody *rout = (DaoRoutineBody*)value; count += rout->regType->size; cycRefCountDecrements( rout->regType ); break; } case DAO_CLASS : { DaoClass *klass = (DaoClass*)value; cycRefCountDecrement( (DaoValue*) klass->nameSpace ); cycRefCountDecrement( (DaoValue*) klass->outerClass ); cycRefCountDecrement( (DaoValue*) klass->clsType ); cycRefCountDecrement( (DaoValue*) klass->initRoutine ); cycRefCountDecrements( klass->constants ); cycRefCountDecrements( klass->variables ); cycRefCountDecrements( klass->instvars ); cycRefCountDecrements( klass->allBases ); cycRefCountDecrements( klass->auxData ); count += klass->constants->size + klass->variables->size + klass->instvars->size; count += klass->allBases->size + klass->auxData->size; break; } case DAO_INTERFACE : { DaoInterface *inter = (DaoInterface*)value; cycRefCountDecrements( inter->bases ); cycRefCountDecrement( (DaoValue*) inter->outerClass ); cycRefCountDecrement( (DaoValue*) inter->nameSpace ); cycRefCountDecrement( (DaoValue*) inter->abtype ); count += DaoGC_ScanMap( inter->concretes, DAO_GC_DEC, 0, 1 ); count += DaoGC_ScanMap( inter->methods, DAO_GC_DEC, 0, 1 ); count += inter->bases->size; break; } case DAO_CINTYPE : { DaoCinType *cintype = (DaoCinType*)value; cycRefCountDecrements( cintype->bases ); cycRefCountDecrement( (DaoValue*) cintype->outerClass ); cycRefCountDecrement( (DaoValue*) cintype->citype ); cycRefCountDecrement( (DaoValue*) cintype->vatype ); cycRefCountDecrement( (DaoValue*) cintype->target ); cycRefCountDecrement( (DaoValue*) cintype->abstract ); count += DaoGC_ScanMap( cintype->methods, DAO_GC_DEC, 0, 1 ); count += cintype->bases->size; break; } case DAO_CINVALUE : { cycRefCountDecrement( value->xCinValue.value ); cycRefCountDecrement( (DaoValue*) value->xCinValue.cintype ); break; } case DAO_NAMESPACE : { DaoNamespace *ns = (DaoNamespace*) value; cycRefCountDecrements( ns->constants ); cycRefCountDecrements( ns->variables ); cycRefCountDecrements( ns->auxData ); count += DaoGC_ScanMap( ns->abstypes, DAO_GC_DEC, 0, 1 ); count += ns->constants->size + ns->variables->size; count += ns->auxData->size; break; } case DAO_TYPE : { DaoType *type = (DaoType*) value; cycRefCountDecrement( type->aux ); cycRefCountDecrement( type->value ); cycRefCountDecrement( (DaoValue*) type->kernel ); cycRefCountDecrement( (DaoValue*) type->cbtype ); cycRefCountDecrement( (DaoValue*) type->quadtype ); cycRefCountDecrement( (DaoValue*) type->nameSpace ); cycRefCountDecrements( type->args ); cycRefCountDecrements( type->bases ); count += DaoGC_ScanMap( type->interfaces, DAO_GC_DEC, 1, 1 ); break; } case DAO_TYPEKERNEL : { DaoTypeKernel *kernel = (DaoTypeKernel*) value; cycRefCountDecrement( (DaoValue*) kernel->abtype ); cycRefCountDecrement( (DaoValue*) kernel->nspace ); cycRefCountDecrement( (DaoValue*) kernel->initRoutines ); count += DaoGC_ScanMap( kernel->values, DAO_GC_DEC, 0, 1 ); count += DaoGC_ScanMap( kernel->methods, DAO_GC_DEC, 0, 1 ); if( kernel->sptree ){ cycRefCountDecrements( kernel->sptree->holders ); cycRefCountDecrements( kernel->sptree->defaults ); cycRefCountDecrements( kernel->sptree->sptypes ); } break; } case DAO_PROCESS : { DaoProcess *vmp = (DaoProcess*) value; DaoStackFrame *frame = vmp->firstFrame; cycRefCountDecrement( (DaoValue*) vmp->future ); cycRefCountDecrement( (DaoValue*) vmp->stdioStream ); cycRefCountDecrements( vmp->exceptions ); cycRefCountDecrements( vmp->defers ); cycRefCountDecrements( vmp->factory ); DaoGC_CycRefCountDecrements( vmp->stackValues, vmp->stackSize ); count += vmp->stackSize; while( frame ){ count += 3; cycRefCountDecrement( (DaoValue*) frame->routine ); cycRefCountDecrement( (DaoValue*) frame->object ); cycRefCountDecrement( (DaoValue*) frame->retype ); frame = frame->next; } break; } default: break; } return count; } static int DaoGC_CycRefCountIncScan( DaoValue *value ) { int count = 1; if( value->xGC.delay ) return 0; switch( value->type ){ case DAO_ENUM : { DaoEnum *en = (DaoEnum*) value; cycRefCountIncrement( (DaoValue*) en->etype ); break; } case DAO_CONSTANT : { cycRefCountIncrement( value->xConst.value ); break; } case DAO_VARIABLE : { cycRefCountIncrement( value->xVar.value ); cycRefCountIncrement( (DaoValue*) value->xVar.dtype ); break; } case DAO_PAR_NAMED : { cycRefCountIncrement( value->xNameValue.value ); cycRefCountIncrement( (DaoValue*) value->xNameValue.ctype ); break; } #ifdef DAO_WITH_NUMARRAY case DAO_ARRAY : { DaoArray *array = (DaoArray*) value; cycRefCountIncrement( (DaoValue*) array->original ); break; } #endif case DAO_TUPLE : { DaoTuple *tuple= (DaoTuple*) value; cycRefCountIncrement( (DaoValue*) tuple->ctype ); if( tuple->ctype == NULL || tuple->ctype->noncyclic ==0 ){ DaoGC_CycRefCountIncrements( tuple->values, tuple->size ); count += tuple->size; } break; } case DAO_LIST : { DaoList *list= (DaoList*) value; cycRefCountIncrement( (DaoValue*) list->ctype ); if( list->ctype == NULL || list->ctype->noncyclic ==0 ){ cycRefCountIncrements( list->value ); count += list->value->size; } break; } case DAO_MAP : { DaoMap *map = (DaoMap*)value; cycRefCountIncrement( (DaoValue*) map->ctype ); count += DaoGC_ScanMap( map->value, DAO_GC_INC, 1, 1 ); break; } case DAO_OBJECT : { DaoObject *obj = (DaoObject*) value; if( obj->isRoot ){ DaoGC_CycRefCountIncrements( obj->objValues, obj->valueCount ); count += obj->valueCount; } cycRefCountIncrement( (DaoValue*) obj->parent ); cycRefCountIncrement( (DaoValue*) obj->rootObject ); cycRefCountIncrement( (DaoValue*) obj->defClass ); break; } case DAO_CTYPE : { DaoCtype *ctype = (DaoCtype*) value; cycRefCountIncrement( (DaoValue*) ctype->nameSpace ); cycRefCountIncrement( (DaoValue*) ctype->classType ); cycRefCountIncrement( (DaoValue*) ctype->valueType ); break; } case DAO_CSTRUCT : case DAO_CDATA : { DaoCstruct *cstruct = (DaoCstruct*) value; cycRefCountIncrement( (DaoValue*) cstruct->object ); cycRefCountIncrement( (DaoValue*) cstruct->ctype ); DaoGC_ScanCstruct( cstruct, DAO_GC_INC ); break; } case DAO_ROUTINE : { DaoRoutine *rout = (DaoRoutine*) value; count += rout->variables ? rout->variables->size : 0; cycRefCountIncrement( (DaoValue*) rout->routType ); cycRefCountIncrement( (DaoValue*) rout->routHost ); cycRefCountIncrement( (DaoValue*) rout->nameSpace ); cycRefCountIncrement( (DaoValue*) rout->original ); cycRefCountIncrement( (DaoValue*) rout->routConsts ); cycRefCountIncrement( (DaoValue*) rout->body ); cycRefCountIncrements( rout->variables ); if( rout->overloads ) cycRefCountIncrements( rout->overloads->array ); if( rout->specialized ) cycRefCountIncrements( rout->specialized->array ); break; } case DAO_ROUTBODY : { DaoRoutineBody *rout = (DaoRoutineBody*)value; count += rout->regType->size; cycRefCountIncrements( rout->regType ); break; } case DAO_CLASS : { DaoClass *klass = (DaoClass*) value; cycRefCountIncrement( (DaoValue*) klass->nameSpace ); cycRefCountIncrement( (DaoValue*) klass->outerClass ); cycRefCountIncrement( (DaoValue*) klass->clsType ); cycRefCountIncrement( (DaoValue*) klass->initRoutine ); cycRefCountIncrements( klass->constants ); cycRefCountIncrements( klass->variables ); cycRefCountIncrements( klass->instvars ); cycRefCountIncrements( klass->allBases ); cycRefCountIncrements( klass->auxData ); count += klass->constants->size + klass->variables->size + klass->instvars->size; count += klass->allBases->size + klass->auxData->size; break; } case DAO_INTERFACE : { DaoInterface *inter = (DaoInterface*)value; cycRefCountIncrements( inter->bases ); cycRefCountIncrement( (DaoValue*) inter->nameSpace ); cycRefCountIncrement( (DaoValue*) inter->outerClass ); cycRefCountIncrement( (DaoValue*) inter->abtype ); count += DaoGC_ScanMap( inter->concretes, DAO_GC_INC, 0, 1 ); count += DaoGC_ScanMap( inter->methods, DAO_GC_INC, 0, 1 ); count += inter->bases->size; break; } case DAO_CINTYPE : { DaoCinType *cintype = (DaoCinType*)value; cycRefCountIncrements( cintype->bases ); cycRefCountIncrement( (DaoValue*) cintype->outerClass ); cycRefCountIncrement( (DaoValue*) cintype->citype ); cycRefCountIncrement( (DaoValue*) cintype->vatype ); cycRefCountIncrement( (DaoValue*) cintype->target ); cycRefCountIncrement( (DaoValue*) cintype->abstract ); count += DaoGC_ScanMap( cintype->methods, DAO_GC_INC, 0, 1 ); count += cintype->bases->size; break; } case DAO_CINVALUE : { cycRefCountIncrement( value->xCinValue.value ); cycRefCountIncrement( (DaoValue*) value->xCinValue.cintype ); break; } case DAO_NAMESPACE : { DaoNamespace *ns = (DaoNamespace*) value; cycRefCountIncrements( ns->constants ); cycRefCountIncrements( ns->variables ); cycRefCountIncrements( ns->auxData ); count += DaoGC_ScanMap( ns->abstypes, DAO_GC_INC, 0, 1 ); count += ns->constants->size + ns->variables->size; count += ns->auxData->size; break; } case DAO_TYPE : { DaoType *type = (DaoType*) value; cycRefCountIncrement( type->aux ); cycRefCountIncrement( type->value ); cycRefCountIncrement( (DaoValue*) type->kernel ); cycRefCountIncrement( (DaoValue*) type->cbtype ); cycRefCountIncrement( (DaoValue*) type->quadtype ); cycRefCountIncrement( (DaoValue*) type->nameSpace ); cycRefCountIncrements( type->args ); cycRefCountIncrements( type->bases ); count += DaoGC_ScanMap( type->interfaces, DAO_GC_INC, 1, 1 ); break; } case DAO_TYPEKERNEL : { DaoTypeKernel *kernel = (DaoTypeKernel*) value; cycRefCountIncrement( (DaoValue*) kernel->abtype ); cycRefCountIncrement( (DaoValue*) kernel->nspace ); cycRefCountIncrement( (DaoValue*) kernel->initRoutines ); count += DaoGC_ScanMap( kernel->values, DAO_GC_INC, 0, 1 ); count += DaoGC_ScanMap( kernel->methods, DAO_GC_INC, 0, 1 ); if( kernel->sptree ){ cycRefCountIncrements( kernel->sptree->holders ); cycRefCountIncrements( kernel->sptree->defaults ); cycRefCountIncrements( kernel->sptree->sptypes ); } break; } case DAO_PROCESS : { DaoProcess *vmp = (DaoProcess*) value; DaoStackFrame *frame = vmp->firstFrame; cycRefCountIncrement( (DaoValue*) vmp->future ); cycRefCountIncrement( (DaoValue*) vmp->stdioStream ); cycRefCountIncrements( vmp->exceptions ); cycRefCountIncrements( vmp->defers ); cycRefCountIncrements( vmp->factory ); DaoGC_CycRefCountIncrements( vmp->stackValues, vmp->stackSize ); count += vmp->stackSize; while( frame ){ count += 3; cycRefCountIncrement( (DaoValue*) frame->routine ); cycRefCountIncrement( (DaoValue*) frame->object ); cycRefCountIncrement( (DaoValue*) frame->retype ); frame = frame->next; } break; } default: break; } return count; } extern void DaoVmSpace_ReleaseCdata2( DaoVmSpace *self, DaoType *type, void *data ); static int DaoGC_RefCountDecScan( DaoValue *value ) { int count = 1; if( value->xGC.delay ) return 0; switch( value->type ){ case DAO_ENUM : { DaoEnum *en = (DaoEnum*) value; directRefCountDecrement( (DaoValue**) & en->etype ); break; } case DAO_CONSTANT : { directRefCountDecrement( & value->xConst.value ); break; } case DAO_VARIABLE : { directRefCountDecrement( & value->xVar.value ); directRefCountDecrement( (DaoValue**) & value->xVar.dtype ); break; } case DAO_PAR_NAMED : { directRefCountDecrement( & value->xNameValue.value ); directRefCountDecrement( (DaoValue**) & value->xNameValue.ctype ); break; } #ifdef DAO_WITH_NUMARRAY case DAO_ARRAY : { DaoArray *array = (DaoArray*) value; directRefCountDecrement( (DaoValue**) & array->original ); break; } #endif case DAO_TUPLE : { DaoTuple *tuple = (DaoTuple*) value; count += tuple->size; directRefCountDecrement( (DaoValue**) & tuple->ctype ); DaoGC_RefCountDecrements( tuple->values, tuple->size ); tuple->size = 0; break; } case DAO_LIST : { DaoList *list = (DaoList*) value; count += list->value->size; directRefCountDecrements( list->value ); directRefCountDecrement( (DaoValue**) & list->ctype ); break; } case DAO_MAP : { DaoMap *map = (DaoMap*) value; count += DaoGC_ScanMap( map->value, DAO_GC_BREAK, 1, 1 ); directRefCountDecrement( (DaoValue**) & map->ctype ); break; } case DAO_OBJECT : { DaoObject *obj = (DaoObject*) value; if( obj->isRoot ){ DaoGC_RefCountDecrements( obj->objValues, obj->valueCount ); count += obj->valueCount; } directRefCountDecrement( (DaoValue**) & obj->parent ); directRefCountDecrement( (DaoValue**) & obj->rootObject ); directRefCountDecrement( (DaoValue**) & obj->defClass ); obj->valueCount = 0; break; } case DAO_CTYPE : { DaoCtype *ctype = (DaoCtype*) value; directRefCountDecrement( (DaoValue**) & ctype->nameSpace ); directRefCountDecrement( (DaoValue**) & ctype->classType ); directRefCountDecrement( (DaoValue**) & ctype->valueType ); break; } case DAO_CSTRUCT : case DAO_CDATA : { DaoCstruct *cstruct = (DaoCstruct*) value; DaoType *ctype = cstruct->ctype; /* // The DaoCdata object might be still held by the DaoVmSpace object // in its cdata cache. So it may happen that DaoVmSpace_MakeCdata() // is called after this cdata object has already been marked for // deletion by the GC. When this happens DaoVmSpace_MakeCdata() // will use DaoGC_IncCycRC() to mark this cdata as becoming alive // again, so its deletion must be postponed. */ if( value->type == DAO_CDATA && value->xCdata.vmSpace != NULL ){ DaoCdata *cdata = (DaoCdata*) value; DaoVmSpace *vmspace = cdata->vmSpace; if( DaoGC_IsConcurrent() ) DaoVmSpace_LockCache( vmspace ); if( cdata->cycRefCount == 0 && cdata->data != NULL ){ DaoVmSpace_ReleaseCdata2( vmspace, cdata->ctype, cdata->data ); } if( DaoGC_IsConcurrent() ) DaoVmSpace_UnlockCache( vmspace ); if( cdata->cycRefCount ) break; /* Postponed; */ /* See DaoVmSpace_MakeCdata() and DaoGC_IncCycRC(); */ } directRefCountDecrement( (DaoValue**) & cstruct->object ); directRefCountDecrement( (DaoValue**) & cstruct->ctype ); cstruct->trait |= DAO_VALUE_BROKEN; cstruct->ctype = ctype; /* // DaoVmSpace_ReleaseCdata2() will set DaoCdata::data to null, // only when a null @type parameter is used. */ DaoGC_ScanCstruct( cstruct, DAO_GC_BREAK ); if( value->type == DAO_CDATA ) DaoCdata_SetData( (DaoCdata*) value, NULL ); break; } case DAO_ROUTINE : { DaoRoutine *rout = (DaoRoutine*)value; count += rout->variables ? rout->variables->size : 0; directRefCountDecrement( (DaoValue**) & rout->nameSpace ); /* may become NULL, if it has already become garbage * in the last cycle */ directRefCountDecrement( (DaoValue**) & rout->routType ); /* may become NULL, if it has already become garbage * in the last cycle */ directRefCountDecrement( (DaoValue**) & rout->routHost ); directRefCountDecrement( (DaoValue**) & rout->original ); directRefCountDecrement( (DaoValue**) & rout->routConsts ); directRefCountDecrement( (DaoValue**) & rout->body ); directRefCountDecrements( rout->variables ); if( rout->overloads ) directRefCountDecrements( rout->overloads->array ); if( rout->specialized ) directRefCountDecrements( rout->specialized->array ); break; } case DAO_ROUTBODY : { DaoRoutineBody *rout = (DaoRoutineBody*)value; count += rout->regType->size; directRefCountDecrements( rout->regType ); break; } case DAO_CLASS : { DaoClass *klass = (DaoClass*)value; count += klass->constants->size + klass->variables->size + klass->instvars->size; count += klass->allBases->size + klass->auxData->size; directRefCountDecrement( (DaoValue**) & klass->nameSpace ); directRefCountDecrement( (DaoValue**) & klass->outerClass ); directRefCountDecrement( (DaoValue**) & klass->clsType ); directRefCountDecrement( (DaoValue**) & klass->initRoutine ); directRefCountDecrements( klass->constants ); directRefCountDecrements( klass->variables ); directRefCountDecrements( klass->instvars ); directRefCountDecrements( klass->allBases ); directRefCountDecrements( klass->auxData ); break; } case DAO_INTERFACE : { DaoInterface *inter = (DaoInterface*)value; directRefCountDecrements( inter->bases ); directRefCountDecrement( (DaoValue**) & inter->nameSpace ); directRefCountDecrement( (DaoValue**) & inter->outerClass ); directRefCountDecrement( (DaoValue**) & inter->abtype ); count += DaoGC_ScanMap( inter->concretes, DAO_GC_BREAK, 0, 1 ); count += DaoGC_ScanMap( inter->methods, DAO_GC_BREAK, 0, 1 ); count += inter->bases->size; break; } case DAO_CINTYPE : { DaoCinType *cintype = (DaoCinType*)value; directRefCountDecrements( cintype->bases ); directRefCountDecrement( (DaoValue**) & cintype->outerClass ); directRefCountDecrement( (DaoValue**) & cintype->citype ); directRefCountDecrement( (DaoValue**) & cintype->vatype ); directRefCountDecrement( (DaoValue**) & cintype->target ); directRefCountDecrement( (DaoValue**) & cintype->abstract ); count += DaoGC_ScanMap( cintype->methods, DAO_GC_BREAK, 0, 1 ); count += cintype->bases->size; break; } case DAO_CINVALUE : { directRefCountDecrement( & value->xCinValue.value ); directRefCountDecrement( (DaoValue**) & value->xCinValue.cintype ); break; } case DAO_NAMESPACE : { DaoNamespace *ns = (DaoNamespace*) value; count += ns->auxData->size; count += ns->constants->size + ns->variables->size; count += DaoGC_ScanMap( ns->abstypes, DAO_GC_BREAK, 0, 1 ); directRefCountDecrements( ns->constants ); directRefCountDecrements( ns->variables ); directRefCountDecrements( ns->auxData ); break; } case DAO_TYPE : { DaoType *type = (DaoType*) value; directRefCountDecrements( type->args ); directRefCountDecrements( type->bases ); directRefCountDecrement( (DaoValue**) & type->aux ); directRefCountDecrement( (DaoValue**) & type->value ); directRefCountDecrement( (DaoValue**) & type->kernel ); directRefCountDecrement( (DaoValue**) & type->cbtype ); directRefCountDecrement( (DaoValue**) & type->quadtype ); directRefCountDecrement( (DaoValue**) & type->nameSpace ); count += DaoGC_ScanMap( type->interfaces, DAO_GC_BREAK, 1, 1 ); break; } case DAO_TYPEKERNEL : { DaoTypeKernel *kernel = (DaoTypeKernel*) value; directRefCountDecrement( (DaoValue**) & kernel->abtype ); directRefCountDecrement( (DaoValue**) & kernel->nspace ); directRefCountDecrement( (DaoValue**) & kernel->initRoutines ); count += DaoGC_ScanMap( kernel->values, DAO_GC_BREAK, 0, 1 ); count += DaoGC_ScanMap( kernel->methods, DAO_GC_BREAK, 0, 1 ); if( kernel->sptree ){ directRefCountDecrements( kernel->sptree->holders ); directRefCountDecrements( kernel->sptree->defaults ); directRefCountDecrements( kernel->sptree->sptypes ); } break; } case DAO_PROCESS : { DaoProcess *vmp = (DaoProcess*) value; DaoStackFrame *frame = vmp->firstFrame; directRefCountDecrement( (DaoValue**) & vmp->future ); directRefCountDecrement( (DaoValue**) & vmp->stdioStream ); directRefCountDecrements( vmp->exceptions ); directRefCountDecrements( vmp->defers ); directRefCountDecrements( vmp->factory ); DaoGC_RefCountDecrements( vmp->stackValues, vmp->stackSize ); count += vmp->stackSize; vmp->stackSize = 0; while( frame ){ count += 3; if( gcWorker.concurrent ) DMutex_Lock( & gcWorker.mutex_idle_list ); if( frame->routine ) frame->routine->refCount --; if( frame->object ) frame->object->refCount --; if( frame->retype ) frame->retype->refCount --; frame->routine = NULL; frame->object = NULL; frame->retype = NULL; if( gcWorker.concurrent ) DMutex_Unlock( & gcWorker.mutex_idle_list ); frame = frame->next; } break; } default: break; } return count; }
1ae1f7c9380fadbb90d770bf6d2dfc3ccb0fd1f4
f7dc806f341ef5dbb0e11252a4693003a66853d5
/thirdparty/libvorbis/sharedbook.c
62a9a00afb8f7d0b4a79a13dc4c4fdba4683d5e0
[ "BSD-3-Clause", "MIT", "OFL-1.1", "JSON", "LicenseRef-scancode-nvidia-2002", "Zlib", "MPL-2.0", "CC0-1.0", "BSL-1.0", "Libpng", "Apache-2.0", "LicenseRef-scancode-public-domain", "Unlicense", "LicenseRef-scancode-free-unknown", "CC-BY-4.0", "Bison-exception-2.2", "LicenseRef-scancode...
permissive
godotengine/godot
8a2419750f4851d1426a8f3bcb52cac5c86f23c2
970be7afdc111ccc7459d7ef3560de70e6d08c80
refs/heads/master
2023-08-21T14:37:00.262883
2023-08-21T06:26:15
2023-08-21T06:26:15
15,634,981
68,852
18,388
MIT
2023-09-14T21:42:16
2014-01-04T16:05:36
C++
UTF-8
C
false
false
17,806
c
sharedbook.c
/******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015 * * by the Xiph.Org Foundation https://xiph.org/ * * * ******************************************************************** function: basic shared codebook operations ********************************************************************/ #include <stdlib.h> #include <limits.h> #include <math.h> #include <string.h> #include <ogg/ogg.h> #include "os.h" #include "misc.h" #include "vorbis/codec.h" #include "codebook.h" #include "scales.h" /**** pack/unpack helpers ******************************************/ int ov_ilog(ogg_uint32_t v){ int ret; for(ret=0;v;ret++)v>>=1; return ret; } /* 32 bit float (not IEEE; nonnormalized mantissa + biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm Why not IEEE? It's just not that important here. */ #define VQ_FEXP 10 #define VQ_FMAN 21 #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */ /* doesn't currently guard under/overflow */ long _float32_pack(float val){ int sign=0; long exp; long mant; if(val<0){ sign=0x80000000; val= -val; } exp= floor(log(val)/log(2.f)+.001); /* +epsilon */ mant=rint(ldexp(val,(VQ_FMAN-1)-exp)); exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN; return(sign|exp|mant); } float _float32_unpack(long val){ double mant=val&0x1fffff; int sign=val&0x80000000; long exp =(val&0x7fe00000L)>>VQ_FMAN; if(sign)mant= -mant; exp=exp-(VQ_FMAN-1)-VQ_FEXP_BIAS; /* clamp excessive exponent values */ if (exp>63){ exp=63; } if (exp<-63){ exp=-63; } return(ldexp(mant,exp)); } /* given a list of word lengths, generate a list of codewords. Works for length ordered or unordered, always assigns the lowest valued codewords first. Extended to handle unused entries (length 0) */ ogg_uint32_t *_make_words(char *l,long n,long sparsecount){ long i,j,count=0; ogg_uint32_t marker[33]; ogg_uint32_t *r=_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r)); memset(marker,0,sizeof(marker)); for(i=0;i<n;i++){ long length=l[i]; if(length>0){ ogg_uint32_t entry=marker[length]; /* when we claim a node for an entry, we also claim the nodes below it (pruning off the imagined tree that may have dangled from it) as well as blocking the use of any nodes directly above for leaves */ /* update ourself */ if(length<32 && (entry>>length)){ /* error condition; the lengths must specify an overpopulated tree */ _ogg_free(r); return(NULL); } r[count++]=entry; /* Look to see if the next shorter marker points to the node above. if so, update it and repeat. */ { for(j=length;j>0;j--){ if(marker[j]&1){ /* have to jump branches */ if(j==1) marker[1]++; else marker[j]=marker[j-1]<<1; break; /* invariant says next upper marker would already have been moved if it was on the same path */ } marker[j]++; } } /* prune the tree; the implicit invariant says all the longer markers were dangling from our just-taken node. Dangle them from our *new* node. */ for(j=length+1;j<33;j++) if((marker[j]>>1) == entry){ entry=marker[j]; marker[j]=marker[j-1]<<1; }else break; }else if(sparsecount==0)count++; } /* any underpopulated tree must be rejected. */ /* Single-entry codebooks are a retconned extension to the spec. They have a single codeword '0' of length 1 that results in an underpopulated tree. Shield that case from the underformed tree check. */ if(!(count==1 && marker[2]==2)){ for(i=1;i<33;i++) if(marker[i] & (0xffffffffUL>>(32-i))){ _ogg_free(r); return(NULL); } } /* bitreverse the words because our bitwise packer/unpacker is LSb endian */ for(i=0,count=0;i<n;i++){ ogg_uint32_t temp=0; for(j=0;j<l[i];j++){ temp<<=1; temp|=(r[count]>>j)&1; } if(sparsecount){ if(l[i]) r[count++]=temp; }else r[count++]=temp; } return(r); } /* there might be a straightforward one-line way to do the below that's portable and totally safe against roundoff, but I haven't thought of it. Therefore, we opt on the side of caution */ long _book_maptype1_quantvals(const static_codebook *b){ long vals; if(b->entries<1){ return(0); } vals=floor(pow((float)b->entries,1.f/b->dim)); /* the above *should* be reliable, but we'll not assume that FP is ever reliable when bitstream sync is at stake; verify via integer means that vals really is the greatest value of dim for which vals^b->bim <= b->entries */ /* treat the above as an initial guess */ if(vals<1){ vals=1; } while(1){ long acc=1; long acc1=1; int i; for(i=0;i<b->dim;i++){ if(b->entries/vals<acc)break; acc*=vals; if(LONG_MAX/(vals+1)<acc1)acc1=LONG_MAX; else acc1*=vals+1; } if(i>=b->dim && acc<=b->entries && acc1>b->entries){ return(vals); }else{ if(i<b->dim || acc>b->entries){ vals--; }else{ vals++; } } } } /* unpack the quantized list of values for encode/decode ***********/ /* we need to deal with two map types: in map type 1, the values are generated algorithmically (each column of the vector counts through the values in the quant vector). in map type 2, all the values came in in an explicit list. Both value lists must be unpacked */ float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){ long j,k,count=0; if(b->maptype==1 || b->maptype==2){ int quantvals; float mindel=_float32_unpack(b->q_min); float delta=_float32_unpack(b->q_delta); float *r=_ogg_calloc(n*b->dim,sizeof(*r)); /* maptype 1 and 2 both use a quantized value vector, but different sizes */ switch(b->maptype){ case 1: /* most of the time, entries%dimensions == 0, but we need to be well defined. We define that the possible vales at each scalar is values == entries/dim. If entries%dim != 0, we'll have 'too few' values (values*dim<entries), which means that we'll have 'left over' entries; left over entries use zeroed values (and are wasted). So don't generate codebooks like that */ quantvals=_book_maptype1_quantvals(b); for(j=0;j<b->entries;j++){ if((sparsemap && b->lengthlist[j]) || !sparsemap){ float last=0.f; int indexdiv=1; for(k=0;k<b->dim;k++){ int index= (j/indexdiv)%quantvals; float val=b->quantlist[index]; val=fabs(val)*delta+mindel+last; if(b->q_sequencep)last=val; if(sparsemap) r[sparsemap[count]*b->dim+k]=val; else r[count*b->dim+k]=val; indexdiv*=quantvals; } count++; } } break; case 2: for(j=0;j<b->entries;j++){ if((sparsemap && b->lengthlist[j]) || !sparsemap){ float last=0.f; for(k=0;k<b->dim;k++){ float val=b->quantlist[j*b->dim+k]; val=fabs(val)*delta+mindel+last; if(b->q_sequencep)last=val; if(sparsemap) r[sparsemap[count]*b->dim+k]=val; else r[count*b->dim+k]=val; } count++; } } break; } return(r); } return(NULL); } void vorbis_staticbook_destroy(static_codebook *b){ if(b->allocedp){ if(b->quantlist)_ogg_free(b->quantlist); if(b->lengthlist)_ogg_free(b->lengthlist); memset(b,0,sizeof(*b)); _ogg_free(b); } /* otherwise, it is in static memory */ } void vorbis_book_clear(codebook *b){ /* static book is not cleared; we're likely called on the lookup and the static codebook belongs to the info struct */ if(b->valuelist)_ogg_free(b->valuelist); if(b->codelist)_ogg_free(b->codelist); if(b->dec_index)_ogg_free(b->dec_index); if(b->dec_codelengths)_ogg_free(b->dec_codelengths); if(b->dec_firsttable)_ogg_free(b->dec_firsttable); memset(b,0,sizeof(*b)); } int vorbis_book_init_encode(codebook *c,const static_codebook *s){ memset(c,0,sizeof(*c)); c->c=s; c->entries=s->entries; c->used_entries=s->entries; c->dim=s->dim; c->codelist=_make_words(s->lengthlist,s->entries,0); /* c->valuelist=_book_unquantize(s,s->entries,NULL); */ c->quantvals=_book_maptype1_quantvals(s); c->minval=(int)rint(_float32_unpack(s->q_min)); c->delta=(int)rint(_float32_unpack(s->q_delta)); return(0); } static ogg_uint32_t bitreverse(ogg_uint32_t x){ x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL); x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL); x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL); x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL); return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL); } static int sort32a(const void *a,const void *b){ return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)- ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b); } /* decode codebook arrangement is more heavily optimized than encode */ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ int i,j,n=0,tabn; int *sortindex; memset(c,0,sizeof(*c)); /* count actually used entries and find max length */ for(i=0;i<s->entries;i++) if(s->lengthlist[i]>0) n++; c->entries=s->entries; c->used_entries=n; c->dim=s->dim; if(n>0){ /* two different remappings go on here. First, we collapse the likely sparse codebook down only to actually represented values/words. This collapsing needs to be indexed as map-valueless books are used to encode original entry positions as integers. Second, we reorder all vectors, including the entry index above, by sorted bitreversed codeword to allow treeless decode. */ /* perform sort */ ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); ogg_uint32_t **codep=alloca(sizeof(*codep)*n); if(codes==NULL)goto err_out; for(i=0;i<n;i++){ codes[i]=bitreverse(codes[i]); codep[i]=codes+i; } qsort(codep,n,sizeof(*codep),sort32a); sortindex=alloca(n*sizeof(*sortindex)); c->codelist=_ogg_malloc(n*sizeof(*c->codelist)); /* the index is a reverse index */ for(i=0;i<n;i++){ int position=codep[i]-codes; sortindex[position]=i; } for(i=0;i<n;i++) c->codelist[sortindex[i]]=codes[i]; _ogg_free(codes); c->valuelist=_book_unquantize(s,n,sortindex); c->dec_index=_ogg_malloc(n*sizeof(*c->dec_index)); for(n=0,i=0;i<s->entries;i++) if(s->lengthlist[i]>0) c->dec_index[sortindex[n++]]=i; c->dec_codelengths=_ogg_malloc(n*sizeof(*c->dec_codelengths)); c->dec_maxlength=0; for(n=0,i=0;i<s->entries;i++) if(s->lengthlist[i]>0){ c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; if(s->lengthlist[i]>c->dec_maxlength) c->dec_maxlength=s->lengthlist[i]; } if(n==1 && c->dec_maxlength==1){ /* special case the 'single entry codebook' with a single bit fastpath table (that always returns entry 0 )in order to use unmodified decode paths. */ c->dec_firsttablen=1; c->dec_firsttable=_ogg_calloc(2,sizeof(*c->dec_firsttable)); c->dec_firsttable[0]=c->dec_firsttable[1]=1; }else{ c->dec_firsttablen=ov_ilog(c->used_entries)-4; /* this is magic */ if(c->dec_firsttablen<5)c->dec_firsttablen=5; if(c->dec_firsttablen>8)c->dec_firsttablen=8; tabn=1<<c->dec_firsttablen; c->dec_firsttable=_ogg_calloc(tabn,sizeof(*c->dec_firsttable)); for(i=0;i<n;i++){ if(c->dec_codelengths[i]<=c->dec_firsttablen){ ogg_uint32_t orig=bitreverse(c->codelist[i]); for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++) c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1; } } /* now fill in 'unused' entries in the firsttable with hi/lo search hints for the non-direct-hits */ { ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen); long lo=0,hi=0; for(i=0;i<tabn;i++){ ogg_uint32_t word=i<<(32-c->dec_firsttablen); if(c->dec_firsttable[bitreverse(word)]==0){ while((lo+1)<n && c->codelist[lo+1]<=word)lo++; while( hi<n && word>=(c->codelist[hi]&mask))hi++; /* we only actually have 15 bits per hint to play with here. In order to overflow gracefully (nothing breaks, efficiency just drops), encode as the difference from the extremes. */ { unsigned long loval=lo; unsigned long hival=n-hi; if(loval>0x7fff)loval=0x7fff; if(hival>0x7fff)hival=0x7fff; c->dec_firsttable[bitreverse(word)]= 0x80000000UL | (loval<<15) | hival; } } } } } } return(0); err_out: vorbis_book_clear(c); return(-1); } long vorbis_book_codeword(codebook *book,int entry){ if(book->c) /* only use with encode; decode optimizations are allowed to break this */ return book->codelist[entry]; return -1; } long vorbis_book_codelen(codebook *book,int entry){ if(book->c) /* only use with encode; decode optimizations are allowed to break this */ return book->c->lengthlist[entry]; return -1; } #ifdef _V_SELFTEST /* Unit tests of the dequantizer; this stuff will be OK cross-platform, I simply want to be sure that special mapping cases actually work properly; a bug could go unnoticed for a while */ #include <stdio.h> /* cases: no mapping full, explicit mapping algorithmic mapping nonsequential sequential */ static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1}; static long partial_quantlist1[]={0,7,2}; /* no mapping */ static_codebook test1={ 4,16, NULL, 0, 0,0,0,0, NULL, 0 }; static float *test1_result=NULL; /* linear, full mapping, nonsequential */ static_codebook test2={ 4,3, NULL, 2, -533200896,1611661312,4,0, full_quantlist1, 0 }; static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2}; /* linear, full mapping, sequential */ static_codebook test3={ 4,3, NULL, 2, -533200896,1611661312,4,1, full_quantlist1, 0 }; static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6}; /* linear, algorithmic mapping, nonsequential */ static_codebook test4={ 3,27, NULL, 1, -533200896,1611661312,4,0, partial_quantlist1, 0 }; static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3, -3, 4,-3, 4, 4,-3, -1, 4,-3, -3,-1,-3, 4,-1,-3, -1,-1,-3, -3,-3, 4, 4,-3, 4, -1,-3, 4, -3, 4, 4, 4, 4, 4, -1, 4, 4, -3,-1, 4, 4,-1, 4, -1,-1, 4, -3,-3,-1, 4,-3,-1, -1,-3,-1, -3, 4,-1, 4, 4,-1, -1, 4,-1, -3,-1,-1, 4,-1,-1, -1,-1,-1}; /* linear, algorithmic mapping, sequential */ static_codebook test5={ 3,27, NULL, 1, -533200896,1611661312,4,1, partial_quantlist1, 0 }; static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7, -3, 1,-2, 4, 8, 5, -1, 3, 0, -3,-4,-7, 4, 3, 0, -1,-2,-5, -3,-6,-2, 4, 1, 5, -1,-4, 0, -3, 1, 5, 4, 8,12, -1, 3, 7, -3,-4, 0, 4, 3, 7, -1,-2, 2, -3,-6,-7, 4, 1, 0, -1,-4,-5, -3, 1, 0, 4, 8, 7, -1, 3, 2, -3,-4,-5, 4, 3, 2, -1,-2,-3}; void run_test(static_codebook *b,float *comp){ float *out=_book_unquantize(b,b->entries,NULL); int i; if(comp){ if(!out){ fprintf(stderr,"_book_unquantize incorrectly returned NULL\n"); exit(1); } for(i=0;i<b->entries*b->dim;i++) if(fabs(out[i]-comp[i])>.0001){ fprintf(stderr,"disagreement in unquantized and reference data:\n" "position %d, %g != %g\n",i,out[i],comp[i]); exit(1); } }else{ if(out){ fprintf(stderr,"_book_unquantize returned a value array: \n" " correct result should have been NULL\n"); exit(1); } } free(out); } int main(){ /* run the nine dequant tests, and compare to the hand-rolled results */ fprintf(stderr,"Dequant test 1... "); run_test(&test1,test1_result); fprintf(stderr,"OK\nDequant test 2... "); run_test(&test2,test2_result); fprintf(stderr,"OK\nDequant test 3... "); run_test(&test3,test3_result); fprintf(stderr,"OK\nDequant test 4... "); run_test(&test4,test4_result); fprintf(stderr,"OK\nDequant test 5... "); run_test(&test5,test5_result); fprintf(stderr,"OK\n\n"); return(0); } #endif
c55ea3e492e312ae8ac6ffc53e3ea79e8ff94ab9
5687d19cfa21bb81d1dc56067bc3f885e8c6459f
/Archived/cpplib_old_eroberts/cslib/map.h
e6fa7b832a3649df715551fa71f9e5b952ea1316
[]
no_license
zelenski/stanford-cpp-library
f6215ab14d36c3a88a1756461734b0e0a8e3ac42
982e7169513136895baaf8f82c030a278987f840
refs/heads/master
2023-08-30T11:08:16.395851
2022-09-25T01:29:23
2022-09-25T01:29:23
13,291,163
221
73
null
2023-04-29T22:25:10
2013-10-03T05:28:09
HTML
UTF-8
C
false
false
3,413
h
map.h
/* * File: map.h * ----------- * This interface defines a map abstraction that associates string-valued * keys with values. In contrast to the <code>HashMap</code> type defined * in the <code>hashmap.h</code> interface, the implementation of the * <code>Map</code> type uses a balanced binary tree, which offers * logarithmic performance and sorted iteration. * * <p>In most applications, the restriction of keys to strings is easy * to circumvent. The simplest strategy is to convert key values to * strings before inserting them into the map. A more general strategy * is to use the <code>bst.h</code> interface instead. */ #ifndef _map_h #define _map_h #include "cslib.h" #include "generic.h" #include "iterator.h" /* * Type: Map * --------- * This type is the ADT used to represent the map. */ typedef struct MapCDT *Map; /* Exported entries */ /* * Function: newMap * Usage: map = newMap(); * ---------------------- * Allocates a new map with no entries. */ Map newMap(); /* * Function: freeMap * Usage: freeMap(map); * -------------------- * Frees the storage associated with the map. */ void freeMap(Map map); /* * Function: size * Usage: n = size(map); * --------------------- * Returns the number of elements in the map. */ int sizeMap(Map map); /* * Function: isEmpty * Usage: if (isEmpty(map)) . . . * ------------------------------ * Returns <code>true</code> if the map has no entries. */ bool isEmptyMap(Map map); /* * Function: clear * Usage: clear(map); * ------------------ * Removes all entries from the map. */ void clearMap(Map map); /* * Function: clone * Usage: newmap = clone(map); * --------------------------- * Creates a copy of the map. The <code>clone</code> function copies * only the first level of the structure and does not copy the individual * elements. */ Map cloneMap(Map map); /* * Function: put * Usage: put(map, key, value); * ---------------------------- * Associates <code>key</code> with <code>value</code> in the map. * Each call to <code>put</code> supersedes any previous definition * for <code>key</code>. */ void putMap(Map map, string key, void *value); /* * Function: get * Usage: void *value = get(map, key); * ----------------------------------- * Returns the value associated with <code>key</code> in the map, * or <code>NULL</code>, if no such value exists. */ void *getMap(Map map, string key); /* * Function: containsKey * Usage: if (containsKey(map, key)) . . . * --------------------------------------- * Checks to see if the map contains the specified key. */ bool containsKeyMap(Map map, string key); /* * Function: remove * Usage: remove(map, key); * ------------------------ * Removes the key and its value from the map. */ void removeMap(Map map, string key); /* * Function: map * Usage: map(map, fn, data); * -------------------------- * Iterates through the map and calls the function <code>fn</code> on * each entry. The callback function takes the following arguments: * *<ul> * <li>The key * <li>The associated value * <li>The <code>data</code> pointer *</ul> * * The <code>data</code> pointer allows the client to pass state * information to the function <code>fn</code>, if necessary. If no such * information is required, this argument should be <code>NULL</code>. */ void mapMap(Map map, proc fn, void *data); #endif
3deb01ca796566d15034c699d77dc1301edb3bfe
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/net/irda/irnet/irnet_irda.h
3e408952a3f178ce98f36da48b400d0d8ec6a8e6
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
4,855
h
irnet_irda.h
/* * IrNET protocol module : Synchronous PPP over an IrDA socket. * * Jean II - HPL `00 - <jt@hpl.hp.com> * * This file contains all definitions and declarations necessary for the * IRDA part of the IrNET module (dealing with IrTTP, IrIAS and co). * This file is a private header, so other modules don't want to know * what's in there... */ #ifndef IRNET_IRDA_H #define IRNET_IRDA_H /***************************** INCLUDES *****************************/ /* Please add other headers in irnet.h */ #include "irnet.h" /* Module global include */ /************************ CONSTANTS & MACROS ************************/ /* * Name of the service (socket name) used by IrNET */ /* IAS object name (or part of it) */ #define IRNET_SERVICE_NAME "IrNetv1" /* IAS attribute */ #define IRNET_IAS_VALUE "IrDA:TinyTP:LsapSel" /* LMP notify name for client (only for /proc/net/irda/irlmp) */ #define IRNET_NOTIFY_NAME "IrNET socket" /* LMP notify name for server (only for /proc/net/irda/irlmp) */ #define IRNET_NOTIFY_NAME_SERV "IrNET server" /****************************** TYPES ******************************/ /* * This is the main structure where we store all the data pertaining to * the IrNET server (listen for connection requests) and the root * of the IrNET socket list */ typedef struct irnet_root { irnet_socket s; /* To pretend we are a client... */ /* Generic stuff */ int magic; /* Paranoia */ int running; /* Are we operational ? */ /* Link list of all IrNET instances opened */ hashbin_t * list; spinlock_t spinlock; /* Serialize access to the list */ /* Note : the way hashbin has been designed is absolutely not * reentrant, beware... So, we blindly protect all with spinlock */ /* Handle for the hint bit advertised in IrLMP */ void * skey; /* Server socket part */ struct ias_object * ias_obj; /* Our service name + lsap in IAS */ } irnet_root; /**************************** PROTOTYPES ****************************/ /* ----------------------- CONTROL CHANNEL ----------------------- */ static void irnet_post_event(irnet_socket *, irnet_event, __u32, __u32, char *, __u16); /* ----------------------- IRDA SUBROUTINES ----------------------- */ static inline int irnet_open_tsap(irnet_socket *); static inline __u8 irnet_ias_to_tsap(irnet_socket *, int, struct ias_value *); static inline int irnet_find_lsap_sel(irnet_socket *); static inline int irnet_connect_tsap(irnet_socket *); static inline int irnet_discover_next_daddr(irnet_socket *); static inline int irnet_discover_daddr_and_lsap_sel(irnet_socket *); static inline int irnet_dname_to_daddr(irnet_socket *); /* ------------------------ SERVER SOCKET ------------------------ */ static inline int irnet_daddr_to_dname(irnet_socket *); static inline irnet_socket * irnet_find_socket(irnet_socket *); static inline int irnet_connect_socket(irnet_socket *, irnet_socket *, struct qos_info *, __u32, __u8); static inline void irnet_disconnect_server(irnet_socket *, struct sk_buff *); static inline int irnet_setup_server(void); static inline void irnet_destroy_server(void); /* ---------------------- IRDA-TTP CALLBACKS ---------------------- */ static int irnet_data_indication(void *, /* instance */ void *, /* sap */ struct sk_buff *); static void irnet_disconnect_indication(void *, void *, LM_REASON, struct sk_buff *); static void irnet_connect_confirm(void *, void *, struct qos_info *, __u32, __u8, struct sk_buff *); static void irnet_flow_indication(void *, void *, LOCAL_FLOW); static void irnet_status_indication(void *, LINK_STATUS, LOCK_STATUS); static void irnet_connect_indication(void *, void *, struct qos_info *, __u32, __u8, struct sk_buff *); /* -------------------- IRDA-IAS/LMP CALLBACKS -------------------- */ static void irnet_getvalue_confirm(int, __u16, struct ias_value *, void *); static void irnet_discovervalue_confirm(int, __u16, struct ias_value *, void *); #ifdef DISCOVERY_EVENTS static void irnet_discovery_indication(discinfo_t *, DISCOVERY_MODE, void *); static void irnet_expiry_indication(discinfo_t *, DISCOVERY_MODE, void *); #endif /**************************** VARIABLES ****************************/ /* * The IrNET server. Listen to connection requests and co... */ static struct irnet_root irnet_server; /* Control channel stuff (note : extern) */ struct irnet_ctrl_channel irnet_events; /* The /proc/net/irda directory, defined elsewhere... */ #ifdef CONFIG_PROC_FS extern struct proc_dir_entry *proc_irda; #endif /* CONFIG_PROC_FS */ #endif /* IRNET_IRDA_H */
951537583f8913b318e063af8fa0c2a7f5361131
0fa1152e1e434ce9fe9e2db95f43f25675bf7d27
/src/drivers/distance_sensor/lightware_sf45_serial/sf45_commands.h
a54334606439ec2b8eaeef24acdb162bf286bd83
[ "BSD-3-Clause" ]
permissive
PX4/PX4-Autopilot
4cc90dccc9285ca4db7f595ac5a7547df02ca92e
3d61ab84c42ff8623bd48ff0ba74f9cf26bb402b
refs/heads/main
2023-08-30T23:58:35.398450
2022-03-26T01:29:03
2023-08-30T15:40:01
5,298,790
3,146
3,798
BSD-3-Clause
2023-09-14T17:22:04
2012-08-04T21:19:36
C++
UTF-8
C
false
false
3,221
h
sf45_commands.h
/**************************************************************************** * * Copyright (c) 2022-2023 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ /** * @file sf45_commands.h * @author Andrew Brahim * * Declarations of sf45 serial commands for the Lightware sf45/b series */ #pragma once #define SF45_MAX_PAYLOAD 256 #define SF45_CRC_FIELDS 2 enum SF_SERIAL_CMD { SF_PRODUCT_NAME = 0, SF_HARDWARE_VERSION = 1, SF_FIRMWARE_VERSION = 2, SF_SERIAL_NUMBER = 3, SF_TEXT_MESSAGE = 7, SF_USER_DATA = 9, SF_TOKEN = 10, SF_SAVE_PARAMETERS = 12, SF_RESET = 14, SF_STAGE_FIRMWARE = 16, SF_COMMIT_FIRMWARE = 17, SF_DISTANCE_OUTPUT = 27, SF_STREAM = 30, SF_DISTANCE_DATA_CM = 44, SF_DISTANCE_DATA_MM = 45, SF_LASER_FIRING = 50, SF_TEMPERATURE = 57, SF_UPDATE_RATE = 66, SF_NOISE = 74, SF_ZERO_OFFSET = 75, SF_LOST_SIGNAL_COUNTER = 76, SF_BAUD_RATE = 79, SF_I2C_ADDRESS = 80, SF_SCAN_SPEED = 85, SF_STEPPER_STATUS = 93, SF_SCAN_ON_STARTUP = 94, SF_SCAN_ENABLE = 96, SF_SCAN_POSITION = 97, SF_SCAN_LOW_ANGLE = 98, SF_HIGH_ANGLE = 99 }; // Store contents of rx'd frame struct { const uint8_t data_fields = 2; // useful for breaking crc's into byte separated fields uint16_t data_len{0}; // last message payload length (1+ bytes in payload) uint8_t data[SF45_MAX_PAYLOAD]; // payload size limited by posix serial uint8_t msg_id{0}; // latest message's message id uint8_t flags_lo{0}; // flags low byte uint8_t flags_hi{0}; // flags high byte uint16_t crc[SF45_CRC_FIELDS] = {0, 0}; uint8_t crc_lo{0}; // crc low byte uint8_t crc_hi{0}; // crc high byte } rx_field;
2737f3f998c20b2e36e3e9822e4d8c8b01772206
55540f3e86f1d5d86ef6b5d295a63518e274efe3
/components/network/ble/blestack/src/services/hog.c
cc740d5bf005f94ce0e957b83ef8d54f761cff14
[ "Apache-2.0" ]
permissive
bouffalolab/bl_iot_sdk
bc5eaf036b70f8c65dd389439062b169f8d09daa
b90664de0bd4c1897a9f1f5d9e360a9631d38b34
refs/heads/master
2023-08-31T03:38:03.369853
2023-08-16T08:50:33
2023-08-18T09:13:27
307,347,250
244
101
Apache-2.0
2023-08-28T06:29:02
2020-10-26T11:16:30
C
UTF-8
C
false
false
5,660
c
hog.c
/** @file * @brief HoG Service sample */ /* * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr/types.h> #include <stddef.h> #include <string.h> #include <sys/errno.h> #include <byteorder.h> #include <zephyr.h> #include <bluetooth.h> #include <conn.h> #include <uuid.h> #include <gatt.h> #include "hog.h" #include "log.h" enum { HIDS_REMOTE_WAKE = BIT(0), HIDS_NORMALLY_CONNECTABLE = BIT(1), }; struct hids_info { uint16_t version; /* version number of base USB HID Specification */ uint8_t code; /* country HID Device hardware is localized for. */ uint8_t flags; } __packed; struct hids_report { uint8_t id; /* report id */ uint8_t type; /* report type */ } __packed; static struct hids_info info = { .version = 0x0000, .code = 0x00, .flags = HIDS_NORMALLY_CONNECTABLE, }; enum { HIDS_INPUT = 0x01, HIDS_OUTPUT = 0x02, HIDS_FEATURE = 0x03, }; static struct hids_report input = { .id = 0x01, .type = HIDS_INPUT, }; static uint8_t simulate_input; static uint8_t ctrl_point; static uint8_t report_map[] = { 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */ 0x09, 0x02, /* Usage (Mouse) */ 0xA1, 0x01, /* Collection (Application) */ 0x09, 0x01, /* Usage (Pointer) */ 0xA1, 0x00, /* Collection (Physical) */ 0x05, 0x09, /* Usage Page (Button) */ 0x19, 0x01, /* Usage Minimum (0x01) */ 0x29, 0x03, /* Usage Maximum (0x03) */ 0x15, 0x00, /* Logical Minimum (0) */ 0x25, 0x01, /* Logical Maximum (1) */ 0x95, 0x03, /* Report Count (3) */ 0x75, 0x01, /* Report Size (1) */ 0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */ 0x95, 0x01, /* Report Count (1) */ 0x75, 0x05, /* Report Size (5) */ 0x81, 0x03, /* Input (Const,Var,Abs,No Wrap,Linear,...) */ 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */ 0x09, 0x30, /* Usage (X) */ 0x09, 0x31, /* Usage (Y) */ 0x15, 0x81, /* Logical Minimum (129) */ 0x25, 0x7F, /* Logical Maximum (127) */ 0x75, 0x08, /* Report Size (8) */ 0x95, 0x02, /* Report Count (2) */ 0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */ 0xC0, /* End Collection */ 0xC0, /* End Collection */ }; static ssize_t read_info(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data, sizeof(struct hids_info)); } static ssize_t read_report_map(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { return bt_gatt_attr_read(conn, attr, buf, len, offset, report_map, sizeof(report_map)); } static ssize_t read_report(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data, sizeof(struct hids_report)); } static void input_ccc_changed(const struct bt_gatt_attr *attr, uint16_t value) { simulate_input = (value == BT_GATT_CCC_NOTIFY) ? 1 : 0; BT_WARN("simulate_input = [%d]\r\n",simulate_input); } static ssize_t read_input_report(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); } static ssize_t write_ctrl_point(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags) { uint8_t *value = attr->user_data; if (offset + len > sizeof(ctrl_point)) { return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); } memcpy(value + offset, buf, len); return len; } /* HID Service Declaration */ static struct bt_gatt_attr attrs[]={ BT_GATT_PRIMARY_SERVICE(BT_UUID_HIDS), BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_INFO, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, read_info, NULL, &info), BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT_MAP, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, read_report_map, NULL, NULL), BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_AUTHEN, read_input_report, NULL, NULL), BT_GATT_CCC(input_ccc_changed, BT_GATT_PERM_READ_AUTHEN | BT_GATT_PERM_WRITE_AUTHEN), BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ, read_report, NULL, &input), BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_CTRL_POINT, BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_WRITE, NULL, write_ctrl_point, &ctrl_point), }; struct hids_remote_key { u8_t hid_page; u16_t hid_usage; } __packed; static struct hids_remote_key remote_kbd_map_tab[] = { {HID_PAGE_KBD, Key_a_or_A2}, {HID_PAGE_KBD, Key_b_or_B}, {HID_PAGE_KBD, Key_c_or_C}, }; int hog_notify(struct bt_conn *conn, uint16_t hid_usage,uint8_t press) { struct bt_gatt_attr *attr; struct hids_remote_key *remote_key = NULL; u8_t len = 4, data[4]; for(int i = 0; i < (sizeof(remote_kbd_map_tab)/sizeof(remote_kbd_map_tab[0])); i++){ if(remote_kbd_map_tab[i].hid_usage == hid_usage){ remote_key = &remote_kbd_map_tab[i]; break; } } if(!remote_key) return EINVAL; if(remote_key->hid_page == HID_PAGE_KBD){ attr = &attrs[BT_CHAR_BLE_HID_REPORT_ATTR_VAL_INDEX]; len = 3; } else return EINVAL; sys_put_le16(hid_usage, data); data[2] = 0; data[3] = 0; if(!press){ memset(data, 0, len); } return bt_gatt_notify(conn, attr, data, len); } struct bt_gatt_service hog_srv = BT_GATT_SERVICE(attrs); void hog_init(void) { bt_gatt_service_register(&hog_srv); }
0177b82770da16e258aff6a870c997c074f07baf
0f83867baae6c990b4b0c254ea7bb36c9a6646a5
/examples/c/testcases/test-lookahead-assign.c
ea4a77158f00ca79a481598712df0fda519f504c
[ "Apache-2.0" ]
permissive
P4ELTE/t4p4s
dc587e7567b62a5679dc7cc4c2985894684d8e6e
7cd5bacc7475892f4a1d8b22c2cf9c28e16e5781
refs/heads/master
2023-03-17T14:52:30.702080
2023-01-11T15:24:33
2023-01-11T15:24:33
62,548,413
107
55
Apache-2.0
2022-01-21T15:22:23
2016-07-04T09:14:10
C
UTF-8
C
false
false
3,054
c
test-lookahead-assign.c
// SPDX-License-Identifier: Apache-2.0 // Copyright 2018 Eotvos Lorand University, Budapest, Hungary #include "test.h" #ifdef TEST_CONST_ENTRIES #define ENABLED_BITS TEST_CONST_ENTRIES #else #define ENABLED_BITS 0xFFFFFFFF #endif fake_cmd_t t4p4s_testcase_test[][RTE_MAX_LCORE] = SINGLE_LCORE( FAST(0, 0, IN("ffffffff"), #if (ENABLED_BITS & (1 << 0)) != 0 "01" #endif #if (ENABLED_BITS & (1 << 1)) != 0 "03" #endif #if (ENABLED_BITS & (1 << 2)) != 0 "07" #endif #if (ENABLED_BITS & (1 << 3)) != 0 "0f" #endif #if (ENABLED_BITS & (1 << 4)) != 0 "1f" #endif #if (ENABLED_BITS & (1 << 5)) != 0 "3f" #endif #if (ENABLED_BITS & (1 << 6)) != 0 "7f" #endif #if (ENABLED_BITS & (1 << 7)) != 0 "ff" #endif #if (ENABLED_BITS & (1 << 8)) != 0 "01ff" #endif #if (ENABLED_BITS & (1 << 9)) != 0 "03ff" #endif #if (ENABLED_BITS & (1 << 10)) != 0 "07ff" #endif #if (ENABLED_BITS & (1 << 11)) != 0 "0fff" #endif #if (ENABLED_BITS & (1 << 12)) != 0 "1fff" #endif #if (ENABLED_BITS & (1 << 13)) != 0 "3fff" #endif #if (ENABLED_BITS & (1 << 14)) != 0 "7fff" #endif #if (ENABLED_BITS & (1 << 15)) != 0 "ffff" #endif #if (ENABLED_BITS & (1 << 16)) != 0 "0001ffff" #endif #if (ENABLED_BITS & (1 << 17)) != 0 "0003ffff" #endif #if (ENABLED_BITS & (1 << 18)) != 0 "0007ffff" #endif #if (ENABLED_BITS & (1 << 19)) != 0 "000fffff" #endif #if (ENABLED_BITS & (1 << 20)) != 0 "001fffff" #endif #if (ENABLED_BITS & (1 << 21)) != 0 "003fffff" #endif #if (ENABLED_BITS & (1 << 22)) != 0 "007fffff" #endif #if (ENABLED_BITS & (1 << 23)) != 0 "00ffffff" #endif #if (ENABLED_BITS & (1 << 24)) != 0 "01ffffff" #endif #if (ENABLED_BITS & (1 << 25)) != 0 "03ffffff" #endif #if (ENABLED_BITS & (1 << 26)) != 0 "07ffffff" #endif #if (ENABLED_BITS & (1 << 27)) != 0 "0fffffff" #endif #if (ENABLED_BITS & (1 << 28)) != 0 "1fffffff" #endif #if (ENABLED_BITS & (1 << 29)) != 0 "3fffffff" #endif #if (ENABLED_BITS & (1 << 30)) != 0 "7fffffff" #endif #if (ENABLED_BITS & (1 << 31)) != 0 "ffffffff" #endif "") ); testcase_t t4p4s_test_suite[MAX_TESTCASES] = { { "test", &t4p4s_testcase_test, "v1model" }, { "psa", &t4p4s_testcase_test, "psa" }, TEST_SUITE_END, };
6da85107d008823a45519e0abd02307d02539a2a
4b15f318ba3332ee946cb0b2838c93e7935b9b89
/inc/ocf_err.h
a8d0563de57556d43e629d2cd2762e5fdc44e8f9
[ "BSD-3-Clause" ]
permissive
Open-CAS/ocf
c4f8a5c9c1b254a905fda75be2c19bd7c8ebd450
016d7a8ee2822d672c308264e79bae4081e7930e
refs/heads/master
2023-05-28T08:40:51.328181
2023-05-11T08:11:57
2023-05-11T08:11:57
152,160,836
168
94
BSD-3-Clause
2023-09-14T08:01:50
2018-10-08T23:46:10
C
UTF-8
C
false
false
3,405
h
ocf_err.h
/* * Copyright(c) 2012-2021 Intel Corporation * SPDX-License-Identifier: BSD-3-Clause */ #ifndef __OCF_ERR_H__ #define __OCF_ERR_H__ /** * @file * @brief OCF error codes definitions */ /** * @brief OCF error enumerator */ typedef enum { OCF_ERR_MIN = 1000000, /** Invalid input parameter value */ OCF_ERR_INVAL = OCF_ERR_MIN, /** Try again */ OCF_ERR_AGAIN, /** Operation interrupted */ OCF_ERR_INTR, /** Operation not supported */ OCF_ERR_NOT_SUPP, /** Out of memory */ OCF_ERR_NO_MEM, /** Lock not acquired */ OCF_ERR_NO_LOCK, /** Metadata version mismatch */ OCF_ERR_METADATA_VER, /** No metadata found on device */ OCF_ERR_NO_METADATA, /** Cache metadata found on device */ OCF_ERR_METADATA_FOUND, /** Metadata on the device doesn't match with metadata in DRAM */ OCF_ERR_SUPERBLOCK_MISMATCH, /** Metadata checksum is not correct. Metadata is damaged */ OCF_ERR_CRC_MISMATCH, /** Invalid volume type */ OCF_ERR_INVAL_VOLUME_TYPE, /** Unknown error occurred */ OCF_ERR_UNKNOWN, /** To many caches */ OCF_ERR_TOO_MANY_CACHES, /** Not enough RAM to start cache */ OCF_ERR_NO_FREE_RAM, /** Start cache failure */ OCF_ERR_START_CACHE_FAIL, /** Cache ID/name does not exist */ OCF_ERR_CACHE_NOT_EXIST, /** Core ID/name does not exist */ OCF_ERR_CORE_NOT_EXIST, /** Cache ID/name already exists */ OCF_ERR_CACHE_EXIST, /** Core ID/name already exists */ OCF_ERR_CORE_EXIST, /** Too many core devices in cache */ OCF_ERR_TOO_MANY_CORES, /** Core device not available */ OCF_ERR_CORE_NOT_AVAIL, /** Cannot open device exclusively*/ OCF_ERR_NOT_OPEN_EXC, /** Cache device not available */ OCF_ERR_CACHE_NOT_AVAIL, /** IO Class does not exist */ OCF_ERR_IO_CLASS_NOT_EXIST, /** IO Error */ OCF_ERR_IO, /** Error while writing to cache device */ OCF_ERR_WRITE_CACHE, /** Error while writing to core device */ OCF_ERR_WRITE_CORE, /*!< Dirty shutdown */ OCF_ERR_DIRTY_SHUTDOWN, /** Cache contains dirty data */ OCF_ERR_DIRTY_EXISTS, /** Flushing of core interrupted */ OCF_ERR_FLUSHING_INTERRUPTED, /** Another flushing operation in progress */ OCF_ERR_FLUSH_IN_PROGRESS, /** Adding core to core pool failed */ OCF_ERR_CANNOT_ADD_CORE_TO_POOL, /** Cache is in incomplete state */ OCF_ERR_CACHE_IN_INCOMPLETE_STATE, /** Core device is in inactive state */ OCF_ERR_CORE_IN_INACTIVE_STATE, /** Invalid cache mode */ OCF_ERR_INVALID_CACHE_MODE, /** Invalid cache line size */ OCF_ERR_INVALID_CACHE_LINE_SIZE, /** Invalid cache name loaded */ OCF_ERR_CACHE_NAME_MISMATCH, /** Device does not meet requirements */ OCF_ERR_INVAL_CACHE_DEV, /** Core with the uuid already exists */ OCF_ERR_CORE_UUID_EXISTS, /** Cache initialized with wrong cache line size */ OCF_ERR_CACHE_LINE_SIZE_MISMATCH, /** Invalid operation for cache in standby state. */ OCF_ERR_CACHE_STANDBY, /** Size of core volume doesn't match the size stored in cache metadata */ OCF_ERR_CORE_SIZE_MISMATCH, /** Operation invalid with cache drive atatched in failover standby */ OCF_ERR_STANDBY_ATTACHED, /** Failed to remove the core */ OCF_ERR_CORE_NOT_REMOVED, /** Operation only allowed in standby mode **/ OCF_ERR_CACHE_NOT_STANDBY, /** Operation not allowed when cleaner is disabled **/ OCF_ERR_CLEANER_DISABLED, OCF_ERR_MAX = OCF_ERR_CLEANER_DISABLED, } ocf_error_t; #endif /* __OCF_ERR_H__ */
20072a3b11991a93577718899ea9a1eb1e4ecad1
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/drivers/scsi/isci/remote_node_context.h
c7ee81d011253487055b982942dff0620c635a17
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
8,885
h
remote_node_context.h
/* * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY * * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * The full GNU General Public License is included in this distribution * in the file called LICENSE.GPL. * * BSD LICENSE * * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ #define _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ /** * This file contains the structures, constants, and prototypes associated with * the remote node context in the silicon. It exists to model and manage * the remote node context in the silicon. * * */ #include "isci.h" /** * * * This constant represents an invalid remote device id, it is used to program * the STPDARNI register so the driver knows when it has received a SIGNATURE * FIS from the SCU. */ #define SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX 0x0FFF enum sci_remote_node_suspension_reasons { SCI_HW_SUSPEND, SCI_SW_SUSPEND_NORMAL, SCI_SW_SUSPEND_LINKHANG_DETECT }; #define SCI_SOFTWARE_SUSPEND_CMD SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX #define SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT SCU_EVENT_TL_RNC_SUSPEND_TX_RX struct isci_request; struct isci_remote_device; struct sci_remote_node_context; typedef void (*scics_sds_remote_node_context_callback)(void *); /** * enum sci_remote_node_context_states * @SCI_RNC_INITIAL initial state for a remote node context. On a resume * request the remote node context will transition to the posting state. * * @SCI_RNC_POSTING: transition state that posts the RNi to the hardware. Once * the RNC is posted the remote node context will be made ready. * * @SCI_RNC_INVALIDATING: transition state that will post an RNC invalidate to * the hardware. Once the invalidate is complete the remote node context will * transition to the posting state. * * @SCI_RNC_RESUMING: transition state that will post an RNC resume to the * hardare. Once the event notification of resume complete is received the * remote node context will transition to the ready state. * * @SCI_RNC_READY: state that the remote node context must be in to accept io * request operations. * * @SCI_RNC_TX_SUSPENDED: state that the remote node context transitions to when * it gets a TX suspend notification from the hardware. * * @SCI_RNC_TX_RX_SUSPENDED: state that the remote node context transitions to * when it gets a TX RX suspend notification from the hardware. * * @SCI_RNC_AWAIT_SUSPENSION: wait state for the remote node context that waits * for a suspend notification from the hardware. This state is entered when * either there is a request to supend the remote node context or when there is * a TC completion where the remote node will be suspended by the hardware. */ #define RNC_STATES {\ C(RNC_INITIAL),\ C(RNC_POSTING),\ C(RNC_INVALIDATING),\ C(RNC_RESUMING),\ C(RNC_READY),\ C(RNC_TX_SUSPENDED),\ C(RNC_TX_RX_SUSPENDED),\ C(RNC_AWAIT_SUSPENSION),\ } #undef C #define C(a) SCI_##a enum scis_sds_remote_node_context_states RNC_STATES; #undef C const char *rnc_state_name(enum scis_sds_remote_node_context_states state); /** * * * This enumeration is used to define the end destination state for the remote * node context. */ enum sci_remote_node_context_destination_state { RNC_DEST_UNSPECIFIED, RNC_DEST_READY, RNC_DEST_FINAL, RNC_DEST_SUSPENDED, /* Set when suspend during post/invalidate */ RNC_DEST_SUSPENDED_RESUME /* Set when a resume was done during posting * or invalidating and already suspending. */ }; /** * struct sci_remote_node_context - This structure contains the data * associated with the remote node context object. The remote node context * (RNC) object models the the remote device information necessary to manage * the silicon RNC. */ struct sci_remote_node_context { /** * This field indicates the remote node index (RNI) associated with * this RNC. */ u16 remote_node_index; /** * This field is the recored suspension type of the remote node * context suspension. */ u32 suspend_type; enum sci_remote_node_suspension_reasons suspend_reason; u32 suspend_count; /** * This field is true if the remote node context is resuming from its current * state. This can cause an automatic resume on receiving a suspension * notification. */ enum sci_remote_node_context_destination_state destination_state; /** * This field contains the callback function that the user requested to be * called when the requested state transition is complete. */ scics_sds_remote_node_context_callback user_callback; /** * This field contains the parameter that is called when the user requested * state transition is completed. */ void *user_cookie; /** * This field contains the data for the object's state machine. */ struct sci_base_state_machine sm; }; void sci_remote_node_context_construct(struct sci_remote_node_context *rnc, u16 remote_node_index); bool sci_remote_node_context_is_ready( struct sci_remote_node_context *sci_rnc); bool sci_remote_node_context_is_suspended(struct sci_remote_node_context *sci_rnc); enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc, u32 event_code); enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc, scics_sds_remote_node_context_callback callback, void *callback_parameter); enum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc, enum sci_remote_node_suspension_reasons reason, u32 suspension_code); enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc, scics_sds_remote_node_context_callback cb_fn, void *cb_p); enum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc, struct isci_request *ireq, scics_sds_remote_node_context_callback cb_fn, void *cb_p); enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc, struct isci_request *ireq); int sci_remote_node_context_is_safe_to_abort( struct sci_remote_node_context *sci_rnc); static inline bool sci_remote_node_context_is_being_destroyed( struct sci_remote_node_context *sci_rnc) { return (sci_rnc->destination_state == RNC_DEST_FINAL) || ((sci_rnc->sm.current_state_id == SCI_RNC_INITIAL) && (sci_rnc->destination_state == RNC_DEST_UNSPECIFIED)); } #endif /* _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ */
74856cbf08b0b2df2b0b3fd5ba049e9a4dd18d9c
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/libavformat/icodec.c
85dab3bca0a7a7160d6fe4846b73758adade81ea
[ "BSD-3-Clause", "LGPL-2.1-or-later", "BSD-2-Clause", "LGPL-2.1-only", "LGPL-3.0-only", "LGPL-2.0-or-later", "GPL-1.0-or-later", "GPL-2.0-only", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "MIT", "GPL-2.0-or-later", "Apache-2.0", "GPL-3.0-only...
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
6,725
c
icodec.c
/* * Microsoft Windows ICO demuxer * Copyright (c) 2011 Peter Ross (pross@xvid.org) * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Microsoft Windows ICO demuxer */ #include "libavutil/intreadwrite.h" #include "libavcodec/bytestream.h" #include "libavcodec/png.h" #include "avformat.h" #include "internal.h" typedef struct { int offset; int size; int nb_pal; } IcoImage; typedef struct { int current_image; int nb_images; IcoImage * images; } IcoDemuxContext; static int probe(const AVProbeData *p) { unsigned i, frames, checked = 0; if (p->buf_size < 22 || AV_RL16(p->buf) || AV_RL16(p->buf + 2) != 1) return 0; frames = AV_RL16(p->buf + 4); if (!frames) return 0; for (i = 0; i < frames && i * 16 + 22 <= p->buf_size; i++) { unsigned offset; if (AV_RL16(p->buf + 10 + i * 16) & ~1) return FFMIN(i, AVPROBE_SCORE_MAX / 4); if (p->buf[13 + i * 16]) return FFMIN(i, AVPROBE_SCORE_MAX / 4); if (AV_RL32(p->buf + 14 + i * 16) < 40) return FFMIN(i, AVPROBE_SCORE_MAX / 4); offset = AV_RL32(p->buf + 18 + i * 16); if (offset < 22) return FFMIN(i, AVPROBE_SCORE_MAX / 4); if (offset > p->buf_size - 8) continue; if (p->buf[offset] != 40 && AV_RB64(p->buf + offset) != PNGSIG) return FFMIN(i, AVPROBE_SCORE_MAX / 4); checked++; } if (checked < frames) return AVPROBE_SCORE_MAX / 4 + FFMIN(checked, 1); return AVPROBE_SCORE_MAX / 2 + 1; } static int read_header(AVFormatContext *s) { IcoDemuxContext *ico = s->priv_data; AVIOContext *pb = s->pb; int i, codec; avio_skip(pb, 4); ico->nb_images = avio_rl16(pb); if (!ico->nb_images) return AVERROR_INVALIDDATA; ico->images = av_malloc_array(ico->nb_images, sizeof(IcoImage)); if (!ico->images) return AVERROR(ENOMEM); for (i = 0; i < ico->nb_images; i++) { AVStream *st; int tmp; if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0) return AVERROR_INVALIDDATA; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->width = avio_r8(pb); st->codecpar->height = avio_r8(pb); ico->images[i].nb_pal = avio_r8(pb); if (ico->images[i].nb_pal == 255) ico->images[i].nb_pal = 0; avio_skip(pb, 5); ico->images[i].size = avio_rl32(pb); if (ico->images[i].size <= 0) { av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size); return AVERROR_INVALIDDATA; } ico->images[i].offset = avio_rl32(pb); if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0) return AVERROR_INVALIDDATA; codec = avio_rl32(pb); switch (codec) { case MKTAG(0x89, 'P', 'N', 'G'): st->codecpar->codec_id = AV_CODEC_ID_PNG; st->codecpar->width = 0; st->codecpar->height = 0; break; case 40: if (ico->images[i].size < 40) return AVERROR_INVALIDDATA; st->codecpar->codec_id = AV_CODEC_ID_BMP; tmp = avio_rl32(pb); if (tmp) st->codecpar->width = tmp; tmp = avio_rl32(pb); if (tmp) st->codecpar->height = tmp / 2; break; default: avpriv_request_sample(s, "codec %d", codec); return AVERROR_INVALIDDATA; } } return 0; } static int read_packet(AVFormatContext *s, AVPacket *pkt) { IcoDemuxContext *ico = s->priv_data; IcoImage *image; AVIOContext *pb = s->pb; AVStream *st; int ret; if (ico->current_image >= ico->nb_images) return AVERROR_EOF; st = s->streams[0]; image = &ico->images[ico->current_image]; if ((ret = avio_seek(pb, image->offset, SEEK_SET)) < 0) return ret; if (s->streams[ico->current_image]->codecpar->codec_id == AV_CODEC_ID_PNG) { if ((ret = av_get_packet(pb, pkt, image->size)) < 0) return ret; } else { uint8_t *buf; if ((ret = av_new_packet(pkt, 14 + image->size)) < 0) return ret; buf = pkt->data; /* add BMP header */ bytestream_put_byte(&buf, 'B'); bytestream_put_byte(&buf, 'M'); bytestream_put_le32(&buf, pkt->size); bytestream_put_le16(&buf, 0); bytestream_put_le16(&buf, 0); bytestream_put_le32(&buf, 0); if ((ret = avio_read(pb, buf, image->size)) != image->size) { return ret < 0 ? ret : AVERROR_INVALIDDATA; } st->codecpar->bits_per_coded_sample = AV_RL16(buf + 14); if (AV_RL32(buf + 32)) image->nb_pal = AV_RL32(buf + 32); if (st->codecpar->bits_per_coded_sample <= 8 && !image->nb_pal) { image->nb_pal = 1 << st->codecpar->bits_per_coded_sample; AV_WL32(buf + 32, image->nb_pal); } if (image->nb_pal > INT_MAX / 4 - 14 - 40) return AVERROR_INVALIDDATA; AV_WL32(buf - 4, 14 + 40 + image->nb_pal * 4); AV_WL32(buf + 8, AV_RL32(buf + 8) / 2); } pkt->stream_index = ico->current_image++; pkt->flags |= AV_PKT_FLAG_KEY; return 0; } static int ico_read_close(AVFormatContext * s) { IcoDemuxContext *ico = s->priv_data; av_freep(&ico->images); return 0; } const AVInputFormat ff_ico_demuxer = { .name = "ico", .long_name = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"), .priv_data_size = sizeof(IcoDemuxContext), .flags_internal = FF_FMT_INIT_CLEANUP, .read_probe = probe, .read_header = read_header, .read_packet = read_packet, .read_close = ico_read_close, .flags = AVFMT_NOTIMESTAMPS, };
9deb4f44399b50ece9912a529b79bfd0397c5547
47677ea94c8e2fd9fe0524e2cb977970ada44341
/src/mat.c
0efd4cac70f6c06cff5bb435a47d455966b6e034
[ "MIT", "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
mkeeter/erizo
13b3da95c5b8124e5e94d18e673a3688ff1572f4
4e5a78fc87cde21f945579e6fbfae69b5f86734b
refs/heads/master
2023-04-15T21:21:47.158447
2021-07-30T00:17:50
2021-07-30T00:17:50
173,751,484
121
13
Apache-2.0
2023-04-12T02:24:40
2019-03-04T13:37:16
C
UTF-8
C
false
false
5,253
c
mat.c
#include "platform.h" #include "mat.h" #include "log.h" mat4_t mat4_identity() { mat4_t out; memset(&out, 0, sizeof(float) * 4 * 4); for (unsigned i=0; i < 4; ++i) { out.m[i][i] = 1.0f; } return out; } mat4_t mat4_translation(const vec3_t d) { mat4_t out = mat4_identity(); for (unsigned i=0; i < 3; ++i) { out.m[3][i] = -d.v[i]; } return out; } mat4_t mat4_scaling(const float s) { mat4_t out = mat4_identity(); for (unsigned i=0; i < 3; ++i) { out.m[i][i] = s; } return out; } mat4_t mat4_mul(const mat4_t a, const mat4_t b) { mat4_t out; for (unsigned i=0; i < 4; ++i) { for (unsigned j=0; j < 4; ++j) { out.m[i][j] = 0.0f; for (unsigned k=0; k < 4; ++k) { out.m[i][j] += a.m[i][k] * b.m[k][j]; } } } return out; } vec3_t mat4_apply(const mat4_t m, const vec3_t v) { float w[4] = {v.v[0], v.v[1], v.v[2], 1.0f}; float o[4] = {0.0f}; for (unsigned i=0; i < 4; ++i) { for (unsigned j=0; j < 4; ++j) { o[i] += m.m[j][i] * w[j]; } } vec3_t out; for (unsigned k=0; k < 3; ++k) { out.v[k] = o[k] / o[3]; } return out; } mat4_t mat4_inv(const mat4_t in) { const float a00 = in.m[0][0]; const float a01 = in.m[0][1]; const float a02 = in.m[0][2]; const float a03 = in.m[0][3]; const float a10 = in.m[1][0]; const float a11 = in.m[1][1]; const float a12 = in.m[1][2]; const float a13 = in.m[1][3]; const float a20 = in.m[2][0]; const float a21 = in.m[2][1]; const float a22 = in.m[2][2]; const float a23 = in.m[2][3]; const float a30 = in.m[3][0]; const float a31 = in.m[3][1]; const float a32 = in.m[3][2]; const float a33 = in.m[3][3]; const float det = a00*a11*a22*a33 + a00*a12*a23*a31 + a00*a13*a21*a32 + a01*a10*a23*a32 + a01*a12*a20*a33 + a01*a13*a22*a30 + a02*a10*a21*a33 + a02*a11*a23*a30 + a02*a13*a20*a31 + a03*a10*a22*a31 + a03*a11*a20*a32 + a03*a12*a21*a30 - a00*a11*a23*a32 - a00*a12*a21*a33 - a00*a13*a22*a31 - a01*a10*a22*a33 - a01*a12*a23*a30 - a01*a13*a20*a32 - a02*a10*a23*a31 - a02*a11*a20*a33 - a02*a13*a21*a30 - a03*a10*a21*a32 - a03*a11*a22*a30 - a03*a12*a20*a31; if (det == 0.0f) { log_warn("Tried to invert noninvertible matrix"); return mat4_identity(); } mat4_t out; out.m[0][0] = a11*a22*a33 + a12*a23*a31 + a13*a21*a32 - a11*a23*a32 - a12*a21*a33 - a13*a22*a31; out.m[0][1] = a01*a23*a32 + a02*a21*a33 + a03*a22*a31 - a01*a22*a33 - a02*a23*a31 - a03*a21*a32; out.m[0][2] = a01*a12*a33 + a02*a13*a31 + a03*a11*a32 - a01*a13*a32 - a02*a11*a33 - a03*a12*a31; out.m[0][3] = a01*a13*a22 + a02*a11*a23 + a03*a12*a21 - a01*a12*a23 - a02*a13*a21 - a03*a11*a22; out.m[1][0] = a10*a23*a32 + a12*a20*a33 + a13*a22*a30 - a10*a22*a33 - a12*a23*a30 - a13*a20*a32; out.m[1][1] = a00*a22*a33 + a02*a23*a30 + a03*a20*a32 - a00*a23*a32 - a02*a20*a33 - a03*a22*a30; out.m[1][2] = a00*a13*a32 + a02*a10*a33 + a03*a12*a30 - a00*a12*a33 - a02*a13*a30 - a03*a10*a32; out.m[1][3] = a00*a12*a23 + a02*a13*a20 + a03*a10*a22 - a00*a13*a22 - a02*a10*a23 - a03*a12*a20; out.m[2][0] = a10*a21*a33 + a11*a23*a30 + a13*a20*a31 - a10*a23*a31 - a11*a20*a33 - a13*a21*a30; out.m[2][1] = a00*a23*a31 + a01*a20*a33 + a03*a21*a30 - a00*a21*a33 - a01*a23*a30 - a03*a20*a31; out.m[2][2] = a00*a11*a33 + a01*a13*a30 + a03*a10*a31 - a00*a13*a31 - a01*a10*a33 - a03*a11*a30; out.m[2][3] = a00*a13*a21 + a01*a10*a23 + a03*a11*a20 - a00*a11*a23 - a01*a13*a20 - a03*a10*a21; out.m[3][0] = a10*a22*a31 + a11*a20*a32 + a12*a21*a30 - a10*a21*a32 - a11*a22*a30 - a12*a20*a31; out.m[3][1] = a00*a21*a32 + a01*a22*a30 + a02*a20*a31 - a00*a22*a31 - a01*a20*a32 - a02*a21*a30; out.m[3][2] = a00*a12*a31 + a01*a10*a32 + a02*a11*a30 - a00*a11*a32 - a01*a12*a30 - a02*a10*a31; out.m[3][3] = a00*a11*a22 + a01*a12*a20 + a02*a10*a21 - a00*a12*a21 - a01*a10*a22 - a02*a11*a20; for (unsigned i=0; i < 4; ++i) { for (unsigned j=0; j < 4; ++j) { out.m[i][j] /= det; } } return out; } float vec3_length(const vec3_t v) { float length = 0.0f; for (unsigned i=0; i < 3; ++i) { length += v.v[i] * v.v[i]; } return sqrtf(length); } vec3_t vec3_normalized(const vec3_t v) { const float length = vec3_length(v); vec3_t out; for (unsigned i=0; i < 3; ++i) { out.v[i] = v.v[i] / length; } return out; } vec3_t vec3_cross(const vec3_t a, const vec3_t b) { return (vec3_t){{ a.v[1] * b.v[2] - a.v[2] * b.v[1], a.v[2] * b.v[0] - a.v[0] * b.v[2], a.v[0] * b.v[1] - a.v[1] * b.v[0]}}; } vec3_t vec3_center(const vec3_t a, const vec3_t b) { vec3_t out; for (unsigned i=0; i < 3; ++i) { out.v[i] = (a.v[i] + b.v[i]) / 2.0f; } return out; }
c70289e0f3aa1141aa2831fbd087e8e12d25dee6
9ceacf33fd96913cac7ef15492c126d96cae6911
/usr.sbin/smtpd/mail.mda.c
d9441a35e00d2d5020c922f6a10847b9d505a8c1
[]
no_license
openbsd/src
ab97ef834fd2d5a7f6729814665e9782b586c130
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
refs/heads/master
2023-09-02T18:54:56.624627
2023-09-02T15:16:12
2023-09-02T15:16:12
66,966,208
3,394
1,235
null
2023-08-08T02:42:25
2016-08-30T18:18:25
C
UTF-8
C
false
false
1,610
c
mail.mda.c
/* * Copyright (c) 2017 Gilles Chehade <gilles@poolp.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/wait.h> #include <err.h> #include <errno.h> #include <stdlib.h> #include <string.h> #include <sysexits.h> #include <unistd.h> int main(int argc, char *argv[]) { int ch; int ret; if (! geteuid()) errx(1, "mail.mda: may not be executed as root"); while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { default: break; } } argc -= optind; argv += optind; if (argc == 0) errx(1, "mail.mda: command required"); if (argc > 1) errx(1, "mail.mda: only one command is supported"); /* could not obtain a shell or could not obtain wait status, * tempfail */ if ((ret = system(argv[0])) == -1) errx(EX_TEMPFAIL, "%s", strerror(errno)); /* not exited properly but we have no details, * tempfail */ if (! WIFEXITED(ret)) exit(EX_TEMPFAIL); exit(WEXITSTATUS(ret)); }
a03ede1c141b30e76f64be2a1154d9c6b5ad58c8
802f0c1dd855693f709da4024b50d6d4938c13ff
/examples/c/crane_model/impl_ode_jac_x_xdot_u.c
62d48b55cd18872650242760e61134e53c593486
[ "BSD-2-Clause" ]
permissive
acados/acados
9cd480da3462725506f06199838e3cdae007d0c8
64166a37859108ab74ce6bf7408501f9bd4a89da
refs/heads/master
2023-08-16T13:03:44.298740
2023-08-15T13:07:48
2023-08-15T13:07:48
55,497,573
558
213
NOASSERTION
2023-09-01T09:01:33
2016-04-05T10:06:48
C
UTF-8
C
false
false
6,361
c
impl_ode_jac_x_xdot_u.c
/* This file was automatically generated by CasADi. The CasADi copyright holders make no ownership claim of its contents. */ #ifdef __cplusplus extern "C" { #endif /* How to prefix internal symbols */ #ifdef CODEGEN_PREFIX #define NAMESPACE_CONCAT(NS, ID) _NAMESPACE_CONCAT(NS, ID) #define _NAMESPACE_CONCAT(NS, ID) NS ## ID #define CASADI_PREFIX(ID) NAMESPACE_CONCAT(CODEGEN_PREFIX, ID) #else #define CASADI_PREFIX(ID) impl_ode_jac_x_xdot_u_ ## ID #endif #include <math.h> #ifndef casadi_real #define casadi_real double #endif #ifndef casadi_int #define casadi_int int #endif /* Add prefix to internal symbols */ #define casadi_f0 CASADI_PREFIX(f0) #define casadi_s0 CASADI_PREFIX(s0) #define casadi_s1 CASADI_PREFIX(s1) #define casadi_s2 CASADI_PREFIX(s2) #define casadi_sq CASADI_PREFIX(sq) /* Symbol visibility in DLLs */ #ifndef CASADI_SYMBOL_EXPORT #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) #if defined(STATIC_LINKED) #define CASADI_SYMBOL_EXPORT #else #define CASADI_SYMBOL_EXPORT __declspec(dllexport) #endif #elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) #define CASADI_SYMBOL_EXPORT __attribute__ ((visibility ("default"))) #else #define CASADI_SYMBOL_EXPORT #endif #endif static const casadi_int casadi_s0[8] = {4, 1, 0, 4, 0, 1, 2, 3}; static const casadi_int casadi_s1[5] = {1, 1, 0, 1, 0}; static const casadi_int casadi_s2[23] = {4, 4, 0, 4, 8, 12, 16, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3}; casadi_real casadi_sq(casadi_real x) { return x*x;} /* casadi_impl_ode_jac_x_xdot_u:(i0[4],i1[4],i2)->(o0[4x4],o1[4x4],o2[4]) */ static int casadi_f0(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, void* mem) { casadi_real a0, a1, a10, a11, a12, a13, a14, a15, a16, a2, a3, a4, a5, a6, a7, a8, a9; a0=0.; if (res[0]!=0) res[0][0]=a0; if (res[0]!=0) res[0][1]=a0; if (res[0]!=0) res[0][2]=a0; if (res[0]!=0) res[0][3]=a0; if (res[0]!=0) res[0][4]=a0; if (res[0]!=0) res[0][5]=a0; a1=arg[0] ? arg[0][3] : 0; a2=casadi_sq(a1); a3=-8.0000000000000016e-02; a4=arg[0] ? arg[0][1] : 0; a5=cos(a4); a5=(a3*a5); a5=(a2*a5); a6=9.8100000000000009e-01; a7=cos(a4); a7=(a6*a7); a8=cos(a4); a8=(a7*a8); a9=sin(a4); a10=sin(a4); a10=(a6*a10); a10=(a9*a10); a8=(a8-a10); a5=(a5+a8); a8=1.1000000000000001e+00; a10=1.0000000000000001e-01; a11=cos(a4); a12=casadi_sq(a11); a12=(a10*a12); a12=(a8-a12); a5=(a5/a12); a13=sin(a4); a13=(a3*a13); a2=(a13*a2); a14=arg[2] ? arg[2][0] : 0; a2=(a2+a14); a7=(a7*a9); a2=(a2+a7); a2=(a2/a12); a2=(a2/a12); a11=(a11+a11); a7=sin(a4); a11=(a11*a7); a11=(a10*a11); a2=(a2*a11); a5=(a5-a2); a5=(-a5); if (res[0]!=0) res[0][6]=a5; a5=casadi_sq(a1); a2=cos(a4); a2=(a3*a2); a11=cos(a4); a11=(a2*a11); a7=sin(a4); a9=sin(a4); a3=(a3*a9); a3=(a7*a3); a11=(a11-a3); a11=(a5*a11); a3=sin(a4); a3=(a14*a3); a11=(a11-a3); a3=cos(a4); a3=(a6*a3); a11=(a11+a3); a3=9.8100000000000005e+00; a9=cos(a4); a9=(a3*a9); a11=(a11+a9); a9=8.0000000000000004e-01; a15=cos(a4); a16=casadi_sq(a15); a16=(a10*a16); a8=(a8-a16); a8=(a9*a8); a11=(a11/a8); a2=(a2*a7); a5=(a2*a5); a7=cos(a4); a14=(a14*a7); a5=(a5+a14); a14=sin(a4); a6=(a6*a14); a5=(a5+a6); a6=sin(a4); a3=(a3*a6); a5=(a5+a3); a5=(a5/a8); a5=(a5/a8); a15=(a15+a15); a4=sin(a4); a15=(a15*a4); a10=(a10*a15); a9=(a9*a10); a5=(a5*a9); a11=(a11-a5); a11=(-a11); if (res[0]!=0) res[0][7]=a11; a11=-1.; if (res[0]!=0) res[0][8]=a11; if (res[0]!=0) res[0][9]=a0; if (res[0]!=0) res[0][10]=a0; if (res[0]!=0) res[0][11]=a0; if (res[0]!=0) res[0][12]=a0; if (res[0]!=0) res[0][13]=a11; a11=(a1+a1); a13=(a13*a11); a13=(a13/a12); a13=(-a13); if (res[0]!=0) res[0][14]=a13; a1=(a1+a1); a2=(a2*a1); a2=(a2/a8); a2=(-a2); if (res[0]!=0) res[0][15]=a2; a2=1.; if (res[1]!=0) res[1][0]=a2; if (res[1]!=0) res[1][1]=a0; if (res[1]!=0) res[1][2]=a0; if (res[1]!=0) res[1][3]=a0; if (res[1]!=0) res[1][4]=a0; if (res[1]!=0) res[1][5]=a2; if (res[1]!=0) res[1][6]=a0; if (res[1]!=0) res[1][7]=a0; if (res[1]!=0) res[1][8]=a0; if (res[1]!=0) res[1][9]=a0; if (res[1]!=0) res[1][10]=a2; if (res[1]!=0) res[1][11]=a0; if (res[1]!=0) res[1][12]=a0; if (res[1]!=0) res[1][13]=a0; if (res[1]!=0) res[1][14]=a0; if (res[1]!=0) res[1][15]=a2; if (res[2]!=0) res[2][0]=a0; if (res[2]!=0) res[2][1]=a0; a12=(1./a12); a12=(-a12); if (res[2]!=0) res[2][2]=a12; a7=(a7/a8); a7=(-a7); if (res[2]!=0) res[2][3]=a7; return 0; } CASADI_SYMBOL_EXPORT int casadi_impl_ode_jac_x_xdot_u(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, void* mem){ return casadi_f0(arg, res, iw, w, mem); } CASADI_SYMBOL_EXPORT void casadi_impl_ode_jac_x_xdot_u_incref(void) { } CASADI_SYMBOL_EXPORT void casadi_impl_ode_jac_x_xdot_u_decref(void) { } CASADI_SYMBOL_EXPORT casadi_int casadi_impl_ode_jac_x_xdot_u_n_in(void) { return 3;} CASADI_SYMBOL_EXPORT casadi_int casadi_impl_ode_jac_x_xdot_u_n_out(void) { return 3;} CASADI_SYMBOL_EXPORT const char* casadi_impl_ode_jac_x_xdot_u_name_in(casadi_int i){ switch (i) { case 0: return "i0"; case 1: return "i1"; case 2: return "i2"; default: return 0; } } CASADI_SYMBOL_EXPORT const char* casadi_impl_ode_jac_x_xdot_u_name_out(casadi_int i){ switch (i) { case 0: return "o0"; case 1: return "o1"; case 2: return "o2"; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* casadi_impl_ode_jac_x_xdot_u_sparsity_in(casadi_int i) { switch (i) { case 0: return casadi_s0; case 1: return casadi_s0; case 2: return casadi_s1; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* casadi_impl_ode_jac_x_xdot_u_sparsity_out(casadi_int i) { switch (i) { case 0: return casadi_s2; case 1: return casadi_s2; case 2: return casadi_s0; default: return 0; } } CASADI_SYMBOL_EXPORT int casadi_impl_ode_jac_x_xdot_u_work(casadi_int *sz_arg, casadi_int* sz_res, casadi_int *sz_iw, casadi_int *sz_w) { if (sz_arg) *sz_arg = 3; if (sz_res) *sz_res = 3; if (sz_iw) *sz_iw = 0; if (sz_w) *sz_w = 0; return 0; } #ifdef __cplusplus } /* extern "C" */ #endif
add9e9fe9b03996bef1cfce58eb3077d74ca34cf
961deb12b1050a6883ce6c9427836b908ca91875
/aosp/libavb1.1/src/avb/c/avb_crypto.c
a99ff80d659b8792c6538907c07b9f77374dbc38
[ "Apache-2.0" ]
permissive
cfig/Android_boot_image_editor
04ff01545ff7ee4df2c02c529280e5362496abf0
82ff5215b7eb4bb6198ca024267c454f1e7958da
refs/heads/master
2023-09-01T13:32:20.862861
2023-07-14T14:52:53
2023-07-14T15:41:55
56,238,465
834
197
Apache-2.0
2022-07-29T00:19:36
2016-04-14T13:12:18
C
UTF-8
C
false
false
25,667
c
avb_crypto.c
/* * Copyright (C) 2016 The Android Open Source Project * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "avb_crypto.h" #include "avb_rsa.h" #include "avb_sha.h" #include "avb_util.h" /* NOTE: The PKC1-v1.5 padding is a blob of binary DER of ASN.1 and is * obtained from section 5.2.2 of RFC 4880. */ static const uint8_t padding_RSA2048_SHA256[AVB_RSA2048_NUM_BYTES - AVB_SHA256_DIGEST_SIZE] = { 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}; static const uint8_t padding_RSA4096_SHA256[AVB_RSA4096_NUM_BYTES - AVB_SHA256_DIGEST_SIZE] = { 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}; static const uint8_t padding_RSA8192_SHA256[AVB_RSA8192_NUM_BYTES - AVB_SHA256_DIGEST_SIZE] = { 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}; static const uint8_t padding_RSA2048_SHA512[AVB_RSA2048_NUM_BYTES - AVB_SHA512_DIGEST_SIZE] = { 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}; static const uint8_t padding_RSA4096_SHA512[AVB_RSA4096_NUM_BYTES - AVB_SHA512_DIGEST_SIZE] = { 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}; static const uint8_t padding_RSA8192_SHA512[AVB_RSA8192_NUM_BYTES - AVB_SHA512_DIGEST_SIZE] = { 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}; static AvbAlgorithmData algorithm_data[_AVB_ALGORITHM_NUM_TYPES] = { /* AVB_ALGORITHM_TYPE_NONE */ {.padding = NULL, .padding_len = 0, .hash_len = 0}, /* AVB_ALGORITHM_TYPE_SHA256_RSA2048 */ {.padding = padding_RSA2048_SHA256, .padding_len = sizeof(padding_RSA2048_SHA256), .hash_len = AVB_SHA256_DIGEST_SIZE}, /* AVB_ALGORITHM_TYPE_SHA256_RSA4096 */ {.padding = padding_RSA4096_SHA256, .padding_len = sizeof(padding_RSA4096_SHA256), .hash_len = AVB_SHA256_DIGEST_SIZE}, /* AVB_ALGORITHM_TYPE_SHA256_RSA8192 */ {.padding = padding_RSA8192_SHA256, .padding_len = sizeof(padding_RSA8192_SHA256), .hash_len = AVB_SHA256_DIGEST_SIZE}, /* AVB_ALGORITHM_TYPE_SHA512_RSA2048 */ {.padding = padding_RSA2048_SHA512, .padding_len = sizeof(padding_RSA2048_SHA512), .hash_len = AVB_SHA512_DIGEST_SIZE}, /* AVB_ALGORITHM_TYPE_SHA512_RSA4096 */ {.padding = padding_RSA4096_SHA512, .padding_len = sizeof(padding_RSA4096_SHA512), .hash_len = AVB_SHA512_DIGEST_SIZE}, /* AVB_ALGORITHM_TYPE_SHA512_RSA8192 */ {.padding = padding_RSA8192_SHA512, .padding_len = sizeof(padding_RSA8192_SHA512), .hash_len = AVB_SHA512_DIGEST_SIZE}, }; const AvbAlgorithmData* avb_get_algorithm_data(AvbAlgorithmType algorithm) { if ((size_t)algorithm < _AVB_ALGORITHM_NUM_TYPES) { return &algorithm_data[algorithm]; } return NULL; } bool avb_rsa_public_key_header_validate_and_byteswap( const AvbRSAPublicKeyHeader* src, AvbRSAPublicKeyHeader* dest) { avb_memcpy(dest, src, sizeof(AvbRSAPublicKeyHeader)); dest->key_num_bits = avb_be32toh(dest->key_num_bits); dest->n0inv = avb_be32toh(dest->n0inv); return true; }
6ce649d317c53723e3ac2077666d47a4a01a5a02
7547d54f6f5f231fdd23a235b3c06bf80a6365df
/ext/polyphony/pipe.c
1008a678637f70e063208ca9fe9e37574590a1b9
[ "MIT" ]
permissive
digital-fabric/polyphony
fed42f534dc4e72ec3b4de60c998fa4ec904795c
77b4e264344ef82ab5a31ebaa832a25489b26cda
refs/heads/master
2023-08-09T06:58:33.581327
2023-08-06T07:19:49
2023-08-06T07:19:49
145,374,867
624
18
MIT
2023-08-06T08:07:26
2018-08-20T06:22:07
C
UTF-8
C
false
false
2,861
c
pipe.c
#include <unistd.h> #include "polyphony.h" typedef struct pipe { int fds[2]; unsigned int w_closed; } Pipe_t; VALUE cPipe = Qnil; VALUE cClosedPipeError = Qnil; static void Pipe_free(void *ptr) { Pipe_t *pipe = ptr; close(pipe->fds[0]); if (!pipe->w_closed) close(pipe->fds[1]); xfree(ptr); } static size_t Pipe_size(const void *ptr) { return sizeof(Pipe_t); } static const rb_data_type_t Pipe_type = { "Pipe", {NULL, Pipe_free, Pipe_size,}, 0, 0, 0 }; static VALUE Pipe_allocate(VALUE klass) { Pipe_t *pipe; pipe = ALLOC(Pipe_t); return TypedData_Wrap_Struct(klass, &Pipe_type, pipe); } /* Creates a new pipe. */ static VALUE Pipe_initialize(VALUE self) { Pipe_t *pipe_struct = RTYPEDDATA_DATA(self); int ret = pipe(pipe_struct->fds); if (ret) { int e = errno; rb_syserr_fail(e, strerror(e)); } pipe_struct->w_closed = 0; return self; } void Pipe_verify_blocking_mode(VALUE self, VALUE blocking) { Pipe_t *pipe = RTYPEDDATA_DATA(self); VALUE blocking_mode = rb_ivar_get(self, ID_ivar_blocking_mode); if (blocking == blocking_mode) return; rb_ivar_set(self, ID_ivar_blocking_mode, blocking); set_fd_blocking_mode(pipe->fds[0], blocking == Qtrue); set_fd_blocking_mode(pipe->fds[1], blocking == Qtrue); } int Pipe_get_fd(VALUE self, int write_mode) { Pipe_t *pipe = RTYPEDDATA_DATA(self); if (write_mode && pipe->w_closed) rb_raise(cClosedPipeError, "Pipe is closed for writing"); return pipe->fds[write_mode ? 1 : 0]; } /* Returns true if the pipe is closed. * * @return [boolean] */ VALUE Pipe_closed_p(VALUE self) { Pipe_t *pipe = RTYPEDDATA_DATA(self); return pipe->w_closed ? Qtrue : Qfalse; } /* Closes the pipe. * * @return [Pipe] self */ VALUE Pipe_close(VALUE self) { Pipe_t *pipe = RTYPEDDATA_DATA(self); if (pipe->w_closed) rb_raise(rb_eRuntimeError, "Pipe is already closed for writing"); Backend_close(BACKEND(), INT2FIX(pipe->fds[1])); pipe->w_closed = 1; return self; } /* Returns an array containing the read and write fds for the pipe, * respectively. * * @return [Array<Integer>] */ VALUE Pipe_fds(VALUE self) { Pipe_t *pipe = RTYPEDDATA_DATA(self); return rb_ary_new_from_args(2, INT2FIX(pipe->fds[0]), INT2FIX(pipe->fds[1])); } void Init_Pipe(void) { cPipe = rb_define_class_under(mPolyphony, "Pipe", rb_cObject); /* * Document-class: Polyphony::Pipe::ClosedPipeError * * An exception raised when trying to read or write to a closed pipe. */ cClosedPipeError = rb_define_class_under(cPipe, "ClosedPipeError", rb_eRuntimeError); rb_define_alloc_func(cPipe, Pipe_allocate); rb_define_method(cPipe, "initialize", Pipe_initialize, 0); rb_define_method(cPipe, "closed?", Pipe_closed_p, 0); rb_define_method(cPipe, "close", Pipe_close, 0); rb_define_method(cPipe, "fds", Pipe_fds, 0); }
781167bfde27097292794b3c4aebcaefbf6379df
85ccd32aa73eecf274a937f1fc3b6f4d484b77da
/test cases/common/145 recursive linking/circular/lib2.c
31cd37cc19c9b8542c222a8643771855c2ea9347
[ "Apache-2.0" ]
permissive
mesonbuild/meson
48321cf4235dfcc0194fed90ff43a57367592bf7
cf5adf0c646474f0259d123fad60ca5ed38ec891
refs/heads/master
2023-09-01T05:58:50.807952
2023-03-17T20:27:37
2023-08-31T11:52:41
19,784,232
5,122
1,848
Apache-2.0
2023-09-14T15:47:23
2014-05-14T15:08:16
Python
UTF-8
C
false
false
124
c
lib2.c
int get_st1_prop (void); int get_st3_prop (void); int get_st2_value (void) { return get_st1_prop () + get_st3_prop (); }
b3c93d13ecab02773ba9601f907a7d91b773a392
321d11eaee885ceb3a74db0a062f9bbdf282148c
/crypto/bio/ossl_core_bio.c
3e6a90abeb980351b5e3f8fa83e867099c504199
[ "Apache-2.0", "OpenSSL", "LicenseRef-scancode-proprietary-license" ]
permissive
openssl/openssl
75691ebaae957793f2ff0673f77545277dfb3988
5318c012885a5382eadbf95aa9c1d35664bca819
refs/heads/master
2023-09-03T15:22:52.727123
2023-09-01T07:10:49
2023-09-02T14:30:01
7,634,677
24,148
11,569
Apache-2.0
2023-09-14T19:48:11
2013-01-15T22:34:48
C
UTF-8
C
false
false
2,846
c
ossl_core_bio.c
/* * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #include <openssl/core.h> #include "bio_local.h" /*- * Core BIO structure * This is distinct from a BIO to prevent casting between the two which could * lead to versioning problems. */ struct ossl_core_bio_st { CRYPTO_REF_COUNT ref_cnt; BIO *bio; }; static OSSL_CORE_BIO *core_bio_new(void) { OSSL_CORE_BIO *cb = OPENSSL_malloc(sizeof(*cb)); if (cb == NULL || !CRYPTO_NEW_REF(&cb->ref_cnt, 1)) { OPENSSL_free(cb); return NULL; } return cb; } int ossl_core_bio_up_ref(OSSL_CORE_BIO *cb) { int ref = 0; return CRYPTO_UP_REF(&cb->ref_cnt, &ref); } int ossl_core_bio_free(OSSL_CORE_BIO *cb) { int ref = 0, res = 1; if (cb != NULL) { CRYPTO_DOWN_REF(&cb->ref_cnt, &ref); if (ref <= 0) { res = BIO_free(cb->bio); CRYPTO_FREE_REF(&cb->ref_cnt); OPENSSL_free(cb); } } return res; } OSSL_CORE_BIO *ossl_core_bio_new_from_bio(BIO *bio) { OSSL_CORE_BIO *cb = core_bio_new(); if (cb == NULL || !BIO_up_ref(bio)) { ossl_core_bio_free(cb); return NULL; } cb->bio = bio; return cb; } static OSSL_CORE_BIO *core_bio_new_from_new_bio(BIO *bio) { OSSL_CORE_BIO *cb = NULL; if (bio == NULL) return NULL; if ((cb = core_bio_new()) == NULL) { BIO_free(bio); return NULL; } cb->bio = bio; return cb; } OSSL_CORE_BIO *ossl_core_bio_new_file(const char *filename, const char *mode) { return core_bio_new_from_new_bio(BIO_new_file(filename, mode)); } OSSL_CORE_BIO *ossl_core_bio_new_mem_buf(const void *buf, int len) { return core_bio_new_from_new_bio(BIO_new_mem_buf(buf, len)); } int ossl_core_bio_read_ex(OSSL_CORE_BIO *cb, void *data, size_t dlen, size_t *readbytes) { return BIO_read_ex(cb->bio, data, dlen, readbytes); } int ossl_core_bio_write_ex(OSSL_CORE_BIO *cb, const void *data, size_t dlen, size_t *written) { return BIO_write_ex(cb->bio, data, dlen, written); } int ossl_core_bio_gets(OSSL_CORE_BIO *cb, char *buf, int size) { return BIO_gets(cb->bio, buf, size); } int ossl_core_bio_puts(OSSL_CORE_BIO *cb, const char *buf) { return BIO_puts(cb->bio, buf); } long ossl_core_bio_ctrl(OSSL_CORE_BIO *cb, int cmd, long larg, void *parg) { return BIO_ctrl(cb->bio, cmd, larg, parg); } int ossl_core_bio_vprintf(OSSL_CORE_BIO *cb, const char *format, va_list args) { return BIO_vprintf(cb->bio, format, args); }
2de00dadeca919c55ff23d056a202734bbedf7d1
6923f79f1eaaba0ab28b25337ba6cb56be97d32d
/Lattice_Boltzmann_Modeling_Thorne/src/lbmpi.h
f3e564e4eb1015a873c35449365f0d69d64a4831
[]
no_license
burakbayramli/books
9fe7ba0cabf06e113eb125d62fe16d4946f4a4f0
5e9a0e03aa7ddf5e5ddf89943ccc68d94b539e95
refs/heads/master
2023-08-17T05:31:08.885134
2023-08-14T10:05:37
2023-08-14T10:05:37
72,460,321
223
174
null
2022-10-24T12:15:06
2016-10-31T17:24:00
Jupyter Notebook
UTF-8
C
false
false
3,694
h
lbmpi.h
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // lbmpi.h // // - Note that this is adapted from a previous implementation in an // old mcmp code from last summer (2004). // #ifndef LBMPI_H #define LBMPI_H struct lbmpi_struct { //############################################################################ // // P A R A L L E L V A R I A B L E S // // 1 ... PX // ------------------------- // | | | | // 1 | | | | // | | | | // ------------------------- // . | | | | // . | | | | // . | |1 .. LX| | // ------------------------- // | 1|-|-|-|-| | // PY | ...|-|-|-|-| | // | LY|-|-|-|-| | // ------------------------- // // 06222004 For now, assume PX (and PY) are evenly divisible by LX (and LY). // // 06222004 As a first step, assume periodic boundaries everywhere... // (See the TODO file...) // int NumProcs, // Number of processes. ProcID; // ID of my (this proc's) process. // Param: NPX // Param: NPY // Type: int // Comments: NPX is the number of processes in the x-direction. NPY is the // number of processes in the y-direction. // int NPX, NPY; // Param: PX // Param: PY // Type: int // Comments: Coordinates of process' subdomain in the 2D array of subdomains. // int PX, PY; // Param: GLX // Param: GLY // Type: int // Comments: GLX-by-GLY is the global domain size (number of lattice nodes in // each direction). This is copied from LX and LY before LX and LY are // computed to store the local domain size of each process based on NPX and // NPY. // int GLX, GLY; // Param: GSX // Param: GSY // Param: GEX // Param: GEY // Type: int // Comments: Global starting and ending coordinates of process' piece of // the domain. Process owns nodes from (GSX,GSY) to (GEX,GEY). // int GSX, GSY, GEX, GEY; int NorthID; // ID of proc with sub-domain to the north. int SouthID; // ID of proc with sub-domain to the south. int EastID; // ID of proc with sub-domain to the east. int WestID; // ID of proc with sub-domain to the west. char filename[1024]; MPI_Status status; int ierr; double tic, toc; // Need a string for accumulating output to send through printf... // Outputting elements of an array (e.g. IndicesEW) individually // will result in a mess under MPI. Better to output them to a // string first and then dump the string all at once... Note that // this is just for small scale debugging. For visualizing // contents of larger arrays, write to a file... char iobuf[1024]; double sendtmp, recvtmp; // For debugging... // Stuff for generating type struct for east/west communication. int *BlockLengthsEW; MPI_Aint *AddrsEW; MPI_Aint *IndicesEW; MPI_Datatype *TypesEW; MPI_Datatype MPI_West2East; MPI_Datatype MPI_East2West; // Stuff for generating type struct for north/south communication. int *BlockLengthsNS; MPI_Aint *AddrsNS; MPI_Aint *IndicesNS; MPI_Datatype *TypesNS; MPI_Datatype MPI_South2North; MPI_Datatype MPI_North2South; MPI_Aint Index0; #if DUMP_AFTER_COMM || DUMP_BEFORE_COMM double **fmat; #endif /* DUMP_AFTER_COMM || DUMP_BEFORE_COMM */ }; //typedef struct lbmpi_struct *lbmpi_ptr; #endif LBMPI_H
693ac2d5c5b9fd1a104b758b0230457e85265099
e1d9c54e9925e30e388a255b53a93cccad0b94cb
/kubernetes/model/v1_component_condition.c
a6e220fa1387bb6f1d52cb55f6ae8b5d7509a033
[ "curl", "Apache-2.0" ]
permissive
kubernetes-client/c
dd4fd8095485c083e0f40f2b48159b1609a6141b
5ac5ff25e9809a92a48111b1f77574b6d040b711
refs/heads/master
2023-08-13T10:51:03.702497
2023-08-07T19:18:32
2023-08-07T19:18:32
247,958,425
127
47
Apache-2.0
2023-09-07T20:07:00
2020-03-17T11:59:05
C
UTF-8
C
false
false
4,072
c
v1_component_condition.c
#include <stdlib.h> #include <string.h> #include <stdio.h> #include "v1_component_condition.h" v1_component_condition_t *v1_component_condition_create( char *error, char *message, char *status, char *type ) { v1_component_condition_t *v1_component_condition_local_var = malloc(sizeof(v1_component_condition_t)); if (!v1_component_condition_local_var) { return NULL; } v1_component_condition_local_var->error = error; v1_component_condition_local_var->message = message; v1_component_condition_local_var->status = status; v1_component_condition_local_var->type = type; return v1_component_condition_local_var; } void v1_component_condition_free(v1_component_condition_t *v1_component_condition) { if(NULL == v1_component_condition){ return ; } listEntry_t *listEntry; if (v1_component_condition->error) { free(v1_component_condition->error); v1_component_condition->error = NULL; } if (v1_component_condition->message) { free(v1_component_condition->message); v1_component_condition->message = NULL; } if (v1_component_condition->status) { free(v1_component_condition->status); v1_component_condition->status = NULL; } if (v1_component_condition->type) { free(v1_component_condition->type); v1_component_condition->type = NULL; } free(v1_component_condition); } cJSON *v1_component_condition_convertToJSON(v1_component_condition_t *v1_component_condition) { cJSON *item = cJSON_CreateObject(); // v1_component_condition->error if(v1_component_condition->error) { if(cJSON_AddStringToObject(item, "error", v1_component_condition->error) == NULL) { goto fail; //String } } // v1_component_condition->message if(v1_component_condition->message) { if(cJSON_AddStringToObject(item, "message", v1_component_condition->message) == NULL) { goto fail; //String } } // v1_component_condition->status if (!v1_component_condition->status) { goto fail; } if(cJSON_AddStringToObject(item, "status", v1_component_condition->status) == NULL) { goto fail; //String } // v1_component_condition->type if (!v1_component_condition->type) { goto fail; } if(cJSON_AddStringToObject(item, "type", v1_component_condition->type) == NULL) { goto fail; //String } return item; fail: if (item) { cJSON_Delete(item); } return NULL; } v1_component_condition_t *v1_component_condition_parseFromJSON(cJSON *v1_component_conditionJSON){ v1_component_condition_t *v1_component_condition_local_var = NULL; // v1_component_condition->error cJSON *error = cJSON_GetObjectItemCaseSensitive(v1_component_conditionJSON, "error"); if (error) { if(!cJSON_IsString(error) && !cJSON_IsNull(error)) { goto end; //String } } // v1_component_condition->message cJSON *message = cJSON_GetObjectItemCaseSensitive(v1_component_conditionJSON, "message"); if (message) { if(!cJSON_IsString(message) && !cJSON_IsNull(message)) { goto end; //String } } // v1_component_condition->status cJSON *status = cJSON_GetObjectItemCaseSensitive(v1_component_conditionJSON, "status"); if (!status) { goto end; } if(!cJSON_IsString(status)) { goto end; //String } // v1_component_condition->type cJSON *type = cJSON_GetObjectItemCaseSensitive(v1_component_conditionJSON, "type"); if (!type) { goto end; } if(!cJSON_IsString(type)) { goto end; //String } v1_component_condition_local_var = v1_component_condition_create ( error && !cJSON_IsNull(error) ? strdup(error->valuestring) : NULL, message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL, strdup(status->valuestring), strdup(type->valuestring) ); return v1_component_condition_local_var; end: return NULL; }
3cf84da00f94d0fd12ea309645ac2c625bf21388
5de3ec4e6c65e60da1ed32b03748f96de7ef0b95
/Pods/Headers/Public/Realm/RLMPlatform.h
41aa0f42c866b1b5cbf2fef06b7b9b90355c5402
[ "MIT" ]
permissive
aaronpearce/DevSwitch
5154730f4f9eabcc14a6ad1222c6823b250b991e
98a1e6ded11907a02d21380ca93999d34b85b0b2
refs/heads/master
2021-06-10T22:56:56.239592
2021-06-04T21:25:40
2021-06-04T21:25:40
177,062,016
457
25
MIT
2019-03-24T22:37:41
2019-03-22T03:00:31
Swift
UTF-8
C
false
false
36
h
RLMPlatform.h
../../../Realm/include/RLMPlatform.h
b666c4a86d311bcc6fe48d13965f8b8a6d326377
ffdc77394c5b5532b243cf3c33bd584cbdc65cb7
/third_party/securec/src/wmemcpy_s.c
236fcce1ff639b71d7b67ca61eead7dcfcf8a42d
[ "Apache-2.0", "LicenseRef-scancode-proprietary-license", "MPL-1.0", "OpenSSL", "LGPL-3.0-only", "LicenseRef-scancode-warranty-disclaimer", "BSD-3-Clause-Open-MPI", "MIT", "MPL-2.0-no-copyleft-exception", "NTP", "BSD-3-Clause", "GPL-1.0-or-later", "0BSD", "MPL-2.0", "LicenseRef-scancode-f...
permissive
mindspore-ai/mindspore
ca7d5bb51a3451c2705ff2e583a740589d80393b
54acb15d435533c815ee1bd9f6dc0b56b4d4cf83
refs/heads/master
2023-07-29T09:17:11.051569
2023-07-17T13:14:15
2023-07-17T13:14:15
239,714,835
4,178
768
Apache-2.0
2023-07-26T22:31:11
2020-02-11T08:43:48
C++
UTF-8
C
false
false
2,935
c
wmemcpy_s.c
/** * Copyright 2020 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "securecutil.h" /* * <FUNCTION DESCRIPTION> * The wmemcpy_s function copies n successive wide characters * from the object pointed to by src into the object pointed to by dest.t. * * <INPUT PARAMETERS> * dest Destination buffer. * destMax Size of the destination buffer. * src Buffer to copy from. * count Number of characters to copy. * * <OUTPUT PARAMETERS> * dest buffer is uptdated. * * <RETURN VALUE> * EOK Success * EINVAL dest is NULL and destMax != 0 and count <= destMax * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN * EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN and count <= destMax * ERANGE destMax > SECUREC_WCHAR_MEM_MAX_LEN or destMax is 0 or * (count > destMax and dest is NULL and destMax != 0 * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN) * ERANGE_AND_RESET count > destMax and dest != NULL and destMax != 0 * and destMax <= SECUREC_WCHAR_MEM_MAX_LEN * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and * count <= destMax destMax != 0 and destMax <= SECUREC_WCHAR_MEM_MAX_LEN * and dest != NULL and src != NULL and dest != src * * if an error occured, dest will be filled with 0 when dest and destMax valid . * If the source and destination overlap, the behavior of wmemcpy_s is undefined. * Use wmemmove_s to handle overlapping regions. */ errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count) { if (destMax == 0 || destMax > SECUREC_WCHAR_MEM_MAX_LEN) { SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s"); return ERANGE; } if (count > destMax) { SECUREC_ERROR_INVALID_PARAMTER("wmemcpy_s"); if (dest != NULL) { (void)memset(dest, 0, destMax * sizeof(wchar_t)); return ERANGE_AND_RESET; } return ERANGE; } return memcpy_s(dest, destMax * sizeof(wchar_t), src, count * sizeof(wchar_t)); }
39ddb4d6840bb4f269cdd3b3bb3fefe3fa44359f
14ac14bee6ddd3f74937ff316b37cb947a4ef882
/Mergesort.c
7c8502ee29ccd88f9c08617449e3848bf876287f
[ "MIT" ]
permissive
gouravthakur39/beginners-C-program-examples
ebe18c68c9b889d0622dc4d45ee0584e63a98d7c
373d27c131e35bacdbf5c500f79fd234c6d4ec9b
refs/heads/master
2023-09-02T16:15:01.129754
2022-07-08T11:50:46
2022-07-08T11:50:46
150,301,917
498
403
MIT
2023-08-07T16:11:02
2018-09-25T17:12:58
C
UTF-8
C
false
false
1,392
c
Mergesort.c
// Merge sort Algorithm #include <stdio.h> void mergesort(int a[], int i, int j); void merge(int a[], int i1, int j1, int i2, int j2); int main() { int a[30], n, i; printf("Enter no of elements:"); scanf("%d", & n); printf("Enter array elements:"); for (i = 0; i < n; i++) scanf("%d", & a[i]); mergesort(a, 0, n - 1); printf("\nSorted array is :"); for (i = 0; i < n; i++) printf("%d ", a[i]); return 0; } void mergesort(int a[], int i, int j) { int mid; if (i < j) { mid = (i + j) / 2; mergesort(a, i, mid); //left recursion mergesort(a, mid + 1, j); //right recursion merge(a, i, mid, mid + 1, j); //merging of two sorted sub-arrays } } void merge(int a[], int i1, int j1, int i2, int j2) { int temp[50]; //array used for merging int i, j, k; i = i1; //beginning of the first list j = i2; //beginning of the second list k = 0; while (i <= j1 && j <= j2) //while elements in both lists { if (a[i] < a[j]) temp[k++] = a[i++]; else temp[k++] = a[j++]; } while (i <= j1) //copy remaining elements of the first list temp[k++] = a[i++]; while (j <= j2) //copy remaining elements of the second list temp[k++] = a[j++]; //Transfer elements from temp[] back to a[] for (i = i1, j = 0; i <= j2; i++, j++) a[i] = temp[j]; }
6b82a12f8065fe4ba91c8b2d257150d98ae050ef
0f76e9f2c2f30ef14e4b8c67fe605cc19a26920d
/Include.win32/yaz/ill-core.h
cb3e396c74ba15c291bbb5f02f9568deac045e4b
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
textbrowser/biblioteq
f9ef6f756059b010488f7b8c9f35285c88361f90
77ff19bec088b6f40321feab44f91ce25778bbea
refs/heads/master
2023-08-31T00:08:02.575660
2023-08-28T15:54:35
2023-08-28T15:54:35
31,837,087
199
51
NOASSERTION
2023-09-14T11:21:21
2015-03-08T03:33:27
C++
UTF-8
C
false
false
47,134
h
ill-core.h
/** \file ill-core.h \brief ASN.1 Module ISO-10161-ILL-1 Generated automatically by YAZ ASN.1 Compiler 0.4 */ #ifndef ill_core_H #define ill_core_H #include <yaz/odr.h> #ifdef __cplusplus extern "C" { #endif typedef struct ILL_APDU ILL_APDU; YAZ_EXPORT int ill_APDU(ODR o, ILL_APDU **p, int opt, const char *name); typedef struct ILL_Request ILL_Request; YAZ_EXPORT int ill_Request(ODR o, ILL_Request **p, int opt, const char *name); typedef struct ILL_Forward_Notification ILL_Forward_Notification; YAZ_EXPORT int ill_Forward_Notification(ODR o, ILL_Forward_Notification **p, int opt, const char *name); typedef struct ILL_Shipped ILL_Shipped; YAZ_EXPORT int ill_Shipped(ODR o, ILL_Shipped **p, int opt, const char *name); typedef struct ILL_Answer ILL_Answer; YAZ_EXPORT int ill_Answer(ODR o, ILL_Answer **p, int opt, const char *name); typedef struct ILL_Conditional_Reply ILL_Conditional_Reply; YAZ_EXPORT int ill_Conditional_Reply(ODR o, ILL_Conditional_Reply **p, int opt, const char *name); typedef struct ILL_Cancel ILL_Cancel; YAZ_EXPORT int ill_Cancel(ODR o, ILL_Cancel **p, int opt, const char *name); typedef struct ILL_Cancel_Reply ILL_Cancel_Reply; YAZ_EXPORT int ill_Cancel_Reply(ODR o, ILL_Cancel_Reply **p, int opt, const char *name); typedef struct ILL_Received ILL_Received; YAZ_EXPORT int ill_Received(ODR o, ILL_Received **p, int opt, const char *name); typedef struct ILL_Recall ILL_Recall; YAZ_EXPORT int ill_Recall(ODR o, ILL_Recall **p, int opt, const char *name); typedef struct ILL_Returned ILL_Returned; YAZ_EXPORT int ill_Returned(ODR o, ILL_Returned **p, int opt, const char *name); typedef struct ILL_Checked_In ILL_Checked_In; YAZ_EXPORT int ill_Checked_In(ODR o, ILL_Checked_In **p, int opt, const char *name); typedef struct ILL_Overdue_ExtensionS ILL_Overdue_ExtensionS; YAZ_EXPORT int ill_Overdue_ExtensionS(ODR o, ILL_Overdue_ExtensionS **p, int opt, const char *name); typedef struct ILL_Overdue ILL_Overdue; YAZ_EXPORT int ill_Overdue(ODR o, ILL_Overdue **p, int opt, const char *name); typedef struct ILL_Renew ILL_Renew; YAZ_EXPORT int ill_Renew(ODR o, ILL_Renew **p, int opt, const char *name); typedef struct ILL_Renew_Answer ILL_Renew_Answer; YAZ_EXPORT int ill_Renew_Answer(ODR o, ILL_Renew_Answer **p, int opt, const char *name); typedef struct ILL_Lost ILL_Lost; YAZ_EXPORT int ill_Lost(ODR o, ILL_Lost **p, int opt, const char *name); typedef struct ILL_Damaged ILL_Damaged; YAZ_EXPORT int ill_Damaged(ODR o, ILL_Damaged **p, int opt, const char *name); typedef struct ILL_Message ILL_Message; YAZ_EXPORT int ill_Message(ODR o, ILL_Message **p, int opt, const char *name); typedef struct ILL_Status_Query ILL_Status_Query; YAZ_EXPORT int ill_Status_Query(ODR o, ILL_Status_Query **p, int opt, const char *name); typedef struct ILL_Status_Or_Error_Report ILL_Status_Or_Error_Report; YAZ_EXPORT int ill_Status_Or_Error_Report(ODR o, ILL_Status_Or_Error_Report **p, int opt, const char *name); typedef struct ILL_Expired ILL_Expired; YAZ_EXPORT int ill_Expired(ODR o, ILL_Expired **p, int opt, const char *name); typedef struct ILL_Already_Forwarded ILL_Already_Forwarded; YAZ_EXPORT int ill_Already_Forwarded(ODR o, ILL_Already_Forwarded **p, int opt, const char *name); typedef struct ILL_Already_Tried_List_Type ILL_Already_Tried_List_Type; YAZ_EXPORT int ill_Already_Tried_List_Type(ODR o, ILL_Already_Tried_List_Type **p, int opt, const char *name); typedef struct ILL_Amount ILL_Amount; YAZ_EXPORT int ill_Amount(ODR o, ILL_Amount **p, int opt, const char *name); typedef char ILL_AmountString; YAZ_EXPORT int ill_AmountString(ODR o, ILL_AmountString **p, int opt, const char *name); typedef struct ILL_Client_Id ILL_Client_Id; YAZ_EXPORT int ill_Client_Id(ODR o, ILL_Client_Id **p, int opt, const char *name); typedef struct ILL_Conditional_Results ILL_Conditional_Results; YAZ_EXPORT int ill_Conditional_Results(ODR o, ILL_Conditional_Results **p, int opt, const char *name); typedef struct ILL_Cost_Info_Type ILL_Cost_Info_Type; YAZ_EXPORT int ill_Cost_Info_Type(ODR o, ILL_Cost_Info_Type **p, int opt, const char *name); typedef Odr_int ILL_Current_State; YAZ_EXPORT int ill_Current_State(ODR o, ILL_Current_State **p, int opt, const char *name); typedef struct ILL_Damaged_DetailsSpecific_units ILL_Damaged_DetailsSpecific_units; YAZ_EXPORT int ill_Damaged_DetailsSpecific_units(ODR o, ILL_Damaged_DetailsSpecific_units **p, int opt, const char *name); typedef struct ILL_Damaged_Details ILL_Damaged_Details; YAZ_EXPORT int ill_Damaged_Details(ODR o, ILL_Damaged_Details **p, int opt, const char *name); typedef struct ILL_Date_Due ILL_Date_Due; YAZ_EXPORT int ill_Date_Due(ODR o, ILL_Date_Due **p, int opt, const char *name); typedef struct ILL_Delivery_Address ILL_Delivery_Address; YAZ_EXPORT int ill_Delivery_Address(ODR o, ILL_Delivery_Address **p, int opt, const char *name); typedef struct ILL_Delivery_ServiceElectronic_delivery ILL_Delivery_ServiceElectronic_delivery; YAZ_EXPORT int ill_Delivery_ServiceElectronic_delivery(ODR o, ILL_Delivery_ServiceElectronic_delivery **p, int opt, const char *name); typedef struct ILL_Delivery_Service ILL_Delivery_Service; YAZ_EXPORT int ill_Delivery_Service(ODR o, ILL_Delivery_Service **p, int opt, const char *name); typedef struct ILL_Electronic_Delivery_Service_0 ILL_Electronic_Delivery_Service_0; YAZ_EXPORT int ill_Electronic_Delivery_Service_0(ODR o, ILL_Electronic_Delivery_Service_0 **p, int opt, const char *name); typedef struct ILL_Electronic_Delivery_Service_1 ILL_Electronic_Delivery_Service_1; YAZ_EXPORT int ill_Electronic_Delivery_Service_1(ODR o, ILL_Electronic_Delivery_Service_1 **p, int opt, const char *name); typedef struct ILL_Electronic_Delivery_Service ILL_Electronic_Delivery_Service; YAZ_EXPORT int ill_Electronic_Delivery_Service(ODR o, ILL_Electronic_Delivery_Service **p, int opt, const char *name); typedef struct ILL_Error_Report ILL_Error_Report; YAZ_EXPORT int ill_Error_Report(ODR o, ILL_Error_Report **p, int opt, const char *name); typedef struct ILL_Estimate_Results ILL_Estimate_Results; YAZ_EXPORT int ill_Estimate_Results(ODR o, ILL_Estimate_Results **p, int opt, const char *name); typedef struct ILL_Extension ILL_Extension; YAZ_EXPORT int ill_Extension(ODR o, ILL_Extension **p, int opt, const char *name); typedef Odr_int ILL_General_Problem; YAZ_EXPORT int ill_General_Problem(ODR o, ILL_General_Problem **p, int opt, const char *name); typedef struct ILL_History_Report ILL_History_Report; YAZ_EXPORT int ill_History_Report(ODR o, ILL_History_Report **p, int opt, const char *name); typedef struct ILL_Hold_Placed_Results ILL_Hold_Placed_Results; YAZ_EXPORT int ill_Hold_Placed_Results(ODR o, ILL_Hold_Placed_Results **p, int opt, const char *name); typedef Odr_int ILL_APDU_Type; YAZ_EXPORT int ill_APDU_Type(ODR o, ILL_APDU_Type **p, int opt, const char *name); typedef Odr_int ILL_Service_Type; YAZ_EXPORT int ill_Service_Type(ODR o, ILL_Service_Type **p, int opt, const char *name); typedef struct ILL_String ILL_String; YAZ_EXPORT int ill_String(ODR o, ILL_String **p, int opt, const char *name); typedef ILL_String ILL_Account_Number; YAZ_EXPORT int ill_Account_Number(ODR o, ILL_Account_Number **p, int opt, const char *name); typedef Odr_int ILL_Intermediary_Problem; YAZ_EXPORT int ill_Intermediary_Problem(ODR o, ILL_Intermediary_Problem **p, int opt, const char *name); typedef char ILL_ISO_Date; YAZ_EXPORT int ill_ISO_Date(ODR o, ILL_ISO_Date **p, int opt, const char *name); typedef char ILL_ISO_Time; YAZ_EXPORT int ill_ISO_Time(ODR o, ILL_ISO_Time **p, int opt, const char *name); typedef struct ILL_Item_Id ILL_Item_Id; YAZ_EXPORT int ill_Item_Id(ODR o, ILL_Item_Id **p, int opt, const char *name); typedef struct ILL_Location_Info ILL_Location_Info; YAZ_EXPORT int ill_Location_Info(ODR o, ILL_Location_Info **p, int opt, const char *name); typedef struct ILL_Locations_Results ILL_Locations_Results; YAZ_EXPORT int ill_Locations_Results(ODR o, ILL_Locations_Results **p, int opt, const char *name); typedef Odr_int ILL_Medium_Type; YAZ_EXPORT int ill_Medium_Type(ODR o, ILL_Medium_Type **p, int opt, const char *name); typedef struct ILL_Name_Of_Person_Or_Institution ILL_Name_Of_Person_Or_Institution; YAZ_EXPORT int ill_Name_Of_Person_Or_Institution(ODR o, ILL_Name_Of_Person_Or_Institution **p, int opt, const char *name); typedef struct ILL_Person_Or_Institution_Symbol ILL_Person_Or_Institution_Symbol; YAZ_EXPORT int ill_Person_Or_Institution_Symbol(ODR o, ILL_Person_Or_Institution_Symbol **p, int opt, const char *name); typedef Odr_int ILL_Place_On_Hold_Type; YAZ_EXPORT int ill_Place_On_Hold_Type(ODR o, ILL_Place_On_Hold_Type **p, int opt, const char *name); typedef struct ILL_Postal_Address ILL_Postal_Address; YAZ_EXPORT int ill_Postal_Address(ODR o, ILL_Postal_Address **p, int opt, const char *name); typedef struct ILL_Provider_Error_Report ILL_Provider_Error_Report; YAZ_EXPORT int ill_Provider_Error_Report(ODR o, ILL_Provider_Error_Report **p, int opt, const char *name); typedef Odr_int ILL_Reason_Locs_Provided; YAZ_EXPORT int ill_Reason_Locs_Provided(ODR o, ILL_Reason_Locs_Provided **p, int opt, const char *name); typedef Odr_int ILL_Reason_No_Report; YAZ_EXPORT int ill_Reason_No_Report(ODR o, ILL_Reason_No_Report **p, int opt, const char *name); typedef Odr_int ILL_Reason_Unfilled; YAZ_EXPORT int ill_Reason_Unfilled(ODR o, ILL_Reason_Unfilled **p, int opt, const char *name); typedef Odr_int ILL_Report_Source; YAZ_EXPORT int ill_Report_Source(ODR o, ILL_Report_Source **p, int opt, const char *name); typedef struct ILL_Requester_Optional_Messages_Type ILL_Requester_Optional_Messages_Type; YAZ_EXPORT int ill_Requester_Optional_Messages_Type(ODR o, ILL_Requester_Optional_Messages_Type **p, int opt, const char *name); typedef struct ILL_Responder_Optional_Messages_Type ILL_Responder_Optional_Messages_Type; YAZ_EXPORT int ill_Responder_Optional_Messages_Type(ODR o, ILL_Responder_Optional_Messages_Type **p, int opt, const char *name); typedef struct ILL_Retry_Results ILL_Retry_Results; YAZ_EXPORT int ill_Retry_Results(ODR o, ILL_Retry_Results **p, int opt, const char *name); typedef struct ILL_Search_Type ILL_Search_Type; YAZ_EXPORT int ill_Search_Type(ODR o, ILL_Search_Type **p, int opt, const char *name); typedef ILL_String ILL_Security_Problem; YAZ_EXPORT int ill_Security_Problem(ODR o, ILL_Security_Problem **p, int opt, const char *name); typedef struct ILL_Send_To_List_Type_s ILL_Send_To_List_Type_s; YAZ_EXPORT int ill_Send_To_List_Type_s(ODR o, ILL_Send_To_List_Type_s **p, int opt, const char *name); typedef struct ILL_Send_To_List_Type ILL_Send_To_List_Type; YAZ_EXPORT int ill_Send_To_List_Type(ODR o, ILL_Send_To_List_Type **p, int opt, const char *name); typedef struct ILL_Service_Date_this ILL_Service_Date_this; YAZ_EXPORT int ill_Service_Date_this(ODR o, ILL_Service_Date_this **p, int opt, const char *name); typedef struct ILL_Service_Date_original ILL_Service_Date_original; YAZ_EXPORT int ill_Service_Date_original(ODR o, ILL_Service_Date_original **p, int opt, const char *name); typedef struct ILL_Service_Date_Time ILL_Service_Date_Time; YAZ_EXPORT int ill_Service_Date_Time(ODR o, ILL_Service_Date_Time **p, int opt, const char *name); typedef ILL_Service_Type ILL_Shipped_Service_Type; YAZ_EXPORT int ill_Shipped_Service_Type(ODR o, ILL_Shipped_Service_Type **p, int opt, const char *name); typedef struct ILL_State_Transition_Prohibited ILL_State_Transition_Prohibited; YAZ_EXPORT int ill_State_Transition_Prohibited(ODR o, ILL_State_Transition_Prohibited **p, int opt, const char *name); typedef struct ILL_Status_Report ILL_Status_Report; YAZ_EXPORT int ill_Status_Report(ODR o, ILL_Status_Report **p, int opt, const char *name); typedef struct ILL_Supplemental_Item_Description ILL_Supplemental_Item_Description; YAZ_EXPORT int ill_Supplemental_Item_Description(ODR o, ILL_Supplemental_Item_Description **p, int opt, const char *name); typedef struct ILL_Supply_Details ILL_Supply_Details; YAZ_EXPORT int ill_Supply_Details(ODR o, ILL_Supply_Details **p, int opt, const char *name); typedef struct ILL_Supply_Medium_Info_Type ILL_Supply_Medium_Info_Type; YAZ_EXPORT int ill_Supply_Medium_Info_Type(ODR o, ILL_Supply_Medium_Info_Type **p, int opt, const char *name); typedef Odr_int ILL_Supply_Medium_Type; YAZ_EXPORT int ill_Supply_Medium_Type(ODR o, ILL_Supply_Medium_Type **p, int opt, const char *name); typedef struct ILL_System_Address ILL_System_Address; YAZ_EXPORT int ill_System_Address(ODR o, ILL_System_Address **p, int opt, const char *name); typedef struct ILL_System_Id ILL_System_Id; YAZ_EXPORT int ill_System_Id(ODR o, ILL_System_Id **p, int opt, const char *name); typedef struct ILL_Third_Party_Info_Type ILL_Third_Party_Info_Type; YAZ_EXPORT int ill_Third_Party_Info_Type(ODR o, ILL_Third_Party_Info_Type **p, int opt, const char *name); typedef struct ILL_Transaction_Id ILL_Transaction_Id; YAZ_EXPORT int ill_Transaction_Id(ODR o, ILL_Transaction_Id **p, int opt, const char *name); typedef Odr_int ILL_Transaction_Id_Problem; YAZ_EXPORT int ill_Transaction_Id_Problem(ODR o, ILL_Transaction_Id_Problem **p, int opt, const char *name); typedef Odr_int ILL_Transaction_Results; YAZ_EXPORT int ill_Transaction_Results(ODR o, ILL_Transaction_Results **p, int opt, const char *name); typedef Odr_int ILL_Transaction_Type; YAZ_EXPORT int ill_Transaction_Type(ODR o, ILL_Transaction_Type **p, int opt, const char *name); typedef ILL_String ILL_Transportation_Mode; YAZ_EXPORT int ill_Transportation_Mode(ODR o, ILL_Transportation_Mode **p, int opt, const char *name); typedef Odr_int ILL_Unable_To_Perform; YAZ_EXPORT int ill_Unable_To_Perform(ODR o, ILL_Unable_To_Perform **p, int opt, const char *name); typedef struct ILL_Unfilled_Results ILL_Unfilled_Results; YAZ_EXPORT int ill_Unfilled_Results(ODR o, ILL_Unfilled_Results **p, int opt, const char *name); typedef struct ILL_Units_Per_Medium_Type ILL_Units_Per_Medium_Type; YAZ_EXPORT int ill_Units_Per_Medium_Type(ODR o, ILL_Units_Per_Medium_Type **p, int opt, const char *name); typedef struct ILL_User_Error_Report ILL_User_Error_Report; YAZ_EXPORT int ill_User_Error_Report(ODR o, ILL_User_Error_Report **p, int opt, const char *name); typedef struct ILL_Will_Supply_Results ILL_Will_Supply_Results; YAZ_EXPORT int ill_Will_Supply_Results(ODR o, ILL_Will_Supply_Results **p, int opt, const char *name); typedef char ILL_EDIFACTString; YAZ_EXPORT int ill_EDIFACTString(ODR o, ILL_EDIFACTString **p, int opt, const char *name); #ifdef __cplusplus } #endif #ifdef __cplusplus extern "C" { #endif struct ILL_APDU { int which; union { ILL_Request *illRequest; ILL_Forward_Notification *Forward_Notification; ILL_Shipped *Shipped; ILL_Answer *illAnswer; ILL_Conditional_Reply *Conditional_Reply; ILL_Cancel *Cancel; ILL_Cancel_Reply *Cancel_Reply; ILL_Received *Received; ILL_Recall *Recall; ILL_Returned *Returned; ILL_Checked_In *Checked_In; ILL_Overdue *Overdue; ILL_Renew *Renew; ILL_Renew_Answer *Renew_Answer; ILL_Lost *Lost; ILL_Damaged *Damaged; ILL_Message *Message; ILL_Status_Query *Status_Query; ILL_Status_Or_Error_Report *Status_Or_Error_Report; ILL_Expired *Expired; #define ILL_APDU_ILL_Request 1 #define ILL_APDU_Forward_Notification 2 #define ILL_APDU_Shipped 3 #define ILL_APDU_ILL_Answer 4 #define ILL_APDU_Conditional_Reply 5 #define ILL_APDU_Cancel 6 #define ILL_APDU_Cancel_Reply 7 #define ILL_APDU_Received 8 #define ILL_APDU_Recall 9 #define ILL_APDU_Returned 10 #define ILL_APDU_Checked_In 11 #define ILL_APDU_Overdue 12 #define ILL_APDU_Renew 13 #define ILL_APDU_Renew_Answer 14 #define ILL_APDU_Lost 15 #define ILL_APDU_Damaged 16 #define ILL_APDU_Message 17 #define ILL_APDU_Status_Query 18 #define ILL_APDU_Status_Or_Error_Report 19 #define ILL_APDU_Expired 20 } u; }; struct ILL_Request { #define ILL_Request_version_1 1 #define ILL_Request_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_Transaction_Type *transaction_type; ILL_Delivery_Address *delivery_address; /* OPT */ ILL_Delivery_Service *delivery_service; /* OPT */ ILL_Delivery_Address *billing_address; /* OPT */ int num_iLL_service_type; ILL_Service_Type **iLL_service_type; Odr_external *responder_specific_service; /* OPT */ ILL_Requester_Optional_Messages_Type *requester_optional_messages; ILL_Search_Type *search_type; /* OPT */ int num_supply_medium_info_type; ILL_Supply_Medium_Info_Type **supply_medium_info_type; /* OPT */ ILL_Place_On_Hold_Type *place_on_hold; ILL_Client_Id *client_id; /* OPT */ ILL_Item_Id *item_id; ILL_Supplemental_Item_Description *supplemental_item_description; /* OPT */ ILL_Cost_Info_Type *cost_info_type; /* OPT */ ILL_String *copyright_compliance; /* OPT */ ILL_Third_Party_Info_Type *third_party_info_type; /* OPT */ Odr_bool *retry_flag; Odr_bool *forward_flag; ILL_String *requester_note; /* OPT */ ILL_String *forward_note; /* OPT */ int num_iLL_request_extensions; ILL_Extension **iLL_request_extensions; /* OPT */ }; struct ILL_Forward_Notification { #define ILL_Forward_Notification_version_1 1 #define ILL_Forward_Notification_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; ILL_System_Address *responder_address; /* OPT */ ILL_System_Id *intermediary_id; ILL_String *notification_note; /* OPT */ int num_forward_notification_extensions; ILL_Extension **forward_notification_extensions; /* OPT */ }; struct ILL_Shipped { #define ILL_Shipped_version_1 1 #define ILL_Shipped_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_System_Address *responder_address; /* OPT */ ILL_System_Id *intermediary_id; /* OPT */ ILL_System_Id *supplier_id; /* OPT */ ILL_Client_Id *client_id; /* OPT */ ILL_Transaction_Type *transaction_type; ILL_Supplemental_Item_Description *supplemental_item_description; /* OPT */ ILL_Shipped_Service_Type *shipped_service_type; ILL_Responder_Optional_Messages_Type *responder_optional_messages; /* OPT */ ILL_Supply_Details *supply_details; ILL_Postal_Address *return_to_address; /* OPT */ ILL_String *responder_note; /* OPT */ int num_shipped_extensions; ILL_Extension **shipped_extensions; /* OPT */ }; struct ILL_Answer { #define ILL_Answer_version_1 1 #define ILL_Answer_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_Transaction_Results *transaction_results; int which; union { ILL_Conditional_Results *conditional_results; ILL_Retry_Results *retry_results; ILL_Unfilled_Results *unfilled_results; ILL_Locations_Results *locations_results; ILL_Will_Supply_Results *will_supply_results; ILL_Hold_Placed_Results *hold_placed_results; ILL_Estimate_Results *estimate_results; #define ILL_Answer_conditional_results 1 #define ILL_Answer_retry_results 2 #define ILL_Answer_unfilled_results 3 #define ILL_Answer_locations_results 4 #define ILL_Answer_will_supply_results 5 #define ILL_Answer_hold_placed_results 6 #define ILL_Answer_estimate_results 7 } u; /* OPT */ Odr_external *responder_specific_results; /* OPT */ ILL_Supplemental_Item_Description *supplemental_item_description; /* OPT */ ILL_Send_To_List_Type *send_to_list; /* OPT */ ILL_Already_Tried_List_Type *already_tried_list; /* OPT */ ILL_Responder_Optional_Messages_Type *responder_optional_messages; /* OPT */ ILL_String *responder_note; /* OPT */ int num_ill_answer_extensions; ILL_Extension **ill_answer_extensions; /* OPT */ }; struct ILL_Conditional_Reply { #define ILL_Conditional_Reply_version_1 1 #define ILL_Conditional_Reply_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ Odr_bool *answer; ILL_String *requester_note; /* OPT */ int num_conditional_reply_extensions; ILL_Extension **conditional_reply_extensions; /* OPT */ }; struct ILL_Cancel { #define ILL_Cancel_version_1 1 #define ILL_Cancel_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_String *requester_note; /* OPT */ int num_cancel_extensions; ILL_Extension **cancel_extensions; /* OPT */ }; struct ILL_Cancel_Reply { #define ILL_Cancel_Reply_version_1 1 #define ILL_Cancel_Reply_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ Odr_bool *answer; ILL_String *responder_note; /* OPT */ int num_cancel_reply_extensions; ILL_Extension **cancel_reply_extensions; /* OPT */ }; struct ILL_Received { #define ILL_Received_version_1 1 #define ILL_Received_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_System_Id *supplier_id; /* OPT */ ILL_Supplemental_Item_Description *supplemental_item_description; /* OPT */ ILL_ISO_Date *date_received; ILL_Shipped_Service_Type *shipped_service_type; ILL_String *requester_note; /* OPT */ int num_received_extensions; ILL_Extension **received_extensions; /* OPT */ }; struct ILL_Recall { #define ILL_Recall_version_1 1 #define ILL_Recall_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_String *responder_note; /* OPT */ int num_recall_extensions; ILL_Extension **recall_extensions; /* OPT */ }; struct ILL_Returned { #define ILL_Returned_version_1 1 #define ILL_Returned_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_Supplemental_Item_Description *supplemental_item_description; /* OPT */ ILL_ISO_Date *date_returned; ILL_Transportation_Mode *returned_via; /* OPT */ ILL_Amount *insured_for; /* OPT */ ILL_String *requester_note; /* OPT */ int num_returned_extensions; ILL_Extension **returned_extensions; /* OPT */ }; struct ILL_Checked_In { #define ILL_Checked_In_version_1 1 #define ILL_Checked_In_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_ISO_Date *date_checked_in; ILL_String *responder_note; /* OPT */ int num_checked_in_extensions; ILL_Extension **checked_in_extensions; /* OPT */ }; struct ILL_Overdue_ExtensionS { int num; ILL_Extension **elements; }; struct ILL_Overdue { #define ILL_Overdue_version_1 1 #define ILL_Overdue_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_Date_Due *date_due; ILL_String *responder_note; /* OPT */ ILL_Overdue_ExtensionS *overdue_extensions; /* OPT */ }; struct ILL_Renew { #define ILL_Renew_version_1 1 #define ILL_Renew_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_ISO_Date *desired_due_date; /* OPT */ ILL_String *requester_note; /* OPT */ int num_renew_extensions; ILL_Extension **renew_extensions; /* OPT */ }; struct ILL_Renew_Answer { #define ILL_Renew_Answer_version_1 1 #define ILL_Renew_Answer_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ Odr_bool *answer; ILL_Date_Due *date_due; /* OPT */ ILL_String *responder_note; /* OPT */ int num_renew_answer_extensions; ILL_Extension **renew_answer_extensions; /* OPT */ }; struct ILL_Lost { #define ILL_Lost_version_1 1 #define ILL_Lost_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_String *note; /* OPT */ int num_lost_extensions; ILL_Extension **lost_extensions; /* OPT */ }; struct ILL_Damaged { #define ILL_Damaged_version_1 1 #define ILL_Damaged_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_Damaged_Details *damaged_details; /* OPT */ ILL_String *note; /* OPT */ int num_damaged_extensions; ILL_Extension **damaged_extensions; /* OPT */ }; struct ILL_Message { #define ILL_Message_version_1 1 #define ILL_Message_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_String *note; int num_message_extensions; ILL_Extension **message_extensions; /* OPT */ }; struct ILL_Status_Query { #define ILL_Status_Query_version_1 1 #define ILL_Status_Query_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_String *note; /* OPT */ int num_status_query_extensions; ILL_Extension **status_query_extensions; /* OPT */ }; struct ILL_Status_Or_Error_Report { #define ILL_Status_Or_Error_Report_version_1 1 #define ILL_Status_Or_Error_Report_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ ILL_Reason_No_Report *reason_no_report; /* OPT */ ILL_Status_Report *status_report; /* OPT */ ILL_Error_Report *error_report; /* OPT */ ILL_String *note; /* OPT */ int num_status_or_error_report_extensions; ILL_Extension **status_or_error_report_extensions; /* OPT */ }; struct ILL_Expired { #define ILL_Expired_version_1 1 #define ILL_Expired_version_2 2 Odr_int *protocol_version_num; ILL_Transaction_Id *transaction_id; ILL_Service_Date_Time *service_date_time; ILL_System_Id *requester_id; /* OPT */ ILL_System_Id *responder_id; /* OPT */ int num_expired_extensions; ILL_Extension **expired_extensions; /* OPT */ }; struct ILL_Already_Forwarded { ILL_System_Id *responder_id; ILL_System_Address *responder_address; /* OPT */ }; struct ILL_Already_Tried_List_Type { int num; ILL_System_Id **elements; }; struct ILL_Amount { char *currency_code; /* OPT */ ILL_AmountString *monetary_value; }; struct ILL_Client_Id { ILL_String *client_name; /* OPT */ ILL_String *client_status; /* OPT */ ILL_String *client_identifier; /* OPT */ }; struct ILL_Conditional_Results { #define ILL_Conditional_Results_cost_exceeds_limit 13 #define ILL_Conditional_Results_charges 14 #define ILL_Conditional_Results_prepayment_required 15 #define ILL_Conditional_Results_lacks_copyright_compliance 16 #define ILL_Conditional_Results_library_use_only 22 #define ILL_Conditional_Results_no_reproduction 23 #define ILL_Conditional_Results_client_signature_required 24 #define ILL_Conditional_Results_special_collections_supervision_required 25 #define ILL_Conditional_Results_other 27 #define ILL_Conditional_Results_responder_specific 28 #define ILL_Conditional_Results_proposed_delivery_service 30 Odr_int *conditions; ILL_ISO_Date *date_for_reply; /* OPT */ int num_locations; ILL_Location_Info **locations; /* OPT */ ILL_Delivery_Service *proposed_delivery_service; /* OPT */ }; struct ILL_Cost_Info_Type { ILL_Account_Number *account_number; /* OPT */ ILL_Amount *maximum_cost; /* OPT */ Odr_bool *reciprocal_agreement; Odr_bool *will_pay_fee; Odr_bool *payment_provided; }; #define ILL_Current_State_nOT_SUPPLIED 1 #define ILL_Current_State_pENDING 2 #define ILL_Current_State_iN_PROCESS 3 #define ILL_Current_State_fORWARD 4 #define ILL_Current_State_cONDITIONAL 5 #define ILL_Current_State_cANCEL_PENDING 6 #define ILL_Current_State_cANCELLED 7 #define ILL_Current_State_sHIPPED 8 #define ILL_Current_State_rECEIVED 9 #define ILL_Current_State_rENEW_PENDING 10 #define ILL_Current_State_nOT_RECEIVED_OVERDUE 11 #define ILL_Current_State_rENEW_OVERDUE 12 #define ILL_Current_State_oVERDUE 13 #define ILL_Current_State_rETURNED 14 #define ILL_Current_State_cHECKED_IN 15 #define ILL_Current_State_rECALL 16 #define ILL_Current_State_lOST 17 #define ILL_Current_State_uNKNOWN 18 struct ILL_Damaged_DetailsSpecific_units { int num; Odr_int **elements; }; struct ILL_Damaged_Details { Odr_oid *document_type_id; /* OPT */ int which; union { Odr_null *complete_document; ILL_Damaged_DetailsSpecific_units *specific_units; #define ILL_Damaged_Details_complete_document 1 #define ILL_Damaged_Details_specific_units 2 } u; }; struct ILL_Date_Due { ILL_ISO_Date *date_due_field; Odr_bool *renewable; }; struct ILL_Delivery_Address { ILL_Postal_Address *postal_address; /* OPT */ ILL_System_Address *electronic_address; /* OPT */ }; struct ILL_Delivery_ServiceElectronic_delivery { int num; ILL_Electronic_Delivery_Service **elements; }; struct ILL_Delivery_Service { int which; union { ILL_Transportation_Mode *physical_delivery; ILL_Delivery_ServiceElectronic_delivery *electronic_delivery; #define ILL_Delivery_Service_physical_delivery 1 #define ILL_Delivery_Service_electronic_delivery 2 } u; }; struct ILL_Electronic_Delivery_Service_0 { Odr_oid *e_delivery_mode; Odr_any *e_delivery_parameters; }; struct ILL_Electronic_Delivery_Service_1 { Odr_oid *document_type_id; Odr_any *document_type_parameters; }; struct ILL_Electronic_Delivery_Service { ILL_Electronic_Delivery_Service_0 *e_delivery_service; /* OPT */ ILL_Electronic_Delivery_Service_1 *document_type; /* OPT */ ILL_String *e_delivery_description; /* OPT */ int which; union { ILL_System_Address *e_delivery_address; ILL_System_Id *e_delivery_id; #define ILL_Electronic_Delivery_Service_e_delivery_address 1 #define ILL_Electronic_Delivery_Service_e_delivery_id 2 } u; ILL_String *name_or_code; /* OPT */ ILL_ISO_Time *delivery_time; /* OPT */ }; struct ILL_Error_Report { ILL_String *correlation_information; ILL_Report_Source *report_source; ILL_User_Error_Report *user_error_report; /* OPT */ ILL_Provider_Error_Report *provider_error_report; /* OPT */ }; struct ILL_Estimate_Results { ILL_String *cost_estimate; int num_locations; ILL_Location_Info **locations; /* OPT */ }; struct ILL_Extension { Odr_int *identifier; Odr_bool *critical; Odr_any *item; }; #define ILL_General_Problem_unrecognized_APDU 1 #define ILL_General_Problem_mistyped_APDU 2 #define ILL_General_Problem_badly_structured_APDU 3 #define ILL_General_Problem_protocol_version_not_supported 4 #define ILL_General_Problem_other 5 struct ILL_History_Report { ILL_ISO_Date *date_requested; /* OPT */ ILL_String *author; /* OPT */ ILL_String *title; /* OPT */ ILL_String *author_of_article; /* OPT */ ILL_String *title_of_article; /* OPT */ ILL_ISO_Date *date_of_last_transition; #define ILL_History_Report_iLL_REQUEST 1 #define ILL_History_Report_fORWARD 21 #define ILL_History_Report_fORWARD_NOTIFICATION 2 #define ILL_History_Report_sHIPPED 3 #define ILL_History_Report_iLL_ANSWER 4 #define ILL_History_Report_cONDITIONAL_REPLY 5 #define ILL_History_Report_cANCEL 6 #define ILL_History_Report_cANCEL_REPLY 7 #define ILL_History_Report_rECEIVED 8 #define ILL_History_Report_rECALL 9 #define ILL_History_Report_rETURNED 10 #define ILL_History_Report_cHECKED_IN 11 #define ILL_History_Report_rENEW_ANSWER 14 #define ILL_History_Report_lOST 15 #define ILL_History_Report_dAMAGED 16 #define ILL_History_Report_mESSAGE 17 #define ILL_History_Report_sTATUS_QUERY 18 #define ILL_History_Report_sTATUS_OR_ERROR_REPORT 19 #define ILL_History_Report_eXPIRED 20 Odr_int *most_recent_service; ILL_ISO_Date *date_of_most_recent_service; ILL_System_Id *initiator_of_most_recent_service; ILL_Shipped_Service_Type *shipped_service_type; /* OPT */ ILL_Transaction_Results *transaction_results; /* OPT */ ILL_String *most_recent_service_note; /* OPT */ }; struct ILL_Hold_Placed_Results { ILL_ISO_Date *estimated_date_available; ILL_Medium_Type *hold_placed_medium_type; /* OPT */ int num_locations; ILL_Location_Info **locations; /* OPT */ }; #define ILL_APDU_Type_iLL_REQUEST 1 #define ILL_APDU_Type_fORWARD_NOTIFICATION 2 #define ILL_APDU_Type_sHIPPED 3 #define ILL_APDU_Type_iLL_ANSWER 4 #define ILL_APDU_Type_cONDITIONAL_REPLY 5 #define ILL_APDU_Type_cANCEL 6 #define ILL_APDU_Type_cANCEL_REPLY 7 #define ILL_APDU_Type_rECEIVED 8 #define ILL_APDU_Type_rECALL 9 #define ILL_APDU_Type_rETURNED 10 #define ILL_APDU_Type_cHECKED_IN 11 #define ILL_APDU_Type_oVERDUE 12 #define ILL_APDU_Type_rENEW 13 #define ILL_APDU_Type_rENEW_ANSWER 14 #define ILL_APDU_Type_lOST 15 #define ILL_APDU_Type_dAMAGED 16 #define ILL_APDU_Type_mESSAGE 17 #define ILL_APDU_Type_sTATUS_QUERY 18 #define ILL_APDU_Type_sTATUS_OR_ERROR_REPORT 19 #define ILL_APDU_Type_eXPIRED 20 #define ILL_Service_Type_loan 1 #define ILL_Service_Type_copy_non_returnable 2 #define ILL_Service_Type_locations 3 #define ILL_Service_Type_estimate 4 #define ILL_Service_Type_responder_specific 5 struct ILL_String { int which; union { char *GeneralString; ILL_EDIFACTString *EDIFACTString; #define ILL_String_GeneralString 1 #define ILL_String_EDIFACTString 2 } u; }; #define ILL_Intermediary_Problem_cannot_send_onward 1 struct ILL_Item_Id { #define ILL_Item_Id_monograph 1 #define ILL_Item_Id_serial 2 #define ILL_Item_Id_other 3 Odr_int *item_type; /* OPT */ ILL_Medium_Type *held_medium_type; /* OPT */ ILL_String *call_number; /* OPT */ ILL_String *author; /* OPT */ ILL_String *title; /* OPT */ ILL_String *sub_title; /* OPT */ ILL_String *sponsoring_body; /* OPT */ ILL_String *place_of_publication; /* OPT */ ILL_String *publisher; /* OPT */ ILL_String *series_title_number; /* OPT */ ILL_String *volume_issue; /* OPT */ ILL_String *edition; /* OPT */ ILL_String *publication_date; /* OPT */ ILL_String *publication_date_of_component; /* OPT */ ILL_String *author_of_article; /* OPT */ ILL_String *title_of_article; /* OPT */ ILL_String *pagination; /* OPT */ Odr_external *national_bibliography_no; /* OPT */ ILL_String *iSBN; /* OPT */ ILL_String *iSSN; /* OPT */ Odr_external *system_no; /* OPT */ ILL_String *additional_no_letters; /* OPT */ ILL_String *verification_reference_source; /* OPT */ }; struct ILL_Location_Info { ILL_System_Id *location_id; ILL_System_Address *location_address; /* OPT */ ILL_String *location_note; /* OPT */ }; struct ILL_Locations_Results { ILL_Reason_Locs_Provided *reason_locs_provided; /* OPT */ int num_locations; ILL_Location_Info **locations; }; #define ILL_Medium_Type_printed 1 #define ILL_Medium_Type_microform 3 #define ILL_Medium_Type_film_or_video_recording 4 #define ILL_Medium_Type_audio_recording 5 #define ILL_Medium_Type_machine_readable 6 #define ILL_Medium_Type_other 7 struct ILL_Name_Of_Person_Or_Institution { int which; union { ILL_String *name_of_person; ILL_String *name_of_institution; #define ILL_Name_Of_Person_Or_Institution_name_of_person 1 #define ILL_Name_Of_Person_Or_Institution_name_of_institution 2 } u; }; struct ILL_Person_Or_Institution_Symbol { int which; union { ILL_String *person_symbol; ILL_String *institution_symbol; #define ILL_Person_Or_Institution_Symbol_person_symbol 1 #define ILL_Person_Or_Institution_Symbol_institution_symbol 2 } u; }; #define ILL_Place_On_Hold_Type_yes 1 #define ILL_Place_On_Hold_Type_no 2 #define ILL_Place_On_Hold_Type_according_to_responder_policy 3 struct ILL_Postal_Address { ILL_Name_Of_Person_Or_Institution *name_of_person_or_institution; /* OPT */ ILL_String *extended_postal_delivery_address; /* OPT */ ILL_String *street_and_number; /* OPT */ ILL_String *post_office_box; /* OPT */ ILL_String *city; /* OPT */ ILL_String *region; /* OPT */ ILL_String *country; /* OPT */ ILL_String *postal_code; /* OPT */ }; struct ILL_Provider_Error_Report { int which; union { ILL_General_Problem *general_problem; ILL_Transaction_Id_Problem *transaction_id_problem; ILL_State_Transition_Prohibited *state_transition_prohibited; #define ILL_Provider_Error_Report_general_problem 1 #define ILL_Provider_Error_Report_transaction_id_problem 2 #define ILL_Provider_Error_Report_state_transition_prohibited 3 } u; }; #define ILL_Reason_Locs_Provided_in_use_on_loan 1 #define ILL_Reason_Locs_Provided_in_process 2 #define ILL_Reason_Locs_Provided_lost 3 #define ILL_Reason_Locs_Provided_non_circulating 4 #define ILL_Reason_Locs_Provided_not_owned 5 #define ILL_Reason_Locs_Provided_on_order 6 #define ILL_Reason_Locs_Provided_volume_issue_not_yet_available 7 #define ILL_Reason_Locs_Provided_at_bindery 8 #define ILL_Reason_Locs_Provided_lacking 9 #define ILL_Reason_Locs_Provided_not_on_shelf 10 #define ILL_Reason_Locs_Provided_on_reserve 11 #define ILL_Reason_Locs_Provided_poor_condition 12 #define ILL_Reason_Locs_Provided_cost_exceeds_limit 13 #define ILL_Reason_Locs_Provided_on_hold 19 #define ILL_Reason_Locs_Provided_other 27 #define ILL_Reason_Locs_Provided_responder_specific 28 #define ILL_Reason_No_Report_temporary 1 #define ILL_Reason_No_Report_permanent 2 #define ILL_Reason_Unfilled_in_use_on_loan 1 #define ILL_Reason_Unfilled_in_process 2 #define ILL_Reason_Unfilled_lost 3 #define ILL_Reason_Unfilled_non_circulating 4 #define ILL_Reason_Unfilled_not_owned 5 #define ILL_Reason_Unfilled_on_order 6 #define ILL_Reason_Unfilled_volume_issue_not_yet_available 7 #define ILL_Reason_Unfilled_at_bindery 8 #define ILL_Reason_Unfilled_lacking 9 #define ILL_Reason_Unfilled_not_on_shelf 10 #define ILL_Reason_Unfilled_on_reserve 11 #define ILL_Reason_Unfilled_poor_condition 12 #define ILL_Reason_Unfilled_cost_exceeds_limit 13 #define ILL_Reason_Unfilled_charges 14 #define ILL_Reason_Unfilled_prepayment_required 15 #define ILL_Reason_Unfilled_lacks_copyright_compliance 16 #define ILL_Reason_Unfilled_not_found_as_cited 17 #define ILL_Reason_Unfilled_locations_not_found 18 #define ILL_Reason_Unfilled_on_hold 19 #define ILL_Reason_Unfilled_policy_problem 20 #define ILL_Reason_Unfilled_mandatory_messaging_not_supported 21 #define ILL_Reason_Unfilled_expiry_not_supported 22 #define ILL_Reason_Unfilled_requested_delivery_services_not_supported 23 #define ILL_Reason_Unfilled_preferred_delivery_time_not_possible 24 #define ILL_Reason_Unfilled_other 27 #define ILL_Reason_Unfilled_responder_specific 28 #define ILL_Report_Source_user 1 #define ILL_Report_Source_provider 2 struct ILL_Requester_Optional_Messages_Type { Odr_bool *can_send_RECEIVED; Odr_bool *can_send_RETURNED; #define ILL_Requester_Optional_Messages_Type_requires 1 #define ILL_Requester_Optional_Messages_Type_desires 2 #define ILL_Requester_Optional_Messages_Type_neither 3 Odr_int *requester_SHIPPED; #define ILL_Requester_Optional_Messages_Type_requires 1 #define ILL_Requester_Optional_Messages_Type_desires 2 #define ILL_Requester_Optional_Messages_Type_neither 3 Odr_int *requester_CHECKED_IN; }; struct ILL_Responder_Optional_Messages_Type { Odr_bool *can_send_SHIPPED; Odr_bool *can_send_CHECKED_IN; #define ILL_Responder_Optional_Messages_Type_requires 1 #define ILL_Responder_Optional_Messages_Type_desires 2 #define ILL_Responder_Optional_Messages_Type_neither 3 Odr_int *responder_RECEIVED; #define ILL_Responder_Optional_Messages_Type_requires 1 #define ILL_Responder_Optional_Messages_Type_desires 2 #define ILL_Responder_Optional_Messages_Type_neither 3 Odr_int *responder_RETURNED; }; struct ILL_Retry_Results { #define ILL_Retry_Results_in_use_on_loan 1 #define ILL_Retry_Results_in_process 2 #define ILL_Retry_Results_on_order 6 #define ILL_Retry_Results_volume_issue_not_yet_available 7 #define ILL_Retry_Results_at_bindery 8 #define ILL_Retry_Results_cost_exceeds_limit 13 #define ILL_Retry_Results_charges 14 #define ILL_Retry_Results_prepayment_required 15 #define ILL_Retry_Results_lacks_copyright_compliance 16 #define ILL_Retry_Results_not_found_as_cited 17 #define ILL_Retry_Results_on_hold 19 #define ILL_Retry_Results_other 27 #define ILL_Retry_Results_responder_specific 28 Odr_int *reason_not_available; /* OPT */ ILL_ISO_Date *retry_date; /* OPT */ int num_locations; ILL_Location_Info **locations; /* OPT */ }; struct ILL_Search_Type { ILL_String *level_of_service; /* OPT */ ILL_ISO_Date *need_before_date; /* OPT */ #define ILL_Search_Type_need_Before_Date 1 #define ILL_Search_Type_other_Date 2 #define ILL_Search_Type_no_Expiry 3 Odr_int *expiry_flag; ILL_ISO_Date *expiry_date; /* OPT */ }; struct ILL_Send_To_List_Type_s { ILL_System_Id *system_id; ILL_Account_Number *account_number; /* OPT */ ILL_System_Address *system_address; /* OPT */ }; struct ILL_Send_To_List_Type { int num; ILL_Send_To_List_Type_s **elements; }; struct ILL_Service_Date_this { ILL_ISO_Date *date; ILL_ISO_Time *time; /* OPT */ }; struct ILL_Service_Date_original { ILL_ISO_Date *date; ILL_ISO_Time *time; /* OPT */ }; struct ILL_Service_Date_Time { ILL_Service_Date_this *date_time_of_this_service; ILL_Service_Date_original *date_time_of_original_service; /* OPT */ }; struct ILL_State_Transition_Prohibited { ILL_APDU_Type *aPDU_type; ILL_Current_State *current_state; }; struct ILL_Status_Report { ILL_History_Report *user_status_report; ILL_Current_State *provider_status_report; }; struct ILL_Supplemental_Item_Description { int num; Odr_external **elements; }; struct ILL_Supply_Details { ILL_ISO_Date *date_shipped; /* OPT */ ILL_Date_Due *date_due; /* OPT */ Odr_int *chargeable_units; /* OPT */ ILL_Amount *cost; /* OPT */ #define ILL_Supply_Details_library_use_only 22 #define ILL_Supply_Details_no_reproduction 23 #define ILL_Supply_Details_client_signature_required 24 #define ILL_Supply_Details_special_collections_supervision_required 25 #define ILL_Supply_Details_other 27 Odr_int *shipped_conditions; /* OPT */ int which; union { ILL_Transportation_Mode *physical_delivery; ILL_Electronic_Delivery_Service *electronic_delivery; #define ILL_Supply_Details_physical_delivery 1 #define ILL_Supply_Details_electronic_delivery 2 } u; /* OPT */ ILL_Amount *insured_for; /* OPT */ ILL_Amount *return_insurance_require; /* OPT */ int num_no_of_units_per_medium; ILL_Units_Per_Medium_Type **no_of_units_per_medium; /* OPT */ }; struct ILL_Supply_Medium_Info_Type { ILL_Supply_Medium_Type *supply_medium_type; ILL_String *medium_characteristics; /* OPT */ }; #define ILL_Supply_Medium_Type_printed 1 #define ILL_Supply_Medium_Type_photocopy 2 #define ILL_Supply_Medium_Type_microform 3 #define ILL_Supply_Medium_Type_film_or_video_recording 4 #define ILL_Supply_Medium_Type_audio_recording 5 #define ILL_Supply_Medium_Type_machine_readable 6 #define ILL_Supply_Medium_Type_other 7 struct ILL_System_Address { ILL_String *telecom_service_identifier; /* OPT */ ILL_String *telecom_service_address; /* OPT */ }; struct ILL_System_Id { ILL_Person_Or_Institution_Symbol *person_or_institution_symbol; /* OPT */ ILL_Name_Of_Person_Or_Institution *name_of_person_or_institution; /* OPT */ }; struct ILL_Third_Party_Info_Type { Odr_bool *permission_to_forward; Odr_bool *permission_to_chain; Odr_bool *permission_to_partition; Odr_bool *permission_to_change_send_to_list; ILL_System_Address *initial_requester_address; /* OPT */ #define ILL_Third_Party_Info_Type_ordered 1 #define ILL_Third_Party_Info_Type_unordered 2 Odr_int *preference; ILL_Send_To_List_Type *send_to_list; /* OPT */ ILL_Already_Tried_List_Type *already_tried_list; /* OPT */ }; struct ILL_Transaction_Id { ILL_System_Id *initial_requester_id; /* OPT */ ILL_String *transaction_group_qualifier; ILL_String *transaction_qualifier; ILL_String *sub_transaction_qualifier; /* OPT */ }; #define ILL_Transaction_Id_Problem_duplicate_transaction_id 1 #define ILL_Transaction_Id_Problem_invalid_transaction_id 2 #define ILL_Transaction_Id_Problem_unknown_transaction_id 3 #define ILL_Transaction_Results_conditional 1 #define ILL_Transaction_Results_retry 2 #define ILL_Transaction_Results_unfilled 3 #define ILL_Transaction_Results_locations_provided 4 #define ILL_Transaction_Results_will_supply 5 #define ILL_Transaction_Results_hold_placed 6 #define ILL_Transaction_Results_estimate 7 #define ILL_Transaction_Type_simple 1 #define ILL_Transaction_Type_chained 2 #define ILL_Transaction_Type_partitioned 3 #define ILL_Unable_To_Perform_not_available 1 #define ILL_Unable_To_Perform_resource_limitation 2 #define ILL_Unable_To_Perform_other 3 struct ILL_Unfilled_Results { ILL_Reason_Unfilled *reason_unfilled; int num_locations; ILL_Location_Info **locations; /* OPT */ }; struct ILL_Units_Per_Medium_Type { ILL_Supply_Medium_Type *medium; Odr_int *no_of_units; }; struct ILL_User_Error_Report { int which; union { ILL_Already_Forwarded *already_forwarded; ILL_Intermediary_Problem *intermediary_problem; ILL_Security_Problem *security_problem; ILL_Unable_To_Perform *unable_to_perform; #define ILL_User_Error_Report_already_forwarded 1 #define ILL_User_Error_Report_intermediary_problem 2 #define ILL_User_Error_Report_security_problem 3 #define ILL_User_Error_Report_unable_to_perform 4 } u; }; struct ILL_Will_Supply_Results { #define ILL_Will_Supply_Results_in_use_on_loan 1 #define ILL_Will_Supply_Results_in_process 2 #define ILL_Will_Supply_Results_on_order 6 #define ILL_Will_Supply_Results_at_bindery 8 #define ILL_Will_Supply_Results_on_hold 19 #define ILL_Will_Supply_Results_being_processed_for_supply 26 #define ILL_Will_Supply_Results_other 27 #define ILL_Will_Supply_Results_responder_specific 28 #define ILL_Will_Supply_Results_electronic_delivery 30 Odr_int *reason_will_supply; ILL_ISO_Date *supply_date; /* OPT */ ILL_Postal_Address *return_to_address; /* OPT */ int num_locations; ILL_Location_Info **locations; /* OPT */ ILL_Electronic_Delivery_Service *electronic_delivery_service; /* OPT */ }; #ifdef __cplusplus } #endif #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif
c6d158525da22b88951543dbcbf1880e57031ba0
0f76e9f2c2f30ef14e4b8c67fe605cc19a26920d
/Include.win32/yaz/soap.h
feff818f44d0366c3ae14071de6eed4430060ea5
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
textbrowser/biblioteq
f9ef6f756059b010488f7b8c9f35285c88361f90
77ff19bec088b6f40321feab44f91ce25778bbea
refs/heads/master
2023-08-31T00:08:02.575660
2023-08-28T15:54:35
2023-08-28T15:54:35
31,837,087
199
51
NOASSERTION
2023-09-14T11:21:21
2015-03-08T03:33:27
C++
UTF-8
C
false
false
3,443
h
soap.h
/* This file is part of the YAZ toolkit. * Copyright (C) Index Data. * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Index Data nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * \file soap.h * \brief Header for SOAP */ #ifndef YAZ_SOAP_H #define YAZ_SOAP_H #include <yaz/odr.h> YAZ_BEGIN_CDECL typedef struct { char *fault_code; char *fault_string; char *details; } Z_SOAP_Fault; typedef struct { int no; char *ns; void *p; } Z_SOAP_Generic; #define Z_SOAP_fault 1 #define Z_SOAP_generic 2 #define Z_SOAP_error 3 typedef struct { int which; union { Z_SOAP_Fault *fault; Z_SOAP_Generic *generic; Z_SOAP_Fault *soap_error; } u; const char *ns; } Z_SOAP; typedef int (*Z_SOAP_fun)(ODR o, void * ptr, void **handler_data, void *client_data, const char *ns); typedef struct { char *ns; void *client_data; Z_SOAP_fun f; } Z_SOAP_Handler; YAZ_EXPORT int z_soap_codec(ODR o, Z_SOAP **pp, char **content_buf, int *content_len, Z_SOAP_Handler *handlers); YAZ_EXPORT int z_soap_codec_enc(ODR o, Z_SOAP **pp, char **content_buf, int *content_len, Z_SOAP_Handler *handlers, const char *encoding); YAZ_EXPORT int z_soap_codec_enc_xsl(ODR o, Z_SOAP **pp, char **content_buf, int *content_len, Z_SOAP_Handler *handlers, const char *encoding, const char *stylesheet); YAZ_EXPORT int z_soap_error(ODR o, Z_SOAP *p, const char *fault_code, const char *fault_string, const char *details); YAZ_END_CDECL #endif /* * Local variables: * c-basic-offset: 4 * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */
3507a75486f20809fe70737d1b9467d89313ec28
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/libavcodec/speexdata.h
476a8c11c6fcecf35062ed5fa9f601e624189257
[ "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later", "BSD-3-Clause", "LGPL-2.1-only", "LGPL-3.0-only", "GPL-2.0-only", "LGPL-2.1-or-later", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "GPL-2.0-or-later", "GPL-3.0-only" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
53,308
h
speexdata.h
/* * Copyright 2002-2008 Xiph.org Foundation * Copyright 2002-2008 Jean-Marc Valin * Copyright 2005-2007 Analog Devices Inc. * Copyright 2005-2008 Commonwealth Scientific and Industrial Research Organisation (CSIRO) * Copyright 1993, 2002, 2006 David Rowe * Copyright 2003 EpicGames * Copyright 1992-1994 Jutta Degener, Carsten Bormann * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - Neither the name of the Xiph.org Foundation nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef AVCODEC_SPEEXDATA_H #define AVCODEC_SPEEXDATA_H #include "libavutil/common.h" static const int8_t high_lsp_cdbk[512] = { 39, 12, -14, -20, -29, -61, -67, -76, -32, -71, -67, 68, 77, 46, 34, 5, -13, -48, -46, -72, -81, -84, -60, -58, -40, -28, 82, 93, 68, 45, 29, 3, -19, -47, -28, -43, -35, -30, -8, -13, -39, -91, -91, -123, -96, 10, 10, -6, -18, -55, -60, -91, -56, -36, -27, -16, -48, -75, 40, 28, -10, -28, 35, 9, 37, 19, 1, -20, -31, -41, -18, -25, -35, -68, -80, 45, 27, -1, 47, 13, 0, -29, -35, -57, -50, -79, -73, -38, -19, 5, 35, 14, -10, -23, 16, -8, 5, -24, -40, -62, -23, -27, -22, -16, -18, -46, -72, -77, 43, 21, 33, 1, -80, -70, -70, -64, -56, -52, -39, -33, -31, -38, -19, -19, -15, 32, 33, -2, 7, -15, -15, -24, -23, -33, -41, -56, -24, -57, 5, 89, 64, 41, 27, 5, -9, -47, -60, -97, -97, -124, -20, -9, -44, -73, 31, 29, -4, 64, 48, 7, -35, -57, 0, -3, -26, -47, -3, -6, -40, -76, -79, -48, 12, 81, 55, 10, 9, -24, -43, -73, -57, -69, 16, 5, -28, -53, 18, 29, 20, 0, -4, -11, 6, -13, 23, 7, -17, -35, -37, -37, -30, -68, -63, 6, 24, -9, -14, 3, 21, -13, -27, -57, -49, -80, -24, -41, -5, -16, -5, 1, 45, 25, 12, -7, 3, -15, -6, -16, -15, -8, 6, -13, -42, -81, -80, -87, 14, 1, -10, -3, -43, -69, -46, -24, -28, -29, 36, 6, -43, -56, -12, 12, 54, 79, 43, 9, 54, 22, 2, 8, -12, -43, -46, -52, -38, -69, -89, -5, 75, 38, 33, 5, -13, -53, -62, -87, -89, -113, -99, -55, -34, -37, 62, 55, 33, 16, 21, -2, -17, -46, -29, -38, -38, -48, -39, -42, -36, -75, -72, -88, -48, -30, 21, 2, -15, -57, -64, -98, -84, -76, 25, 1, -46, -80, -12, 18, -7, 3, 34, 6, 38, 31, 23, 4, -1, 20, 14, -15, -43, -78, -91, -24, 14, -3, 54, 16, 0, -27, -28, -44, -56, -83, -92, -89, -3, 34, 56, 41, 36, 22, 20, -8, -7, -35, -42, -62, -49, 3, 12, -10, -50, -87, -96, -66, 92, 70, 38, 9, -70, -71, -62, -42, -39, -43, -11, -7, -50, -79, -58, -50, -31, 32, 31, -6, -4, -25, 7, -17, -38, -70, -58, -27, -43, -83, -28, 59, 36, 20, 31, 2, -27, -71, -80, -109, -98, -75, -33, -32, -31, -2, 33, 15, -6, 43, 33, -5, 0, -22, -10, -27, -34, -49, -11, -20, -41, -91, -100, -121, -39, 57, 41, 10, -19, -50, -38, -59, -60, -70, -18, -20, -8, -31, -8, -15, 1, -14, -26, -25, 33, 21, 32, 17, 1, -19, -19, -26, -58, -81, -35, -22, 45, 30, 11, -11, 3, -26, -48, -87, -67, -83, -58, 3, -1, -26, -20, 44, 10, 25, 39, 5, -9, -35, -27, -38, 7, 10, 4, -9, -42, -85, -102, -127, 52, 44, 28, 10, -47, -61, -40, -39, -17, -1, -10, -33, -42, -74, -48, 21, -4, 70, 52, 10 }; static const int8_t high_lsp_cdbk2[512] = { -36, -62, 6, -9, -10, -14, -56, 23, 1, -26, 23, -48, -17, 12, 8, -7, 23, 29, -36, -28, -6, -29, -17, -5, 40, 23, 10, 10, -46, -13, 36, 6, 4, -30, -29, 62, 32, -32, -1, 22, -14, 1, -4, -22, -45, 2, 54, 4, -30, -57, -59, -12, 27, -3, -31, 8, -9, 5, 10, -14, 32, 66, 19, 9, 2, -25, -37, 23, -15, 18, -38, -31, 5, -9, -21, 15, 0, 22, 62, 30, 15, -12, -14, -46, 77, 21, 33, 3, 34, 29, -19, 50, 2, 11, 9, -38, -12, -37, 62, 1, -15, 54, 32, 6, 2, -24, 20, 35, -21, 2, 19, 24, -13, 55, 4, 9, 39, -19, 30, -1, -21, 73, 54, 33, 8, 18, 3, 15, 6, -19, -47, 6, -3, -48, -50, 1, 26, 20, 8, -23, -50, 65, -14, -55, -17, -31, -37, -28, 53, -1, -17, -53, 1, 57, 11, -8, -25, -30, -37, 64, 5, -52, -45, 15, 23, 31, 15, 14, -25, 24, 33, -2, -44, -56, -18, 6, -21, -43, 4, -12, 17, -37, 20, -10, 34, 15, 2, 15, 55, 21, -11, -31, -6, 46, 25, 16, -9, -25, -8, -62, 28, 17, 20, -32, -29, 26, 30, 25, -19, 2, -16, -17, 26, -51, 2, 50, 42, 19, -66, 23, 29, -2, 3, 19, -19, -37, 32, 15, 6, 30, -34, 13, 11, -5, 40, 31, 10, -42, 4, -9, 26, -9, -70, 17, -2, -23, 20, -22, -55, 51, -24, -31, 22, -22, 15, -13, 3, -10, -28, -16, 56, 4, -63, 11, -18, -15, -18, -38, -35, 16, -7, 34, -1, -21, -49, -47, 9, -37, 7, 8, 69, 55, 20, 6, -33, -45, -10, -9, 6, -9, 12, 71, 15, -3, -42, -7, -24, 32, -35, -2, -42, -17, -5, 0, -2, -33, -54, 13, -12, -34, 47, 23, 19, 55, 7, -8, 74, 31, 14, 16, -23, -26, 19, 12, -18, -49, -28, -31, -20, 2, -14, -20, -47, 78, 40, 13, -23, -11, 21, -6, 18, 1, 47, 5, 38, 35, 32, 46, 22, 8, 13, 16, -14, 18, 51, 19, 40, 39, 11, -26, -1, -17, 47, 2, -53, -15, 31, -22, 38, 21, -15, -16, 5, -33, 53, 15, -38, 86, 11, -3, -24, 49, 13, -4, -11, -18, 28, 20, -12, -27, -26, 35, -25, -35, -3, -20, -61, 30, 10, -55, -12, -22, -52, -54, -14, 19, -32, -12, 45, 15, -8, -48, -9, 11, -32, 8, -16, -34, -13, 51, 18, 38, -2, -32, -17, 22, -2, -18, -28, -70, 59, 27, -28, -19, -10, -20, -9, -9, -8, -21, 21, -8, 35, -2, 45, -3, -9, 12, 0, 30, 7, -39, 43, 27, -38, -91, 30, 26, 19, -55, -4, 63, 14, -17, 13, 9, 13, 2, 7, 4, 6, 61, 72, -1, -17, 29, -1, -22, -17, 8, -28, -37, 63, 44, 41, 3, 2, 14, 9, -6, 75, -8, -7, -12, -15, -12, 13, 9, -4, 30, -22, -65, 15, 0, -45, 4, -4, 1, 5, 22, 11, 23 }; static const int8_t exc_5_256_table[1280] = { -8, -37, 5, -43, 5, 73, 61, 39, 12, -3, -61, -32, 2, 42, 30, -3, 17, -27, 9, 34, 20, -1, -5, 2, 23, -7, -46, 26, 53, -47, 20, -2, -33, -89, -51, -64, 27, 11, 15, -34, -5, -56, 25, -9, -1, -29, 1, 40, 67, -23, -16, 16, 33, 19, 7, 14, 85, 22, -10, -10, -12, -7, -1, 52, 89, 29, 11, -20, -37, -46, -15, 17, -24, -28, 24, 2, 1, 0, 23, -101, 23, 14, -1, -23, -18, 9, 5, -13, 38, 1, -28, -28, 4, 27, 51, -26, 34, -40, 35, 47, 54, 38, -54, -26, -6, 42, -25, 13, -30, -36, 18, 41, -4, -33, 23, -32, -7, -4, 51, -3, 17, -52, 56, -47, 36, -2, -21, 36, 10, 8, -33, 31, 19, 9, -5, -40, 10, -9, -21, 19, 18, -78, -18, -5, 0, -26, -36, -47, -51, -44, 18, 40, 27, -2, 29, 49, -26, 2, 32, -54, 30, -73, 54, 3, -5, 36, 22, 53, 10, -1, -84, -53, -29, -5, 3, -44, 53, -51, 4, 22, 71, -35, -1, 33, -5, -27, -7, 36, 17, -23, -39, 16, -9, -55, -15, -20, 39, -35, 6, -39, -14, 18, 48, -64, -17, -15, 9, 39, 81, 37, -68, 37, 47, -21, -6, -104, 13, 6, 9, -2, 35, 8, -23, 18, 42, 45, 21, 33, -5, -49, 9, -6, -43, -56, 39, 2, -16, -25, 87, 1, -3, -9, 17, -25, -11, -9, -1, 10, 2, -14, -14, 4, -1, -10, 28, -23, 40, -32, 26, -9, 26, 4, -27, -23, 3, 42, -60, 1, 49, -3, 27, 10, -52, -40, -2, 18, 45, -23, 17, -44, 3, -3, 17, -46, 52, -40, -47, 25, 75, 31, -49, 53, 30, -30, -32, -36, 38, -6, -15, -16, 54, -27, -48, 3, 38, -29, -32, -22, -14, -4, -23, -13, 32, -39, 9, 8, -45, -13, 34, -16, 49, 40, 32, 31, 28, 23, 23, 32, 47, 59, -68, 8, 62, 44, 25, -14, -24, -65, -16, 36, 67, -25, -38, -21, 4, -33, -2, 42, 5, -63, 40, 11, 26, -42, -23, -61, 79, -31, 23, -20, 10, -32, 53, -25, -36, 10, -26, -5, 3, 0, -71, 5, -10, -37, 1, -24, 21, -54, -17, 1, -29, -25, -15, -27, 32, 68, 45, -16, -37, -18, -5, 1, 0, -77, 71, -6, 3, -20, 71, -67, 29, -35, 10, -30, 19, 4, 16, 17, 5, 0, -14, 19, 2, 28, 26, 59, 3, 2, 24, 39, 55, -50, -45, -18, -17, 33, -35, 14, -1, 1, 8, 87, -35, -29, 0, -27, 13, -7, 23, -13, 37, -40, 50, -35, 14, 19, -7, -14, 49, 54, -5, 22, -2, -29, -8, -27, 38, 13, 27, 48, 12, -41, -21, -15, 28, 7, -16, -24, -19, -20, 11, -20, 9, 2, 13, 23, -20, 11, 27, -27, 71, -69, 8, 2, -6, 22, 12, 16, 16, 9, -16, -8, -17, 1, 25, 1, 40, -37, -33, 66, 94, 53, 4, -22, -25, -41, -42, 25, 35, -16, -15, 57, 31, -29, -32, 21, 16, -60, 45, 15, -1, 7, 57, -26, -47, -29, 11, 8, 15, 19, -105, -8, 54, 27, 10, -17, 6, -12, -1, -10, 4, 0, 23, -10, 31, 13, 11, 10, 12, -64, 23, -3, -8, -19, 16, 52, 24, -40, 16, 10, 40, 5, 9, 0, -13, -7, -21, -8, -6, -7, -21, 59, 16, -53, 18, -60, 11, -47, 14, -18, 25, -13, -24, 4, -39, 16, -28, 54, 26, -67, 30, 27, -20, -52, 20, -12, 55, 12, 18, -16, 39, -14, -6, -26, 56, -88, -55, 12, 25, 26, -37, 6, 75, 0, -34, -81, 54, -30, 1, -7, 49, -23, -14, 21, 10, -62, -58, -57, -47, -34, 15, -4, 34, -78, 31, 25, -11, 7, 50, -10, 42, -63, 14, -36, -4, 57, 55, 57, 53, 42, -42, -1, 15, 40, 37, 15, 25, -11, 6, 1, 31, -2, -6, -1, -7, -64, 34, 28, 30, -1, 3, 21, 0, -88, -12, -56, 25, -28, 40, 8, -28, -14, 9, 12, 2, -6, -17, 22, 49, -6, -26, 14, 28, -20, 4, -12, 50, 35, 40, 13, -38, -58, -29, 17, 30, 22, 60, 26, -54, -39, -12, 58, -28, -63, 10, -21, -8, -12, 26, -62, 6, -10, -11, -22, -6, -7, 4, 1, 18, 2, -70, 11, 14, 4, 13, 19, -24, -34, 24, 67, 17, 51, -21, 13, 23, 54, -30, 48, 1, -13, 80, 26, -16, -2, 13, -4, 6, -30, 29, -24, 73, -58, 30, -27, 20, -2, -21, 41, 45, 30, -27, -3, -5, -18, -20, -49, -3, -35, 10, 42, -19, -67, -53, -11, 9, 13, -15, -33, -51, -30, 15, 7, 25, -30, 4, 28, -22, -34, 54, -29, 39, -46, 20, 16, 34, -4, 47, 75, 1, -44, -55, -24, 7, -1, 9, -42, 50, -8, -36, 41, 68, 0, -4, -10, -23, -15, -50, 64, 36, -9, -27, 12, 25, -38, -47, -37, 32, -49, 51, -36, 2, -4, 69, -26, 19, 7, 45, 67, 46, 13, -63, 46, 15, -47, 4, -41, 13, -6, 5, -21, 37, 26, -55, -7, 33, -1, -28, 10, -17, -64, -14, 0, -36, -17, 93, -3, -9, -66, 44, -21, 3, -12, 38, -6, -13, -12, 19, 13, 43, -43, -10, -12, 6, -5, 9, -49, 32, -5, 2, 4, 5, 15, -16, 10, -21, 8, -62, -8, 64, 8, 79, -1, -66, -49, -18, 5, 40, -5, -30, -45, 1, -6, 21, -32, 93, -18, -30, -21, 32, 21, -18, 22, 8, 5, -41, -54, 80, 22, -10, -7, -8, -23, -64, 66, 56, -14, -30, -41, -46, -14, -29, -37, 27, -14, 42, -2, -9, -29, 34, 14, 33, -14, 22, 4, 10, 26, 26, 28, 32, 23, -72, -32, 3, 0, -14, 35, -42, -78, -32, 6, 29, -18, -45, -5, 7, -33, -45, -3, -22, -34, 8, -8, 4, -51, -25, -9, 59, -78, 21, -5, -25, -48, 66, -15, -17, -24, -49, -13, 25, -23, -64, -6, 40, -24, -19, -11, 57, -33, -8, 1, 10, -52, -54, 28, 39, 49, 34, -11, -61, -41, -43, 10, 15, -15, 51, 30, 15, -51, 32, -34, -2, -34, 14, 18, 16, 1, 1, -3, -3, 1, 1, -18, 6, 16, 48, 12, -5, -42, 7, 36, 48, 7, -20, -10, 7, 12, 2, 54, 39, -38, 37, 54, 4, -11, -8, -46, -10, 5, -10, -34, 46, -12, 29, -37, 39, 36, -11, 24, 56, 17, 14, 20, 25, 0, -25, -28, 55, -7, -5, 27, 3, 9, -26, -8, 6, -24, -10, -30, -31, -34, 18, 4, 22, 21, 40, -1, -29, -37, -8, -21, 92, -29, 11, -3, 11, 73, 23, 22, 7, 4, -44, -9, -11, 21, -13, 11, 9, -78, -1, 47, 114, -12, -37, -19, -5, -11, -22, 19, 12, -30, 7, 38, 45, -21, -8, -9, 55, -45, 56, -21, 7, 17, 46, -57, -87, -6, 27, 31, 31, 7, -56, -12, 46, 21, -5, -12, 36, 3, 3, -21, 43, 19, 12, -7, 9, -14, 0, -9, -33, -91, 7, 26, 3, -11, 64, 83, -31, -46, 25, 2, 9, 5, 2, 2, -1, 20, -17, 10, -5, -27, -8, 20, 8, -19, 16, -21, -13, -31, 5, 5, 42, 24, 9, 34, -20, 28, -61, 22, 11, -39, 64, -20, -1, -30, -9, -20, 24, -25, -24, -29, 22, -60, 6, -5, 41, -9, -87, 14, 34, 15, -57, 52, 69, 15, -3, -102, 58, 16, 3, 6, 60, -75, -32, 26, 7, -57, -27, -32, -24, -21, -29, -16, 62, -46, 31, 30, -27, -15, 7, 15 }; static const int8_t exc_5_64_table[320] = { 1, 5, -15, 49, -66, -48, -4, 50, -44, 7, 37, 16, -18, 25, -26, -26, -15, 19, 19, -27, -47, 28, 57, 5, -17, -32, -41, 68, 21, -2, 64, 56, 8, -16, -13, -26, -9, -16, 11, 6, -39, 25, -19, 22, -31, 20, -45, 55, -43, 10, -16, 47, -40, 40, -20, -51, 3, -17, -14, -15, -24, 53, -20, -46, 46, 27, -68, 32, 3, -18, -5, 9, -31, 16, -9, -10, -1, -23, 48, 95, 47, 25, -41, -32, -3, 15, -25, -55, 36, 41, -27, 20, 5, 13, 14, -22, 5, 2, -23, 18, 46, -15, 17, -18, -34, -5, -8, 27, -55, 73, 16, 2, -1, -17, 40, -78, 33, 0, 2, 19, 4, 53, -16, -15, -16, -28, -3, -13, 49, 8, -7, -29, 27, -13, 32, 20, 32, -61, 16, 14, 41, 44, 40, 24, 20, 7, 4, 48, -60, -77, 17, -6, -48, 65, -15, 32, -30, -71, -10, -3, -6, 10, -2, -7, -29, -56, 67, -30, 7, -5, 86, -6, -10, 0, 5, -31, 60, 34, -38, -3, 24, 10, -2, 30, 23, 24, -41, 12, 70, -43, 15, -17, 6, 13, 16, -13, 8, 30, -15, -8, 5, 23, -34, -98, -4, -13, 13, -48, -31, 70, 12, 31, 25, 24, -24, 26, -7, 33, -16, 8, 5, -11, -14, -8, -65, 13, 10, -2, -9, 0, -3, -68, 5, 35, 7, 0, -31, -1, -17, -9, -9, 16, -37, -18, -1, 69, -48, -28, 22, -21, -11, 5, 49, 55, 23, -86, -36, 16, 2, 13, 63, -51, 30, -11, 13, 24, -18, -6, 14, -19, 1, 41, 9, -5, 27, -36, -44, -34, -37, -21, -26, 31, -39, 15, 43, 5, -8, 29, 20, -8, -20, -52, -28, -1, 13, 26, -34, -10, -9, 27, -8, 8, 27, -66, 4, 12, -22, 49, 10, -77, 32, -18, 3, -38, 12, -3, -1, 2, 2, 0 }; static const int8_t gain_cdbk_nb[512] = { -32, -32, -32, 0, -28, -67, -5, 33, -42, -6, -32, 18, -57, -10, -54, 35, -16, 27, -41, 42, 19, -19, -40, 36, -45, 24, -21, 40, -8, -14, -18, 28, 1, 14, -58, 53, -18, -88, -39, 39, -38, 21, -18, 37, -19, 20, -43, 38, 10, 17, -48, 54, -52, -58, -13, 33, -44, -1, -11, 32, -12, -11, -34, 22, 14, 0, -46, 46, -37, -35, -34, 5, -25, 44, -30, 43, 6, -4, -63, 49, -31, 43, -41, 43, -23, 30, -43, 41, -43, 26, -14, 44, -33, 1, -13, 27, -13, 18, -37, 37, -46, -73, -45, 34, -36, 24, -25, 34, -36, -11, -20, 19, -25, 12, -18, 33, -36, -69, -59, 34, -45, 6, 8, 46, -22, -14, -24, 18, -1, 13, -44, 44, -39, -48, -26, 15, -32, 31, -37, 34, -33, 15, -46, 31, -24, 30, -36, 37, -41, 31, -23, 41, -50, 22, -4, 50, -22, 2, -21, 28, -17, 30, -34, 40, -7, -60, -28, 29, -38, 42, -28, 42, -44, -11, 21, 43, -16, 8, -44, 34, -39, -55, -43, 21, -11, -35, 26, 41, -9, 0, -34, 29, -8, 121, -81, 113, 7, -16, -22, 33, -37, 33, -31, 36, -27, -7, -36, 17, -34, 70, -57, 65, -37, -11, -48, 21, -40, 17, -1, 44, -33, 6, -6, 33, -9, 0, -20, 34, -21, 69, -33, 57, -29, 33, -31, 35, -55, 12, -1, 49, -33, 27, -22, 35, -50, -33, -47, 17, -50, 54, 51, 94, -1, -5, -44, 35, -4, 22, -40, 45, -39, -66, -25, 24, -33, 1, -26, 20, -24, -23, -25, 12, -11, 21, -45, 44, -25, -45, -19, 17, -43, 105, -16, 82, 5, -21, 1, 41, -16, 11, -33, 30, -13, -99, -4, 57, -37, 33, -15, 44, -25, 37, -63, 54, -36, 24, -31, 31, -53, -56, -38, 26, -41, -4, 4, 37, -33, 13, -30, 24, 49, 52, -94, 114, -5, -30, -15, 23, 1, 38, -40, 56, -23, 12, -36, 29, -17, 40, -47, 51, -37, -41, -39, 11, -49, 34, 0, 58, -18, -7, -4, 34, -16, 17, -27, 35, 30, 5, -62, 65, 4, 48, -68, 76, -43, 11, -11, 38, -18, 19, -15, 41, -23, -62, -39, 23, -42, 10, -2, 41, -21, -13, -13, 25, -9, 13, -47, 42, -23, -62, -24, 24, -44, 60, -21, 58, -18, -3, -52, 32, -22, 22, -36, 34, -75, 57, 16, 90, -19, 3, 10, 45, -29, 23, -38, 32, -5, -62, -51, 38, -51, 40, -18, 53, -42, 13, -24, 32, -34, 14, -20, 30, -56, -75, -26, 37, -26, 32, 15, 59, -26, 17, -29, 29, -7, 28, -52, 53, -12, -30, 5, 30, -5, -48, -5, 35, 2, 2, -43, 40, 21, 16, 16, 75, -25, -45, -32, 10, -43, 18, -10, 42, 9, 0, -1, 52, -1, 7, -30, 36, 19, -48, -4, 48, -28, 25, -29, 32, -22, 0, -31, 22, -32, 17, -10, 36, -64, -41, -62, 36, -52, 15, 16, 58, -30, -22, -32, 6, -7, 9, -38, 36 }; static const int8_t exc_8_128_table[1024] = { -14, 9, 13, -32, 2, -10, 31, -10, -8, -8, 6, -4, -1, 10, -64, 23, 6, 20, 13, 6, 8, -22, 16, 34, 7, 42, -49, -28, 5, 26, 4, -15, 41, 34, 41, 32, 33, 24, 23, 14, 8, 40, 34, 4, -24, -41, -19, -15, 13, -13, 33, -54, 24, 27, -44, 33, 27, -15, -15, 24, -19, 14, -36, 14, -9, 24, -12, -4, 37, -5, 16, -34, 5, 10, 33, -15, -54, -16, 12, 25, 12, 1, 2, 0, 3, -1, -4, -4, 11, 2, -56, 54, 27, -20, 13, -6, -46, -41, -33, -11, -5, 7, 12, 14, -14, -5, 8, 20, 6, 3, 4, -8, -5, -42, 11, 8, -14, 25, -2, 2, 13, 11, -22, 39, -9, 9, 5, -45, -9, 7, -9, 12, -7, 34, -17, -102, 7, 2, -42, 18, 35, -9, -34, 11, -5, -2, 3, 22, 46, -52, -25, -9, -94, 8, 11, -5, -5, -5, 4, -7, -35, -7, 54, 5, -32, 3, 24, -9, -22, 8, 65, 37, -1, -12, -23, -6, -9, -28, 55, -33, 14, -3, 2, 18, -60, 41, -17, 8, -16, 17, -11, 0, -11, 29, -28, 37, 9, -53, 33, -14, -9, 7, -25, -7, -11, 26, -32, -8, 24, -21, 22, -19, 19, -10, 29, -14, 0, 0, 0, 0, 0, 0, 0, 0, -5, -52, 10, 41, 6, -30, -4, 16, 32, 22, -27, -22, 32, -3, -28, -3, 3, -35, 6, 17, 23, 21, 8, 2, 4, -45, -17, 14, 23, -4, -31, -11, -3, 14, 1, 19, -11, 2, 61, -8, 9, -12, 7, -10, 12, -3, -24, 99, -48, 23, 50, -37, -5, -23, 0, 8, -14, 35, -64, -5, 46, -25, 13, -1, -49, -19, -15, 9, 34, 50, 25, 11, -6, -9, -16, -20, -32, -33, -32, -27, 10, -8, 12, -15, 56, -14, -32, 33, 3, -9, 1, 65, -9, -9, -10, -2, -6, -23, 9, 17, 3, -28, 13, -32, 4, -2, -10, 4, -16, 76, 12, -52, 6, 13, 33, -6, 4, -14, -9, -3, 1, -15, -16, 28, 1, -15, 11, 16, 9, 4, -21, -37, -40, -6, 22, 12, -15, -23, -14, -17, -16, -9, -10, -9, 13, -39, 41, 5, -9, 16, -38, 25, 46, -47, 4, 49, -14, 17, -2, 6, 18, 5, -6, -33, -22, 44, 50, -2, 1, 3, -6, 7, 7, -3, -21, 38, -18, 34, -14, -41, 60, -13, 6, 16, -24, 35, 19, -13, -36, 24, 3, -17, -14, -10, 36, 44, -44, -29, -3, 3, -54, -8, 12, 55, 26, 4, -2, -5, 2, -11, 22, -23, 2, 22, 1, -25, -39, 66, -49, 21, -8, -2, 10, -14, -60, 25, 6, 10, 27, -25, 16, 5, -2, -9, 26, -13, -20, 58, -2, 7, 52, -9, 2, 5, -4, -15, 23, -1, -38, 23, 8, 27, -6, 0, -27, -7, 39, -10, -14, 26, 11, -45, -12, 9, -5, 34, 4, -35, 10, 43, -22, -11, 56, -7, 20, 1, 10, 1, -26, 9, 94, 11, -27, -14, -13, 1, -11, 0, 14, -5, -6, -10, -4, -15, -8, -41, 21, -5, 1, -28, -8, 22, -9, 33, -23, -4, -4, -12, 39, 4, -7, 3, -60, 80, 8, -17, 2, -6, 12, -5, 1, 9, 15, 27, 31, 30, 27, 23, 61, 47, 26, 10, -5, -8, -12, -13, 5, -18, 25, -15, -4, -15, -11, 12, -2, -2, -16, -2, -6, 24, 12, 11, -4, 9, 1, -9, 14, -45, 57, 12, 20, -35, 26, 11, -64, 32, -10, -10, 42, -4, -9, -16, 32, 24, 7, 10, 52, -11, -57, 29, 0, 8, 0, -6, 17, -17, -56, -40, 7, 20, 18, 12, -6, 16, 5, 7, -1, 9, 1, 10, 29, 12, 16, 13, -2, 23, 7, 9, -3, -4, -5, 18, -64, 13, 55, -25, 9, -9, 24, 14, -25, 15, -11, -40, -30, 37, 1, -19, 22, -5, -31, 13, -2, 0, 7, -4, 16, -67, 12, 66, -36, 24, -8, 18, -15, -23, 19, 0, -45, -7, 4, 3, -13, 13, 35, 5, 13, 33, 10, 27, 23, 0, -7, -11, 43, -74, 36, -12, 2, 5, -8, 6, -33, 11, -16, -14, -5, -7, -3, 17, -34, 27, -16, 11, -9, 15, 33, -31, 8, -16, 7, -6, -7, 63, -55, -17, 11, -1, 20, -46, 34, -30, 6, 9, 19, 28, -9, 5, -24, -8, -23, -2, 31, -19, -16, -5, -15, -18, 0, 26, 18, 37, -5, -15, -2, 17, 5, -27, 21, -33, 44, 12, -27, -9, 17, 11, 25, -21, -31, -7, 13, 33, -8, -25, -7, 7, -10, 4, -6, -9, 48, -82, -23, -8, 6, 11, -23, 3, -3, 49, -29, 25, 31, 4, 14, 16, 9, -4, -18, 10, -26, 3, 5, -44, -9, 9, -47, -55, 15, 9, 28, 1, 4, -3, 46, 6, -6, -38, -29, -31, -15, -6, 3, 0, 14, -6, 8, -54, -50, 33, -5, 1, -14, 33, -48, 26, -4, -5, -3, -5, -3, -5, -28, -22, 77, 55, -1, 2, 10, 10, -9, -14, -66, -49, 11, -36, -6, -20, 10, -10, 16, 12, 4, -1, -16, 45, -44, -50, 31, -2, 25, 42, 23, -32, -22, 0, 11, 20, -40, -35, -40, -36, -32, -26, -21, -13, 52, -22, 6, -24, -20, 17, -5, -8, 36, -25, -11, 21, -26, 6, 34, -8, 7, 20, -3, 5, -25, -8, 18, -5, -9, -4, 1, -9, 20, 20, 39, 48, -24, 9, 5, -65, 22, 29, 4, 3, -43, -11, 32, -6, 9, 19, -27, -10, -47, -14, 24, 10, -7, -36, -7, -1, -4, -5, -5, 16, 53, 25, -26, -29, -4, -12, 45, -58, -34, 33, -5, 2, -1, 27, -48, 31, -15, 22, -5, 4, 7, 7, -25, -3, 11, -22, 16, -12, 8, -3, 7, -11, 45, 14, -73, -19, 56, -46, 24, -20, 28, -12, -2, -1, -36, -3, -33, 19, -6, 7, 2, -15, 5, -31, -45, 8, 35, 13, 20, 0, -9, 48, -13, -43, -3, -13, 2, -5, 72, -68, -27, 2, 1, -2, -7, 5, 36, 33, -40, -12, -4, -5, 23, 19 }; static const int8_t exc_10_32_table[320] = { 7, 17, 17, 27, 25, 22, 12, 4, -3, 0, 28, -36, 39, -24, -15, 3, -9, 15, -5, 10, 31, -28, 11, 31, -21, 9, -11, -11, -2, -7, -25, 14, -22, 31, 4, -14, 19, -12, 14, -5, 4, -7, 4, -5, 9, 0, -2, 42, -47, -16, 1, 8, 0, 9, 23, -57, 0, 28, -11, 6, -31, 55, -45, 3, -5, 4, 2, -2, 4, -7, -3, 6, -2, 7, -3, 12, 5, 8, 54, -10, 8, -7, -8, -24, -25, -27, -14, -5, 8, 5, 44, 23, 5, -9, -11, -11, -13, -9, -12, -8, -29, -8, -22, 6, -15, 3, -12, -1, -5, -3, 34, -1, 29, -16, 17, -4, 12, 2, 1, 4, -2, -4, 2, -1, 11, -3, -52, 28, 30, -9, -32, 25, 44, -20, -24, 4, 6, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -25, -10, 22, 29, 13, -13, -22, -13, -4, 0, -4, -16, 10, 15, -36, -24, 28, 25, -1, -3, 66, -33, -11, -15, 6, 0, 3, 4, -2, 5, 24, -20, -47, 29, 19, -2, -4, -1, 0, -1, -2, 3, 1, 8, -11, 5, 5, -57, 28, 28, 0, -16, 4, -4, 12, -6, -1, 2, -20, 61, -9, 24, -22, -42, 29, 6, 17, 8, 4, 2, -65, 15, 8, 10, 5, 6, 5, 3, 2, -2, -3, 5, -9, 4, -5, 23, 13, 23, -3, -63, 3, -5, -4, -6, 0, -3, 23, -36, -46, 9, 5, 5, 8, 4, 9, -5, 1, -3, 10, 1, -6, 10, -11, 24, -47, 31, 22, -12, 14, -10, 6, 11, -7, -7, 7, -31, 51, -12, -6, 7, 6, -17, 9, -11, -20, 52, -19, 3, -6, -6, -8, -5, 23, -41, 37, 1, -21, 10, -14, 8, 7, 5, -15, -15, 23, 39, -26, -33, 7, 2, -32, -30, -21, -8, 4, 12, 17, 15, 14, 11 }; static const int8_t exc_10_16_table[160] = { 22, 39, 14, 44, 11, 35, -2, 23, -4, 6, 46, -28, 13, -27, -23, 12, 4, 20, -5, 9, 37, -18, -23, 23, 0, 9, -6, -20, 4, -1, -17, -5, -4, 17, 0, 1, 9, -2, 1, 2, 2, -12, 8, -25, 39, 15, 9, 16, -55, -11, 9, 11, 5, 10, -2, -60, 8, 13, -6, 11, -16, 27, -47, -12, 11, 1, 16, -7, 9, -3, -29, 9, -14, 25, -19, 34, 36, 12, 40, -10, -3, -24, -14, -37, -21, -35, -2, -36, 3, -6, 67, 28, 6, -17, -3, -12, -16, -15, -17, -7, -59, -36, -13, 1, 7, 1, 2, 10, 2, 11, 13, 10, 8, -2, 7, 3, 5, 4, 2, 2, -3, -8, 4, -5, 6, 7, -42, 15, 35, -2, -46, 38, 28, -20, -9, 1, 7, -3, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, -28, 52, 32, 5, -5, -17, -20, -10, -1 }; static const int8_t gain_cdbk_lbr[128] = { -32, -32, -32, 0, -31, -58, -16, 22, -41, -24, -43, 14, -56, -22, -55, 29, -13, 33, -41, 47, -4, -39, -9, 29, -41, 15, -12, 38, -8, -15, -12, 31, 1, 2, -44, 40, -22, -66, -42, 27, -38, 28, -23, 38, -21, 14, -37, 31, 0, 21, -50, 52, -53, -71, -27, 33, -37, -1, -19, 25, -19, -5, -28, 22, 6, 65, -44, 74, -33, -48, -33, 9, -40, 57, -14, 58, -17, 4, -45, 32, -31, 38, -33, 36, -23, 28, -40, 39, -43, 29, -12, 46, -34, 13, -23, 28, -16, 15, -27, 34, -14, -82, -15, 43, -31, 25, -32, 29, -21, 5, -5, 38, -47, -63, -51, 33, -46, 12, 3, 47, -28, -17, -29, 11, -10, 14, -40, 38 }; static const int8_t exc_20_32_table[640] = { 12, 32, 25, 46, 36, 33, 9, 14, -3, 6, 1, -8, 0, -10, -5, -7, -7, -7, -5, -5, 31, -27, 24, -32, -4, 10, -11, 21, -3, 19, 23, -9, 22, 24, -10, -1, -10, -13, -7, -11, 42, -33, 31, 19, -8, 0, -10, -16, 1, -21, -17, 10, -8, 14, 8, 4, 11, -2, 5, -2, -33, 11, -16, 33, 11, -4, 9, -4, 11, 2, 6, -5, 8, -5, 11, -4, -6, 26, -36, -16, 0, 4, -2, -8, 12, 6, -1, 34, -46, -22, 9, 9, 21, 9, 5, -66, -5, 26, 2, 10, 13, 2, 19, 9, 12, -81, 3, 13, 13, 0, -14, 22, -35, 6, -7, -4, 6, -6, 10, -6, -31, 38, -33, 0, -10, -11, 5, -12, 12, -17, 5, 0, -6, 13, -9, 10, 8, 25, 33, 2, -12, 8, -6, 10, -2, 21, 7, 17, 43, 5, 11, -7, -9, -20, -36, -20, -23, -4, -4, -3, 27, -9, -9, -49, -39, -38, -11, -9, 6, 5, 23, 25, 5, 3, 3, 4, 1, 2, -3, -1, 87, 39, 17, -21, -9, -19, -9, -15, -13, -14, -17, -11, -10, -11, -8, -6, -1, -3, -3, -1, -54, -34, -27, -8, -11, -4, -5, 0, 0, 4, 8, 6, 9, 7, 9, 7, 6, 5, 5, 5, 48, 10, 19, -10, 12, -1, 9, -3, 2, 5, -3, 2, -2, -2, 0, -2, -26, 6, 9, -7, -16, -9, 2, 7, 7, -5, -43, 11, 22, -11, -9, 34, 37, -15, -13, -6, 1, -1, 1, 1, -64, 56, 52, -11, -27, 5, 4, 3, 1, 2, 1, 3, -1, -4, -4, -10, -7, -4, -4, 2, -1, -7, -7, -12, -10, -15, -9, -5, -5, -11, -16, -13, 6, 16, 4, -13, -16, -10, -4, 2, -47, -13, 25, 47, 19, -14, -20, -8, -17, 0, -3, -13, 1, 6, -17, -14, 15, 1, 10, 6, -24, 0, -10, 19, -69, -8, 14, 49, 17, -5, 33, -29, 3, -4, 0, 2, -8, 5, -6, 2, 120, -56, -12, -47, 23, -9, 6, -5, 1, 2, -5, 1, -10, 4, -1, -1, 4, -1, 0, -3, 30, -52, -67, 30, 22, 11, -1, -4, 3, 0, 7, 2, 0, 1, -10, -4, -8, -13, 5, 1, 1, -1, 5, 13, -9, -3, -10, -62, 22, 48, -4, -6, 2, 3, 5, 1, 1, 4, 1, 13, 3, -20, 10, -9, 13, -2, -4, 9, -20, 44, -1, 20, -32, -67, 19, 0, 28, 11, 8, 2, -11, 15, -19, -53, 31, 2, 34, 10, 6, -4, -58, 8, 10, 13, 14, 1, 12, 2, 0, 0, -128, 37, -8, 44, -9, 26, -3, 18, 2, 6, 11, -1, 9, 1, 5, 3, 0, 1, 1, 2, 12, 3, -2, -3, 7, 25, 9, 18, -6, -37, 3, -8, -16, 3, -10, -7, 17, -34, -44, 11, 17, -15, -3, -16, -1, -13, 11, -46, -65, -2, 8, 13, 2, 4, 4, 5, 15, 5, 9, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 19, -12, 12, -28, 38, 29, -1, 12, 2, 5, 23, -10, 3, 4, -15, 21, -4, 3, 3, 6, 17, -9, -4, -8, -20, 26, 5, -10, 6, 1, -19, 18, -15, -12, 47, -6, -2, -7, -9, -1, -17, -2, -2, -14, 30, -14, 2, -7, -4, -1, -12, 11, -25, 16, -3, -12, 11, -7, 7, -17, 1, 19, -28, 31, -7, -10, 7, -10, 3, 12, 5, -16, 6, 24, 41, -29, -54, 0, 1, 7, -1, 5, -6, 13, 10, -4, -8, 8, -9, -27, -53, -38, -1, 10, 19, 17, 16, 12, 12, 0, 3, -7, -4, 13, 12, -31, -14, 6, -5, 3, 5, 17, 43, 50, 25, 10, 1, -6, -2 }; static const int8_t cdbk_nb[640] = { 30, 19, 38, 34, 40, 32, 46, 43, 58, 43, 5, -18, -25, -40, -33, -55, -52, 20, 34, 28, -20, -63, -97, -92, 61, 53, 47, 49, 53, 75, -14, -53, -77, -79, 0, -3, -5, 19, 22, 26, -9, -53, -55, 66, 90, 72, 85, 68, 74, 52, -4, -41, -58, -31, -18, -31, 27, 32, 30, 18, 24, 3, 8, 5, -12, -3, 26, 28, 74, 63, -2, -39, -67, -77, -106, -74, 59, 59, 73, 65, 44, 40, 71, 72, 82, 83, 98, 88, 89, 60, -6, -31, -47, -48, -13, -39, -9, 7, 2, 79, -1, -39, -60, -17, 87, 81, 65, 50, 45, 19, -21, -67, -91, -87, -41, -50, 7, 18, 39, 74, 10, -31, -28, 39, 24, 13, 23, 5, 56, 45, 29, 10, -5, -13, -11, -35, -18, -8, -10, -8, -25, -71, -77, -21, 2, 16, 50, 63, 87, 87, 5, -32, -40, -51, -68, 0, 12, 6, 54, 34, 5, -12, 32, 52, 68, 64, 69, 59, 65, 45, 14, -16, -31, -40, -65, -67, 41, 49, 47, 37, -11, -52, -75, -84, -4, 57, 48, 42, 42, 33, -11, -51, -68, -6, 13, 0, 8, -8, 26, 32, -23, -53, 0, 36, 56, 76, 97, 105, 111, 97, -1, -28, -39, -40, -43, -54, -44, -40, -18, 35, 16, -20, -19, -28, -42, 29, 47, 38, 74, 45, 3, -29, -48, -62, -80, -104, -33, 56, 59, 59, 10, 17, 46, 72, 84, 101, 117, 123, 123, 106, -7, -33, -49, -51, -70, -67, -27, -31, 70, 67, -16, -62, -85, -20, 82, 71, 86, 80, 85, 74, -19, -58, -75, -45, -29, -33, -18, -25, 45, 57, -12, -42, -5, 12, 28, 36, 52, 64, 81, 82, 13, -9, -27, -28, 22, 3, 2, 22, 26, 6, -6, -44, -51, 2, 15, 10, 48, 43, 49, 34, -19, -62, -84, -89, -102, -24, 8, 17, 61, 68, 39, 24, 23, 19, 16, -5, 12, 15, 27, 15, -8, -44, -49, -60, -18, -32, -28, 52, 54, 62, -8, -48, -77, -70, 66, 101, 83, 63, 61, 37, -12, -50, -75, -64, 33, 17, 13, 25, 15, 77, 1, -42, -29, 72, 64, 46, 49, 31, 61, 44, -8, -47, -54, -46, -30, 19, 20, -1, -16, 0, 16, -12, -18, -9, -26, -27, -10, -22, 53, 45, -10, -47, -75, -82, -105, -109, 8, 25, 49, 77, 50, 65, 114, 117, 124, 118, 115, 96, 90, 61, -9, -45, -63, -60, -75, -57, 8, 11, 20, 29, 0, -35, -49, -43, 40, 47, 35, 40, 55, 38, -24, -76, -103, -112, -27, 3, 23, 34, 52, 75, 8, -29, -43, 12, 63, 38, 35, 29, 24, 8, 25, 11, 1, -15, -18, -43, -7, 37, 40, 21, -20, -56, -19, -19, -4, -2, 11, 29, 51, 63, -2, -44, -62, -75, -89, 30, 57, 51, 74, 51, 50, 46, 68, 64, 65, 52, 63, 55, 65, 43, 18, -9, -26, -35, -55, -69, 3, 6, 8, 17, -15, -61, -86, -97, 1, 86, 93, 74, 78, 67, -1, -38, -66, -48, 48, 39, 29, 25, 17, -1, 13, 13, 29, 39, 50, 51, 69, 82, 97, 98, -2, -36, -46, -27, -16, -30, -13, -4, -7, -4, 25, -5, -11, -6, -25, -21, 33, 12, 31, 29, -8, -38, -52, -63, -68, -89, -33, -1, 10, 74, -2, -15, 59, 91, 105, 105, 101, 87, 84, 62, -7, -33, -50, -35, -54, -47, 25, 17, 82, 81, -13, -56, -83, 21, 58, 31, 42, 25, 72, 65, -24, -66, -91, -56, 9, -2, 21, 10, 69, 75, 2, -24, 11, 22, 25, 28, 38, 34, 48, 33, 7, -29, -26, 17, 15, -1, 14, 0, -2, 0, -6, -41, -67, 6, -2, -9, 19, 2, 85, 74, -22, -67, -84, -71, -50, 3, 11, -9, 2, 62 }; static const int8_t cdbk_nb_low1[320] = { -34, -52, -15, 45, 2, 23, 21, 52, 24, -33, -9, -1, 9, -44, -41, -13, -17, 44, 22, -17, -6, -4, -1, 22, 38, 26, 16, 2, 50, 27, -35, -34, -9, -41, 6, 0, -16, -34, 51, 8, -14, -31, -49, 15, -33, 45, 49, 33, -11, -37, -62, -54, 45, 11, -5, -72, 11, -1, -12, -11, 24, 27, -11, -43, 46, 43, 33, -12, -9, -1, 1, -4, -23, -57, -71, 11, 8, 16, 17, -8, -20, -31, -41, 53, 48, -16, 3, 65, -24, -8, -23, -32, -37, -32, -49, -10, -17, 6, 38, 5, -9, -17, -46, 8, 52, 3, 6, 45, 40, 39, -7, -6, -34, -74, 31, 8, 1, -16, 43, 68, -11, -19, -31, 4, 6, 0, -6, -17, -16, -38, -16, -30, 2, 9, -39, -16, -1, 43, -10, 48, 3, 3, -16, -31, -3, 62, 68, 43, 13, 3, -10, 8, 20, -56, 12, 12, -2, -18, 22, -15, -40, -36, 1, 7, 41, 0, 1, 46, -6, -62, -4, -12, -2, -11, -83, -13, -2, 91, 33, -10, 0, 4, -11, -16, 79, 32, 37, 14, 9, 51, -21, -28, -56, -34, 0, 21, 9, -26, 11, 28, -42, -54, -23, -2, -15, 31, 30, 8, -39, -66, -39, -36, 31, -28, -40, -46, 35, 40, 22, 24, 33, 48, 23, -34, 14, 40, 32, 17, 27, -3, 25, 26, -13, -61, -17, 11, 4, 31, 60, -6, -26, -41, -64, 13, 16, -26, 54, 31, -11, -23, -9, -11, -34, -71, -21, -34, -35, 55, 50, 29, -22, -27, -50, -38, 57, 33, 42, 57, 48, 26, 11, 0, -49, -31, 26, -4, -14, 5, 78, 37, 17, 0, -49, -12, -23, 26, 14, 2, 2, -43, -17, -12, 10, -8, -4, 8, 18, 12, -6, 20, -12, -6, -13, -25, 34, 15, 40, 49, 7, 8, 13, 20, 20, -19, -22, -2, -8, 2, 51, -51 }; static const int8_t cdbk_nb_low2[320] = { -6, 53, -21, -24, 4, 26, 17, -4, -37, 25, 17, -36, -13, 31, 3, -6, 27, 15, -10, 31, 28, 26, -10, -10, -40, 16, -7, 15, 13, 41, -9, 0, -4, 50, -6, -7, 14, 38, 22, 0, -48, 2, 1, -13, -19, 32, -3, -60, 11, -17, -1, -24, -34, -1, 35, -5, -27, 28, 44, 13, 25, 15, 42, -11, 15, 51, 35, -36, 20, 8, -4, -12, -29, 19, -47, 49, -15, -4, 16, -29, -39, 14, -30, 4, 25, -9, -5, -51, -14, -3, -40, -32, 38, 5, -9, -8, -4, -1, -22, 71, -3, 14, 26, -18, -22, 24, -41, -25, -24, 6, 23, 19, -10, 39, -26, -27, 65, 45, 2, -7, -26, -8, 22, -12, 16, 15, 16, -35, -5, 33, -21, -8, 0, 23, 33, 34, 6, 21, 36, 6, -7, -22, 8, -37, -14, 31, 38, 11, -4, -3, -39, -32, -8, 32, -23, -6, -12, 16, 20, -28, -4, 23, 13, -52, -1, 22, 6, -33, -40, -6, 4, -62, 13, 5, -26, 35, 39, 11, 2, 57, -11, 9, -20, -28, -33, 52, -5, -6, -2, 22, -14, -16, -48, 35, 1, -58, 20, 13, 33, -1, -74, 56, -18, -22, -31, 12, 6, -14, 4, -2, -9, -47, 10, -3, 29, -17, -5, 61, 14, 47, -12, 2, 72, -39, -17, 92, 64, -53, -51, -15, -30, -38, -41, -29, -28, 27, 9, 36, 9, -35, -42, 81, -21, 20, 25, -16, -5, -17, -35, 21, 15, -28, 48, 2, -2, 9, -19, 29, -40, 30, -18, -18, 18, -16, -57, 15, -20, -12, -15, -37, -15, 33, -39, 21, -22, -13, 35, 11, 13, -38, -63, 29, 23, -27, 32, 18, 3, -26, 42, 33, -64, -66, -17, 16, 56, 2, 36, 3, 31, 21, -41, -39, 8, -57, 14, 37, -2, 19, -36, -19, -23, -29, -16, 1, -3, -8, -10, 31, 64, -65 }; static const int8_t cdbk_nb_high1[320] = { -26, -8, 29, 21, 4, 19, -39, 33, -7, -36, 56, 54, 48, 40, 29, -4, -24, -42, -66, -43, -60, 19, -2, 37, 41, -10, -37, -60, -64, 18, -22, 77, 73, 40, 25, 4, 19, -19, -66, -2, 11, 5, 21, 14, 26, -25, -86, -4, 18, 1, 26, -37, 10, 37, -1, 24, -12, -59, -11, 20, -6, 34, -16, -16, 42, 19, -28, -51, 53, 32, 4, 10, 62, 21, -12, -34, 27, 4, -48, -48, -50, -49, 31, -7, -21, -42, -25, -4, -43, -22, 59, 2, 27, 12, -9, -6, -16, -8, -32, -58, -16, -29, -5, 41, 23, -30, -33, -46, -13, -10, -38, 52, 52, 1, -17, -9, 10, 26, -25, -6, 33, -20, 53, 55, 25, -32, -5, -42, 23, 21, 66, 5, -28, 20, 9, 75, 29, -7, -42, -39, 15, 3, -23, 21, 6, 11, 1, -29, 14, 63, 10, 54, 26, -24, -51, -49, 7, -23, -51, 15, -66, 1, 60, 25, 10, 0, -30, -4, -15, 17, 19, 59, 40, 4, -5, 33, 6, -22, -58, -70, -5, 23, -6, 60, 44, -29, -16, -47, -29, 52, -19, 50, 28, 16, 35, 31, 36, 0, -21, 6, 21, 27, 22, 42, 7, -66, -40, -8, 7, 19, 46, 0, -4, 60, 36, 45, -7, -29, -6, -32, -39, 2, 6, -9, 33, 20, -51, -34, 18, -6, 19, 6, 11, 5, -19, -29, -2, 42, -11, -45, -21, -55, 57, 37, 2, -14, -67, -16, -27, -38, 69, 48, 19, 2, -17, 20, -20, -16, -34, -17, -25, -61, 10, 73, 45, 16, -40, -64, -17, -29, -22, 56, 17, -39, 8, -11, 8, -25, -18, -13, -19, 8, 54, 57, 36, -17, -26, -4, 6, -21, 40, 42, -4, 20, 31, 53, 10, -34, -53, 31, -17, 35, 0, 15, -6, -20, -63, -73, 22, 25, 29, 17, 8, -29, -39, -69, 18, 15, -15, -5 }; static const int8_t cdbk_nb_high2[320] = { 11, 47, 16, -9, -46, -32, 26, -64, 34, -5, 38, -7, 47, 20, 2, -73, -99, -3, -45, 20, 70, -52, 15, -6, -7, -82, 31, 21, 47, 51, 39, -3, 9, 0, -41, -7, -15, -54, 2, 0, 27, -31, 9, -45, -22, -38, -24, -24, 8, -33, 23, 5, 50, -36, -17, -18, -51, -2, 13, 19, 43, 12, -15, -12, 61, 38, 38, 7, 13, 0, 6, -1, 3, 62, 9, 27, 22, -33, 38, -35, -9, 30, -43, -9, -32, -1, 4, -4, 1, -5, -11, -8, 38, 31, 11, -10, -42, -21, -37, 1, 43, 15, -13, -35, -19, -18, 15, 23, -26, 59, 1, -21, 53, 8, -41, -50, -14, -28, 4, 21, 25, -28, -40, 5, -40, -41, 4, 51, -33, -8, -8, 1, 17, -60, 12, 25, -41, 17, 34, 43, 19, 45, 7, -37, 24, -15, 56, -2, 35, -10, 48, 4, -47, -2, 5, -5, -54, 5, -3, -33, -10, 30, -2, -44, -24, -38, 9, -9, 42, 4, 6, -56, 44, -16, 9, -40, -26, 18, -20, 10, 28, -41, -21, -4, 13, -18, 32, -30, -3, 37, 15, 22, 28, 50, -40, 3, -29, -64, 7, 51, -19, -11, 17, -27, -40, -64, 24, -12, -7, -27, 3, 37, 48, -1, 2, -9, -38, -34, 46, 1, 27, -6, 19, -13, 26, 10, 34, 20, 25, 40, 50, -6, -7, 30, 9, -24, 0, -23, 71, -61, 22, 58, -34, -4, 2, -49, -33, 25, 30, -8, -6, -16, 77, 2, 38, -8, -35, -6, -30, 56, 78, 31, 33, -20, 13, -39, 20, 22, 4, 21, -8, 4, -6, 10, -83, -41, 9, -25, -43, 15, -7, -12, -34, -39, -37, -33, 19, 30, 16, -33, 42, -25, 25, -68, 44, -15, -11, -4, 23, 50, 14, 4, -39, -43, 20, -30, 60, 9, -20, 7, 16, 19, -33, 37, 29, 16, -35, 7, 38, -27 }; static const int8_t hexc_table[1024] = { -24, 21, -20, 5, -5, -7, 14, -10, 2, -27, 16, -20, 0, -32, 26, 19, 8, -11, -41, 31, 28, -27, -32, 34, 42, 34, -17, 22, -10, 13, -29, 18, -12, -26, -24, 11, 22, 5, -5, -5, 54, -68, -43, 57, -25, 24, 4, 4, 26, -8, -12, -17, 54, 30, -45, 1, 10, -15, 18, -41, 11, 68, -67, 37, -16, -24, -16, 38, -22, 6, -29, 30, 66, -27, 5, 7, -16, 13, 2, -12, -7, -3, -20, 36, 4, -28, 9, 3, 32, 48, 26, 39, 3, 0, 7, -21, -13, 5, -82, -7, 73, -20, 34, -9, -5, 1, -1, 10, -5, -10, -1, 9, 1, -9, 10, 0, -14, 11, -1, -2, -1, 11, 20, 96, -81, -22, -12, -9, -58, 9, 24, -30, 26, -35, 27, -12, 13, -18, 56, -59, 15, -7, 23, -15, -1, 6, -25, 14, -22, -20, 47, -11, 16, 2, 38, -23, -19, -30, -9, 40, -11, 5, 4, -6, 8, 26, -21, -11, 127, 4, 1, 6, -9, 2, -7, -2, -3, 7, -5, 10, -19, 7, -106, 91, -3, 9, -4, 21, -8, 26, -80, 8, 1, -2, -10, -17, -17, -27, 32, 71, 6, -29, 11, -23, 54, -38, 29, -22, 39, 87, -31, -12, -20, 3, -2, -2, 2, 20, 0, -1, -35, 27, 9, -6, -12, 3, -12, -6, 13, 1, 14, -22, -59, -15, -17, -25, 13, -7, 7, 3, 0, 1, -7, 6, -3, 61, -37, -23, -23, -29, 38, -31, 27, 1, -8, 2, -27, 23, -26, 36, -34, 5, 24, -24, -6, 7, 3, -59, 78, -62, 44, -16, 1, 6, 0, 17, 8, 45, 0, -110, 6, 14, -2, 32, -77, -56, 62, -3, 3, -13, 4, -16, 102, -15, -36, -1, 9, -113, 6, 23, 0, 9, 9, 5, -8, -1, -14, 5, -12, 121, -53, -27, -8, -9, 22, -13, 3, 2, -3, 1, -2, -71, 95, 38, -19, 15, -16, -5, 71, 10, 2, -32, -13, -5, 15, -1, -2, -14, -85, 30, 29, 6, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, -65, -56, -9, 18, 18, 23, -14, -2, 0, 12, -29, 26, -12, 1, 2, -12, -64, 90, -6, 4, 1, 5, -5, -110, -3, -31, 22, -29, 9, 0, 8, -40, -5, 21, -5, -5, 13, 10, -18, 40, 1, 35, -20, 30, -28, 11, -6, 19, 7, 14, 18, -64, 9, -6, 16, 51, 68, 8, 16, 12, -8, 0, -9, 20, -22, 25, 7, -4, -13, 41, -35, 93, -18, -54, 11, -1, 1, -9, 4, -66, 66, -31, 20, -22, 25, -23, 11, 10, 9, 19, 15, 11, -5, -31, -10, -23, -28, -6, -6, -3, -4, 5, 3, -28, 22, -11, -42, 25, -25, -16, 41, 34, 47, -6, 2, 42, -19, -22, 5, -39, 32, 6, -35, 22, 17, -30, 8, -26, -11, -11, 3, -12, 33, 33, -37, 21, -1, 6, -4, 3, 0, -5, 5, 12, -12, 57, 27, -61, -3, 20, -17, 2, 0, 4, 0, -2, -33, -58, 81, -23, 39, -10, -5, 2, 6, -7, 5, 4, -3, -2, -13, -23, -72, 107, 15, -5, 0, -7, -3, -6, 5, -4, 15, 47, 12, -31, 25, -16, 8, 22, -25, -62, -56, -18, 14, 28, 12, 2, -11, 74, -66, 41, -20, -7, 16, -20, 16, -8, 0, -16, 4, -19, 92, 12, -59, -14, -39, 49, -25, -16, 23, -27, 19, -3, -33, 19, 85, -29, 6, -7, -10, 16, -7, -12, 1, -6, 2, 4, -2, 64, 10, -25, 41, -2, -31, 15, 0, 110, 50, 69, 35, 28, 19, -10, 2, -43, -49, -56, -15, -16, 10, 3, 12, -1, -8, 1, 26, -12, -1, 7, -11, -27, 41, 25, 1, -11, -18, 22, -7, -1, -47, -8, 23, -3, -17, -7, 18, -125, 59, -5, 3, 18, 1, 2, 3, 27, -35, 65, -53, 50, -46, 37, -21, -28, 7, 14, -37, -5, -5, 12, 5, -8, 78, -19, 21, -6, -16, 8, -7, 5, 2, 7, 2, 10, -6, 12, -60, 44, 11, -36, -32, 31, 0, 2, -2, 2, 1, -3, 7, -10, 17, -21, 10, 6, -2, 19, -2, 59, -38, -86, 38, 8, -41, -30, -45, -33, 7, 15, 28, 29, -7, 24, -40, 7, 7, 5, -2, 9, 24, -23, -18, 6, -29, 30, 2, 28, 49, -11, -46, 10, 43, -13, -9, -1, -3, -7, -7, -17, -6, 97, -33, -21, 3, 5, 1, 12, -43, -8, 28, 7, -43, -7, 17, -20, 19, -1, 2, -13, 9, 54, 34, 9, -28, -11, -9, -17, 110, -59, 44, -26, 0, 3, -12, -47, 73, -34, -43, 38, -33, 16, -5, -46, -4, -6, -2, -25, 19, -29, 28, -13, 5, 14, 27, -40, -43, 4, 32, -13, -2, -35, -4, 112, -42, 9, -12, 37, -28, 17, 14, -19, 35, -39, 23, 3, -14, -1, -57, -5, 94, -9, 3, -39, 5, 30, -10, -32, 42, -13, -14, -97, -63, 30, -9, 1, -7, 12, 5, 20, 17, -9, -36, -30, 25, 47, -9, -15, 12, -22, 98, -8, -50, 15, -27, 21, -16, -11, 2, 12, -10, 10, -3, 33, 36, -96, 0, -17, 31, -9, 9, 3, -20, 13, -11, 8, -4, 10, -10, 9, 1, 112, -70, -27, 5, -21, 2, -57, -3, -29, 10, 19, -21, 21, -10, -66, -3, 91, -35, 30, -12, 0, -7, 59, -28, 26, 2, 14, -18, 1, 1, 11, 17, 20, -54, -59, 27, 4, 29, 32, 5, 19, 12, -4, 1, 7, -10, 5, -2, 10, 0, 23, -5, 28, -104, 46, 11, 16, 3, 29, 1, -8, -14, 1, 7, -50, 88, -62, 26, 8, -17, -14, 50, 0, 32, -12, -3, -27, 18, -8, -5, 8, 3, -20, -11, 37, -12, 9, 33, 46, -101, -1, -4, 1, 6, -1, 28, -42, -15, 16, 5, -1, -2, -55, 85, 38, -9, -4, 11, -2, -9, -6, 3, -20, -10, -77, 89, 24, -3, -104, -57, -26, -31, -20, -6, -9, 14, 20, -23, 46, -15, -31, 28, 1, -15, -2, 6, -2, 31, 45, -76, 23, -25, }; static const int8_t hexc_10_32_table[320] = { -3, -2, -1, 0, -4, 5, 35, -40, -9, 13, -44, 5, -27, -1, -7, 6, -11, 7, -8, 7, 19, -14, 15, -4, 9, -10, 10, -8, 10, -9, -1, 1, 0, 0, 2, 5, -18, 22, -53, 50, 1, -23, 50, -36, 15, 3, -13, 14, -10, 6, 1, 5, -3, 4, -2, 5, -32, 25, 5, -2, -1, -4, 1, 11, -29, 26, -6, -15, 30, -18, 0, 15, -17, 40, -41, 3, 9, -2, -2, 3, -3, -1, -5, 2, 21, -6, -16, -21, 23, 2, 60, 15, 16, -16, -9, 14, 9, -1, 7, -9, 0, 1, 1, 0, -1, -6, 17, -28, 54, -45, -1, 1, -1, -6, -6, 2, 11, 26, -29, -2, 46, -21, 34, 12, -23, 32, -23, 16, -10, 3, 66, 19, -20, 24, 7, 11, -3, 0, -3, -1, -50, -46, 2, -18, -3, 4, -1, -2, 3, -3, -19, 41, -36, 9, 11, -24, 21, -16, 9, -3, -25, -3, 10, 18, -9, -2, -5, -1, -5, 6, -4, -3, 2, -26, 21, -19, 35, -15, 7, -13, 17, -19, 39, -43, 48, -31, 16, -9, 7, -2, -5, 3, -4, 9, -19, 27, -55, 63, -35, 10, 26, -44, -2, 9, 4, 1, -6, 8, -9, 5, -8, -1, -3, -16, 45, -42, 5, 15, -16, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, 24, -55, 47, -38, 27, -19, 7, -3, 1, 16, 27, 20, -19, 18, 5, -7, 1, -5, 2, -6, 8, -22, 0, -3, -3, 8, -1, 7, -8, 1, -3, 5, 0, 17, -48, 58, -52, 29, -7, -2, 3, -10, 6, -26, 58, -31, 1, -6, 3, 93, -29, 39, 3, 17, 5, 6, -1, -1, -1, 27, 13, 10, 19, -7, -34, 12, 10, -4, 9, -76, 9, 8, -28, -2, -11, 2, -1, 3, 1, -83, 38, -39, 4, -16, -6, -2, -5, 5, -2, }; static const float shift_filt[3][7] = { {-0.011915f, 0.046995f, -0.152373f, 0.614108f, 0.614108f, -0.152373f, 0.046995f}, {-0.0324855f, 0.0859768f, -0.2042986f, 0.9640297f, 0.2086420f, -0.0302054f, -0.0063646f}, {-0.0063646f, -0.0302054f, 0.2086420f, 0.9640297f, -0.2042986f, 0.0859768f, -0.0324855f} }; static const float vbr_hb_thresh[5][11] = { {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, /* silence */ {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, /* 2 kbps */ {11.0f, 11.0f, 9.5f, 8.5f, 7.5f, 6.0f, 5.0f, 3.9f, 3.0f, 2.0f, 1.0f}, /* 6 kbps */ {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 8.7f, 7.8f, 7.0f, 6.5f, 4.0f}, /* 10 kbps */ {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.8f, 7.5f, 5.5f} /* 18 kbps */ }; static const float vbr_uhb_thresh[2][11] = { {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, /* silence */ { 3.9f, 2.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f} /* 2 kbps */ }; static const float h0[64] = { 3.596189e-05f, -0.0001123515f, -0.0001104587f, 0.0002790277f, 0.0002298438f, -0.0005953563f, -0.0003823631f, 0.00113826f, 0.0005308539f, -0.001986177f, -0.0006243724f, 0.003235877f, 0.0005743159f, -0.004989147f, -0.0002584767f, 0.007367171f, -0.0004857935f, -0.01050689f, 0.001894714f, 0.01459396f, -0.004313674f, -0.01994365f, 0.00828756f, 0.02716055f, -0.01485397f, -0.03764973f, 0.026447f, 0.05543245f, -0.05095487f, -0.09779096f, 0.1382363f, 0.4600981f, 0.4600981f, 0.1382363f, -0.09779096f, -0.05095487f, 0.05543245f, 0.026447f, -0.03764973f, -0.01485397f, 0.02716055f, 0.00828756f, -0.01994365f, -0.004313674f, 0.01459396f, 0.001894714f, -0.01050689f, -0.0004857935f, 0.007367171f, -0.0002584767f, -0.004989147f, 0.0005743159f, 0.003235877f, -0.0006243724f, -0.001986177f, 0.0005308539f, 0.00113826f, -0.0003823631f, -0.0005953563f, 0.0002298438f, 0.0002790277f, -0.0001104587f, -0.0001123515f, 3.596189e-05f }; static const float gc_quant_bound[16] = { 0.97979, 1.28384, 1.68223, 2.20426, 2.88829, 3.78458, 4.95900, 6.49787, 8.51428, 11.15642, 14.61846, 19.15484, 25.09895, 32.88761, 43.09325, 56.46588 }; static const uint16_t wb_skip_table[8] = { 0, 36, 112, 192, 352, 0, 0, 0 }; static const float e_ratio_quant[4] = {.25f, .315f, .397f, .5f}; static const float e_ratio_quant_bounds[3] = {0.2825f, 0.356f, 0.4485f}; static const float attenuation[10] = { 1.f, 0.961f, 0.852f, 0.698f, 0.527f, 0.368f, 0.237f, 0.141f, 0.077f, 0.039f }; static const float exc_gain_quant_scal3_bound[7] = { 0.112338f, 0.236980f, 0.369316f, 0.492054f, 0.637471f, 0.828874f, 1.132784f }; static const float exc_gain_quant_scal3[8] = { 0.061130f, 0.163546f, 0.310413f, 0.428220f, 0.555887f, 0.719055f, 0.938694f, 1.326874f }; static const float exc_gain_quant_scal1_bound[1] = { 0.87798f }; static const float exc_gain_quant_scal1[2] = { 0.70469f, 1.05127f }; #endif /* AVCODEC_SPEEXDATA_H */
a266c07f6357a347ca8a36ce01b793e25ed19624
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/u-boot_new/include/configs/ls2085a_emu.h
a5cea63b337633f0735534998b8a61851454def8
[ "LicenseRef-scancode-free-unknown", "Apache-2.0", "GPL-2.0-or-later" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
433
h
ls2085a_emu.h
/* * Copyright 2014 Freescale Semiconductor * * SPDX-License-Identifier: GPL-2.0+ */ #ifndef __LS2_EMU_H #define __LS2_EMU_H #include "ls2085a_common.h" #define CONFIG_DDR_SPD #define CONFIG_SYS_FSL_DDR_EMU /* Support emulator */ #define SPD_EEPROM_ADDRESS1 0x51 #define SPD_EEPROM_ADDRESS2 0x52 #define SPD_EEPROM_ADDRESS SPD_EEPROM_ADDRESS1 #define CONFIG_SYS_SPD_BUS_NUM 1 /* SPD on I2C bus 1 */ #endif /* __LS2_EMU_H */
6505577ebf493660e7887f478a88f2775c1667fc
2cdd793c4a2f8354e2623b3d7009e1117910d171
/src/assert.c
39d63bc9a1746ccbf5338d17c878fa5598e77b57
[ "BSD-2-Clause" ]
permissive
Yubico/libfido2
20017a50f1dcf393327992b6afec6f1e01eb2bef
79fd7bd96bf715f3472f0eaaafa012126becf805
refs/heads/main
2023-08-31T23:26:24.114268
2023-07-21T12:24:53
2023-08-02T11:52:16
130,169,332
487
180
NOASSERTION
2023-09-08T07:20:38
2018-04-19T06:32:10
C
UTF-8
C
false
false
26,929
c
assert.c
/* * Copyright (c) 2018-2023 Yubico AB. All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file. * SPDX-License-Identifier: BSD-2-Clause */ #include <openssl/sha.h> #include "fido.h" #include "fido/es256.h" #include "fido/rs256.h" #include "fido/eddsa.h" static int adjust_assert_count(const cbor_item_t *key, const cbor_item_t *val, void *arg) { fido_assert_t *assert = arg; uint64_t n; /* numberOfCredentials; see section 6.2 */ if (cbor_isa_uint(key) == false || cbor_int_get_width(key) != CBOR_INT_8 || cbor_get_uint8(key) != 5) { fido_log_debug("%s: cbor_type", __func__); return (0); /* ignore */ } if (cbor_decode_uint64(val, &n) < 0 || n > SIZE_MAX) { fido_log_debug("%s: cbor_decode_uint64", __func__); return (-1); } if (assert->stmt_len != 0 || assert->stmt_cnt != 1 || (size_t)n < assert->stmt_cnt) { fido_log_debug("%s: stmt_len=%zu, stmt_cnt=%zu, n=%zu", __func__, assert->stmt_len, assert->stmt_cnt, (size_t)n); return (-1); } if (fido_assert_set_count(assert, (size_t)n) != FIDO_OK) { fido_log_debug("%s: fido_assert_set_count", __func__); return (-1); } assert->stmt_len = 0; /* XXX */ return (0); } static int parse_assert_reply(const cbor_item_t *key, const cbor_item_t *val, void *arg) { fido_assert_stmt *stmt = arg; if (cbor_isa_uint(key) == false || cbor_int_get_width(key) != CBOR_INT_8) { fido_log_debug("%s: cbor type", __func__); return (0); /* ignore */ } switch (cbor_get_uint8(key)) { case 1: /* credential id */ return (cbor_decode_cred_id(val, &stmt->id)); case 2: /* authdata */ if (fido_blob_decode(val, &stmt->authdata_raw) < 0) { fido_log_debug("%s: fido_blob_decode", __func__); return (-1); } return (cbor_decode_assert_authdata(val, &stmt->authdata_cbor, &stmt->authdata, &stmt->authdata_ext)); case 3: /* signature */ return (fido_blob_decode(val, &stmt->sig)); case 4: /* user attributes */ return (cbor_decode_user(val, &stmt->user)); case 7: /* large blob key */ return (fido_blob_decode(val, &stmt->largeblob_key)); default: /* ignore */ fido_log_debug("%s: cbor type", __func__); return (0); } } static int fido_dev_get_assert_tx(fido_dev_t *dev, fido_assert_t *assert, const es256_pk_t *pk, const fido_blob_t *ecdh, const char *pin, int *ms) { fido_blob_t f; fido_opt_t uv = assert->uv; cbor_item_t *argv[7]; const uint8_t cmd = CTAP_CBOR_ASSERT; int r; memset(argv, 0, sizeof(argv)); memset(&f, 0, sizeof(f)); /* do we have everything we need? */ if (assert->rp_id == NULL || assert->cdh.ptr == NULL) { fido_log_debug("%s: rp_id=%p, cdh.ptr=%p", __func__, (void *)assert->rp_id, (void *)assert->cdh.ptr); r = FIDO_ERR_INVALID_ARGUMENT; goto fail; } if ((argv[0] = cbor_build_string(assert->rp_id)) == NULL || (argv[1] = fido_blob_encode(&assert->cdh)) == NULL) { fido_log_debug("%s: cbor encode", __func__); r = FIDO_ERR_INTERNAL; goto fail; } /* allowed credentials */ if (assert->allow_list.len) { const fido_blob_array_t *cl = &assert->allow_list; if ((argv[2] = cbor_encode_pubkey_list(cl)) == NULL) { fido_log_debug("%s: cbor_encode_pubkey_list", __func__); r = FIDO_ERR_INTERNAL; goto fail; } } if (assert->ext.mask) if ((argv[3] = cbor_encode_assert_ext(dev, &assert->ext, ecdh, pk)) == NULL) { fido_log_debug("%s: cbor_encode_assert_ext", __func__); r = FIDO_ERR_INTERNAL; goto fail; } /* user verification */ if (pin != NULL || (uv == FIDO_OPT_TRUE && fido_dev_supports_permissions(dev))) { if ((r = cbor_add_uv_params(dev, cmd, &assert->cdh, pk, ecdh, pin, assert->rp_id, &argv[5], &argv[6], ms)) != FIDO_OK) { fido_log_debug("%s: cbor_add_uv_params", __func__); goto fail; } uv = FIDO_OPT_OMIT; } /* options */ if (assert->up != FIDO_OPT_OMIT || uv != FIDO_OPT_OMIT) if ((argv[4] = cbor_encode_assert_opt(assert->up, uv)) == NULL) { fido_log_debug("%s: cbor_encode_assert_opt", __func__); r = FIDO_ERR_INTERNAL; goto fail; } /* frame and transmit */ if (cbor_build_frame(cmd, argv, nitems(argv), &f) < 0 || fido_tx(dev, CTAP_CMD_CBOR, f.ptr, f.len, ms) < 0) { fido_log_debug("%s: fido_tx", __func__); r = FIDO_ERR_TX; goto fail; } r = FIDO_OK; fail: cbor_vector_free(argv, nitems(argv)); free(f.ptr); return (r); } static int fido_dev_get_assert_rx(fido_dev_t *dev, fido_assert_t *assert, int *ms) { unsigned char *msg; int msglen; int r; fido_assert_reset_rx(assert); if ((msg = malloc(FIDO_MAXMSG)) == NULL) { r = FIDO_ERR_INTERNAL; goto out; } if ((msglen = fido_rx(dev, CTAP_CMD_CBOR, msg, FIDO_MAXMSG, ms)) < 0) { fido_log_debug("%s: fido_rx", __func__); r = FIDO_ERR_RX; goto out; } /* start with room for a single assertion */ if ((assert->stmt = calloc(1, sizeof(fido_assert_stmt))) == NULL) { r = FIDO_ERR_INTERNAL; goto out; } assert->stmt_len = 0; assert->stmt_cnt = 1; /* adjust as needed */ if ((r = cbor_parse_reply(msg, (size_t)msglen, assert, adjust_assert_count)) != FIDO_OK) { fido_log_debug("%s: adjust_assert_count", __func__); goto out; } /* parse the first assertion */ if ((r = cbor_parse_reply(msg, (size_t)msglen, &assert->stmt[0], parse_assert_reply)) != FIDO_OK) { fido_log_debug("%s: parse_assert_reply", __func__); goto out; } assert->stmt_len = 1; r = FIDO_OK; out: freezero(msg, FIDO_MAXMSG); return (r); } static int fido_get_next_assert_tx(fido_dev_t *dev, int *ms) { const unsigned char cbor[] = { CTAP_CBOR_NEXT_ASSERT }; if (fido_tx(dev, CTAP_CMD_CBOR, cbor, sizeof(cbor), ms) < 0) { fido_log_debug("%s: fido_tx", __func__); return (FIDO_ERR_TX); } return (FIDO_OK); } static int fido_get_next_assert_rx(fido_dev_t *dev, fido_assert_t *assert, int *ms) { unsigned char *msg; int msglen; int r; if ((msg = malloc(FIDO_MAXMSG)) == NULL) { r = FIDO_ERR_INTERNAL; goto out; } if ((msglen = fido_rx(dev, CTAP_CMD_CBOR, msg, FIDO_MAXMSG, ms)) < 0) { fido_log_debug("%s: fido_rx", __func__); r = FIDO_ERR_RX; goto out; } /* sanity check */ if (assert->stmt_len >= assert->stmt_cnt) { fido_log_debug("%s: stmt_len=%zu, stmt_cnt=%zu", __func__, assert->stmt_len, assert->stmt_cnt); r = FIDO_ERR_INTERNAL; goto out; } if ((r = cbor_parse_reply(msg, (size_t)msglen, &assert->stmt[assert->stmt_len], parse_assert_reply)) != FIDO_OK) { fido_log_debug("%s: parse_assert_reply", __func__); goto out; } r = FIDO_OK; out: freezero(msg, FIDO_MAXMSG); return (r); } static int fido_dev_get_assert_wait(fido_dev_t *dev, fido_assert_t *assert, const es256_pk_t *pk, const fido_blob_t *ecdh, const char *pin, int *ms) { int r; if ((r = fido_dev_get_assert_tx(dev, assert, pk, ecdh, pin, ms)) != FIDO_OK || (r = fido_dev_get_assert_rx(dev, assert, ms)) != FIDO_OK) return (r); while (assert->stmt_len < assert->stmt_cnt) { if ((r = fido_get_next_assert_tx(dev, ms)) != FIDO_OK || (r = fido_get_next_assert_rx(dev, assert, ms)) != FIDO_OK) return (r); assert->stmt_len++; } return (FIDO_OK); } static int decrypt_hmac_secrets(const fido_dev_t *dev, fido_assert_t *assert, const fido_blob_t *key) { for (size_t i = 0; i < assert->stmt_cnt; i++) { fido_assert_stmt *stmt = &assert->stmt[i]; if (stmt->authdata_ext.hmac_secret_enc.ptr != NULL) { if (aes256_cbc_dec(dev, key, &stmt->authdata_ext.hmac_secret_enc, &stmt->hmac_secret) < 0) { fido_log_debug("%s: aes256_cbc_dec %zu", __func__, i); return (-1); } } } return (0); } int fido_dev_get_assert(fido_dev_t *dev, fido_assert_t *assert, const char *pin) { fido_blob_t *ecdh = NULL; es256_pk_t *pk = NULL; int ms = dev->timeout_ms; int r; #ifdef USE_WINHELLO if (dev->flags & FIDO_DEV_WINHELLO) return (fido_winhello_get_assert(dev, assert, pin, ms)); #endif if (assert->rp_id == NULL || assert->cdh.ptr == NULL) { fido_log_debug("%s: rp_id=%p, cdh.ptr=%p", __func__, (void *)assert->rp_id, (void *)assert->cdh.ptr); return (FIDO_ERR_INVALID_ARGUMENT); } if (fido_dev_is_fido2(dev) == false) { if (pin != NULL || assert->ext.mask != 0) return (FIDO_ERR_UNSUPPORTED_OPTION); return (u2f_authenticate(dev, assert, &ms)); } if (pin != NULL || (assert->uv == FIDO_OPT_TRUE && fido_dev_supports_permissions(dev)) || (assert->ext.mask & FIDO_EXT_HMAC_SECRET)) { if ((r = fido_do_ecdh(dev, &pk, &ecdh, &ms)) != FIDO_OK) { fido_log_debug("%s: fido_do_ecdh", __func__); goto fail; } } r = fido_dev_get_assert_wait(dev, assert, pk, ecdh, pin, &ms); if (r == FIDO_OK && (assert->ext.mask & FIDO_EXT_HMAC_SECRET)) if (decrypt_hmac_secrets(dev, assert, ecdh) < 0) { fido_log_debug("%s: decrypt_hmac_secrets", __func__); r = FIDO_ERR_INTERNAL; goto fail; } fail: es256_pk_free(&pk); fido_blob_free(&ecdh); return (r); } int fido_check_flags(uint8_t flags, fido_opt_t up, fido_opt_t uv) { fido_log_debug("%s: flags=%02x", __func__, flags); fido_log_debug("%s: up=%d, uv=%d", __func__, up, uv); if (up == FIDO_OPT_TRUE && (flags & CTAP_AUTHDATA_USER_PRESENT) == 0) { fido_log_debug("%s: CTAP_AUTHDATA_USER_PRESENT", __func__); return (-1); /* user not present */ } if (uv == FIDO_OPT_TRUE && (flags & CTAP_AUTHDATA_USER_VERIFIED) == 0) { fido_log_debug("%s: CTAP_AUTHDATA_USER_VERIFIED", __func__); return (-1); /* user not verified */ } return (0); } static int check_extensions(int authdata_ext, int ext) { /* XXX: largeBlobKey is not part of extensions map */ ext &= ~FIDO_EXT_LARGEBLOB_KEY; if (authdata_ext != ext) { fido_log_debug("%s: authdata_ext=0x%x != ext=0x%x", __func__, authdata_ext, ext); return (-1); } return (0); } static int get_es256_hash(fido_blob_t *dgst, const fido_blob_t *clientdata, const fido_blob_t *authdata) { const EVP_MD *md; EVP_MD_CTX *ctx = NULL; if (dgst->len < SHA256_DIGEST_LENGTH || (md = EVP_sha256()) == NULL || (ctx = EVP_MD_CTX_new()) == NULL || EVP_DigestInit_ex(ctx, md, NULL) != 1 || EVP_DigestUpdate(ctx, authdata->ptr, authdata->len) != 1 || EVP_DigestUpdate(ctx, clientdata->ptr, clientdata->len) != 1 || EVP_DigestFinal_ex(ctx, dgst->ptr, NULL) != 1) { EVP_MD_CTX_free(ctx); return (-1); } dgst->len = SHA256_DIGEST_LENGTH; EVP_MD_CTX_free(ctx); return (0); } static int get_es384_hash(fido_blob_t *dgst, const fido_blob_t *clientdata, const fido_blob_t *authdata) { const EVP_MD *md; EVP_MD_CTX *ctx = NULL; if (dgst->len < SHA384_DIGEST_LENGTH || (md = EVP_sha384()) == NULL || (ctx = EVP_MD_CTX_new()) == NULL || EVP_DigestInit_ex(ctx, md, NULL) != 1 || EVP_DigestUpdate(ctx, authdata->ptr, authdata->len) != 1 || EVP_DigestUpdate(ctx, clientdata->ptr, clientdata->len) != 1 || EVP_DigestFinal_ex(ctx, dgst->ptr, NULL) != 1) { EVP_MD_CTX_free(ctx); return (-1); } dgst->len = SHA384_DIGEST_LENGTH; EVP_MD_CTX_free(ctx); return (0); } static int get_eddsa_hash(fido_blob_t *dgst, const fido_blob_t *clientdata, const fido_blob_t *authdata) { if (SIZE_MAX - authdata->len < clientdata->len || dgst->len < authdata->len + clientdata->len) return (-1); memcpy(dgst->ptr, authdata->ptr, authdata->len); memcpy(dgst->ptr + authdata->len, clientdata->ptr, clientdata->len); dgst->len = authdata->len + clientdata->len; return (0); } int fido_get_signed_hash(int cose_alg, fido_blob_t *dgst, const fido_blob_t *clientdata, const fido_blob_t *authdata_cbor) { cbor_item_t *item = NULL; fido_blob_t authdata; struct cbor_load_result cbor; int ok = -1; fido_log_debug("%s: cose_alg=%d", __func__, cose_alg); if ((item = cbor_load(authdata_cbor->ptr, authdata_cbor->len, &cbor)) == NULL || cbor_isa_bytestring(item) == false || cbor_bytestring_is_definite(item) == false) { fido_log_debug("%s: authdata", __func__); goto fail; } authdata.ptr = cbor_bytestring_handle(item); authdata.len = cbor_bytestring_length(item); switch (cose_alg) { case COSE_ES256: case COSE_RS256: ok = get_es256_hash(dgst, clientdata, &authdata); break; case COSE_ES384: ok = get_es384_hash(dgst, clientdata, &authdata); break; case COSE_EDDSA: ok = get_eddsa_hash(dgst, clientdata, &authdata); break; default: fido_log_debug("%s: unknown cose_alg", __func__); break; } fail: if (item != NULL) cbor_decref(&item); return (ok); } int fido_assert_verify(const fido_assert_t *assert, size_t idx, int cose_alg, const void *pk) { unsigned char buf[1024]; /* XXX */ fido_blob_t dgst; const fido_assert_stmt *stmt = NULL; int ok = -1; int r; dgst.ptr = buf; dgst.len = sizeof(buf); if (idx >= assert->stmt_len || pk == NULL) { r = FIDO_ERR_INVALID_ARGUMENT; goto out; } stmt = &assert->stmt[idx]; /* do we have everything we need? */ if (assert->cdh.ptr == NULL || assert->rp_id == NULL || stmt->authdata_cbor.ptr == NULL || stmt->sig.ptr == NULL) { fido_log_debug("%s: cdh=%p, rp_id=%s, authdata=%p, sig=%p", __func__, (void *)assert->cdh.ptr, assert->rp_id, (void *)stmt->authdata_cbor.ptr, (void *)stmt->sig.ptr); r = FIDO_ERR_INVALID_ARGUMENT; goto out; } if (fido_check_flags(stmt->authdata.flags, assert->up, assert->uv) < 0) { fido_log_debug("%s: fido_check_flags", __func__); r = FIDO_ERR_INVALID_PARAM; goto out; } if (check_extensions(stmt->authdata_ext.mask, assert->ext.mask) < 0) { fido_log_debug("%s: check_extensions", __func__); r = FIDO_ERR_INVALID_PARAM; goto out; } if (fido_check_rp_id(assert->rp_id, stmt->authdata.rp_id_hash) != 0) { fido_log_debug("%s: fido_check_rp_id", __func__); r = FIDO_ERR_INVALID_PARAM; goto out; } if (fido_get_signed_hash(cose_alg, &dgst, &assert->cdh, &stmt->authdata_cbor) < 0) { fido_log_debug("%s: fido_get_signed_hash", __func__); r = FIDO_ERR_INTERNAL; goto out; } switch (cose_alg) { case COSE_ES256: ok = es256_pk_verify_sig(&dgst, pk, &stmt->sig); break; case COSE_ES384: ok = es384_pk_verify_sig(&dgst, pk, &stmt->sig); break; case COSE_RS256: ok = rs256_pk_verify_sig(&dgst, pk, &stmt->sig); break; case COSE_EDDSA: ok = eddsa_pk_verify_sig(&dgst, pk, &stmt->sig); break; default: fido_log_debug("%s: unsupported cose_alg %d", __func__, cose_alg); r = FIDO_ERR_UNSUPPORTED_OPTION; goto out; } if (ok < 0) r = FIDO_ERR_INVALID_SIG; else r = FIDO_OK; out: explicit_bzero(buf, sizeof(buf)); return (r); } int fido_assert_set_clientdata(fido_assert_t *assert, const unsigned char *data, size_t data_len) { if (!fido_blob_is_empty(&assert->cdh) || fido_blob_set(&assert->cd, data, data_len) < 0) { return (FIDO_ERR_INVALID_ARGUMENT); } if (fido_sha256(&assert->cdh, data, data_len) < 0) { fido_blob_reset(&assert->cd); return (FIDO_ERR_INTERNAL); } return (FIDO_OK); } int fido_assert_set_clientdata_hash(fido_assert_t *assert, const unsigned char *hash, size_t hash_len) { if (!fido_blob_is_empty(&assert->cd) || fido_blob_set(&assert->cdh, hash, hash_len) < 0) return (FIDO_ERR_INVALID_ARGUMENT); return (FIDO_OK); } int fido_assert_set_hmac_salt(fido_assert_t *assert, const unsigned char *salt, size_t salt_len) { if ((salt_len != 32 && salt_len != 64) || fido_blob_set(&assert->ext.hmac_salt, salt, salt_len) < 0) return (FIDO_ERR_INVALID_ARGUMENT); return (FIDO_OK); } int fido_assert_set_hmac_secret(fido_assert_t *assert, size_t idx, const unsigned char *secret, size_t secret_len) { if (idx >= assert->stmt_len || (secret_len != 32 && secret_len != 64) || fido_blob_set(&assert->stmt[idx].hmac_secret, secret, secret_len) < 0) return (FIDO_ERR_INVALID_ARGUMENT); return (FIDO_OK); } int fido_assert_set_rp(fido_assert_t *assert, const char *id) { if (assert->rp_id != NULL) { free(assert->rp_id); assert->rp_id = NULL; } if (id == NULL) return (FIDO_ERR_INVALID_ARGUMENT); if ((assert->rp_id = strdup(id)) == NULL) return (FIDO_ERR_INTERNAL); return (FIDO_OK); } #ifdef USE_WINHELLO int fido_assert_set_winhello_appid(fido_assert_t *assert, const char *id) { if (assert->appid != NULL) { free(assert->appid); assert->appid = NULL; } if (id == NULL) return (FIDO_ERR_INVALID_ARGUMENT); if ((assert->appid = strdup(id)) == NULL) return (FIDO_ERR_INTERNAL); return (FIDO_OK); } #else int fido_assert_set_winhello_appid(fido_assert_t *assert, const char *id) { (void)assert; (void)id; return (FIDO_ERR_UNSUPPORTED_EXTENSION); } #endif /* USE_WINHELLO */ int fido_assert_allow_cred(fido_assert_t *assert, const unsigned char *ptr, size_t len) { fido_blob_t id; fido_blob_t *list_ptr; int r; memset(&id, 0, sizeof(id)); if (assert->allow_list.len == SIZE_MAX) { r = FIDO_ERR_INVALID_ARGUMENT; goto fail; } if (fido_blob_set(&id, ptr, len) < 0 || (list_ptr = recallocarray(assert->allow_list.ptr, assert->allow_list.len, assert->allow_list.len + 1, sizeof(fido_blob_t))) == NULL) { r = FIDO_ERR_INVALID_ARGUMENT; goto fail; } list_ptr[assert->allow_list.len++] = id; assert->allow_list.ptr = list_ptr; return (FIDO_OK); fail: free(id.ptr); return (r); } int fido_assert_empty_allow_list(fido_assert_t *assert) { fido_free_blob_array(&assert->allow_list); memset(&assert->allow_list, 0, sizeof(assert->allow_list)); return (FIDO_OK); } int fido_assert_set_extensions(fido_assert_t *assert, int ext) { if (ext == 0) assert->ext.mask = 0; else { if ((ext & FIDO_EXT_ASSERT_MASK) != ext) return (FIDO_ERR_INVALID_ARGUMENT); assert->ext.mask |= ext; } return (FIDO_OK); } int fido_assert_set_options(fido_assert_t *assert, bool up, bool uv) { assert->up = up ? FIDO_OPT_TRUE : FIDO_OPT_FALSE; assert->uv = uv ? FIDO_OPT_TRUE : FIDO_OPT_FALSE; return (FIDO_OK); } int fido_assert_set_up(fido_assert_t *assert, fido_opt_t up) { assert->up = up; return (FIDO_OK); } int fido_assert_set_uv(fido_assert_t *assert, fido_opt_t uv) { assert->uv = uv; return (FIDO_OK); } const unsigned char * fido_assert_clientdata_hash_ptr(const fido_assert_t *assert) { return (assert->cdh.ptr); } size_t fido_assert_clientdata_hash_len(const fido_assert_t *assert) { return (assert->cdh.len); } fido_assert_t * fido_assert_new(void) { return (calloc(1, sizeof(fido_assert_t))); } void fido_assert_reset_tx(fido_assert_t *assert) { free(assert->rp_id); free(assert->appid); fido_blob_reset(&assert->cd); fido_blob_reset(&assert->cdh); fido_blob_reset(&assert->ext.hmac_salt); fido_assert_empty_allow_list(assert); memset(&assert->ext, 0, sizeof(assert->ext)); assert->rp_id = NULL; assert->appid = NULL; assert->up = FIDO_OPT_OMIT; assert->uv = FIDO_OPT_OMIT; } static void fido_assert_reset_extattr(fido_assert_extattr_t *ext) { fido_blob_reset(&ext->hmac_secret_enc); fido_blob_reset(&ext->blob); memset(ext, 0, sizeof(*ext)); } void fido_assert_reset_rx(fido_assert_t *assert) { for (size_t i = 0; i < assert->stmt_cnt; i++) { free(assert->stmt[i].user.icon); free(assert->stmt[i].user.name); free(assert->stmt[i].user.display_name); fido_blob_reset(&assert->stmt[i].user.id); fido_blob_reset(&assert->stmt[i].id); fido_blob_reset(&assert->stmt[i].hmac_secret); fido_blob_reset(&assert->stmt[i].authdata_cbor); fido_blob_reset(&assert->stmt[i].authdata_raw); fido_blob_reset(&assert->stmt[i].largeblob_key); fido_blob_reset(&assert->stmt[i].sig); fido_assert_reset_extattr(&assert->stmt[i].authdata_ext); memset(&assert->stmt[i], 0, sizeof(assert->stmt[i])); } free(assert->stmt); assert->stmt = NULL; assert->stmt_len = 0; assert->stmt_cnt = 0; } void fido_assert_free(fido_assert_t **assert_p) { fido_assert_t *assert; if (assert_p == NULL || (assert = *assert_p) == NULL) return; fido_assert_reset_tx(assert); fido_assert_reset_rx(assert); free(assert); *assert_p = NULL; } size_t fido_assert_count(const fido_assert_t *assert) { return (assert->stmt_len); } const char * fido_assert_rp_id(const fido_assert_t *assert) { return (assert->rp_id); } uint8_t fido_assert_flags(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].authdata.flags); } uint32_t fido_assert_sigcount(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].authdata.sigcount); } const unsigned char * fido_assert_authdata_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].authdata_cbor.ptr); } size_t fido_assert_authdata_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].authdata_cbor.len); } const unsigned char * fido_assert_authdata_raw_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].authdata_raw.ptr); } size_t fido_assert_authdata_raw_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].authdata_raw.len); } const unsigned char * fido_assert_sig_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].sig.ptr); } size_t fido_assert_sig_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].sig.len); } const unsigned char * fido_assert_id_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].id.ptr); } size_t fido_assert_id_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].id.len); } const unsigned char * fido_assert_user_id_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].user.id.ptr); } size_t fido_assert_user_id_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].user.id.len); } const char * fido_assert_user_icon(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].user.icon); } const char * fido_assert_user_name(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].user.name); } const char * fido_assert_user_display_name(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].user.display_name); } const unsigned char * fido_assert_hmac_secret_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].hmac_secret.ptr); } size_t fido_assert_hmac_secret_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].hmac_secret.len); } const unsigned char * fido_assert_largeblob_key_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].largeblob_key.ptr); } size_t fido_assert_largeblob_key_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].largeblob_key.len); } const unsigned char * fido_assert_blob_ptr(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (NULL); return (assert->stmt[idx].authdata_ext.blob.ptr); } size_t fido_assert_blob_len(const fido_assert_t *assert, size_t idx) { if (idx >= assert->stmt_len) return (0); return (assert->stmt[idx].authdata_ext.blob.len); } static void fido_assert_clean_authdata(fido_assert_stmt *stmt) { fido_blob_reset(&stmt->authdata_cbor); fido_blob_reset(&stmt->authdata_raw); fido_assert_reset_extattr(&stmt->authdata_ext); memset(&stmt->authdata, 0, sizeof(stmt->authdata)); } int fido_assert_set_authdata(fido_assert_t *assert, size_t idx, const unsigned char *ptr, size_t len) { cbor_item_t *item = NULL; fido_assert_stmt *stmt = NULL; struct cbor_load_result cbor; int r; if (idx >= assert->stmt_len || ptr == NULL || len == 0) return (FIDO_ERR_INVALID_ARGUMENT); stmt = &assert->stmt[idx]; fido_assert_clean_authdata(stmt); if ((item = cbor_load(ptr, len, &cbor)) == NULL) { fido_log_debug("%s: cbor_load", __func__); r = FIDO_ERR_INVALID_ARGUMENT; goto fail; } if (fido_blob_decode(item, &stmt->authdata_raw) < 0) { fido_log_debug("%s: fido_blob_decode", __func__); r = FIDO_ERR_INTERNAL; goto fail; } if (cbor_decode_assert_authdata(item, &stmt->authdata_cbor, &stmt->authdata, &stmt->authdata_ext) < 0) { fido_log_debug("%s: cbor_decode_assert_authdata", __func__); r = FIDO_ERR_INVALID_ARGUMENT; goto fail; } r = FIDO_OK; fail: if (item != NULL) cbor_decref(&item); if (r != FIDO_OK) fido_assert_clean_authdata(stmt); return (r); } int fido_assert_set_authdata_raw(fido_assert_t *assert, size_t idx, const unsigned char *ptr, size_t len) { cbor_item_t *item = NULL; fido_assert_stmt *stmt = NULL; int r; if (idx >= assert->stmt_len || ptr == NULL || len == 0) return (FIDO_ERR_INVALID_ARGUMENT); stmt = &assert->stmt[idx]; fido_assert_clean_authdata(stmt); if (fido_blob_set(&stmt->authdata_raw, ptr, len) < 0) { fido_log_debug("%s: fido_blob_set", __func__); r = FIDO_ERR_INTERNAL; goto fail; } if ((item = cbor_build_bytestring(ptr, len)) == NULL) { fido_log_debug("%s: cbor_build_bytestring", __func__); r = FIDO_ERR_INTERNAL; goto fail; } if (cbor_decode_assert_authdata(item, &stmt->authdata_cbor, &stmt->authdata, &stmt->authdata_ext) < 0) { fido_log_debug("%s: cbor_decode_assert_authdata", __func__); r = FIDO_ERR_INVALID_ARGUMENT; goto fail; } r = FIDO_OK; fail: if (item != NULL) cbor_decref(&item); if (r != FIDO_OK) fido_assert_clean_authdata(stmt); return (r); } int fido_assert_set_sig(fido_assert_t *a, size_t idx, const unsigned char *ptr, size_t len) { if (idx >= a->stmt_len || ptr == NULL || len == 0) return (FIDO_ERR_INVALID_ARGUMENT); if (fido_blob_set(&a->stmt[idx].sig, ptr, len) < 0) return (FIDO_ERR_INTERNAL); return (FIDO_OK); } /* XXX shrinking leaks memory; fortunately that shouldn't happen */ int fido_assert_set_count(fido_assert_t *assert, size_t n) { void *new_stmt; #ifdef FIDO_FUZZ if (n > UINT8_MAX) { fido_log_debug("%s: n > UINT8_MAX", __func__); return (FIDO_ERR_INTERNAL); } #endif new_stmt = recallocarray(assert->stmt, assert->stmt_cnt, n, sizeof(fido_assert_stmt)); if (new_stmt == NULL) return (FIDO_ERR_INTERNAL); assert->stmt = new_stmt; assert->stmt_cnt = n; assert->stmt_len = n; return (FIDO_OK); }
3d985b14c24f19ef283dbaddd6f84e59230ddcf3
59864cbd213b5da6f50d6255b0a021564b3d5bd4
/disabled-challenges/adventure_game/src/NameChangeObject.h
b238edc9622c78673a58ec550b65be4955fef3db
[ "MIT" ]
permissive
trailofbits/cb-multios
8af96a4fbc3b34644367faa135347f88e0e0d0a3
810d7b24b1f62f56ef49b148fe155b0d0629cad2
refs/heads/master
2023-09-05T03:56:20.229403
2022-12-27T15:47:54
2022-12-27T15:47:54
41,688,943
522
133
MIT
2023-06-29T02:47:13
2015-08-31T17:04:31
C
UTF-8
C
false
false
291
h
NameChangeObject.h
#ifndef NAME_CHANGE_OBJECT_H_ #define NAME_CHANGE_OBJECT_H_ #include "oo.h" #include "MapObject.h" DeclareClass(NameChangeObject, MapObject) EndDeclareClass(NameChangeObject, MapObject) DeclareClassFunctions(NameChangeObject, MapObject) EndDeclareClassFunctions(NameChangeObject) #endif
8b6848290b38098cd3b088aaded0c69328f60b8e
dd6bdce2131e1f608ae711be1426765c9db44122
/src/daemon/modules/container/leftover_cleanup/cleanup.h
7ad124f461497e973a69541154da95d30628f042
[]
no_license
openeuler-mirror/iSulad
df3b7bdd285e3ed0e2b572ec02c3cef8a80fa8a9
1faaae7ee243bc8b9484ede632302a3cd4bc8670
refs/heads/master
2023-09-01T04:07:42.243619
2023-08-26T01:28:08
2023-08-26T01:28:08
246,005,159
350
25
null
null
null
null
UTF-8
C
false
false
1,593
h
cleanup.h
/****************************************************************************** * Copyright (c) Huawei Technologies Co., Ltd. 2018-2022. All rights reserved. * iSulad licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: * http://license.coscl.org.cn/MulanPSL2 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR * PURPOSE. * See the Mulan PSL v2 for more details. * Author: wangrunze * Create: 2022-10-31 * Description: provide cleanup definition *********************************************************************************/ #ifndef DAEMON_MODULES_CONTAINER_LEFTOVER_CLEANUP_CLEANERS_H #define DAEMON_MODULES_CONTAINER_LEFTOVER_CLEANUP_CLEANERS_H #include <stdlib.h> #include "linked_list.h" #include "isula_libutils/log.h" #include "clean_context.h" #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif typedef int clean_func_t(struct clean_ctx *ctx); struct clean_node { const char *desc; clean_func_t *cleaner; int error_code; }; struct cleaners { int count; int done_clean; struct linked_list cleaner_list; }; struct cleaners *cleaners_init(); void destroy_cleaners(struct cleaners *clns); void cleaners_do_clean(struct cleaners *clns, struct clean_ctx *ctx); void do_isulad_tmpdir_cleaner(void); #if defined(__cplusplus) || defined(c_plusplus) } #endif #endif
ac71601edca587e12b56d41e3507539af6d30690
50fd4227fb802d65ae6620a3859dd992cb650717
/src/ui/ui_common/prepare_environment.h
65cff0062d80766f3b4727909993e91f148d6cb6
[ "Zlib" ]
permissive
danpla/dpscreenocr
626c8004a388289589fa254b8b8916b8a3ada50a
00ef775dae03e6de74bc07cfd04a0918febc8e30
refs/heads/master
2023-08-16T07:01:34.946170
2023-08-15T19:13:28
2023-08-15T19:13:28
173,785,193
193
19
Zlib
2020-05-29T19:56:53
2019-03-04T16:55:10
C++
UTF-8
C
false
false
366
h
prepare_environment.h
#pragma once #ifdef __cplusplus extern "C" { #endif /** * Prepare environment before running the program. * * This function is mainly intended to set up environment variables. * Since it can restart the executable, it should be one of the very * first routines called from main(). */ void uiPrepareEnvironment(char* argv[]); #ifdef __cplusplus } #endif
52bf7810dc19c6f931e64240e0e5bf2a2a9e0d8d
ea8fc70c7dbf49059431fa45a940742736c68fb8
/ext/sync/mutex.c
e7f5b5922acfb79d8fcd884d1be92c80f2fd599d
[ "BSD-3-Clause" ]
permissive
dreamsxin/cphalcon7
1bd2194a251657b48857326927db69fef617ab91
1b8c6b04b4ca237a5ead87d4752df0d2e85c7a9d
refs/heads/master
2023-03-08T04:53:08.829432
2022-07-07T07:48:59
2022-07-07T07:48:59
47,245,335
298
73
null
2021-06-22T11:53:25
2015-12-02T07:44:43
C
UTF-8
C
false
false
6,361
c
mutex.c
/* +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | | | | If you did not receive a copy of the license and are unable to | | obtain it through the world-wide-web, please send an email | | to license@phalconphp.com so we can send you a copy immediately. | +------------------------------------------------------------------------+ | Authors: Andres Gutierrez <andres@phalconphp.com> | | Eduar Carvajal <eduar@phalconphp.com> | | ZhuZongXin <dreamsxin@qq.com> | +------------------------------------------------------------------------+ */ #include "sync/mutex.h" #include "sync/exception.h" #include "kernel/main.h" #include "kernel/object.h" #include "kernel/array.h" #include "kernel/string.h" #include "kernel/fcall.h" #include "kernel/concat.h" #include "kernel/operators.h" #include "kernel/exception.h" #include "kernel/time.h" /** * Phalcon\Sync\Mutex * */ zend_class_entry *phalcon_sync_mutex_ce; PHP_METHOD(Phalcon_Sync_Mutex, __construct); PHP_METHOD(Phalcon_Sync_Mutex, lock); PHP_METHOD(Phalcon_Sync_Mutex, unlock); ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_sync_mutex___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_sync_mutex_lock, 0, 0, 0) ZEND_ARG_TYPE_INFO(0, wait, IS_LONG, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_sync_mutex_unlock, 0, 0, 0) ZEND_ARG_TYPE_INFO(0, all, _IS_BOOL, 1) ZEND_END_ARG_INFO() static const zend_function_entry phalcon_sync_mutex_method_entry[] = { PHP_ME(Phalcon_Sync_Mutex, __construct, arginfo_phalcon_sync_mutex___construct, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Sync_Mutex, lock, arginfo_phalcon_sync_mutex_lock, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Sync_Mutex, unlock, arginfo_phalcon_sync_mutex_unlock, ZEND_ACC_PUBLIC) PHP_FE_END }; zend_object_handlers phalcon_sync_mutex_object_handlers; zend_object* phalcon_sync_mutex_object_create_handler(zend_class_entry *ce) { phalcon_sync_mutex_object *intern = ecalloc(1, sizeof(phalcon_sync_mutex_object) + zend_object_properties_size(ce)); intern->std.ce = ce; zend_object_std_init(&intern->std, ce); object_properties_init(&intern->std, ce); intern->std.handlers = &phalcon_sync_mutex_object_handlers; /* Initialize Mutex information. */ intern->MxNamed = 0; intern->MxMem = NULL; pthread_mutex_init(&intern->MxPthreadCritSection, NULL); intern->MxOwnerID = 0; intern->MxCount = 0; return &intern->std; } void phalcon_sync_mutex_object_free_handler(zend_object *object) { phalcon_sync_mutex_object *intern = phalcon_sync_mutex_object_from_obj(object); phalcon_mutex_unlock_internal(intern, 1); if (intern->MxMem != NULL) { if (intern->MxNamed) { phalcon_namedmem_unmap(intern->MxMem, phalcon_semaphore_getsize()); } else { phalcon_semaphore_free(&intern->MxPthreadMutex); efree(intern->MxMem); } } pthread_mutex_destroy(&intern->MxPthreadCritSection); } /** * Phalcon\Sync\Mutex initializer */ PHALCON_INIT_CLASS(Phalcon_Sync_Mutex){ PHALCON_REGISTER_CLASS_CREATE_OBJECT(Phalcon\\Sync, Mutex, sync_mutex, phalcon_sync_mutex_method_entry, 0); return SUCCESS; } /** * Phalcon\Sync\Mutex constructor * * @param string $name */ PHP_METHOD(Phalcon_Sync_Mutex, __construct){ zval *name = NULL; phalcon_sync_mutex_object *intern; size_t Pos, TempSize; int result; phalcon_fetch_params(0, 0, 1, &name); intern = phalcon_sync_mutex_object_from_obj(Z_OBJ_P(getThis())); if (!name || PHALCON_IS_EMPTY(name)) { intern->MxNamed = 0; } else { intern->MxNamed = 1; } TempSize = phalcon_semaphore_getsize(); result = phalcon_namedmem_init(&intern->MxMem, &Pos, "/Sync_Mutex", intern->MxNamed ? Z_STRVAL_P(name) : NULL, TempSize); if (result < 0) { PHALCON_THROW_EXCEPTION_STR(phalcon_sync_exception_ce, "Mutex could not be created"); return; } phalcon_semaphore_get(&intern->MxPthreadMutex, intern->MxMem + Pos); /* Handle the first time this mutex has been opened. */ if (result == 0) { phalcon_semaphore_init(&intern->MxPthreadMutex, intern->MxNamed, 1, 1); if (intern->MxNamed) phalcon_namedmem_ready(intern->MxMem); } } /** * Locks a mutex object */ PHP_METHOD(Phalcon_Sync_Mutex, lock){ zval *_wait = NULL; zend_long wait = -1; phalcon_sync_mutex_object *intern; phalcon_fetch_params(0, 0, 1, &_wait); if (_wait && Z_TYPE_P(_wait) == IS_LONG) { wait = Z_LVAL_P(_wait); } intern = phalcon_sync_mutex_object_from_obj(Z_OBJ_P(getThis())); if (pthread_mutex_lock(&intern->MxPthreadCritSection) != 0) { PHALCON_THROW_EXCEPTION_STR(phalcon_sync_exception_ce, "Unable to acquire mutex critical section"); RETURN_FALSE; } /* Check to see if this mutex is already owned by the calling thread. */ if (intern->MxOwnerID == phalcon_getcurrent_threadid()) { intern->MxCount++; pthread_mutex_unlock(&intern->MxPthreadCritSection); RETURN_TRUE; } pthread_mutex_unlock(&intern->MxPthreadCritSection); if (!phalcon_semaphore_wait(&intern->MxPthreadMutex, (uint32_t)(wait > -1 ? wait : INFINITE))) RETURN_FALSE; pthread_mutex_lock(&intern->MxPthreadCritSection); intern->MxOwnerID = phalcon_getcurrent_threadid(); intern->MxCount = 1; pthread_mutex_unlock(&intern->MxPthreadCritSection); RETURN_TRUE; } /** * Unlocks a mutex object * * @param boolean $all */ PHP_METHOD(Phalcon_Sync_Mutex, unlock){ zval *all = NULL; phalcon_sync_mutex_object *intern; phalcon_fetch_params(0, 0, 1, &all); if (!all || Z_TYPE_P(all) == IS_NULL) { all = &PHALCON_GLOBAL(z_false); } intern = phalcon_sync_mutex_object_from_obj(Z_OBJ_P(getThis())); if (!phalcon_mutex_unlock_internal(intern, zend_is_true(all) ? 1 : 0)) { RETURN_FALSE; } RETURN_TRUE; }
de9b0294dd959ccb621827e12bbb9fbc2ae2b885
ad631b8a408c085a7ea611973c46cc03a5f60c1f
/bpf/include/linux/byteorder.h
4a16b56377c5fe7f42919ef3cdb9101aeff331f8
[ "BSD-2-Clause", "GPL-1.0-or-later", "GPL-2.0-only", "Apache-2.0", "BSD-3-Clause" ]
permissive
cilium/cilium
6434786ea19052f1c684a70cd8e0fb2667aa52d8
710316a4cf64202e210ec29c97be08209f96c69a
refs/heads/main
2023-09-01T04:29:44.222786
2023-08-31T22:28:15
2023-08-31T23:52:01
48,109,239
16,781
2,829
Apache-2.0
2023-09-14T19:57:29
2015-12-16T12:33:31
Go
UTF-8
C
false
false
372
h
byteorder.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* Copyright Authors of the Linux kernel */ /* Copyright Authors of Cilium */ #ifndef __ASM_BYTEORDER_H_ #define __ASM_BYTEORDER_H_ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #include <linux/byteorder/little_endian.h> #else #include <linux/byteorder/big_endian.h> #endif #endif /* __ASM_BYTEORDER_H_ */
8fc195c73af47e35503015c6db4fed4fb2ba64fe
cb80ffbfe6b12be3f42322537aff3552fd9239f2
/src/external/glfw/src/window.c
1c8519ff748d6aab64de556beaa64eba59661281
[ "Zlib", "LicenseRef-scancode-other-permissive", "LicenseRef-scancode-unknown-license-reference" ]
permissive
raysan5/raylib
afe80387401361d6f35f9831978b0b379d2d9971
a86c93ebc0095f6c2ffc14656bfc9e1e37070f72
refs/heads/master
2023-08-16T20:49:02.921768
2023-08-14T22:09:27
2023-08-14T22:09:27
13,836,499
15,971
2,825
Zlib
2023-09-14T21:19:02
2013-10-24T15:46:04
C
UTF-8
C
false
false
34,789
c
window.c
//======================================================================== // GLFW 3.4 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard // Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org> // Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages // arising from the use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it // freely, subject to the following restrictions: // // 1. The origin of this software must not be misrepresented; you must not // claim that you wrote the original software. If you use this software // in a product, an acknowledgment in the product documentation would // be appreciated but is not required. // // 2. Altered source versions must be plainly marked as such, and must not // be misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source // distribution. // //======================================================================== // Please use C89 style variable declarations in this file because VS 2010 //======================================================================== #include "internal.h" #include <assert.h> #include <string.h> #include <stdlib.h> #include <float.h> ////////////////////////////////////////////////////////////////////////// ////// GLFW event API ////// ////////////////////////////////////////////////////////////////////////// // Notifies shared code that a window has lost or received input focus // void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused) { assert(window != NULL); assert(focused == GLFW_TRUE || focused == GLFW_FALSE); if (window->callbacks.focus) window->callbacks.focus((GLFWwindow*) window, focused); if (!focused) { int key, button; for (key = 0; key <= GLFW_KEY_LAST; key++) { if (window->keys[key] == GLFW_PRESS) { const int scancode = _glfw.platform.getKeyScancode(key); _glfwInputKey(window, key, scancode, GLFW_RELEASE, 0); } } for (button = 0; button <= GLFW_MOUSE_BUTTON_LAST; button++) { if (window->mouseButtons[button] == GLFW_PRESS) _glfwInputMouseClick(window, button, GLFW_RELEASE, 0); } } } // Notifies shared code that a window has moved // The position is specified in content area relative screen coordinates // void _glfwInputWindowPos(_GLFWwindow* window, int x, int y) { assert(window != NULL); if (window->callbacks.pos) window->callbacks.pos((GLFWwindow*) window, x, y); } // Notifies shared code that a window has been resized // The size is specified in screen coordinates // void _glfwInputWindowSize(_GLFWwindow* window, int width, int height) { assert(window != NULL); assert(width >= 0); assert(height >= 0); if (window->callbacks.size) window->callbacks.size((GLFWwindow*) window, width, height); } // Notifies shared code that a window has been iconified or restored // void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified) { assert(window != NULL); assert(iconified == GLFW_TRUE || iconified == GLFW_FALSE); if (window->callbacks.iconify) window->callbacks.iconify((GLFWwindow*) window, iconified); } // Notifies shared code that a window has been maximized or restored // void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized) { assert(window != NULL); assert(maximized == GLFW_TRUE || maximized == GLFW_FALSE); if (window->callbacks.maximize) window->callbacks.maximize((GLFWwindow*) window, maximized); } // Notifies shared code that a window framebuffer has been resized // The size is specified in pixels // void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height) { assert(window != NULL); assert(width >= 0); assert(height >= 0); if (window->callbacks.fbsize) window->callbacks.fbsize((GLFWwindow*) window, width, height); } // Notifies shared code that a window content scale has changed // The scale is specified as the ratio between the current and default DPI // void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscale) { assert(window != NULL); assert(xscale > 0.f); assert(xscale < FLT_MAX); assert(yscale > 0.f); assert(yscale < FLT_MAX); if (window->callbacks.scale) window->callbacks.scale((GLFWwindow*) window, xscale, yscale); } // Notifies shared code that the window contents needs updating // void _glfwInputWindowDamage(_GLFWwindow* window) { assert(window != NULL); if (window->callbacks.refresh) window->callbacks.refresh((GLFWwindow*) window); } // Notifies shared code that the user wishes to close a window // void _glfwInputWindowCloseRequest(_GLFWwindow* window) { assert(window != NULL); window->shouldClose = GLFW_TRUE; if (window->callbacks.close) window->callbacks.close((GLFWwindow*) window); } // Notifies shared code that a window has changed its desired monitor // void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor) { assert(window != NULL); window->monitor = monitor; } ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share) { _GLFWfbconfig fbconfig; _GLFWctxconfig ctxconfig; _GLFWwndconfig wndconfig; _GLFWwindow* window; assert(title != NULL); assert(width >= 0); assert(height >= 0); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (width <= 0 || height <= 0) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid window size %ix%i", width, height); return NULL; } fbconfig = _glfw.hints.framebuffer; ctxconfig = _glfw.hints.context; wndconfig = _glfw.hints.window; wndconfig.width = width; wndconfig.height = height; wndconfig.title = title; ctxconfig.share = (_GLFWwindow*) share; if (!_glfwIsValidContextConfig(&ctxconfig)) return NULL; window = _glfw_calloc(1, sizeof(_GLFWwindow)); window->next = _glfw.windowListHead; _glfw.windowListHead = window; window->videoMode.width = width; window->videoMode.height = height; window->videoMode.redBits = fbconfig.redBits; window->videoMode.greenBits = fbconfig.greenBits; window->videoMode.blueBits = fbconfig.blueBits; window->videoMode.refreshRate = _glfw.hints.refreshRate; window->monitor = (_GLFWmonitor*) monitor; window->resizable = wndconfig.resizable; window->decorated = wndconfig.decorated; window->autoIconify = wndconfig.autoIconify; window->floating = wndconfig.floating; window->focusOnShow = wndconfig.focusOnShow; window->mousePassthrough = wndconfig.mousePassthrough; window->cursorMode = GLFW_CURSOR_NORMAL; window->doublebuffer = fbconfig.doublebuffer; window->minwidth = GLFW_DONT_CARE; window->minheight = GLFW_DONT_CARE; window->maxwidth = GLFW_DONT_CARE; window->maxheight = GLFW_DONT_CARE; window->numer = GLFW_DONT_CARE; window->denom = GLFW_DONT_CARE; if (!_glfw.platform.createWindow(window, &wndconfig, &ctxconfig, &fbconfig)) { glfwDestroyWindow((GLFWwindow*) window); return NULL; } return (GLFWwindow*) window; } void glfwDefaultWindowHints(void) { _GLFW_REQUIRE_INIT(); // The default is OpenGL with minimum version 1.0 memset(&_glfw.hints.context, 0, sizeof(_glfw.hints.context)); _glfw.hints.context.client = GLFW_OPENGL_API; _glfw.hints.context.source = GLFW_NATIVE_CONTEXT_API; _glfw.hints.context.major = 1; _glfw.hints.context.minor = 0; // The default is a focused, visible, resizable window with decorations memset(&_glfw.hints.window, 0, sizeof(_glfw.hints.window)); _glfw.hints.window.resizable = GLFW_TRUE; _glfw.hints.window.visible = GLFW_TRUE; _glfw.hints.window.decorated = GLFW_TRUE; _glfw.hints.window.focused = GLFW_TRUE; _glfw.hints.window.autoIconify = GLFW_TRUE; _glfw.hints.window.centerCursor = GLFW_TRUE; _glfw.hints.window.focusOnShow = GLFW_TRUE; _glfw.hints.window.xpos = GLFW_ANY_POSITION; _glfw.hints.window.ypos = GLFW_ANY_POSITION; // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil, // double buffered memset(&_glfw.hints.framebuffer, 0, sizeof(_glfw.hints.framebuffer)); _glfw.hints.framebuffer.redBits = 8; _glfw.hints.framebuffer.greenBits = 8; _glfw.hints.framebuffer.blueBits = 8; _glfw.hints.framebuffer.alphaBits = 8; _glfw.hints.framebuffer.depthBits = 24; _glfw.hints.framebuffer.stencilBits = 8; _glfw.hints.framebuffer.doublebuffer = GLFW_TRUE; // The default is to select the highest available refresh rate _glfw.hints.refreshRate = GLFW_DONT_CARE; // The default is to use full Retina resolution framebuffers _glfw.hints.window.ns.retina = GLFW_TRUE; } GLFWAPI void glfwWindowHint(int hint, int value) { _GLFW_REQUIRE_INIT(); switch (hint) { case GLFW_RED_BITS: _glfw.hints.framebuffer.redBits = value; return; case GLFW_GREEN_BITS: _glfw.hints.framebuffer.greenBits = value; return; case GLFW_BLUE_BITS: _glfw.hints.framebuffer.blueBits = value; return; case GLFW_ALPHA_BITS: _glfw.hints.framebuffer.alphaBits = value; return; case GLFW_DEPTH_BITS: _glfw.hints.framebuffer.depthBits = value; return; case GLFW_STENCIL_BITS: _glfw.hints.framebuffer.stencilBits = value; return; case GLFW_ACCUM_RED_BITS: _glfw.hints.framebuffer.accumRedBits = value; return; case GLFW_ACCUM_GREEN_BITS: _glfw.hints.framebuffer.accumGreenBits = value; return; case GLFW_ACCUM_BLUE_BITS: _glfw.hints.framebuffer.accumBlueBits = value; return; case GLFW_ACCUM_ALPHA_BITS: _glfw.hints.framebuffer.accumAlphaBits = value; return; case GLFW_AUX_BUFFERS: _glfw.hints.framebuffer.auxBuffers = value; return; case GLFW_STEREO: _glfw.hints.framebuffer.stereo = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_DOUBLEBUFFER: _glfw.hints.framebuffer.doublebuffer = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_TRANSPARENT_FRAMEBUFFER: _glfw.hints.framebuffer.transparent = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_SAMPLES: _glfw.hints.framebuffer.samples = value; return; case GLFW_SRGB_CAPABLE: _glfw.hints.framebuffer.sRGB = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_RESIZABLE: _glfw.hints.window.resizable = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_DECORATED: _glfw.hints.window.decorated = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_FOCUSED: _glfw.hints.window.focused = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_AUTO_ICONIFY: _glfw.hints.window.autoIconify = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_FLOATING: _glfw.hints.window.floating = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_MAXIMIZED: _glfw.hints.window.maximized = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_VISIBLE: _glfw.hints.window.visible = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_POSITION_X: _glfw.hints.window.xpos = value; return; case GLFW_POSITION_Y: _glfw.hints.window.ypos = value; return; case GLFW_COCOA_RETINA_FRAMEBUFFER: _glfw.hints.window.ns.retina = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_WIN32_KEYBOARD_MENU: _glfw.hints.window.win32.keymenu = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_COCOA_GRAPHICS_SWITCHING: _glfw.hints.context.nsgl.offline = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_SCALE_TO_MONITOR: _glfw.hints.window.scaleToMonitor = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_CENTER_CURSOR: _glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_FOCUS_ON_SHOW: _glfw.hints.window.focusOnShow = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_MOUSE_PASSTHROUGH: _glfw.hints.window.mousePassthrough = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_CLIENT_API: _glfw.hints.context.client = value; return; case GLFW_CONTEXT_CREATION_API: _glfw.hints.context.source = value; return; case GLFW_CONTEXT_VERSION_MAJOR: _glfw.hints.context.major = value; return; case GLFW_CONTEXT_VERSION_MINOR: _glfw.hints.context.minor = value; return; case GLFW_CONTEXT_ROBUSTNESS: _glfw.hints.context.robustness = value; return; case GLFW_OPENGL_FORWARD_COMPAT: _glfw.hints.context.forward = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_CONTEXT_DEBUG: _glfw.hints.context.debug = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_CONTEXT_NO_ERROR: _glfw.hints.context.noerror = value ? GLFW_TRUE : GLFW_FALSE; return; case GLFW_OPENGL_PROFILE: _glfw.hints.context.profile = value; return; case GLFW_CONTEXT_RELEASE_BEHAVIOR: _glfw.hints.context.release = value; return; case GLFW_REFRESH_RATE: _glfw.hints.refreshRate = value; return; } _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint 0x%08X", hint); } GLFWAPI void glfwWindowHintString(int hint, const char* value) { assert(value != NULL); _GLFW_REQUIRE_INIT(); switch (hint) { case GLFW_COCOA_FRAME_NAME: strncpy(_glfw.hints.window.ns.frameName, value, sizeof(_glfw.hints.window.ns.frameName) - 1); return; case GLFW_X11_CLASS_NAME: strncpy(_glfw.hints.window.x11.className, value, sizeof(_glfw.hints.window.x11.className) - 1); return; case GLFW_X11_INSTANCE_NAME: strncpy(_glfw.hints.window.x11.instanceName, value, sizeof(_glfw.hints.window.x11.instanceName) - 1); return; case GLFW_WAYLAND_APP_ID: strncpy(_glfw.hints.window.wl.appId, value, sizeof(_glfw.hints.window.wl.appId) - 1); return; } _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint); } GLFWAPI void glfwDestroyWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; _GLFW_REQUIRE_INIT(); // Allow closing of NULL (to match the behavior of free) if (window == NULL) return; // Clear all callbacks to avoid exposing a half torn-down window object memset(&window->callbacks, 0, sizeof(window->callbacks)); // The window's context must not be current on another thread when the // window is destroyed if (window == _glfwPlatformGetTls(&_glfw.contextSlot)) glfwMakeContextCurrent(NULL); _glfw.platform.destroyWindow(window); // Unlink window from global linked list { _GLFWwindow** prev = &_glfw.windowListHead; while (*prev != window) prev = &((*prev)->next); *prev = window->next; } _glfw_free(window); } GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(0); return window->shouldClose; } GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); window->shouldClose = value; } GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); assert(title != NULL); _GLFW_REQUIRE_INIT(); _glfw.platform.setWindowTitle(window, title); } GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle, int count, const GLFWimage* images) { int i; _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); assert(count >= 0); assert(count == 0 || images != NULL); _GLFW_REQUIRE_INIT(); if (count < 0) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid image count for window icon"); return; } for (i = 0; i < count; i++) { assert(images[i].pixels != NULL); if (images[i].width <= 0 || images[i].height <= 0) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid image dimensions for window icon"); return; } } _glfw.platform.setWindowIcon(window, count, images); } GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); if (xpos) *xpos = 0; if (ypos) *ypos = 0; _GLFW_REQUIRE_INIT(); _glfw.platform.getWindowPos(window, xpos, ypos); } GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); if (window->monitor) return; _glfw.platform.setWindowPos(window, xpos, ypos); } GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); if (width) *width = 0; if (height) *height = 0; _GLFW_REQUIRE_INIT(); _glfw.platform.getWindowSize(window, width, height); } GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); assert(width >= 0); assert(height >= 0); _GLFW_REQUIRE_INIT(); window->videoMode.width = width; window->videoMode.height = height; _glfw.platform.setWindowSize(window, width, height); } GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* handle, int minwidth, int minheight, int maxwidth, int maxheight) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); if (minwidth != GLFW_DONT_CARE && minheight != GLFW_DONT_CARE) { if (minwidth < 0 || minheight < 0) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid window minimum size %ix%i", minwidth, minheight); return; } } if (maxwidth != GLFW_DONT_CARE && maxheight != GLFW_DONT_CARE) { if (maxwidth < 0 || maxheight < 0 || maxwidth < minwidth || maxheight < minheight) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid window maximum size %ix%i", maxwidth, maxheight); return; } } window->minwidth = minwidth; window->minheight = minheight; window->maxwidth = maxwidth; window->maxheight = maxheight; if (window->monitor || !window->resizable) return; _glfw.platform.setWindowSizeLimits(window, minwidth, minheight, maxwidth, maxheight); } GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); assert(numer != 0); assert(denom != 0); _GLFW_REQUIRE_INIT(); if (numer != GLFW_DONT_CARE && denom != GLFW_DONT_CARE) { if (numer <= 0 || denom <= 0) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid window aspect ratio %i:%i", numer, denom); return; } } window->numer = numer; window->denom = denom; if (window->monitor || !window->resizable) return; _glfw.platform.setWindowAspectRatio(window, numer, denom); } GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); if (width) *width = 0; if (height) *height = 0; _GLFW_REQUIRE_INIT(); _glfw.platform.getFramebufferSize(window, width, height); } GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle, int* left, int* top, int* right, int* bottom) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); if (left) *left = 0; if (top) *top = 0; if (right) *right = 0; if (bottom) *bottom = 0; _GLFW_REQUIRE_INIT(); _glfw.platform.getWindowFrameSize(window, left, top, right, bottom); } GLFWAPI void glfwGetWindowContentScale(GLFWwindow* handle, float* xscale, float* yscale) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); if (xscale) *xscale = 0.f; if (yscale) *yscale = 0.f; _GLFW_REQUIRE_INIT(); _glfw.platform.getWindowContentScale(window, xscale, yscale); } GLFWAPI float glfwGetWindowOpacity(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(1.f); return _glfw.platform.getWindowOpacity(window); } GLFWAPI void glfwSetWindowOpacity(GLFWwindow* handle, float opacity) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); assert(opacity == opacity); assert(opacity >= 0.f); assert(opacity <= 1.f); _GLFW_REQUIRE_INIT(); if (opacity != opacity || opacity < 0.f || opacity > 1.f) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid window opacity %f", opacity); return; } _glfw.platform.setWindowOpacity(window, opacity); } GLFWAPI void glfwIconifyWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); _glfw.platform.iconifyWindow(window); } GLFWAPI void glfwRestoreWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); _glfw.platform.restoreWindow(window); } GLFWAPI void glfwMaximizeWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); if (window->monitor) return; _glfw.platform.maximizeWindow(window); } GLFWAPI void glfwShowWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); if (window->monitor) return; _glfw.platform.showWindow(window); if (window->focusOnShow) _glfw.platform.focusWindow(window); } GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); _glfw.platform.requestWindowAttention(window); } GLFWAPI void glfwHideWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); if (window->monitor) return; _glfw.platform.hideWindow(window); } GLFWAPI void glfwFocusWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); _glfw.platform.focusWindow(window); } GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(0); switch (attrib) { case GLFW_FOCUSED: return _glfw.platform.windowFocused(window); case GLFW_ICONIFIED: return _glfw.platform.windowIconified(window); case GLFW_VISIBLE: return _glfw.platform.windowVisible(window); case GLFW_MAXIMIZED: return _glfw.platform.windowMaximized(window); case GLFW_HOVERED: return _glfw.platform.windowHovered(window); case GLFW_FOCUS_ON_SHOW: return window->focusOnShow; case GLFW_MOUSE_PASSTHROUGH: return window->mousePassthrough; case GLFW_TRANSPARENT_FRAMEBUFFER: return _glfw.platform.framebufferTransparent(window); case GLFW_RESIZABLE: return window->resizable; case GLFW_DECORATED: return window->decorated; case GLFW_FLOATING: return window->floating; case GLFW_AUTO_ICONIFY: return window->autoIconify; case GLFW_DOUBLEBUFFER: return window->doublebuffer; case GLFW_CLIENT_API: return window->context.client; case GLFW_CONTEXT_CREATION_API: return window->context.source; case GLFW_CONTEXT_VERSION_MAJOR: return window->context.major; case GLFW_CONTEXT_VERSION_MINOR: return window->context.minor; case GLFW_CONTEXT_REVISION: return window->context.revision; case GLFW_CONTEXT_ROBUSTNESS: return window->context.robustness; case GLFW_OPENGL_FORWARD_COMPAT: return window->context.forward; case GLFW_CONTEXT_DEBUG: return window->context.debug; case GLFW_OPENGL_PROFILE: return window->context.profile; case GLFW_CONTEXT_RELEASE_BEHAVIOR: return window->context.release; case GLFW_CONTEXT_NO_ERROR: return window->context.noerror; } _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib); return 0; } GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); value = value ? GLFW_TRUE : GLFW_FALSE; switch (attrib) { case GLFW_AUTO_ICONIFY: window->autoIconify = value; return; case GLFW_RESIZABLE: window->resizable = value; if (!window->monitor) _glfw.platform.setWindowResizable(window, value); return; case GLFW_DECORATED: window->decorated = value; if (!window->monitor) _glfw.platform.setWindowDecorated(window, value); return; case GLFW_FLOATING: window->floating = value; if (!window->monitor) _glfw.platform.setWindowFloating(window, value); return; case GLFW_FOCUS_ON_SHOW: window->focusOnShow = value; return; case GLFW_MOUSE_PASSTHROUGH: window->mousePassthrough = value; _glfw.platform.setWindowMousePassthrough(window, value); return; } _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib); } GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return (GLFWmonitor*) window->monitor; } GLFWAPI void glfwSetWindowMonitor(GLFWwindow* wh, GLFWmonitor* mh, int xpos, int ypos, int width, int height, int refreshRate) { _GLFWwindow* window = (_GLFWwindow*) wh; _GLFWmonitor* monitor = (_GLFWmonitor*) mh; assert(window != NULL); assert(width >= 0); assert(height >= 0); _GLFW_REQUIRE_INIT(); if (width <= 0 || height <= 0) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid window size %ix%i", width, height); return; } if (refreshRate < 0 && refreshRate != GLFW_DONT_CARE) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid refresh rate %i", refreshRate); return; } window->videoMode.width = width; window->videoMode.height = height; window->videoMode.refreshRate = refreshRate; _glfw.platform.setWindowMonitor(window, monitor, xpos, ypos, width, height, refreshRate); } GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT(); window->userPointer = pointer; } GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->userPointer; } GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowposfun, window->callbacks.pos, cbfun); return cbfun; } GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowsizefun, window->callbacks.size, cbfun); return cbfun; } GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowclosefun, window->callbacks.close, cbfun); return cbfun; } GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowrefreshfun, window->callbacks.refresh, cbfun); return cbfun; } GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowfocusfun, window->callbacks.focus, cbfun); return cbfun; } GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowiconifyfun, window->callbacks.iconify, cbfun); return cbfun; } GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* handle, GLFWwindowmaximizefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowmaximizefun, window->callbacks.maximize, cbfun); return cbfun; } GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle, GLFWframebuffersizefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWframebuffersizefun, window->callbacks.fbsize, cbfun); return cbfun; } GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* handle, GLFWwindowcontentscalefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP(GLFWwindowcontentscalefun, window->callbacks.scale, cbfun); return cbfun; } GLFWAPI void glfwPollEvents(void) { _GLFW_REQUIRE_INIT(); _glfw.platform.pollEvents(); } GLFWAPI void glfwWaitEvents(void) { _GLFW_REQUIRE_INIT(); _glfw.platform.waitEvents(); } GLFWAPI void glfwWaitEventsTimeout(double timeout) { _GLFW_REQUIRE_INIT(); assert(timeout == timeout); assert(timeout >= 0.0); assert(timeout <= DBL_MAX); if (timeout != timeout || timeout < 0.0 || timeout > DBL_MAX) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid time %f", timeout); return; } _glfw.platform.waitEventsTimeout(timeout); } GLFWAPI void glfwPostEmptyEvent(void) { _GLFW_REQUIRE_INIT(); _glfw.platform.postEmptyEvent(); }
192d6af635546b7fb3c385c9fef3f174a165e70a
9e1a59ba13b7da264a2b434243ccb7e9bdf01b89
/bjoern/statsd_tags.h
dc974d79d6f8488bee334a47fa271715e1028b04
[ "BSD-2-Clause" ]
permissive
jonashaag/bjoern
efbc9dc85aa96d2f5b4c44cded2de6aa031e17c5
25b14e5042f51eb869d6bfb67fe7e6213c9747ee
refs/heads/master
2023-06-25T04:35:42.988962
2022-09-11T18:36:33
2022-09-11T18:40:12
542,089
2,641
220
NOASSERTION
2023-06-17T21:36:30
2010-03-01T23:46:47
C
UTF-8
C
false
false
266
h
statsd_tags.h
#ifndef __statsd_tags__ #define __statsd_tags__ #include "statsd-client.h" int send_stats_with_tags(statsd_link* link, char *stat, size_t value, const char *type, const char* tags); int statsd_inc_with_tags(statsd_link* link, char *stat, const char* tags); #endif
66df135a59d025873969e0bea5916dfd3a23e7f4
03666e5f961946fc1a0ac67781ac1425562ef0d7
/src/databases/Cube/avtCubeOptions.C
7d371347e191fb88b3fcd4bdedcb879243f06e73
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
visit-dav/visit
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
601ae46e0bef2e18425b482a755d03490ade0493
refs/heads/develop
2023-09-06T08:19:38.397058
2023-09-05T21:29:32
2023-09-05T21:29:32
165,565,988
335
120
BSD-3-Clause
2023-09-14T00:53:37
2019-01-13T23:27:26
C
UTF-8
C
false
false
2,759
c
avtCubeOptions.C
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt // Project developers. See the top-level LICENSE file for dates and other // details. No copyright assignment is required to contribute to VisIt. // ************************************************************************* // // avtCubeOptions.C // // ************************************************************************* // #include <avtCubeOptions.h> #include <DBOptionsAttributes.h> #include <string> // **************************************************************************** // Function: GetCubeReadOptions // // Purpose: // Creates the options for Cube readers. // // Important Note: // The code below sets up empty options. If your format // does not require read options, no modifications are // necessary. // // Programmer: prabhat -- generated by xml2avt // Creation: Fri Jun 12 09:11:12 PDT 2009 // // Programmer: oruebel -- Rename to Cube and removed Walker functionality // Modified: Thu May 12 11:18 PDT 2009 // // Programmer: jfavre -- Added a boolean to extend the grid by one cell for CP2K users // Modified: Fri Apr 26 11:12:38 CEST 2013 // // **************************************************************************** DBOptionsAttributes * GetCubeReadOptions(void) { DBOptionsAttributes *rv = new DBOptionsAttributes; //default value false means this is the unchanged behavior up to version 2.6.2 rv->SetBool("ExtendVolumeByOneCell", true); /* EXAMPLE OF OPTIONS rv->SetBool("Big Endian", false); rv->SetEnum("Dimension", 1); vector<string> dims; dims.push_back("0D"); dims.push_back("1D"); dims.push_back("2D"); dims.push_back("3D"); rv->SetEnumStrings("Dimension", dims); rv->SetInt("Number of variables", 5); rv->SetString("Name of auxiliary file", ); rv->SetDouble("Displacement factor", 1.0); // When reading or writing the file, you can get the options out of this object like: rv->GetDouble("Displacement factor"); */ return rv; } // **************************************************************************** // Function: GetCubeWriteOptions // // Purpose: // Creates the options for Cube writers. // // Important Note: // The code below sets up empty options. If your format // does not require write options, no modifications are // necessary. // // Programmer: prabhat -- generated by xml2avt // Creation: Fri Jun 12 09:11:12 PDT 2009 // // **************************************************************************** DBOptionsAttributes * GetCubeWriteOptions(void) { DBOptionsAttributes *rv = new DBOptionsAttributes; return rv; }
04c709ac5ceb3fea28add134a4c4f012a8e19212
9823f12bbe144dae3c9decaba2bc38d3a2e94e90
/user/board/spark_f1/mcu_config.h
72127270557f4ecf617f417c3ff688477a480ee2
[ "MIT" ]
permissive
eboxmaker/eBox_Framework
e8512fe26ecd729df97fdf38c875567677954858
b6c19c526568ac68df3032295c46cbd26212e111
refs/heads/master
2023-08-15T10:41:53.584433
2023-07-23T04:10:52
2023-07-23T04:10:52
95,169,842
133
68
MIT
2020-10-31T01:02:41
2017-06-23T01:07:19
C
GB18030
C
false
false
2,088
h
mcu_config.h
#ifndef __MCU_CONFIG_H #define __MCU_CONFIG_H #include "stdint.h" #include "ebox_type.h" //用户配置区域 //请查阅ebox_cpu_type.h寻找特定信号CPU的详细配置 #define STM32_TYPE STM32F103C8 #define STM32_PINS 48 #define STM32_RAM1 20 #define STM32_COMPANY "ST\0" #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ //由于KEIL自身有编译的宏定义会导致此选项无效,所以要更改keil的device选项,选择正确的MCU //#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL) //#if (STM32_FLASH <= 32) //#define STM32F10X_LD //#elif (STM32_FLASH <= 128) //#define STM32F10X_MD //#elif (MCU_FLASH <= 1024) //#define STM32F10X_HD //#endif //#endif //外设配置 //------------------抽象层宏定义------------------------ #define MCU_TYPE STM32_TYPE #define MCU_PINS STM32_PINS #define MCU_COMPANY STM32_COMPANY //RAM 区域定义 #define MCU_SRAM1_SIZE STM32_RAM1*1024 #define MCU_SRAM1_BEGIN 0x20000000 #define MCU_SRAM1_END (MCU_SRAM1_BEGIN + MCU_SRAM1_SIZE) #if defined(__CC_ARM) || defined(__clang__) extern int Image$$RW_IRAM1$$ZI$$Limit; #define MCU_HEAP_BEGIN ((uint32_t)&Image$$RW_IRAM1$$ZI$$Limit) #elif __ICCARM__ #pragma section="HEAP" #else extern int __bss_end; #endif #define MCU_HEAP_END MCU_SRAM1_END #define MCU_HEAP_SIZE (MCU_HEAP_END - MCU_HEAP_BEGIN) #define MCU_SRAM1_USED (MCU_HEAP_BEGIN - MCU_SRAM1_BEGIN) #define MCU_SRAM1_REMAIND (MCU_SRAM1_END - MCU_HEAP_BEGIN) //FLASH 区域定义 #if defined(__CC_ARM) || defined(__clang__) extern int SHT$$INIT_ARRAY$$Limit; #define MCU_FLASH_PRG_END ((uint32_t)&SHT$$INIT_ARRAY$$Limit) #endif #define MCU_FLASH_BEGIN 0x8000000 #define MCU_FLASH_USED (MCU_FLASH_PRG_END - MCU_FLASH_BEGIN) //-------------------------------------------------------- #include "stm32f10x.h" #endif
e4fa959a032d138c38b75a113e812fe4c8f2b1bc
32ebd1bf59f0e9be34363e3c9e34b10d2cf3eb9e
/2021/Reversing/Lonely_Knight/Admin/chall/level_data.c
4b02524e2d3712a349a5e24332b9a5f8c7ad9b34
[ "MIT" ]
permissive
teambi0s/InCTFi
d7fb450ec7b8b08e36dcee656d6111d9bd14127c
b249e5b41dba80bcbfc6ccd986c8fd64d8afa87c
refs/heads/master
2022-07-22T09:54:58.393301
2021-08-19T18:14:40
2021-08-19T18:14:40
152,749,662
139
64
null
2022-07-05T22:14:31
2018-10-12T12:48:23
CSS
UTF-8
C
false
false
4,911
c
level_data.c
enum{COIN_REG, COIN_END}; //NOTE MAX_COINS = 12 //y, room, x, type //y = TURN_OFF end of list const unsigned char level_1_coins[]={ 0x90, 0, 0x70, COIN_REG, 0xc0, 1, 0x40, COIN_REG, 0x60, 1, 0x90, COIN_REG, 0x80, 2, 0x00, COIN_REG, 0xa1, 2, 0x70, COIN_REG, 0x69, 3, 0xa0, COIN_REG, 0x71, 4, 0xd0, COIN_REG, 0x75, 5, 0xf0, COIN_REG, 0xc3, 6, 0x20, COIN_REG, 0xb9, 7, 0xc0, COIN_END, TURN_OFF }; const unsigned char level_2_coins[]={ 0xa0, 0, 0x20, COIN_REG, 0xa0, 1, 0x40, COIN_REG, 0x60, 2, 0x70, COIN_REG, 0xaf, 3, 0x20, COIN_REG, 0xbc, 3, 0x70, COIN_REG, 0xc1, 5, 0x50, COIN_REG, 0x7a, 6, 0x90, COIN_REG, 0x9a, 6, 0xd0, COIN_REG, 0x60, 7, 0x30, COIN_END, 0xa0, 7, 0x40, COIN_REG, TURN_OFF }; const unsigned char level_3_coins[]={ 0x80, 0, 0x80, COIN_REG, 0x70, 1, 0x50, COIN_REG, 0x80, 1, 0xd0, COIN_REG, 0x80, 2, 0x40, COIN_REG, 0x80, 2, 0x80, COIN_REG, 0x80, 2, 0xc0, COIN_REG, 0x80, 3, 0x30, COIN_REG, 0xa0, 7, 0x25, COIN_END, 0x70, 7, 0x80, COIN_REG, 0xb0, 7, 0xd0, COIN_REG, TURN_OFF }; const unsigned char level_4_coins[]={ 0x69, 1, 0x50, COIN_REG, 0x79, 1, 0x80, COIN_REG, 0x8a, 1, 0xd0, COIN_REG, 0x8f, 2, 0x40, COIN_REG, 0x8b, 2, 0x80, COIN_REG, 0x81, 2, 0xc0, COIN_REG, 0x80, 3, 0x30, COIN_REG, 0xa0, 7, 0x25, COIN_REG, 0xc0, 7, 0x80, COIN_END, 0xb0, 7, 0xe0, COIN_REG, TURN_OFF }; const unsigned char * const Coins_list[]={ level_1_coins, level_2_coins, level_3_coins , level_4_coins }; enum{ENEMY_CHASE, ENEMY_BOUNCE}; //NOTE MAX_ENEMY = 10 //NOTE, after testing, we can only handle 4 enemies on the same screen //y, room, x //y = TURN_OFF end of list const unsigned char level_1_enemies[]={ /* stress test 0x11,0,0xe2,ENEMY_CHASE, 0x21,0,0xe4,ENEMY_CHASE, 0x31,0,0xe6,ENEMY_CHASE, 0x41,0,0xe8,ENEMY_CHASE, 0x51,0,0xe8,ENEMY_CHASE, 0x61,0,0xe8,ENEMY_CHASE, 0x71,0,0xe8,ENEMY_CHASE, */ 0xc0, 0, 0xc0, ENEMY_CHASE, 0xc0, 1, 0xe0, ENEMY_CHASE, 0xc0, 2, 0x30, ENEMY_CHASE, 0xc0, 3, 0x90, ENEMY_CHASE, 0xb0, 4, 0x20, ENEMY_CHASE, 0xc0, 5, 0xb0, ENEMY_CHASE, 0x80, 6, 0x00, ENEMY_CHASE, 0xc0, 7, 0x90, ENEMY_CHASE, TURN_OFF }; const unsigned char level_2_enemies[]={ 0xc0, 0, 0x90, ENEMY_BOUNCE, 0xc0, 1, 0xd0, ENEMY_BOUNCE, 0x40, 2, 0x40, ENEMY_BOUNCE, 0xc0, 3, 0x30, ENEMY_BOUNCE, 0xc0, 4, 0x80, ENEMY_BOUNCE, 0xc0, 5, 0x20, ENEMY_BOUNCE, 0xc0, 6, 0x20, ENEMY_BOUNCE, 0xc0, 7, 0x60, ENEMY_BOUNCE, TURN_OFF }; const unsigned char level_3_enemies[]={ 0xc0, 0, 0xc0, ENEMY_BOUNCE, 0xc0, 1, 0xf0, ENEMY_BOUNCE, 0xc0, 2, 0x80, ENEMY_CHASE, 0xc0, 3, 0xd0, ENEMY_CHASE, 0xc0, 4, 0x40, ENEMY_BOUNCE, 0xc0, 5, 0x80, ENEMY_BOUNCE, 0xc0, 6, 0xc0, ENEMY_BOUNCE, 0xb0, 7, 0x10, ENEMY_CHASE, TURN_OFF }; const unsigned char level_4_enemies[]={ 0xc0, 0, 0xc0, ENEMY_BOUNCE, 0xc0, 1, 0xf0, ENEMY_BOUNCE, 0xc0, 2, 0x80, ENEMY_CHASE, 0xc0, 3, 0xd0, ENEMY_CHASE, 0xc0, 4, 0x40, ENEMY_BOUNCE, 0xc0, 5, 0x80, ENEMY_BOUNCE, 0xc0, 6, 0xc0, ENEMY_BOUNCE, 0xb0, 7, 0x10, ENEMY_BOUNCE, 0xb0, 7, 0x60, ENEMY_CHASE, TURN_OFF }; const unsigned char * const Enemy_list[]={ level_1_enemies, level_2_enemies, level_3_enemies,level_4_enemies }; // 5 bytes per metatile definition, tile TL, TR, BL, BR, palette 0-3 // T means top, B means bottom, L left,R right // 51 maximum # of metatiles = 255 bytes // 5th byte, 1000 0000 = floor collision // 0100 0000 = all collision, solid // 0000 0011 = palette const unsigned char metatiles1[]={ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 3, 3, 3, 3, 0, 4, 4, 4, 4, 0, 20, 20, 20, 20, 0, 5, 7, 24, 26, 0, 18, 18, 18, 18, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 3, 3, 3, 3, 1, 17, 17, 17, 17, 1, 18, 18, 18, 18, 1, 5, 7, 24, 26, 1, 20, 20, 20, 20, 2, 4, 4, 4, 4, 2, 18, 18, 18, 18, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 2, 5, 7, 24, 26, 2, 18, 18, 18, 18, 3, 17, 17, 17, 17, 3, 1, 1, 1, 1, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 5, 7, 24, 26, 3 }; #define COL_DOWN 0x80 #define COL_ALL 0x40 /* const unsigned char is_solid[]={ 0, COL_DOWN, COL_ALL+COL_DOWN, COL_DOWN, COL_DOWN, COL_DOWN, 0, 0, 0, 0, 0, 0 }; */ const unsigned char is_solid[]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #include "BG/Level1.c" #include "BG/Level2.c" #include "BG/Level3.c" #include "BG/Level4.c" const unsigned char * const Levels_list[]={ Level1_0,Level1_1,Level1_2,Level1_3,Level1_4,Level1_5,Level1_6,Level1_7, Level2_0,Level2_1,Level2_2,Level2_3,Level2_4,Level2_5,Level2_6,Level2_7, Level3_0,Level3_1,Level3_2,Level3_3,Level3_4,Level3_5,Level3_6,Level3_7, Level4_0,Level4_1,Level4_2,Level4_3,Level4_4,Level4_5,Level4_6,Level4_7 }; const unsigned char Level_offsets[]={ 0,8,16,24 }; #define MAX_ROOMS (8-1) #define MAX_SCROLL (MAX_ROOMS*0x100)-1 // data is exactly 240 bytes, 16 * 15 // doubles as the collision map data
ba07e62bb634cae23ee13e889f7e15090e8cb64b
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/include/linux/spi/sh_msiof.h
2e8db3d2d2e5ef7aedbd834534cd7fe6625d9c34
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
185
h
sh_msiof.h
#ifndef __SPI_SH_MSIOF_H__ #define __SPI_SH_MSIOF_H__ struct sh_msiof_spi_info { int tx_fifo_override; int rx_fifo_override; u16 num_chipselect; }; #endif /* __SPI_SH_MSIOF_H__ */
715f46a257af5f792708662bdc9d7de09992edae
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/drivers/base/power/main.c
287b3c4a139bbf3a99e122633f0467814d500003
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
36,402
c
main.c
/* * drivers/base/power/main.c - Where the driver meets power management. * * Copyright (c) 2003 Patrick Mochel * Copyright (c) 2003 Open Source Development Lab * * This file is released under the GPLv2 * * * The driver model core calls device_pm_add() when a device is registered. * This will initialize the embedded device_pm_info object in the device * and add it to the list of power-controlled devices. sysfs entries for * controlling device power management will also be added. * * A separate list is used for keeping track of power info, because the power * domain dependencies may differ from the ancestral dependencies that the * subsystem list maintains. */ #include <linux/device.h> #include <linux/kallsyms.h> #include <linux/export.h> #include <linux/mutex.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/resume-trace.h> #include <linux/interrupt.h> #include <linux/sched.h> #include <linux/async.h> #include <linux/suspend.h> #include <trace/events/power.h> #include <linux/cpufreq.h> #include <linux/cpuidle.h> #include <linux/timer.h> #include <linux/wakeup_reason.h> #include <linux/delay.h> #include "../base.h" #include "power.h" typedef int (*pm_callback_t)(struct device *); /* * The entries in the dpm_list list are in a depth first order, simply * because children are guaranteed to be discovered after parents, and * are inserted at the back of the list on discovery. * * Since device_pm_add() may be called with a device lock held, * we must never try to acquire a device lock while holding * dpm_list_mutex. */ LIST_HEAD(dpm_list); static LIST_HEAD(dpm_prepared_list); static LIST_HEAD(dpm_suspended_list); static LIST_HEAD(dpm_late_early_list); static LIST_HEAD(dpm_noirq_list); struct suspend_stats suspend_stats; static DEFINE_MUTEX(dpm_list_mtx); static pm_message_t pm_transition; struct dpm_watchdog { struct device *dev; struct task_struct *tsk; struct timer_list timer; }; static int async_error; /** * device_pm_sleep_init - Initialize system suspend-related device fields. * @dev: Device object being initialized. */ void device_pm_sleep_init(struct device *dev) { dev->power.is_prepared = false; dev->power.is_suspended = false; init_completion(&dev->power.completion); complete_all(&dev->power.completion); dev->power.wakeup = NULL; INIT_LIST_HEAD(&dev->power.entry); } /** * device_pm_lock - Lock the list of active devices used by the PM core. */ void device_pm_lock(void) { mutex_lock(&dpm_list_mtx); } /** * device_pm_unlock - Unlock the list of active devices used by the PM core. */ void device_pm_unlock(void) { mutex_unlock(&dpm_list_mtx); } /** * device_pm_add - Add a device to the PM core's list of active devices. * @dev: Device to add to the list. */ void device_pm_add(struct device *dev) { pr_debug("PM: Adding info for %s:%s\n", dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); mutex_lock(&dpm_list_mtx); if (dev->parent && dev->parent->power.is_prepared) dev_warn(dev, "parent %s should not be sleeping\n", dev_name(dev->parent)); list_add_tail(&dev->power.entry, &dpm_list); mutex_unlock(&dpm_list_mtx); } /** * device_pm_remove - Remove a device from the PM core's list of active devices. * @dev: Device to be removed from the list. */ void device_pm_remove(struct device *dev) { pr_debug("PM: Removing info for %s:%s\n", dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); complete_all(&dev->power.completion); mutex_lock(&dpm_list_mtx); list_del_init(&dev->power.entry); mutex_unlock(&dpm_list_mtx); device_wakeup_disable(dev); pm_runtime_remove(dev); } /** * device_pm_move_before - Move device in the PM core's list of active devices. * @deva: Device to move in dpm_list. * @devb: Device @deva should come before. */ void device_pm_move_before(struct device *deva, struct device *devb) { pr_debug("PM: Moving %s:%s before %s:%s\n", deva->bus ? deva->bus->name : "No Bus", dev_name(deva), devb->bus ? devb->bus->name : "No Bus", dev_name(devb)); /* Delete deva from dpm_list and reinsert before devb. */ list_move_tail(&deva->power.entry, &devb->power.entry); } /** * device_pm_move_after - Move device in the PM core's list of active devices. * @deva: Device to move in dpm_list. * @devb: Device @deva should come after. */ void device_pm_move_after(struct device *deva, struct device *devb) { pr_debug("PM: Moving %s:%s after %s:%s\n", deva->bus ? deva->bus->name : "No Bus", dev_name(deva), devb->bus ? devb->bus->name : "No Bus", dev_name(devb)); /* Delete deva from dpm_list and reinsert after devb. */ list_move(&deva->power.entry, &devb->power.entry); } /** * device_pm_move_last - Move device to end of the PM core's list of devices. * @dev: Device to move in dpm_list. */ void device_pm_move_last(struct device *dev) { pr_debug("PM: Moving %s:%s to end of list\n", dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); list_move_tail(&dev->power.entry, &dpm_list); } static ktime_t initcall_debug_start(struct device *dev) { ktime_t calltime = ktime_set(0, 0); if (pm_print_times_enabled) { pr_info("calling %s+ @ %i, parent: %s\n", dev_name(dev), task_pid_nr(current), dev->parent ? dev_name(dev->parent) : "none"); calltime = ktime_get(); } return calltime; } static void initcall_debug_report(struct device *dev, ktime_t calltime, int error) { ktime_t delta, rettime; if (pm_print_times_enabled) { rettime = ktime_get(); delta = ktime_sub(rettime, calltime); pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev), error, (unsigned long long)ktime_to_ns(delta) >> 10); if(initcall_debug_delay_ms > 0){ printk("sleep %d ms for debug. \n", initcall_debug_delay_ms); msleep(initcall_debug_delay_ms); } } } /** * dpm_wait - Wait for a PM operation to complete. * @dev: Device to wait for. * @async: If unset, wait only if the device's power.async_suspend flag is set. */ static void dpm_wait(struct device *dev, bool async) { if (!dev) return; if (async || (pm_async_enabled && dev->power.async_suspend)) wait_for_completion(&dev->power.completion); } static int dpm_wait_fn(struct device *dev, void *async_ptr) { dpm_wait(dev, *((bool *)async_ptr)); return 0; } static void dpm_wait_for_children(struct device *dev, bool async) { device_for_each_child(dev, &async, dpm_wait_fn); } /** * pm_op - Return the PM operation appropriate for given PM event. * @ops: PM operations to choose from. * @state: PM transition of the system being carried out. */ static pm_callback_t pm_op(const struct dev_pm_ops *ops, pm_message_t state) { switch (state.event) { #ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND: return ops->suspend; case PM_EVENT_RESUME: return ops->resume; #endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: return ops->freeze; case PM_EVENT_HIBERNATE: return ops->poweroff; case PM_EVENT_THAW: case PM_EVENT_RECOVER: return ops->thaw; break; case PM_EVENT_RESTORE: return ops->restore; #endif /* CONFIG_HIBERNATE_CALLBACKS */ } return NULL; } /** * pm_late_early_op - Return the PM operation appropriate for given PM event. * @ops: PM operations to choose from. * @state: PM transition of the system being carried out. * * Runtime PM is disabled for @dev while this function is being executed. */ static pm_callback_t pm_late_early_op(const struct dev_pm_ops *ops, pm_message_t state) { switch (state.event) { #ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND: return ops->suspend_late; case PM_EVENT_RESUME: return ops->resume_early; #endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: return ops->freeze_late; case PM_EVENT_HIBERNATE: return ops->poweroff_late; case PM_EVENT_THAW: case PM_EVENT_RECOVER: return ops->thaw_early; case PM_EVENT_RESTORE: return ops->restore_early; #endif /* CONFIG_HIBERNATE_CALLBACKS */ } return NULL; } /** * pm_noirq_op - Return the PM operation appropriate for given PM event. * @ops: PM operations to choose from. * @state: PM transition of the system being carried out. * * The driver of @dev will not receive interrupts while this function is being * executed. */ static pm_callback_t pm_noirq_op(const struct dev_pm_ops *ops, pm_message_t state) { switch (state.event) { #ifdef CONFIG_SUSPEND case PM_EVENT_SUSPEND: return ops->suspend_noirq; case PM_EVENT_RESUME: return ops->resume_noirq; #endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: return ops->freeze_noirq; case PM_EVENT_HIBERNATE: return ops->poweroff_noirq; case PM_EVENT_THAW: case PM_EVENT_RECOVER: return ops->thaw_noirq; case PM_EVENT_RESTORE: return ops->restore_noirq; #endif /* CONFIG_HIBERNATE_CALLBACKS */ } return NULL; } static char *pm_verb(int event) { switch (event) { case PM_EVENT_SUSPEND: return "suspend"; case PM_EVENT_RESUME: return "resume"; case PM_EVENT_FREEZE: return "freeze"; case PM_EVENT_QUIESCE: return "quiesce"; case PM_EVENT_HIBERNATE: return "hibernate"; case PM_EVENT_THAW: return "thaw"; case PM_EVENT_RESTORE: return "restore"; case PM_EVENT_RECOVER: return "recover"; default: return "(unknown PM event)"; } } static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info) { dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event), ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ? ", may wakeup" : ""); } static void pm_dev_err(struct device *dev, pm_message_t state, char *info, int error) { printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n", dev_name(dev), pm_verb(state.event), info, error); } static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info) { ktime_t calltime; u64 usecs64; int usecs; calltime = ktime_get(); usecs64 = ktime_to_ns(ktime_sub(calltime, starttime)); do_div(usecs64, NSEC_PER_USEC); usecs = usecs64; if (usecs == 0) usecs = 1; pr_info("PM: %s%s%s of devices complete after %ld.%03ld msecs\n", info ?: "", info ? " " : "", pm_verb(state.event), usecs / USEC_PER_MSEC, usecs % USEC_PER_MSEC); } static int dpm_run_callback(pm_callback_t cb, struct device *dev, pm_message_t state, char *info) { ktime_t calltime; int error; if (!cb) return 0; calltime = initcall_debug_start(dev); pm_dev_dbg(dev, state, info); error = cb(dev); suspend_report_result(cb, error); initcall_debug_report(dev, calltime, error); return error; } /** * dpm_wd_handler - Driver suspend / resume watchdog handler. * * Called when a driver has timed out suspending or resuming. * There's not much we can do here to recover so BUG() out for * a crash-dump */ static void dpm_wd_handler(unsigned long data) { struct dpm_watchdog *wd = (void *)data; struct device *dev = wd->dev; struct task_struct *tsk = wd->tsk; dev_emerg(dev, "**** DPM device timeout ****\n"); show_stack(tsk, NULL); BUG(); } /** * dpm_wd_set - Enable pm watchdog for given device. * @wd: Watchdog. Must be allocated on the stack. * @dev: Device to handle. */ static void dpm_wd_set(struct dpm_watchdog *wd, struct device *dev) { struct timer_list *timer = &wd->timer; wd->dev = dev; wd->tsk = get_current(); init_timer_on_stack(timer); timer->expires = jiffies + (initcall_debug_delay_ms/1000 + 12) * HZ; timer->function = dpm_wd_handler; timer->data = (unsigned long)wd; add_timer(timer); } /** * dpm_wd_clear - Disable pm watchdog. * @wd: Watchdog to disable. */ static void dpm_wd_clear(struct dpm_watchdog *wd) { struct timer_list *timer = &wd->timer; del_timer_sync(timer); destroy_timer_on_stack(timer); } /*------------------------- Resume routines -------------------------*/ /** * device_resume_noirq - Execute an "early resume" callback for given device. * @dev: Device to handle. * @state: PM transition of the system being carried out. * * The driver of @dev will not receive interrupts while this function is being * executed. */ static int device_resume_noirq(struct device *dev, pm_message_t state) { pm_callback_t callback = NULL; char *info = NULL; int error = 0; TRACE_DEVICE(dev); TRACE_RESUME(0); if (dev->power.syscore) goto Out; if (dev->pm_domain) { info = "noirq power domain "; callback = pm_noirq_op(&dev->pm_domain->ops, state); } else if (dev->type && dev->type->pm) { info = "noirq type "; callback = pm_noirq_op(dev->type->pm, state); } else if (dev->class && dev->class->pm) { info = "noirq class "; callback = pm_noirq_op(dev->class->pm, state); } else if (dev->bus && dev->bus->pm) { info = "noirq bus "; callback = pm_noirq_op(dev->bus->pm, state); } if (!callback && dev->driver && dev->driver->pm) { info = "noirq driver "; callback = pm_noirq_op(dev->driver->pm, state); } error = dpm_run_callback(callback, dev, state, info); Out: TRACE_RESUME(error); return error; } /** * dpm_resume_noirq - Execute "noirq resume" callbacks for all devices. * @state: PM transition of the system being carried out. * * Call the "noirq" resume handlers for all devices in dpm_noirq_list and * enable device drivers to receive interrupts. */ static void dpm_resume_noirq(pm_message_t state) { ktime_t starttime = ktime_get(); mutex_lock(&dpm_list_mtx); while (!list_empty(&dpm_noirq_list)) { struct device *dev = to_device(dpm_noirq_list.next); int error; get_device(dev); list_move_tail(&dev->power.entry, &dpm_late_early_list); mutex_unlock(&dpm_list_mtx); error = device_resume_noirq(dev, state); if (error) { suspend_stats.failed_resume_noirq++; dpm_save_failed_step(SUSPEND_RESUME_NOIRQ); dpm_save_failed_dev(dev_name(dev)); pm_dev_err(dev, state, " noirq", error); } mutex_lock(&dpm_list_mtx); put_device(dev); } mutex_unlock(&dpm_list_mtx); dpm_show_time(starttime, state, "noirq"); resume_device_irqs(); cpuidle_resume(); } /** * device_resume_early - Execute an "early resume" callback for given device. * @dev: Device to handle. * @state: PM transition of the system being carried out. * * Runtime PM is disabled for @dev while this function is being executed. */ static int device_resume_early(struct device *dev, pm_message_t state) { pm_callback_t callback = NULL; char *info = NULL; int error = 0; TRACE_DEVICE(dev); TRACE_RESUME(0); if (dev->power.syscore) goto Out; if (dev->pm_domain) { info = "early power domain "; callback = pm_late_early_op(&dev->pm_domain->ops, state); } else if (dev->type && dev->type->pm) { info = "early type "; callback = pm_late_early_op(dev->type->pm, state); } else if (dev->class && dev->class->pm) { info = "early class "; callback = pm_late_early_op(dev->class->pm, state); } else if (dev->bus && dev->bus->pm) { info = "early bus "; callback = pm_late_early_op(dev->bus->pm, state); } if (!callback && dev->driver && dev->driver->pm) { info = "early driver "; callback = pm_late_early_op(dev->driver->pm, state); } error = dpm_run_callback(callback, dev, state, info); Out: TRACE_RESUME(error); pm_runtime_enable(dev); return error; } /** * dpm_resume_early - Execute "early resume" callbacks for all devices. * @state: PM transition of the system being carried out. */ static void dpm_resume_early(pm_message_t state) { ktime_t starttime = ktime_get(); mutex_lock(&dpm_list_mtx); while (!list_empty(&dpm_late_early_list)) { struct device *dev = to_device(dpm_late_early_list.next); int error; get_device(dev); list_move_tail(&dev->power.entry, &dpm_suspended_list); mutex_unlock(&dpm_list_mtx); error = device_resume_early(dev, state); if (error) { suspend_stats.failed_resume_early++; dpm_save_failed_step(SUSPEND_RESUME_EARLY); dpm_save_failed_dev(dev_name(dev)); pm_dev_err(dev, state, " early", error); } mutex_lock(&dpm_list_mtx); put_device(dev); } mutex_unlock(&dpm_list_mtx); dpm_show_time(starttime, state, "early"); } /** * dpm_resume_start - Execute "noirq" and "early" device callbacks. * @state: PM transition of the system being carried out. */ void dpm_resume_start(pm_message_t state) { dpm_resume_noirq(state); dpm_resume_early(state); } EXPORT_SYMBOL_GPL(dpm_resume_start); /** * device_resume - Execute "resume" callbacks for given device. * @dev: Device to handle. * @state: PM transition of the system being carried out. * @async: If true, the device is being resumed asynchronously. */ static int device_resume(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback = NULL; char *info = NULL; int error = 0; struct dpm_watchdog wd; TRACE_DEVICE(dev); TRACE_RESUME(0); if (dev->power.syscore) goto Complete; dpm_wait(dev->parent, async); device_lock(dev); /* * This is a fib. But we'll allow new children to be added below * a resumed device, even if the device hasn't been completed yet. */ dev->power.is_prepared = false; dpm_wd_set(&wd, dev); if (!dev->power.is_suspended) goto Unlock; if (dev->pm_domain) { info = "power domain "; callback = pm_op(&dev->pm_domain->ops, state); goto Driver; } if (dev->type && dev->type->pm) { info = "type "; callback = pm_op(dev->type->pm, state); goto Driver; } if (dev->class) { if (dev->class->pm) { info = "class "; callback = pm_op(dev->class->pm, state); goto Driver; } else if (dev->class->resume) { info = "legacy class "; callback = dev->class->resume; goto End; } } if (dev->bus) { if (dev->bus->pm) { info = "bus "; callback = pm_op(dev->bus->pm, state); } else if (dev->bus->resume) { info = "legacy bus "; callback = dev->bus->resume; goto End; } } Driver: if (!callback && dev->driver && dev->driver->pm) { info = "driver "; callback = pm_op(dev->driver->pm, state); } End: error = dpm_run_callback(callback, dev, state, info); dev->power.is_suspended = false; Unlock: device_unlock(dev); dpm_wd_clear(&wd); Complete: complete_all(&dev->power.completion); TRACE_RESUME(error); return error; } static void async_resume(void *data, async_cookie_t cookie) { struct device *dev = (struct device *)data; int error; error = device_resume(dev, pm_transition, true); if (error) pm_dev_err(dev, pm_transition, " async", error); put_device(dev); } static bool is_async(struct device *dev) { return dev->power.async_suspend && pm_async_enabled && !pm_trace_is_enabled(); } /** * dpm_resume - Execute "resume" callbacks for non-sysdev devices. * @state: PM transition of the system being carried out. * * Execute the appropriate "resume" callback for all devices whose status * indicates that they are suspended. */ void dpm_resume(pm_message_t state) { struct device *dev; ktime_t starttime = ktime_get(); might_sleep(); mutex_lock(&dpm_list_mtx); pm_transition = state; async_error = 0; list_for_each_entry(dev, &dpm_suspended_list, power.entry) { INIT_COMPLETION(dev->power.completion); if (is_async(dev)) { get_device(dev); async_schedule(async_resume, dev); } } while (!list_empty(&dpm_suspended_list)) { dev = to_device(dpm_suspended_list.next); get_device(dev); if (!is_async(dev)) { int error; mutex_unlock(&dpm_list_mtx); error = device_resume(dev, state, false); if (error) { suspend_stats.failed_resume++; dpm_save_failed_step(SUSPEND_RESUME); dpm_save_failed_dev(dev_name(dev)); pm_dev_err(dev, state, "", error); } mutex_lock(&dpm_list_mtx); } if (!list_empty(&dev->power.entry)) list_move_tail(&dev->power.entry, &dpm_prepared_list); put_device(dev); } mutex_unlock(&dpm_list_mtx); async_synchronize_full(); dpm_show_time(starttime, state, NULL); cpufreq_resume(); } /** * device_complete - Complete a PM transition for given device. * @dev: Device to handle. * @state: PM transition of the system being carried out. */ static void device_complete(struct device *dev, pm_message_t state) { void (*callback)(struct device *) = NULL; char *info = NULL; if (dev->power.syscore) return; device_lock(dev); if (dev->pm_domain) { info = "completing power domain "; callback = dev->pm_domain->ops.complete; } else if (dev->type && dev->type->pm) { info = "completing type "; callback = dev->type->pm->complete; } else if (dev->class && dev->class->pm) { info = "completing class "; callback = dev->class->pm->complete; } else if (dev->bus && dev->bus->pm) { info = "completing bus "; callback = dev->bus->pm->complete; } if (!callback && dev->driver && dev->driver->pm) { info = "completing driver "; callback = dev->driver->pm->complete; } if (callback) { pm_dev_dbg(dev, state, info); callback(dev); } device_unlock(dev); pm_runtime_put(dev); } /** * dpm_complete - Complete a PM transition for all non-sysdev devices. * @state: PM transition of the system being carried out. * * Execute the ->complete() callbacks for all devices whose PM status is not * DPM_ON (this allows new devices to be registered). */ void dpm_complete(pm_message_t state) { struct list_head list; might_sleep(); INIT_LIST_HEAD(&list); mutex_lock(&dpm_list_mtx); while (!list_empty(&dpm_prepared_list)) { struct device *dev = to_device(dpm_prepared_list.prev); get_device(dev); dev->power.is_prepared = false; list_move(&dev->power.entry, &list); mutex_unlock(&dpm_list_mtx); device_complete(dev, state); mutex_lock(&dpm_list_mtx); put_device(dev); } list_splice(&list, &dpm_list); mutex_unlock(&dpm_list_mtx); } /** * dpm_resume_end - Execute "resume" callbacks and complete system transition. * @state: PM transition of the system being carried out. * * Execute "resume" callbacks for all devices and complete the PM transition of * the system. */ void dpm_resume_end(pm_message_t state) { dpm_resume(state); dpm_complete(state); } EXPORT_SYMBOL_GPL(dpm_resume_end); /*------------------------- Suspend routines -------------------------*/ /** * resume_event - Return a "resume" message for given "suspend" sleep state. * @sleep_state: PM message representing a sleep state. * * Return a PM message representing the resume event corresponding to given * sleep state. */ static pm_message_t resume_event(pm_message_t sleep_state) { switch (sleep_state.event) { case PM_EVENT_SUSPEND: return PMSG_RESUME; case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: return PMSG_RECOVER; case PM_EVENT_HIBERNATE: return PMSG_RESTORE; } return PMSG_ON; } /** * device_suspend_noirq - Execute a "late suspend" callback for given device. * @dev: Device to handle. * @state: PM transition of the system being carried out. * * The driver of @dev will not receive interrupts while this function is being * executed. */ static int device_suspend_noirq(struct device *dev, pm_message_t state) { pm_callback_t callback = NULL; char *info = NULL; if (dev->power.syscore) return 0; if (dev->pm_domain) { info = "noirq power domain "; callback = pm_noirq_op(&dev->pm_domain->ops, state); } else if (dev->type && dev->type->pm) { info = "noirq type "; callback = pm_noirq_op(dev->type->pm, state); } else if (dev->class && dev->class->pm) { info = "noirq class "; callback = pm_noirq_op(dev->class->pm, state); } else if (dev->bus && dev->bus->pm) { info = "noirq bus "; callback = pm_noirq_op(dev->bus->pm, state); } if (!callback && dev->driver && dev->driver->pm) { info = "noirq driver "; callback = pm_noirq_op(dev->driver->pm, state); } return dpm_run_callback(callback, dev, state, info); } /** * dpm_suspend_noirq - Execute "noirq suspend" callbacks for all devices. * @state: PM transition of the system being carried out. * * Prevent device drivers from receiving interrupts and call the "noirq" suspend * handlers for all non-sysdev devices. */ static int dpm_suspend_noirq(pm_message_t state) { ktime_t starttime = ktime_get(); char suspend_abort[MAX_SUSPEND_ABORT_LEN]; int error = 0; cpuidle_pause(); suspend_device_irqs(); mutex_lock(&dpm_list_mtx); while (!list_empty(&dpm_late_early_list)) { struct device *dev = to_device(dpm_late_early_list.prev); get_device(dev); mutex_unlock(&dpm_list_mtx); error = device_suspend_noirq(dev, state); mutex_lock(&dpm_list_mtx); if (error) { pm_dev_err(dev, state, " noirq", error); suspend_stats.failed_suspend_noirq++; dpm_save_failed_step(SUSPEND_SUSPEND_NOIRQ); dpm_save_failed_dev(dev_name(dev)); put_device(dev); break; } if (!list_empty(&dev->power.entry)) list_move(&dev->power.entry, &dpm_noirq_list); put_device(dev); if (pm_wakeup_pending()) { pm_get_active_wakeup_sources(suspend_abort, MAX_SUSPEND_ABORT_LEN); log_suspend_abort_reason(suspend_abort); error = -EBUSY; break; } } mutex_unlock(&dpm_list_mtx); if (error) dpm_resume_noirq(resume_event(state)); else dpm_show_time(starttime, state, "noirq"); return error; } /** * device_suspend_late - Execute a "late suspend" callback for given device. * @dev: Device to handle. * @state: PM transition of the system being carried out. * * Runtime PM is disabled for @dev while this function is being executed. */ static int device_suspend_late(struct device *dev, pm_message_t state) { pm_callback_t callback = NULL; char *info = NULL; __pm_runtime_disable(dev, false); if (dev->power.syscore) return 0; if (dev->pm_domain) { info = "late power domain "; callback = pm_late_early_op(&dev->pm_domain->ops, state); } else if (dev->type && dev->type->pm) { info = "late type "; callback = pm_late_early_op(dev->type->pm, state); } else if (dev->class && dev->class->pm) { info = "late class "; callback = pm_late_early_op(dev->class->pm, state); } else if (dev->bus && dev->bus->pm) { info = "late bus "; callback = pm_late_early_op(dev->bus->pm, state); } if (!callback && dev->driver && dev->driver->pm) { info = "late driver "; callback = pm_late_early_op(dev->driver->pm, state); } return dpm_run_callback(callback, dev, state, info); } /** * dpm_suspend_late - Execute "late suspend" callbacks for all devices. * @state: PM transition of the system being carried out. */ static int dpm_suspend_late(pm_message_t state) { ktime_t starttime = ktime_get(); char suspend_abort[MAX_SUSPEND_ABORT_LEN]; int error = 0; mutex_lock(&dpm_list_mtx); while (!list_empty(&dpm_suspended_list)) { struct device *dev = to_device(dpm_suspended_list.prev); get_device(dev); mutex_unlock(&dpm_list_mtx); error = device_suspend_late(dev, state); mutex_lock(&dpm_list_mtx); if (error) { pm_dev_err(dev, state, " late", error); suspend_stats.failed_suspend_late++; dpm_save_failed_step(SUSPEND_SUSPEND_LATE); dpm_save_failed_dev(dev_name(dev)); put_device(dev); break; } if (!list_empty(&dev->power.entry)) list_move(&dev->power.entry, &dpm_late_early_list); put_device(dev); if (pm_wakeup_pending()) { pm_get_active_wakeup_sources(suspend_abort, MAX_SUSPEND_ABORT_LEN); log_suspend_abort_reason(suspend_abort); error = -EBUSY; break; } } mutex_unlock(&dpm_list_mtx); if (error) dpm_resume_early(resume_event(state)); else dpm_show_time(starttime, state, "late"); return error; } /** * dpm_suspend_end - Execute "late" and "noirq" device suspend callbacks. * @state: PM transition of the system being carried out. */ int dpm_suspend_end(pm_message_t state) { int error = dpm_suspend_late(state); if (error) return error; error = dpm_suspend_noirq(state); if (error) { dpm_resume_early(resume_event(state)); return error; } return 0; } EXPORT_SYMBOL_GPL(dpm_suspend_end); /** * legacy_suspend - Execute a legacy (bus or class) suspend callback for device. * @dev: Device to suspend. * @state: PM transition of the system being carried out. * @cb: Suspend callback to execute. */ static int legacy_suspend(struct device *dev, pm_message_t state, int (*cb)(struct device *dev, pm_message_t state)) { int error; ktime_t calltime; calltime = initcall_debug_start(dev); error = cb(dev, state); suspend_report_result(cb, error); initcall_debug_report(dev, calltime, error); return error; } /** * device_suspend - Execute "suspend" callbacks for given device. * @dev: Device to handle. * @state: PM transition of the system being carried out. * @async: If true, the device is being suspended asynchronously. */ static int __device_suspend(struct device *dev, pm_message_t state, bool async) { pm_callback_t callback = NULL; char *info = NULL; int error = 0; struct dpm_watchdog wd; char suspend_abort[MAX_SUSPEND_ABORT_LEN]; dpm_wait_for_children(dev, async); if (async_error) goto Complete; /* * If a device configured to wake up the system from sleep states * has been suspended at run time and there's a resume request pending * for it, this is equivalent to the device signaling wakeup, so the * system suspend operation should be aborted. */ if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) pm_wakeup_event(dev, 0); if (pm_wakeup_pending()) { pm_get_active_wakeup_sources(suspend_abort, MAX_SUSPEND_ABORT_LEN); log_suspend_abort_reason(suspend_abort); async_error = -EBUSY; goto Complete; } if (dev->power.syscore) goto Complete; dpm_wd_set(&wd, dev); device_lock(dev); if (dev->pm_domain) { info = "power domain "; callback = pm_op(&dev->pm_domain->ops, state); goto Run; } if (dev->type && dev->type->pm) { info = "type "; callback = pm_op(dev->type->pm, state); goto Run; } if (dev->class) { if (dev->class->pm) { info = "class "; callback = pm_op(dev->class->pm, state); goto Run; } else if (dev->class->suspend) { pm_dev_dbg(dev, state, "legacy class "); error = legacy_suspend(dev, state, dev->class->suspend); goto End; } } if (dev->bus) { if (dev->bus->pm) { info = "bus "; callback = pm_op(dev->bus->pm, state); } else if (dev->bus->suspend) { pm_dev_dbg(dev, state, "legacy bus "); error = legacy_suspend(dev, state, dev->bus->suspend); goto End; } } Run: if (!callback && dev->driver && dev->driver->pm) { info = "driver "; callback = pm_op(dev->driver->pm, state); } error = dpm_run_callback(callback, dev, state, info); End: if (!error) { dev->power.is_suspended = true; if (dev->power.wakeup_path && dev->parent && !dev->parent->power.ignore_children) dev->parent->power.wakeup_path = true; } device_unlock(dev); dpm_wd_clear(&wd); Complete: complete_all(&dev->power.completion); if (error) async_error = error; return error; } static void async_suspend(void *data, async_cookie_t cookie) { struct device *dev = (struct device *)data; int error; error = __device_suspend(dev, pm_transition, true); if (error) { dpm_save_failed_dev(dev_name(dev)); pm_dev_err(dev, pm_transition, " async", error); } put_device(dev); } static int device_suspend(struct device *dev) { INIT_COMPLETION(dev->power.completion); if (pm_async_enabled && dev->power.async_suspend) { get_device(dev); async_schedule(async_suspend, dev); return 0; } return __device_suspend(dev, pm_transition, false); } /** * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. * @state: PM transition of the system being carried out. */ int dpm_suspend(pm_message_t state) { ktime_t starttime = ktime_get(); int error = 0; might_sleep(); cpufreq_suspend(); mutex_lock(&dpm_list_mtx); pm_transition = state; async_error = 0; while (!list_empty(&dpm_prepared_list)) { struct device *dev = to_device(dpm_prepared_list.prev); get_device(dev); mutex_unlock(&dpm_list_mtx); error = device_suspend(dev); mutex_lock(&dpm_list_mtx); if (error) { pm_dev_err(dev, state, "", error); dpm_save_failed_dev(dev_name(dev)); put_device(dev); break; } if (!list_empty(&dev->power.entry)) list_move(&dev->power.entry, &dpm_suspended_list); put_device(dev); if (async_error) break; } mutex_unlock(&dpm_list_mtx); async_synchronize_full(); if (!error) error = async_error; if (error) { suspend_stats.failed_suspend++; dpm_save_failed_step(SUSPEND_SUSPEND); } else dpm_show_time(starttime, state, NULL); return error; } /** * device_prepare - Prepare a device for system power transition. * @dev: Device to handle. * @state: PM transition of the system being carried out. * * Execute the ->prepare() callback(s) for given device. No new children of the * device may be registered after this function has returned. */ static int device_prepare(struct device *dev, pm_message_t state) { int (*callback)(struct device *) = NULL; char *info = NULL; int error = 0; if (dev->power.syscore) return 0; /* * If a device's parent goes into runtime suspend at the wrong time, * it won't be possible to resume the device. To prevent this we * block runtime suspend here, during the prepare phase, and allow * it again during the complete phase. */ pm_runtime_get_noresume(dev); device_lock(dev); dev->power.wakeup_path = device_may_wakeup(dev); if (dev->pm_domain) { info = "preparing power domain "; callback = dev->pm_domain->ops.prepare; } else if (dev->type && dev->type->pm) { info = "preparing type "; callback = dev->type->pm->prepare; } else if (dev->class && dev->class->pm) { info = "preparing class "; callback = dev->class->pm->prepare; } else if (dev->bus && dev->bus->pm) { info = "preparing bus "; callback = dev->bus->pm->prepare; } if (!callback && dev->driver && dev->driver->pm) { info = "preparing driver "; callback = dev->driver->pm->prepare; } if (callback) { error = callback(dev); suspend_report_result(callback, error); } device_unlock(dev); return error; } /** * dpm_prepare - Prepare all non-sysdev devices for a system PM transition. * @state: PM transition of the system being carried out. * * Execute the ->prepare() callback(s) for all devices. */ int dpm_prepare(pm_message_t state) { int error = 0; might_sleep(); mutex_lock(&dpm_list_mtx); while (!list_empty(&dpm_list)) { struct device *dev = to_device(dpm_list.next); get_device(dev); mutex_unlock(&dpm_list_mtx); error = device_prepare(dev, state); mutex_lock(&dpm_list_mtx); if (error) { if (error == -EAGAIN) { put_device(dev); error = 0; continue; } printk(KERN_INFO "PM: Device %s not prepared " "for power transition: code %d\n", dev_name(dev), error); put_device(dev); break; } dev->power.is_prepared = true; if (!list_empty(&dev->power.entry)) list_move_tail(&dev->power.entry, &dpm_prepared_list); put_device(dev); } mutex_unlock(&dpm_list_mtx); return error; } /** * dpm_suspend_start - Prepare devices for PM transition and suspend them. * @state: PM transition of the system being carried out. * * Prepare all non-sysdev devices for system PM transition and execute "suspend" * callbacks for them. */ int dpm_suspend_start(pm_message_t state) { int error; error = dpm_prepare(state); if (error) { suspend_stats.failed_prepare++; dpm_save_failed_step(SUSPEND_PREPARE); } else error = dpm_suspend(state); return error; } EXPORT_SYMBOL_GPL(dpm_suspend_start); void __suspend_report_result(const char *function, void *fn, int ret) { if (ret) printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret); } EXPORT_SYMBOL_GPL(__suspend_report_result); /** * device_pm_wait_for_dev - Wait for suspend/resume of a device to complete. * @dev: Device to wait for. * @subordinate: Device that needs to wait for @dev. */ int device_pm_wait_for_dev(struct device *subordinate, struct device *dev) { dpm_wait(dev, subordinate->power.async_suspend); return async_error; } EXPORT_SYMBOL_GPL(device_pm_wait_for_dev); /** * dpm_for_each_dev - device iterator. * @data: data for the callback. * @fn: function to be called for each device. * * Iterate over devices in dpm_list, and call @fn for each device, * passing it @data. */ void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *)) { struct device *dev; if (!fn) return; device_pm_lock(); list_for_each_entry(dev, &dpm_list, power.entry) fn(dev, data); device_pm_unlock(); } EXPORT_SYMBOL_GPL(dpm_for_each_dev);
9e48dc5ca1c39a26857e5c6bac85dc23146a2346
21c92afbd7fd022a206fb31294c523aebb770104
/SuiteSparse/CXSparse/Demo/cs_ldemo.c
9fbfec5eb175c055c23079f5883a6f6d47711121
[ "BSD-3-Clause", "DOC", "LicenseRef-scancode-free-unknown", "LicenseRef-scancode-unknown-license-reference", "GPL-2.0-or-later", "GPL-3.0-only", "LGPL-2.1-or-later", "LGPL-2.0-or-later", "GPL-1.0-or-later", "LicenseRef-scancode-other-copyleft", "LicenseRef-scancode-warranty-disclaimer", "Apache...
permissive
jlblancoc/suitesparse-metis-for-windows
70e6bcab2b525afb41758d61f823efa0618f67cf
5ee2eb4bc7bfd6d27af2f7fb027b1545cfc0fa3f
refs/heads/master
2023-08-30T21:15:39.624300
2023-03-09T10:16:48
2023-03-09T10:16:48
16,236,582
423
251
BSD-3-Clause
2023-03-09T10:18:08
2014-01-25T18:06:21
C
UTF-8
C
false
false
1,622
c
cs_ldemo.c
#include "cs.h" /* test real/complex conversion routines (cs_long_t version) */ int main (void) { cs_cl *T, *A, *A1, *A2, *B ; cs_dl *C1, *C2, *Treal, *Timag ; printf ("\n--- cs_ldemo, size of CS_INT: %d\n", (int) sizeof (CS_INT)) ; T = cs_cl_load (stdin) ; /* load a complex triplet matrix, T */ printf ("\nT:\n") ; cs_cl_print (T, 0) ; Treal = cs_l_real (T, 1) ; /* Treal = real part of T */ printf ("\nTreal:\n") ; cs_dl_print (Treal, 0) ; Timag = cs_l_real (T, 0) ; /* Treal = imaginary part of T */ printf ("\nTimag:\n") ; cs_dl_print (Timag, 0) ; A = cs_cl_compress (T) ; /* A = compressed-column form of T */ printf ("\nA:\n") ; cs_cl_print (A, 0) ; C1 = cs_l_real (A, 1) ; /* C1 = real (A) */ printf ("\nC1 = real(A):\n") ; cs_dl_print (C1, 0) ; C2 = cs_l_real (A, 0) ; /* C2 = imag (A) */ printf ("\nC2 = imag(A):\n") ; cs_dl_print (C2, 0) ; A1 = cs_l_complex (C1, 1) ; /* A1 = complex version of C1 */ printf ("\nA1:\n") ; cs_cl_print (A1, 0) ; A2 = cs_l_complex (C2, 0) ; /* A2 = complex version of C2 (imag.) */ printf ("\nA2:\n") ; cs_cl_print (A2, 0) ; B = cs_cl_add (A1, A2, 1., -1.) ; /* B = A1 - A2 */ printf ("\nB = conj(A):\n") ; cs_cl_print (B, 0) ; cs_cl_spfree (T) ; cs_cl_spfree (A) ; cs_cl_spfree (A1) ; cs_cl_spfree (A2) ; cs_cl_spfree (B) ; cs_dl_spfree (C1) ; cs_dl_spfree (C2) ; cs_dl_spfree (Treal) ; cs_dl_spfree (Timag) ; return (0) ; }
f73b9ef3d01e3738b515a3f9461b8477dcad0cc7
2b4867ce106d3068b67f2244019247df9cf6f341
/tests/runner-tests/expr/explicit_casts/7.c
16c25b09fa941b07a9007c2e90b42f3194a07b38
[ "BSD-3-Clause" ]
permissive
jyn514/saltwater
d22b29ac40a4e3deb6128d904759d9183f081ab4
097c72d30e325de57fbed8a506431754a0560374
refs/heads/master
2023-05-09T05:44:43.147928
2021-06-03T02:53:32
2021-06-03T02:53:32
190,940,981
131
25
BSD-3-Clause
2021-04-07T22:58:39
2019-06-08T22:26:45
Rust
UTF-8
C
false
false
37
c
7.c
// fail void f() { return (void)5; }
34f694c973df9f36630176b1d8dfaff8f9d2c3b4
300faec2eec21d101ce5e8196601a5c2c612c911
/Quicksilver/Code-QuickStepFoundation/QSGCD.h
795c238bc92616fe2cb27aa10e27c775a1bd72fb
[ "Apache-2.0", "LicenseRef-scancode-warranty-disclaimer" ]
permissive
quicksilver/Quicksilver
ae2d1b3552a5194bb262c23eecc577435f922f97
d8b1eaedae47222023537f3086215973c45b5e3e
refs/heads/main
2023-08-31T10:44:58.558185
2023-08-27T23:20:23
2023-08-27T23:20:23
358,078
1,790
273
Apache-2.0
2023-09-12T00:04:54
2009-11-02T14:55:23
Objective-C
UTF-8
C
false
false
1,992
h
QSGCD.h
// // QSGCD.h // Quicksilver // // Created by Patrick Robertson on 13/01/2013. // // #ifndef __QSGCD__ #define __QSGCD__ extern const char *kQueueCatalogEntry; inline void QSGCDQueueSync(dispatch_queue_t queue, void (^block)(void)) { if (dispatch_queue_get_label(queue) == dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)) { block(); } else { dispatch_sync(queue, block); } } inline void QSGCDQueueAsync(dispatch_queue_t queue, void (^block)(void)) { dispatch_async(queue, block); } inline void QSGCDQueueDelayed(dispatch_queue_t queue, NSTimeInterval delay, void (^block)(void)) { dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)); dispatch_after(popTime, queue, block); } inline void QSGCDMainSync(void (^block)(void)) { QSGCDQueueSync(dispatch_get_main_queue(), block); } inline void QSGCDMainAsync(void (^block)(void)) { QSGCDQueueAsync(dispatch_get_main_queue(), block); } inline void QSGCDMainDelayed(NSTimeInterval delay, void(^block)(void)) { QSGCDQueueDelayed(dispatch_get_main_queue(), delay, block); } inline void QSGCDSync(void (^block)(void)) { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); QSGCDQueueSync(queue, block); } inline void QSGCDAsync(void (^block)(void)) { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); QSGCDQueueAsync(queue, block); } inline void QSGCDDelayed(NSTimeInterval delay, void (^block)(void)) { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); QSGCDQueueDelayed(queue, delay, block); } // Remove those when the plugins are call-free // Don't forget to remove definitions in .m file void runOnMainQueueSync(void (^block)(void)) QS_DEPRECATED_MSG("Use QSGCDMainSync"); void runOnQueueSync(dispatch_queue_t queue, void (^block)(void)) QS_DEPRECATED_MSG("Use QSGCDQueueSync"); #endif // __QSGCD__
5c5c2eefd49c2cc42d48eb29b95c7a58dc5d0f47
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/x86/um/sysrq_64.c
a0e7fb1134a074c292b248eef68f952aba755581
[ "LicenseRef-scancode-free-unknown", "Apache-2.0", "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
1,379
c
sysrq_64.c
/* * Copyright 2003 PathScale, Inc. * * Licensed under the GPL */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/sched.h> #include <linux/utsname.h> #include <asm/current.h> #include <asm/ptrace.h> #include <asm/sysrq.h> void __show_regs(struct pt_regs *regs) { printk("\n"); print_modules(); printk(KERN_INFO "Pid: %d, comm: %.20s %s %s\n", task_pid_nr(current), current->comm, print_tainted(), init_utsname()->release); printk(KERN_INFO "RIP: %04lx:[<%016lx>]\n", PT_REGS_CS(regs) & 0xffff, PT_REGS_IP(regs)); printk(KERN_INFO "RSP: %016lx EFLAGS: %08lx\n", PT_REGS_SP(regs), PT_REGS_EFLAGS(regs)); printk(KERN_INFO "RAX: %016lx RBX: %016lx RCX: %016lx\n", PT_REGS_AX(regs), PT_REGS_BX(regs), PT_REGS_CX(regs)); printk(KERN_INFO "RDX: %016lx RSI: %016lx RDI: %016lx\n", PT_REGS_DX(regs), PT_REGS_SI(regs), PT_REGS_DI(regs)); printk(KERN_INFO "RBP: %016lx R08: %016lx R09: %016lx\n", PT_REGS_BP(regs), PT_REGS_R8(regs), PT_REGS_R9(regs)); printk(KERN_INFO "R10: %016lx R11: %016lx R12: %016lx\n", PT_REGS_R10(regs), PT_REGS_R11(regs), PT_REGS_R12(regs)); printk(KERN_INFO "R13: %016lx R14: %016lx R15: %016lx\n", PT_REGS_R13(regs), PT_REGS_R14(regs), PT_REGS_R15(regs)); } void show_regs(struct pt_regs *regs) { __show_regs(regs); show_trace(current, (unsigned long *) &regs); }
77f0987a5a4d648a7072c06352fcc16246634244
53ada3c2059b315f19073ac9df58d785c7b3678b
/src/HexEdit/DlgModify.c
0b48c5c40d37a8a5bd9be88f7e12dda2cb07245e
[ "MIT" ]
permissive
strobejb/HexEdit
946cb21d6bf68c6aaa8e71ab6ea48c99b4f29817
f8ae7cdbecc40f85d83c357882b92c6ca5899988
refs/heads/master
2023-06-02T15:45:18.485383
2023-05-16T09:14:24
2023-05-16T09:14:24
2,203,082
239
84
MIT
2023-05-16T09:14:25
2011-08-13T20:53:28
C++
UTF-8
C
false
false
5,905
c
DlgModify.c
// // DlgModify.c // // www.catch22.net // // Copyright (C) 2012 James Brown // Please refer to the file LICENCE.TXT for copying permission // #include <windows.h> #include <tchar.h> #include <commctrl.h> #include "resource.h" #include "..\HexView\HexView.h" #include "HexUtils.h" #include "HexEdit.h" static BYTE operandData[8]; static int operandLen; BOOL UpdateSearchData(HWND hwndSource, int searchType, BOOL fBigEndian, BYTE *searchData, int *searchLen); void transform( BYTE * buf, size_t len, int operation, BYTE * operand, int basetype, int endian ); TCHAR * szOpList[] = { TEXT("Byte Swap (Endian Change)"), TEXT("Bit Flip"), TEXT("Shift Left"), TEXT("Shift Right"), TEXT("Add"), TEXT("Subtract"), TEXT("Multiply"), TEXT("Divide"), TEXT("Modulus"), TEXT("Bitwise AND"), TEXT("Bitwise OR"), TEXT("Bitwise XOR"), 0, }; TCHAR * szTypeList[] = { TEXT("byte"), TEXT("word"), TEXT("dword"), TEXT("qword"), TEXT("signed byte"), TEXT("signed word"), TEXT("signed dword"), TEXT("signed qword"), TEXT("float"), TEXT("double"), 0 }; BOOL ModifyData(BYTE * buf, size_t len, int operation, BYTE * operand, int ty, BOOL fEndian) { transform(buf, len, operation, operand, ty, fEndian); /* return TRUE; for(i = 0; i < len; i++) { switch(operation) { case 0: break; case 1: buf[i] = ~buf[i]; break; case 2: buf[i] = buf[i] >> operand; break; case 3: buf[i] = buf[i] << operand; break; case 4: buf[i] = buf[i] + operand; break; case 5: buf[i] = buf[i] - operand; break; case 6: buf[i] = buf[i] * operand; break; case 7: buf[i] = buf[i] / operand; break; case 8: buf[i] = buf[i] & operand; break; case 9: buf[i] = buf[i] | operand; break; case 10: buf[i] = buf[i] ^ operand; break; } } */ return TRUE; } BOOL ModifyHexViewData(HWND hwndHV, int nOperation, BYTE * operand, size_w nLength, int nType, BOOL fEndian) { size_w start, offset; size_w remaining = nLength; size_w length = nLength; BYTE buf[0x100]; HexView_GetSelStart(hwndHV, &start); offset = start; // turn off redraw so the cursor/display doesn't update whilst we are // writing data to the hexview SendMessage(hwndHV, WM_SETREDRAW, FALSE, 0); while(nLength > 0) { ULONG len = (ULONG)min(nLength, 0x100); // get data at current cursor position! if(HexView_GetData(hwndHV, offset, buf, len)) { // do the operation! if(ModifyData(buf, len, nOperation, operand, nType, fEndian)) { // write the data back to the hexview HexView_SetData(hwndHV, offset, buf, len); } } else { return FALSE; } offset += len; nLength -= len; } HexView_SetSelStart(hwndHV, start); HexView_SetSelEnd(hwndHV, start+length); SendMessage(hwndHV, WM_SETREDRAW, TRUE, 0); return TRUE; } INT_PTR CALLBACK ModifyDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static size_w len; HWND hwndHV = g_hwndHexView; static BOOL fHexLength = FALSE; static int nLastOperand = 0; static int nLastOperation = 0; static BOOL fBigEndian = FALSE; int basetype; int searchtype; static const int SearchTypeFromBaseType[] = { SEARCHTYPE_BYTE, SEARCHTYPE_WORD, SEARCHTYPE_DWORD, SEARCHTYPE_QWORD, SEARCHTYPE_BYTE, SEARCHTYPE_WORD, SEARCHTYPE_DWORD, SEARCHTYPE_QWORD, SEARCHTYPE_FLOAT, SEARCHTYPE_DOUBLE, }; switch (iMsg) { case WM_INITDIALOG: AddComboStringList(GetDlgItem(hwnd, IDC_MODIFY_DATATYPE), szTypeList, 0); AddComboStringList(GetDlgItem(hwnd, IDC_MODIFY_OPERATION), szOpList, nLastOperation); SetDlgItemBaseInt(hwnd, IDC_MODIFY_OPERAND, nLastOperand, fHexLength ? 16 : 10, FALSE); CheckDlgButton(hwnd, IDC_HEX, fHexLength ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwnd, IDC_ENDIAN, fBigEndian ? BST_CHECKED : BST_UNCHECKED); //len = HexView_GetSelSize(hwndHV); //SetDlgItemBaseInt(hwnd, IDC_MODIFY_NUMBYTES, len, fHexLength ? 16 : 10, FALSE); CenterWindow(hwnd); return TRUE; case WM_CLOSE: EndDialog(hwnd, FALSE); return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_MODIFY_OPERATION: case IDC_MODIFY_OPERAND: case IDC_MODIFY_NUMBYTES: nLastOperation = (int)SendDlgItemMessage(hwnd, IDC_MODIFY_OPERATION, CB_GETCURSEL, 0, 0); nLastOperand = (int)GetDlgItemBaseInt(hwnd, IDC_MODIFY_OPERAND, fHexLength ? 16 : 10); len = GetDlgItemBaseInt(hwnd, IDC_MODIFY_NUMBYTES, fHexLength ? 16 : 10); return TRUE; case IDC_ENDIAN: fBigEndian = IsDlgButtonChecked(hwnd, IDC_ENDIAN); return TRUE; case IDC_HEX: fHexLength = IsDlgButtonChecked(hwnd, IDC_HEX); /* len = HexView_GetSelSize(hwndHV); SetDlgItemBaseInt(hwnd, IDC_MODIFY_NUMBYTES, len, fHexLength ? 16 : 10, FALSE); */ SetDlgItemBaseInt(hwnd, IDC_MODIFY_OPERAND, nLastOperand, fHexLength ? 16 : 10, FALSE); SendDlgItemMessage(hwnd, IDC_MODIFY_OPERAND, EM_SETSEL, 0, -1); SetDlgItemFocus(hwnd, IDC_MODIFY_OPERAND); return TRUE; case IDOK: // get the basetype we are using basetype = (int)SendDlgItemMessage(hwnd, IDC_INSERT_DATATYPE, CB_GETCURSEL, 0, 0); searchtype = SearchTypeFromBaseType[basetype]; // get the operand in raw-byte format, ensure it is always little-endian // as we must do these calculations using the native byte ordering format operandLen = sizeof(operandData); UpdateSearchData(GetDlgItem(hwnd, IDC_MODIFY_OPERAND), searchtype, FALSE, operandData, &operandLen); HexView_GetSelSize(hwndHV, &len); ModifyHexViewData(hwndHV, nLastOperation, operandData, len, basetype, fBigEndian); EndDialog(hwnd, TRUE); return TRUE; case IDCANCEL: EndDialog(hwnd, FALSE); return TRUE; default: return FALSE; } case WM_HELP: return HandleContextHelp(hwnd, lParam, IDD_TRANSFORM); default: break; } return FALSE; } BOOL ShowModifyDlg(HWND hwnd) { return (BOOL)DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_TRANSFORM), hwnd, ModifyDlgProc); }
c3ce8a04e6b0ff7f5ec4400b56bd5121dfc215e2
03666e5f961946fc1a0ac67781ac1425562ef0d7
/src/common/misc/VisItInit.C
32ac6b2769a70a1588d9b318b9081070dc15fe98
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
visit-dav/visit
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
601ae46e0bef2e18425b482a755d03490ade0493
refs/heads/develop
2023-09-06T08:19:38.397058
2023-09-05T21:29:32
2023-09-05T21:29:32
165,565,988
335
120
BSD-3-Clause
2023-09-14T00:53:37
2019-01-13T23:27:26
C
UTF-8
C
false
false
23,002
c
VisItInit.C
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt // Project developers. See the top-level LICENSE file for dates and other // details. No copyright assignment is required to contribute to VisIt. // ************************************************************************* // // Init.C // // ************************************************************************* // #include <VisItInit.h> #include <stdio.h> #include <stdlib.h> #if defined(_WIN32) #include <process.h> #include <winsock2.h> #include <winuser.h> #else #include <ctype.h> #include <unistd.h> #include <sys/types.h> #endif #include <new> #include <cstring> #include <sstream> using std::ostringstream; #include <ConfigureInfo.h> #include <DebugStreamFull.h> #include <DebugStream.h> #include <InstallationFunctions.h> #include <TimingsManager.h> #include <visit-config.h> static void RemovePrependedDirs(const char *, char *); static char executableName[256]; static char componentName[256]; static const char *AVTPREP = "avtprep"; static const char *CLI = "cli"; static const char *ENGINE = "engine"; static const char *GUI = "gui"; static const char *LAUNCHER = "launcher"; static const char *MDSERVER = "mdserver"; static const char *VIEWER = "viewer"; static const char *const allComponentNames[] = { AVTPREP, CLI, ENGINE, GUI, LAUNCHER, MDSERVER, VIEWER }; static ErrorFunction errorFunction = NULL; static void *errorFunctionArgs = NULL; static bool initializeCalled = false; static bool finalizeCalled = false; static ThreadIDFunction threadIDFunction = NULL; static void *threadIDFunctionArgs = NULL; static int numThreads = 1; // **************************************************************************** // Function: striparg // // Purpose: // Given an argc and an argv, strip off the arguments from i to i+n. // // Arguments: // i The first argument to strip (i) // n The number of arguments to strip (i) // argc The number of total arguments (io) // argv The array of arguments (io) // // Programmer: Jeremy Meredith // Creation: November 16, 2000 // // Modifications: // Jeremy Meredith, Fri Feb 1 16:05:05 PST 2002 // Fixed a bug where it was copying beyond the end of the array. // // **************************************************************************** static void striparg(int i, int n, int &argc, char *argv[]) { for ( ; i+n<argc; i++) argv[i] = argv[i+n]; argc -= n; } // **************************************************************************** // Function: NewHandler // // Purpose: // Called when the component runs out of memory. // // Programmer: Hank Childs // Creation: August 21, 2001 // // Modifications: // // Hank Childs, Tue Nov 20 13:07:51 PST 2001 // Added an abort. // // **************************************************************************** static void NewHandler(void) { debug1 << "This component has run out of memory." << endl; abort(); // HOOKS_IGNORE } // **************************************************************************** // Function: VisItInit::Initialize // // Purpose: // Parse any common commandline arguments (e.g. "-debug N") and do // common initialization. // // Arguments: // argc The number of total arguments (io) // argv The array of arguments (io) // r The rank of this process (i) // n The total number of processes (i) // strip Whether or not to strip the argument from the list. (i) // // Programmer: Jeremy Meredith // Creation: November 16, 2000 // // Modifications: // Brad Whitlock, Mon Nov 27 16:25:07 PST 2000 // I added a new flag that indicates whether or not to strip the argument // from the list after processing it. // // Hank Childs, Sat Mar 10 15:35:36 PST 2001 // Start timings manager too. // // Hank Childs, Mon Aug 13 13:43:21 PDT 2001 // Remove the directory before the program name to allow debug stream to // go to current directory. // // Hank Childs, Tue Aug 21 13:05:28 PDT 2001 // Registered a new handler. // // Jeremy Meredith, Fri Feb 1 16:05:36 PST 2002 // Added an 'else' to the if test when checking arguments, and added a // '--i' when stripping the arg. // // Brad Whitlock, Thu Mar 14 12:43:34 PDT 2002 // Made it work on Windows. Added code to initialize sockets. // // Jeremy Meredith, Wed Aug 7 13:17:01 PDT 2002 // Made it clamp the debug level to 0 through 5. // // Brad Whitlock, Wed May 21 17:03:56 PST 2003 // I made it write the command line arguments to the debug logs. // // Brad Whitlock, Wed Jun 18 11:15:22 PDT 2003 // I made it understand the -timing argument. // // Hank Childs, Tue Jun 1 11:47:36 PDT 2004 // Removed atexit call, since that is buggy with gcc. // // Jeremy Meredith, Tue May 17 11:20:51 PDT 2005 // Allow disabling of signal handlers. // // Mark C. Miller, Wed Aug 2 19:58:44 PDT 2006 // Added explicit call to SetFilename for TimingsManager. This is to // handle cases where TimingsManager may have already been instanced // before Initialize is called as in the engine. // // Kathleen Bonnell, Wed Aug 22 18:00:57 PDT 2007 // On Windows, write timings and log files to User's directory. // // Cyrus Harrison, Tue Sep 4 10:54:59 PDT 2007 // If -vtk-debug is specified make sure the debug level is at least 1 // for the engine // // Hank Childs, Tue Dec 18 15:53:10 PST 2007 // Add support for -svn_revision. // // Cyrus Harrison, Wed Jan 23 09:23:19 PST 2008 // Changed set_new_handler to std::set_new_handler b/c of change from // deprecated <new.h> to <new> // // Brad Whitlock, Wed Jun 25 10:42:58 PDT 2008 // Added check to return early in case this function gets called multiple // times as when you include multiple VisIt components in a single // executable. // // Dave Pugmire, Thu Jan 15 16:35:08 EST 2009 // Add support for -debug_engine_rank, limiting debug output to the specified // rank. // // Brad Whitlock, Fri Apr 10 16:00:55 PDT 2009 // I added support for reading -dv. // // Mark C. Miller, Tue Apr 21 14:24:18 PDT 2009 // Added logic to manage buffering of debug logs; an extra 'b' after level. // // Brad Whitlock, Thu Jun 18 15:21:06 PDT 2009 // I added -debug-processor-stride // // Kathleen Bonnell, Thu Sep 7 12:02:15 PDT 2010 // Use InstallationFunction GetUserVisItDirectory instead of retreiving // VISITUSERHOME directly from environment (in case it is not set). // // Tom Fogal, Wed Sep 28 13:40:21 MDT 2011 // Fix a UMR that valgrind complained about. // // Mark C. Miller, Thu Sep 10 11:07:15 PDT 2015 // Added logic to manage decoration of level 1 debug logs with __FILE__ // and __LINE__; an extra 'd' in debug level arg will turn on these log // decorations. // // Eric Brugger, Tue Jan 29 09:09:44 PST 2019 // I modified the method to work with Git. // // **************************************************************************** void VisItInit::Initialize(int &argc, char *argv[], int r, int n, bool strip, bool sigs) { // Return if Initialize has already been called. if(initializeCalled) return; initializeCalled = true; int i, debuglevel = 0, engineDebugRank=-1, debugStride = 1; #if defined(_WIN32) bool usePid = true; #else bool usePid = false; #endif bool bufferDebug = false; bool decorateDebug1 = false; bool clobberVlogs = false; bool vtk_debug = false; bool enableTimings = false; int threadDebugLogs=1; for (i=1; i<argc; i++) { if (strcmp("-debug_engine_rank", argv[i]) == 0) { engineDebugRank = -1; if (i+1 < argc && isdigit(*(argv[i+1]))) engineDebugRank = atoi(argv[i+1]); else cerr<<"Warning: debug engine rank not specified. Igorning.\n"; if (engineDebugRank >= n) { cerr<<"Warning: clamping debug engine rank to "<<n-1<<endl; engineDebugRank = n-1; } else if (engineDebugRank < 0) { cerr<<"Warning: clamping debug engine rank to 0\n"; engineDebugRank = 0; } if(strip) { striparg(i,2, argc,argv); --i; } else ++i; } if (strncmp("-debug",argv[i],6) == 0) { if ((strlen(argv[i]) > 7 && IsComponent(&argv[i][7])) || strlen(argv[i]) == 6) { debuglevel = 1; if (i+1 < argc && isdigit(*(argv[i+1]))) debuglevel = atoi(argv[i+1]); else cerr << "Warning: debug level not specified, assuming 1\n"; if (debuglevel > 5) { cerr << "Warning: clamping debug level to 5\n"; debuglevel = 5; } if (debuglevel < 0) { cerr << "Warning: clamping debug level to 0\n"; debuglevel = 0; } if (i+1 < argc && strchr(argv[i+1],'b')) bufferDebug = true; if (i+1 < argc && strchr(argv[i+1],'d')) decorateDebug1 = true; if(strip) { striparg(i,2, argc,argv); --i; } else { ++i; } } } else if (strcmp("-thread-debug", argv[i]) == 0) { if(i+1 < argc && isdigit(*(argv[i+1]))) threadDebugLogs = atoi(argv[i+1]); else cerr << "Warning: number of threaded debug logs not specified, assuming 1\n"; } else if (strcmp("-debug-processor-stride", argv[i]) == 0) { if(i+1 < argc) { debugStride = atoi(argv[i+1]); ++i; } else cerr << "Warning: debug processor stride not specified." << endl; } else if (strcmp("-clobber_vlogs", argv[i]) == 0) { clobberVlogs = true; } else if (strcmp("-pid", argv[i]) == 0) { usePid = true; } else if (strcmp("-vtk-debug", argv[i]) == 0) { vtk_debug = true; } else if (strcmp("-timing", argv[i]) == 0 || strcmp("-timings", argv[i]) == 0) { enableTimings = true; } else if (strcmp("-dv", argv[i]) == 0) { SetIsDevelopmentVersion(true); } else if (strcmp("-git_revision", argv[i]) == 0) { std::string msg; if(visitcommon::GITVersion() == "") msg = "GIT version is unknown!"; else msg = "Built from version " + visitcommon::GITVersion(); #if defined(WIN32) && defined(VISIT_WINDOWS_APPLICATION) MessageBox(NULL, LPCSTR(msg.c_str()), LPCSTR(""), MB_ICONINFORMATION | MB_OK); #else cerr << msg << endl; #endif exit(0); // HOOKS_IGNORE } } char progname_wo_dir[256]; RemovePrependedDirs(argv[0], progname_wo_dir); strcpy(executableName, progname_wo_dir); strcpy(componentName, progname_wo_dir); #ifdef WIN32 // On windows, we want timings and log files to go in user's directory, // not install directory, because users may not have write permissions. std::string homedir = GetUserVisItDirectory(); if(!homedir.empty()) { if(homedir[homedir.size() - 1] != visitcommon::SlashChar()) homedir += VISIT_SLASH_STRING; homedir += executableName; strcpy(progname_wo_dir, homedir.c_str()); } #endif char progname[256] = {0}; if (n > 1) { sprintf(progname, "%s.%03d", progname_wo_dir, r); } else { strcpy(progname, progname_wo_dir); } if (usePid) { #if defined(_WIN32) int pid = _getpid(); #else int pid = (int) getpid(); #endif char progname2[256]; sprintf(progname2, "%s.%d", progname, pid); strcpy(progname, progname2); } // if this is the engine and -vtk-debug is enabled, make sure the // debuglevel is at least 1 if(vtk_debug && strstr(progname,"engine") != NULL && debuglevel < 1) debuglevel = 1; // If debug rank specified, and we are not rank 'r', then turn off debuging. if ((strncmp(progname, ENGINE, strlen(ENGINE)) == 0) && engineDebugRank != -1 && engineDebugRank != r) { debuglevel = 0; } // Turn off the processors that don't meet the debug stride. if(n > 1 && debuglevel >= 1) { if((r % debugStride) > 0) debuglevel = 0; } // Initialize the debug streams and also add the command line arguments // to the debug logs. DebugStreamFull::Initialize(progname, debuglevel, threadDebugLogs, sigs, clobberVlogs, bufferDebug, decorateDebug1); ostringstream oss; for(i = 0; i < argc; ++i) oss << argv[i] << " "; oss << endl; debug1 << oss.str(); TimingsManager::Initialize(progname); // In case TimingsManager was already initialized... visitTimer->SetFilename(progname); if(enableTimings) visitTimer->Enable(); atexit(VisItInit::Finalize); #if !defined(_WIN32) std::set_new_handler(NewHandler); #endif #if defined(_WIN32) // Windows specific code WORD wVersionRequested; WSADATA wsaData; // Initiate the use of a Winsock DLL (WS2_32.DLL), necessary for sockets. wVersionRequested = MAKEWORD(2,2); WSAStartup(wVersionRequested, &wsaData); #endif } // **************************************************************************** // Function: VisItInit::SetComponentName // // Purpose: Sets the name of the component // // **************************************************************************** void VisItInit::SetComponentName(const char *cname) { size_t len; if (cname != 0 && (len = strlen(cname)) > 0) { len = len < sizeof(componentName) ? len : sizeof(componentName) - 1; strncpy(componentName, cname, len); componentName[len]='\0'; } } // **************************************************************************** // Function: VisItInit::GetComponentName // // Purpose: Gets the name of the component. Defaults to name of the // executable of it was not set. // // **************************************************************************** const char * VisItInit::GetComponentName(void) { return (const char *) componentName; } // **************************************************************************** // Function: VisItInit::ComponentNameToID // // Purpose: Return integer index of component name in list of all components // // **************************************************************************** int VisItInit::ComponentNameToID(const char *compName) { int n = sizeof(allComponentNames) / sizeof(allComponentNames[0]); for (int i = 0; i < n; i++) { if (strcmp(compName, allComponentNames[i]) == 0) return i; } return -1; } // **************************************************************************** // Function: VisItInit::ComponentNameToID // // Purpose: Return name of component with given index in list of all components // // **************************************************************************** const char* VisItInit::ComponentIDToName(const int id) { int n = sizeof(allComponentNames) / sizeof(allComponentNames[0]); if (id >= 0 && id < n) return allComponentNames[id]; else return "unknown"; } // **************************************************************************** // Function: VisItInit::IsComponent // // Purpose: Tests name of component against name passed as argument // // **************************************************************************** bool VisItInit::IsComponent(const char *compName) { if (strcmp(compName, VisItInit::GetComponentName()) == 0) return true; else return false; } // **************************************************************************** // Function: VisItInit::GetExecutableName // // Purpose: Gets the name of the executable // // **************************************************************************** const char * VisItInit::GetExecutableName(void) { return (const char *) executableName; } // **************************************************************************** // Function: VisItInit::ComponentRegisterErrorFunction // // Purpose: // Registers an error function. // // Programmer: Hank Childs // Creation: August 8, 2003 // // **************************************************************************** void VisItInit::ComponentRegisterErrorFunction(ErrorFunction ef, void *args) { errorFunctionArgs = args; errorFunction = ef; } // **************************************************************************** // Function: VisItInit::ComponentIssueError // // Purpose: // Issues an error message on that component. // // Programmer: Hank Childs // Creation: August 8, 2003 // // **************************************************************************** void VisItInit::ComponentIssueError(const char *msg) { debug1 << "Error issued: " << msg << endl; if (errorFunction != NULL) { errorFunction(errorFunctionArgs, msg); } else { debug1 << "Not able to issue error because no function was registered." << endl; } } // **************************************************************************** // Method: VisItInit::Finalize // // Purpose: // Calls cleanup functions before the application exits. // // Programmer: Brad Whitlock // Creation: Tue Mar 19 16:12:37 PST 2002 // // Modifications: // Brad Whitlock, Wed Jun 18 11:14:50 PDT 2003 // Added code to dump timings. // // Hank Childs, Tue Jun 1 11:47:36 PDT 2004 // Made the method be associated with the Init namespace. // // Mark C. Miller, Tue Jul 25 18:26:10 PDT 2006 // Pushed timer dump and finalization down into TimingsManager::Finalize // // Brad Whitlock, Wed Jun 25 10:44:24 PDT 2008 // Added check to return early if Finalize has already been called, which // can happen when multiple VisIt components are part of the same executable. // // **************************************************************************** void VisItInit::Finalize(void) { // Return if Finalize has already been called. if(finalizeCalled) return; finalizeCalled = true; TimingsManager::Finalize(); #if defined(_WIN32) // Terminates use of the WS2_32.DLL, the Winsock DLL. WSACleanup(); #endif } // **************************************************************************** // Function: RemovePrependedDirs // // Purpose: // Removes prepended directories from a program name. // // Arguments: // path The input. A program name with a path. // name The output. Only the name at the end. // // Programmer: Hank Childs // Creation: August 13, 2001 // // Modifications: // Kathleen Bonnell, Wed Aug 22 18:00:57 PDT 2007 // Use SLASH_CHAR. // // **************************************************************************** static void RemovePrependedDirs(const char *path, char *name) { // // Find the last slash by going to the end and working backwards. // int len = (int)strlen(path); int lastSlash; for (lastSlash=len ; lastSlash>=0 && path[lastSlash]!=visitcommon::SlashChar() ; lastSlash--) { continue; } // // Last slash can get to be less than zero if there are no slashes. // if (lastSlash < 0) { lastSlash = 0; } // // if (path[lastSlash] == visitcommon::SlashChar()) { strcpy(name, path + lastSlash + 1); } else { strcpy(name, path + lastSlash); } } // **************************************************************************** // Function: VisItInit::GetNumberOfThreads // // Purpose: // Gets the number of threads for this component. (This is currently // always 1, except for when the engine is running with threads. This // function helps modules like DebugStream and TimingsManager deal with // the possibility of threading.) // // Programmer: Hank Childs // Creation: July 4, 2015 // // **************************************************************************** int VisItInit::GetNumberOfThreads() { return numThreads; } // **************************************************************************** // Function: VisItInit::SetNumberOfThreads // // Purpose: // Sets the number of threads for this component. (This is currently // always 1, except for when the engine is running with threads. This // function helps modules like DebugStream and TimingsManager deal with // the possibility of threading. It is only anticipated that this function // is called on the engine.) // // Programmer: Hank Childs // Creation: July 4, 2015 // // **************************************************************************** void VisItInit::SetNumberOfThreads(int nt) { numThreads = nt; } // **************************************************************************** // Function: VisItInit::RegisterThreadIDFunction // // Purpose: // Sets a function that can get the thread ID. This is currently only // expected to be called on the engine, when running with threading. // // Programmer: Hank Childs // Creation: July 4, 2015 // // **************************************************************************** void VisItInit::RegisterThreadIDFunction(ThreadIDFunction f, void *a) { threadIDFunction = f; threadIDFunctionArgs = a; } // **************************************************************************** // Function: VisItInit::GetMyThreadID // // Purpose: // Gets the current thread's ID. Returns 0 if not running in a threaded // mode. // // Programmer: Hank Childs // Creation: July 4, 2015 // // **************************************************************************** int VisItInit::GetMyThreadID(void) { if (threadIDFunction != NULL) return threadIDFunction(threadIDFunctionArgs); return 0; }
e52e63d8b338f4e2772632a33244e211b7e32fc5
5b36d2a4ff03d9912f2e461ad67ea5e2d9a7ce61
/libdimentio.h
fd607c6e908aa210b090ab9293001acf1bd6fa94
[ "Apache-2.0" ]
permissive
0x7ff/dimentio
aeba5e9d4831e41da18028c952df3d1c8746633b
7ffffffb4ebfcdbc46ab5e8f1becc0599a05711d
refs/heads/main
2023-04-30T02:04:32.188147
2023-02-02T11:57:55
2023-02-02T11:57:55
205,834,119
106
41
Apache-2.0
2023-04-22T04:03:30
2019-09-02T10:37:20
C
UTF-8
C
false
false
1,166
h
libdimentio.h
/* Copyright 2023 0x7ff * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef LIBDIMENTIO_H # define LIBDIMENTIO_H # include <CommonCrypto/CommonCrypto.h> # include <CoreFoundation/CoreFoundation.h> # define KADDR_FMT "0x%" PRIX64 typedef uint64_t kaddr_t; typedef kern_return_t (*kread_func_t)(kaddr_t, void *, size_t), (*kwrite_func_t)(kaddr_t, const void *, size_t); void dimentio_term(void); kern_return_t dimentio_init(kaddr_t, kread_func_t, kwrite_func_t); kern_return_t dimentio(uint64_t *, bool, uint8_t[CC_SHA384_DIGEST_LENGTH], size_t *); kern_return_t dimentio_preinit(uint64_t *, bool, uint8_t[CC_SHA384_DIGEST_LENGTH], size_t *); #endif
59180904e468d7b5174b8b54be6209f56f188044
c7e162a9878dae6f21c828f8c5d5014305c75702
/src/varintdecode.c
ce9be694bac563fefb48e039169c114ca9983344
[ "Apache-2.0", "GPL-1.0-or-later", "MIT" ]
permissive
lemire/MaskedVByte
523898ab3502d9ff5c0efd72aef709f29c3beb61
4d668512b53459145c227f0cdc76787bb28d567c
refs/heads/master
2023-08-18T23:45:49.397654
2023-01-05T14:02:18
2023-01-05T14:02:18
26,868,077
124
27
Apache-2.0
2023-01-05T13:50:22
2014-11-19T15:38:44
C
UTF-8
C
false
false
112,027
c
varintdecode.c
#include "varintdecode.h" #if defined(_MSC_VER) #define ALIGNED(x) __declspec(align(x)) #else #if defined(__GNUC__) #define ALIGNED(x) __attribute__ ((aligned(x))) #endif #endif #if defined(_MSC_VER) # include <intrin.h> /* 64-bit needs extending */ # define SIMDCOMP_CTZ(result, mask) do { \ unsigned long index; \ if (!_BitScanForward(&(index), (mask))) { \ (result) = 32U; \ } else { \ (result) = (uint32_t)(index); \ } \ } while (0) #else #include <x86intrin.h> # define SIMDCOMP_CTZ(result, mask) \ result = __builtin_ctz(mask) #endif typedef struct index_bytes_consumed { uint8_t index; uint8_t bytes_consumed; } index_bytes_consumed; static const index_bytes_consumed ALIGNED(0x1000) combined_lookup[] = { {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {60, 10}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {58, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {54, 10}, {83, 7}, {160, 5}, {7, 9}, {46, 10}, {30, 10}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {142, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {57, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {53, 10}, {83, 7}, {160, 5}, {6, 8}, {45, 10}, {29, 10}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {51, 10}, {82, 6}, {160, 5}, {5, 8}, {43, 10}, {27, 10}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {39, 10}, {23, 10}, {122, 8}, {15, 10}, {62, 11}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {140, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {134, 10}, {72, 8}, {116, 10}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {138, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {132, 10}, {71, 7}, {114, 10}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {126, 10}, {69, 7}, {108, 10}, {90, 10}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {169, 10}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {61, 11}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {59, 11}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {55, 11}, {83, 7}, {160, 5}, {7, 9}, {47, 11}, {31, 11}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {143, 11}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {101, 7}, {83, 7}, {160, 5}, {6, 8}, {95, 7}, {77, 7}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {100, 6}, {82, 6}, {160, 5}, {5, 8}, {94, 6}, {76, 6}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {92, 6}, {74, 6}, {122, 8}, {68, 6}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {141, 11}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {135, 11}, {72, 8}, {117, 11}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {156, 5}, {71, 7}, {152, 5}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {155, 4}, {69, 7}, {151, 4}, {147, 4}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {0, 4}, {0, 5}, {0, 5}, {0, 4}, {0, 5}, {0, 4}, {0, 4}, {0, 5}, {0, 5}, {0, 3}, {0, 3}, {0, 5}, {0, 2}, {0, 5}, {0, 5}, {0, 0}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {60, 10}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {58, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {54, 10}, {83, 7}, {160, 5}, {7, 9}, {46, 10}, {30, 10}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {142, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {57, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {53, 10}, {83, 7}, {160, 5}, {6, 8}, {45, 10}, {29, 10}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {51, 10}, {82, 6}, {160, 5}, {5, 8}, {43, 10}, {27, 10}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {39, 10}, {23, 10}, {122, 8}, {15, 10}, {63, 12}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {140, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {134, 10}, {72, 8}, {116, 10}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {138, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {132, 10}, {71, 7}, {114, 10}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {126, 10}, {69, 7}, {108, 10}, {90, 10}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {169, 10}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {101, 7}, {83, 7}, {160, 5}, {7, 9}, {95, 7}, {77, 7}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {144, 12}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {101, 7}, {83, 7}, {160, 5}, {6, 8}, {95, 7}, {77, 7}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {100, 6}, {82, 6}, {160, 5}, {5, 8}, {94, 6}, {76, 6}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {92, 6}, {74, 6}, {122, 8}, {68, 6}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {156, 5}, {72, 8}, {152, 5}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {156, 5}, {71, 7}, {152, 5}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {155, 4}, {69, 7}, {151, 4}, {147, 4}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 5}, {0, 6}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 6}, {0, 5}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 4}, {0, 6}, {0, 6}, {0, 4}, {0, 6}, {0, 4}, {0, 4}, {0, 6}, {0, 6}, {0, 3}, {0, 3}, {0, 6}, {0, 2}, {0, 6}, {0, 6}, {0, 0}, {0, 4}, {0, 5}, {0, 5}, {0, 4}, {0, 5}, {0, 4}, {0, 4}, {0, 5}, {0, 5}, {0, 3}, {0, 3}, {0, 5}, {0, 2}, {0, 5}, {0, 5}, {0, 0}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {60, 10}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {58, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {54, 10}, {83, 7}, {160, 5}, {7, 9}, {46, 10}, {30, 10}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {142, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {57, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {53, 10}, {83, 7}, {160, 5}, {6, 8}, {45, 10}, {29, 10}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {51, 10}, {82, 6}, {160, 5}, {5, 8}, {43, 10}, {27, 10}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {39, 10}, {23, 10}, {122, 8}, {15, 10}, {62, 11}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {140, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {134, 10}, {72, 8}, {116, 10}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {138, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {132, 10}, {71, 7}, {114, 10}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {126, 10}, {69, 7}, {108, 10}, {90, 10}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {169, 10}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {61, 11}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {59, 11}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {55, 11}, {83, 7}, {160, 5}, {7, 9}, {47, 11}, {31, 11}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {143, 11}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {101, 7}, {83, 7}, {160, 5}, {6, 8}, {95, 7}, {77, 7}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {100, 6}, {82, 6}, {160, 5}, {5, 8}, {94, 6}, {76, 6}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {92, 6}, {74, 6}, {122, 8}, {68, 6}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {141, 11}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {135, 11}, {72, 8}, {117, 11}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {156, 5}, {71, 7}, {152, 5}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {155, 4}, {69, 7}, {151, 4}, {147, 4}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {0, 4}, {0, 5}, {0, 5}, {0, 4}, {0, 5}, {0, 4}, {0, 4}, {0, 5}, {0, 5}, {0, 3}, {0, 3}, {0, 5}, {0, 2}, {0, 5}, {0, 5}, {0, 0}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {60, 10}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {58, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {54, 10}, {83, 7}, {160, 5}, {7, 9}, {46, 10}, {30, 10}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {142, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {57, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {53, 10}, {83, 7}, {160, 5}, {6, 8}, {45, 10}, {29, 10}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {51, 10}, {82, 6}, {160, 5}, {5, 8}, {43, 10}, {27, 10}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {39, 10}, {23, 10}, {122, 8}, {15, 10}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {140, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {134, 10}, {72, 8}, {116, 10}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {138, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {132, 10}, {71, 7}, {114, 10}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {126, 10}, {69, 7}, {108, 10}, {90, 10}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {169, 10}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {101, 7}, {83, 7}, {160, 5}, {7, 9}, {95, 7}, {77, 7}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {101, 7}, {83, 7}, {160, 5}, {6, 8}, {95, 7}, {77, 7}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {100, 6}, {82, 6}, {160, 5}, {5, 8}, {94, 6}, {76, 6}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {92, 6}, {74, 6}, {122, 8}, {68, 6}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {156, 5}, {72, 8}, {152, 5}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {0, 7}, {0, 7}, {0, 6}, {0, 7}, {0, 6}, {0, 6}, {0, 5}, {0, 7}, {0, 6}, {0, 6}, {0, 7}, {0, 6}, {0, 7}, {0, 5}, {0, 6}, {0, 7}, {0, 6}, {0, 6}, {0, 7}, {0, 6}, {0, 7}, {0, 7}, {0, 6}, {0, 6}, {0, 7}, {0, 7}, {0, 6}, {0, 2}, {0, 6}, {0, 6}, {0, 0}, {0, 7}, {0, 5}, {0, 5}, {0, 7}, {0, 5}, {0, 7}, {0, 7}, {0, 5}, {0, 5}, {0, 7}, {0, 7}, {0, 5}, {0, 7}, {0, 5}, {0, 5}, {0, 7}, {0, 4}, {0, 7}, {0, 7}, {0, 4}, {0, 7}, {0, 4}, {0, 4}, {0, 7}, {0, 2}, {0, 3}, {0, 3}, {0, 7}, {0, 2}, {0, 7}, {0, 0}, {0, 0}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 5}, {0, 6}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 6}, {0, 5}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 4}, {0, 6}, {0, 6}, {0, 4}, {0, 6}, {0, 4}, {0, 4}, {0, 6}, {0, 6}, {0, 3}, {0, 3}, {0, 6}, {0, 2}, {0, 6}, {0, 6}, {0, 0}, {0, 4}, {0, 5}, {0, 5}, {0, 4}, {0, 5}, {0, 4}, {0, 4}, {0, 5}, {0, 5}, {0, 3}, {0, 3}, {0, 5}, {0, 2}, {0, 5}, {0, 5}, {0, 0}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0} }; static const int8_t ALIGNED(0x1000) vectorsrawbytes[] = { 0, -1, 4, -1, 1, -1, 5, -1, 2, -1, -1, -1, 3, -1, -1, -1, // 0 0, -1, 4, -1, 1, -1, 5, 6, 2, -1, -1, -1, 3, -1, -1, -1, // 1 0, -1, 4, 5, 1, -1, 6, -1, 2, -1, -1, -1, 3, -1, -1, -1, // 2 0, -1, 4, 5, 1, -1, 6, 7, 2, -1, -1, -1, 3, -1, -1, -1, // 3 0, -1, 5, -1, 1, -1, 6, -1, 2, -1, -1, -1, 3, 4, -1, -1, // 4 0, -1, 5, -1, 1, -1, 6, 7, 2, -1, -1, -1, 3, 4, -1, -1, // 5 0, -1, 5, 6, 1, -1, 7, -1, 2, -1, -1, -1, 3, 4, -1, -1, // 6 0, -1, 5, 6, 1, -1, 7, 8, 2, -1, -1, -1, 3, 4, -1, -1, // 7 0, -1, 5, -1, 1, -1, 6, -1, 2, 3, -1, -1, 4, -1, -1, -1, // 8 0, -1, 5, -1, 1, -1, 6, 7, 2, 3, -1, -1, 4, -1, -1, -1, // 9 0, -1, 5, 6, 1, -1, 7, -1, 2, 3, -1, -1, 4, -1, -1, -1, // 10 0, -1, 5, 6, 1, -1, 7, 8, 2, 3, -1, -1, 4, -1, -1, -1, // 11 0, -1, 6, -1, 1, -1, 7, -1, 2, 3, -1, -1, 4, 5, -1, -1, // 12 0, -1, 6, -1, 1, -1, 7, 8, 2, 3, -1, -1, 4, 5, -1, -1, // 13 0, -1, 6, 7, 1, -1, 8, -1, 2, 3, -1, -1, 4, 5, -1, -1, // 14 0, -1, 6, 7, 1, -1, 8, 9, 2, 3, -1, -1, 4, 5, -1, -1, // 15 0, -1, 5, -1, 1, 2, 6, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 16 0, -1, 5, -1, 1, 2, 6, 7, 3, -1, -1, -1, 4, -1, -1, -1, // 17 0, -1, 5, 6, 1, 2, 7, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 18 0, -1, 5, 6, 1, 2, 7, 8, 3, -1, -1, -1, 4, -1, -1, -1, // 19 0, -1, 6, -1, 1, 2, 7, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 20 0, -1, 6, -1, 1, 2, 7, 8, 3, -1, -1, -1, 4, 5, -1, -1, // 21 0, -1, 6, 7, 1, 2, 8, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 22 0, -1, 6, 7, 1, 2, 8, 9, 3, -1, -1, -1, 4, 5, -1, -1, // 23 0, -1, 6, -1, 1, 2, 7, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 24 0, -1, 6, -1, 1, 2, 7, 8, 3, 4, -1, -1, 5, -1, -1, -1, // 25 0, -1, 6, 7, 1, 2, 8, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 26 0, -1, 6, 7, 1, 2, 8, 9, 3, 4, -1, -1, 5, -1, -1, -1, // 27 0, -1, 7, -1, 1, 2, 8, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 28 0, -1, 7, -1, 1, 2, 8, 9, 3, 4, -1, -1, 5, 6, -1, -1, // 29 0, -1, 7, 8, 1, 2, 9, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 30 0, -1, 7, 8, 1, 2, 9, 10, 3, 4, -1, -1, 5, 6, -1, -1, // 31 0, 1, 5, -1, 2, -1, 6, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 32 0, 1, 5, -1, 2, -1, 6, 7, 3, -1, -1, -1, 4, -1, -1, -1, // 33 0, 1, 5, 6, 2, -1, 7, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 34 0, 1, 5, 6, 2, -1, 7, 8, 3, -1, -1, -1, 4, -1, -1, -1, // 35 0, 1, 6, -1, 2, -1, 7, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 36 0, 1, 6, -1, 2, -1, 7, 8, 3, -1, -1, -1, 4, 5, -1, -1, // 37 0, 1, 6, 7, 2, -1, 8, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 38 0, 1, 6, 7, 2, -1, 8, 9, 3, -1, -1, -1, 4, 5, -1, -1, // 39 0, 1, 6, -1, 2, -1, 7, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 40 0, 1, 6, -1, 2, -1, 7, 8, 3, 4, -1, -1, 5, -1, -1, -1, // 41 0, 1, 6, 7, 2, -1, 8, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 42 0, 1, 6, 7, 2, -1, 8, 9, 3, 4, -1, -1, 5, -1, -1, -1, // 43 0, 1, 7, -1, 2, -1, 8, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 44 0, 1, 7, -1, 2, -1, 8, 9, 3, 4, -1, -1, 5, 6, -1, -1, // 45 0, 1, 7, 8, 2, -1, 9, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 46 0, 1, 7, 8, 2, -1, 9, 10, 3, 4, -1, -1, 5, 6, -1, -1, // 47 0, 1, 6, -1, 2, 3, 7, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 48 0, 1, 6, -1, 2, 3, 7, 8, 4, -1, -1, -1, 5, -1, -1, -1, // 49 0, 1, 6, 7, 2, 3, 8, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 50 0, 1, 6, 7, 2, 3, 8, 9, 4, -1, -1, -1, 5, -1, -1, -1, // 51 0, 1, 7, -1, 2, 3, 8, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 52 0, 1, 7, -1, 2, 3, 8, 9, 4, -1, -1, -1, 5, 6, -1, -1, // 53 0, 1, 7, 8, 2, 3, 9, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 54 0, 1, 7, 8, 2, 3, 9, 10, 4, -1, -1, -1, 5, 6, -1, -1, // 55 0, 1, 7, -1, 2, 3, 8, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 56 0, 1, 7, -1, 2, 3, 8, 9, 4, 5, -1, -1, 6, -1, -1, -1, // 57 0, 1, 7, 8, 2, 3, 9, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 58 0, 1, 7, 8, 2, 3, 9, 10, 4, 5, -1, -1, 6, -1, -1, -1, // 59 0, 1, 8, -1, 2, 3, 9, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 60 0, 1, 8, -1, 2, 3, 9, 10, 4, 5, -1, -1, 6, 7, -1, -1, // 61 0, 1, 8, 9, 2, 3, 10, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 62 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, -1, -1, 6, 7, -1, -1, // 63 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, // 64 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, // 65 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, // 66 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, // 67 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, // 68 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, // 69 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, // 70 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, // 71 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, // 72 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 73 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 74 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1, // 75 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 76 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 77 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1, // 78 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1, // 79 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1, // 80 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1, // 81 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 82 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 83 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, 7, -1, // 84 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 85 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 86 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, 8, -1, // 87 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, -1, -1, -1, // 88 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, -1, -1, // 89 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, 9, -1, // 90 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 91 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 92 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1, // 93 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 94 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 95 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1, // 96 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1, // 97 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1, // 98 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1, // 99 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 100 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 101 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1, // 102 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 103 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 104 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1, // 105 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1, // 106 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1, // 107 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1, // 108 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, -1, -1, -1, // 109 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, -1, -1, // 110 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, 8, -1, // 111 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, -1, -1, -1, // 112 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, -1, -1, // 113 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, 9, -1, // 114 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, -1, -1, -1, // 115 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, -1, -1, // 116 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, 10, -1, // 117 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 118 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 119 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1, // 120 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 121 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 122 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1, // 123 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1, // 124 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1, // 125 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1, // 126 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1, // 127 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, -1, -1, // 128 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, 8, -1, // 129 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, -1, -1, -1, // 130 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1, // 131 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, 9, -1, // 132 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, -1, -1, -1, // 133 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, -1, -1, // 134 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, 10, -1, // 135 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, -1, -1, -1, // 136 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, -1, -1, // 137 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, 9, -1, // 138 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, -1, -1, -1, // 139 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, -1, -1, // 140 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, 10, -1, // 141 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, -1, -1, -1, // 142 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, -1, -1, // 143 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, -1, // 144 -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 1, // 145 -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, -1, -1, -1, -1, -1, 1, // 146 -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, 3, -1, -1, -1, -1, 1, // 147 -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, 3, -1, 4, -1, -1, 1, // 148 -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, 3, -1, 4, -1, 5, 1, // 149 1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 2, // 150 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, -1, -1, -1, -1, -1, 2, // 151 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, 4, -1, -1, -1, -1, 2, // 152 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, 4, -1, 5, -1, -1, 2, // 153 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, 4, -1, 5, -1, 6, 2, // 154 1, -1, 2, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 3, // 155 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, -1, -1, -1, -1, -1, 3, // 156 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, 5, -1, -1, -1, -1, 3, // 157 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, 5, -1, 6, -1, -1, 3, // 158 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, 5, -1, 6, -1, 7, 3, // 159 1, -1, 2, -1, 3, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 4, // 160 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, -1, -1, -1, -1, -1, 4, // 161 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, 6, -1, -1, -1, -1, 4, // 162 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, 6, -1, 7, -1, -1, 4, // 163 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, 6, -1, 7, -1, 8, 4, // 164 1, -1, 2, -1, 3, -1, 4, 0, -1, -1, -1, -1, -1, -1, -1, 5, // 165 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, -1, -1, -1, -1, -1, 5, // 166 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, 7, -1, -1, -1, -1, 5, // 167 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, 7, -1, 8, -1, -1, 5, // 168 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, 7, -1, 8, -1, 9, 5, // 169 }; static const __m128i* vectors = (const __m128i*)vectorsrawbytes; static int read_int(const uint8_t* in, uint32_t* out) { *out = in[0] & 0x7F; if (in[0] < 128) { return 1; } *out = ((in[1] & 0x7FU) << 7) | *out; if (in[1] < 128) { return 2; } *out = ((in[2] & 0x7FU) << 14) | *out; if (in[2] < 128) { return 3; } *out = ((in[3] & 0x7FU) << 21) | *out; if (in[3] < 128) { return 4; } *out = ((in[4] & 0x7FU) << 28) | *out; return 5; } static inline int read_int_delta(const uint8_t* in, uint32_t* out, uint32_t* prev) { *out = in[0] & 0x7F; if (in[0] < 128) { *prev += *out; *out = *prev; return 1; } *out = ((in[1] & 0x7FU) << 7) | *out; if (in[1] < 128) { *prev += *out; *out = *prev; return 2; } *out = ((in[2] & 0x7FU) << 14) | *out; if (in[2] < 128) { *prev += *out; *out = *prev; return 3; } *out = ((in[3] & 0x7FU) << 21) | *out; if (in[3] < 128) { *prev += *out; *out = *prev; return 4; } *out = ((in[4] & 0x7FU) << 28) | *out; *prev += *out; *out = *prev; return 5; } static uint64_t masked_vbyte_read_group(const uint8_t* in, uint32_t* out, uint64_t mask, uint64_t* ints_read) { __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); __m128i * mout = (__m128i *) out; if (!(mask & 0xFFFF)) { __m128i result = _mm_cvtepi8_epi32(initial); _mm_storeu_si128(mout, result); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); _mm_storeu_si128(mout + 1, result); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); _mm_storeu_si128(mout + 2, result); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); _mm_storeu_si128(mout + 3, result); *ints_read = 16; return 16; } uint32_t low_12_bits = mask & 0xFFF; // combine index and bytes consumed into a single lookup index_bytes_consumed combined = combined_lookup[low_12_bits]; uint64_t consumed = combined.bytes_consumed; uint8_t index = combined.index; __m128i shuffle_vector = vectors[index]; if (index < 64) { *ints_read = 6; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x007F)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x7F00)); __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); __m128i unpacked_result_a = _mm_and_si128(packed_result, _mm_set1_epi32(0x0000FFFF)); _mm_storeu_si128(mout, unpacked_result_a); __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); _mm_storel_epi64(mout+1, unpacked_result_b); //_mm_storeu_si128(mout + 1, unpacked_result_b); // maybe faster to write 16 bytes? return consumed; } if (index < 145) { *ints_read = 4; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x0000007F)); __m128i middle_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x00007F00)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x007F0000)); __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); _mm_storeu_si128(mout, result); return consumed; } *ints_read = 2; __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); __m128i result_evens = _mm_or_si128(recombined, low_byte); __m128i result = _mm_shuffle_epi8(result_evens, _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1)); _mm_storel_epi64(mout, result); //_mm_storeu_si128(mout, result); // maybe faster to write 16 bytes? return consumed; } static inline __m128i PrefixSum(__m128i curr, __m128i prev) { __m128i Add = _mm_slli_si128(curr, 4); // Cycle 1: [- A B C] (already done) prev = _mm_shuffle_epi32(prev, 0xff); // Cycle 2: [P P P P] curr = _mm_add_epi32(curr, Add); // Cycle 2: [A AB BC CD] Add = _mm_slli_si128(curr, 8); // Cycle 3: [- - A AB] curr = _mm_add_epi32(curr, prev); // Cycle 3: [PA PAB PBC PCD] curr = _mm_add_epi32(curr, Add); // Cycle 4: [PA PAB PABC PABCD] return curr; } // only the first two ints of curr are meaningful, rest is garbage to beignored static inline __m128i PrefixSum2ints(__m128i curr, __m128i prev) { __m128i Add = _mm_slli_si128(curr, 4); // Cycle 1: [- A B G] (already done) prev = _mm_shuffle_epi32(prev, 0xff); // Cycle 2: [P P P P] curr = _mm_add_epi32(curr, Add); // Cycle 2: [A AB BG GG] curr = _mm_shuffle_epi32(curr, 0x54); //Cycle 3:[A AB AB AB] curr = _mm_add_epi32(curr, prev); // Cycle 4: [PA PAB PAB PAB] return curr; } static uint64_t masked_vbyte_read_group_delta(const uint8_t* in, uint32_t* out, uint64_t mask, uint64_t* ints_read, __m128i * prev) { __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); __m128i * mout = (__m128i *) out; if (!(mask & 0xFFFF)) { __m128i result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout, *prev); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout + 1, *prev); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout + 2, *prev); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout + 3, *prev); *ints_read = 16; return 16; } uint32_t low_12_bits = mask & 0xFFF; // combine index and bytes consumed into a single lookup index_bytes_consumed combined = combined_lookup[low_12_bits]; uint64_t consumed = combined.bytes_consumed; uint8_t index = combined.index; __m128i shuffle_vector = vectors[index]; if (index < 64) { *ints_read = 6; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x007F)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x7F00)); __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); __m128i unpacked_result_a = _mm_and_si128(packed_result, _mm_set1_epi32(0x0000FFFF)); *prev = PrefixSum(unpacked_result_a, *prev); _mm_storeu_si128(mout, *prev); __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); *prev = PrefixSum2ints(unpacked_result_b, *prev); _mm_storel_epi64(mout + 1, *prev); return consumed; } if (index < 145) { *ints_read = 4; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x0000007F)); __m128i middle_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x00007F00)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x007F0000)); __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout, *prev); return consumed; } *ints_read = 2; __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); __m128i result_evens = _mm_or_si128(recombined, low_byte); __m128i result = _mm_shuffle_epi8(result_evens, _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1)); *prev = PrefixSum2ints(result, *prev); _mm_storel_epi64(mout, *prev); return consumed; } static int read_int_group(const uint8_t* in, uint32_t* out, int* ints_read) { __m128i initial = _mm_lddqu_si128((const __m128i *) in); __m128i * const mout = (__m128i *) out; int mask = _mm_movemask_epi8(initial); if (mask == 0) { __m128i result; result = _mm_cvtepi8_epi32(initial); initial = _mm_srli_si128(initial, 4); _mm_storeu_si128(mout, result); result = _mm_cvtepi8_epi32(initial); initial = _mm_srli_si128(initial, 4); _mm_storeu_si128(mout + 1, result); result = _mm_cvtepi8_epi32(initial); initial = _mm_srli_si128(initial, 4); _mm_storeu_si128(mout + 2, result); result = _mm_cvtepi8_epi32(initial); _mm_storeu_si128(mout + 3, result); *ints_read = 16; return 16; } int mask2 = mask & 0xFFF; index_bytes_consumed combined = combined_lookup[mask2]; int index = combined.index; __m128i shuffle_vector = vectors[index]; int consumed = combined.bytes_consumed; if (index < 64) { *ints_read = 6; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x007F)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x7F00)); __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); __m128i unpacked_result_a = _mm_and_si128(packed_result, _mm_set1_epi32(0x0000FFFF)); _mm_storeu_si128(mout, unpacked_result_a); __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); _mm_storel_epi64(mout + 1, unpacked_result_b); return consumed; } if (index < 145) { *ints_read = 4; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x0000007F)); __m128i middle_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x00007F00)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x007F0000)); __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); _mm_storeu_si128(mout, result); return consumed; } *ints_read = 2; __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); __m128i result_evens = _mm_or_si128(recombined, low_byte); __m128i result = _mm_shuffle_epi8(result_evens, _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1)); _mm_storel_epi64(mout, result); return consumed; } // len_signed : number of ints we want to decode size_t masked_vbyte_decode(const uint8_t* in, uint32_t* out, uint64_t length) { size_t consumed = 0; // number of bytes read uint64_t count = 0; // how many integers we have read so far uint64_t sig = 0; int availablebytes = 0; if (96 < length) { size_t scanned = 0; #ifdef __AVX2__ __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); uint32_t lowSig = _mm256_movemask_epi8(low); #else __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); uint32_t lowSig1 = _mm_movemask_epi8(low1); __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); uint32_t lowSig2 = _mm_movemask_epi8(low2); uint32_t lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif // excess verbosity to avoid problems with sign extension on conversions // better to think about what's happening and make it clearer __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); uint32_t highSig = _mm_movemask_epi8(high); uint64_t nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; scanned += 48; do { uint64_t thisSig = nextSig; #ifdef __AVX2__ low = _mm256_loadu_si256((__m256i *)(in + scanned)); lowSig = _mm256_movemask_epi8(low); #else low1 = _mm_loadu_si128((__m128i *) (in + scanned)); lowSig1 = _mm_movemask_epi8(low1); low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); lowSig2 = _mm_movemask_epi8(low2); lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); highSig = _mm_movemask_epi8(high); nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; uint64_t remaining = scanned - (consumed + 48); sig = (thisSig << remaining) | sig; uint64_t reload = scanned - 16; scanned += 48; // need to reload when less than 16 scanned bytes remain in sig while (consumed < reload) { uint64_t ints_read; uint64_t bytes = masked_vbyte_read_group(in + consumed, out + count, sig, &ints_read); sig >>= bytes; // seems like this might force the compiler to prioritize shifting sig >>= bytes if (sig == 0xFFFFFFFFFFFFFFFF) return 0; // fake check to force earliest evaluation consumed += bytes; count += ints_read; } } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig sig = (nextSig << (scanned - consumed - 48)) | sig; availablebytes = scanned - consumed; } while (availablebytes + count < length) { if (availablebytes < 16) { if (availablebytes + count + 31 < length) { #ifdef __AVX2__ uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); sig |= (newsigavx << availablebytes); #else uint64_t newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); uint64_t newsig2 = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + 16 + consumed))); sig |= (newsig << availablebytes) | (newsig2 << (availablebytes + 16)); #endif availablebytes += 32; } else if (availablebytes + count + 15 < length) { int newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); sig |= newsig << availablebytes; availablebytes += 16; } else { break; } } uint64_t ints_read; uint64_t eaten = masked_vbyte_read_group(in + consumed, out + count, sig, &ints_read); consumed += eaten; availablebytes -= eaten; sig >>= eaten; count += ints_read; } for (; count < length; count++) { consumed += read_int(in + consumed, out + count); } return consumed; } // inputsize : number of input bytes we want to decode // returns the number of written ints size_t masked_vbyte_decode_fromcompressedsize(const uint8_t* in, uint32_t* out, size_t inputsize) { size_t consumed = 0; // number of bytes read uint32_t * initout = out; uint64_t sig = 0; int availablebytes = 0; if (96 < inputsize) { size_t scanned = 0; #ifdef __AVX2__ __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); uint32_t lowSig = _mm256_movemask_epi8(low); #else __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); uint32_t lowSig1 = _mm_movemask_epi8(low1); __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); uint32_t lowSig2 = _mm_movemask_epi8(low2); uint32_t lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif // excess verbosity to avoid problems with sign extension on conversions // better to think about what's happening and make it clearer __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); uint32_t highSig = _mm_movemask_epi8(high); uint64_t nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; scanned += 48; do { uint64_t thisSig = nextSig; #ifdef __AVX2__ low = _mm256_loadu_si256((__m256i *)(in + scanned)); lowSig = _mm256_movemask_epi8(low); #else low1 = _mm_loadu_si128((__m128i *) (in + scanned)); lowSig1 = _mm_movemask_epi8(low1); low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); lowSig2 = _mm_movemask_epi8(low2); lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); highSig = _mm_movemask_epi8(high); nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; uint64_t remaining = scanned - (consumed + 48); sig = (thisSig << remaining) | sig; uint64_t reload = scanned - 16; scanned += 48; // need to reload when less than 16 scanned bytes remain in sig while (consumed < reload) { uint64_t ints_read; uint64_t bytes = masked_vbyte_read_group(in + consumed, out, sig, &ints_read); sig >>= bytes; // seems like this might force the compiler to prioritize shifting sig >>= bytes if (sig == 0xFFFFFFFFFFFFFFFF) return 0; // fake check to force earliest evaluation consumed += bytes; out += ints_read; } } while (scanned + 112 < inputsize); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig sig = (nextSig << (scanned - consumed - 48)) | sig; availablebytes = scanned - consumed; } while (1) { if (availablebytes < 16) { if (availablebytes + consumed + 31 < inputsize) { #ifdef __AVX2__ uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); sig |= (newsigavx << availablebytes); #else uint64_t newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); uint64_t newsig2 = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + 16 + consumed))); sig |= (newsig << availablebytes) | (newsig2 << (availablebytes + 16)); #endif availablebytes += 32; } else if(availablebytes + consumed + 15 < inputsize ) { int newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); sig |= newsig << availablebytes; availablebytes += 16; } else { break; } } uint64_t ints_read; uint64_t bytes = masked_vbyte_read_group(in + consumed, out, sig, &ints_read); consumed += bytes; availablebytes -= bytes; sig >>= bytes; out += ints_read; } while (consumed < inputsize) { unsigned int shift = 0; for (uint32_t v = 0; consumed < inputsize; shift += 7) { uint8_t c = in[consumed++]; if ((c & 128) == 0) { out[0] = v + (c << shift); ++out; break; } else { v += (c & 127) << shift; } } } return out - initout; } size_t read_ints(const uint8_t* in, uint32_t* out, int length) { size_t consumed = 0; int count; for (count = 0; count + 15 < length;) { int ints_read; consumed += read_int_group(in + consumed, out + count, &ints_read); count += ints_read; } for (; count < length; count++) { consumed += read_int(in + consumed, out + count); } return consumed; } static int read_int_group_delta(const uint8_t* in, uint32_t* out, int* ints_read, __m128i * prev) { __m128i initial = _mm_lddqu_si128((const __m128i *) in); __m128i * const mout = (__m128i *) out; int mask = _mm_movemask_epi8(initial); if (mask == 0) { __m128i result; result = _mm_cvtepi8_epi32(initial); initial = _mm_srli_si128(initial, 4); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout, *prev); result = _mm_cvtepi8_epi32(initial); initial = _mm_srli_si128(initial, 4); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout + 1, *prev); result = _mm_cvtepi8_epi32(initial); initial = _mm_srli_si128(initial, 4); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout + 2, *prev); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout + 3, *prev); *ints_read = 16; return 16; } int mask2 = mask & 0xFFF; index_bytes_consumed combined = combined_lookup[mask2]; int index = combined.index; __m128i shuffle_vector = vectors[index]; int consumed = combined.bytes_consumed; if (index < 64) { *ints_read = 6; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x007F)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x7F00)); __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); __m128i unpacked_result_a = _mm_and_si128(packed_result, _mm_set1_epi32(0x0000FFFF)); *prev = PrefixSum(unpacked_result_a, *prev); _mm_storeu_si128(mout, *prev); __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); *prev = PrefixSum2ints(unpacked_result_b, *prev); _mm_storeu_si128(mout + 1, *prev); return consumed; } if (index < 145) { *ints_read = 4; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x0000007F)); __m128i middle_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x00007F00)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x007F0000)); __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); *prev = PrefixSum(result, *prev); _mm_storeu_si128(mout, *prev); return consumed; } *ints_read = 2; __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); __m128i result_evens = _mm_or_si128(recombined, low_byte); __m128i result = _mm_shuffle_epi8(result_evens, _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1)); *prev = PrefixSum2ints(result, *prev); _mm_storeu_si128(mout, *prev); return consumed; } // len_signed : number of ints we want to decode size_t masked_vbyte_decode_delta(const uint8_t* in, uint32_t* out, uint64_t length, uint32_t prev) { //uint64_t length = (uint64_t) len_signed; // number of ints we want to decode size_t consumed = 0; // number of bytes read __m128i mprev = _mm_set1_epi32(prev); uint64_t count = 0; // how many integers we have read so far uint64_t sig = 0; int availablebytes = 0; if (96 < length) { size_t scanned = 0; #ifdef __AVX2__ __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); uint32_t lowSig = _mm256_movemask_epi8(low); #else __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); uint32_t lowSig1 = _mm_movemask_epi8(low1); __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); uint32_t lowSig2 = _mm_movemask_epi8(low2); uint32_t lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif // excess verbosity to avoid problems with sign extension on conversions // better to think about what's happening and make it clearer __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); uint32_t highSig = _mm_movemask_epi8(high); uint64_t nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; scanned += 48; do { uint64_t thisSig = nextSig; #ifdef __AVX2__ low = _mm256_loadu_si256((__m256i *)(in + scanned)); lowSig = _mm256_movemask_epi8(low); #else low1 = _mm_loadu_si128((__m128i *) (in + scanned)); lowSig1 = _mm_movemask_epi8(low1); low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); lowSig2 = _mm_movemask_epi8(low2); lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); highSig = _mm_movemask_epi8(high); nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; uint64_t remaining = scanned - (consumed + 48); sig = (thisSig << remaining) | sig; uint64_t reload = scanned - 16; scanned += 48; // need to reload when less than 16 scanned bytes remain in sig while (consumed < reload) { uint64_t ints_read; uint64_t bytes = masked_vbyte_read_group_delta(in + consumed, out + count, sig, &ints_read, &mprev); sig >>= bytes; // seems like this might force the compiler to prioritize shifting sig >>= bytes if (sig == 0xFFFFFFFFFFFFFFFF) return 0; // fake check to force earliest evaluation consumed += bytes; count += ints_read; } } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig sig = (nextSig << (scanned - consumed - 48)) | sig; availablebytes = scanned - consumed; } while (availablebytes + count < length) { if (availablebytes < 16) break; if (availablebytes < 16) { if (availablebytes + count + 31 < length) { #ifdef __AVX2__ uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); sig |= (newsigavx << availablebytes); #else uint64_t newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); uint64_t newsig2 = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + 16 + consumed))); sig |= (newsig << availablebytes) | (newsig2 << (availablebytes + 16)); #endif availablebytes += 32; } else if (availablebytes + count + 15 < length) { int newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); sig |= newsig << availablebytes; availablebytes += 16; } else { break; } } uint64_t ints_read; uint64_t eaten = masked_vbyte_read_group_delta(in + consumed, out + count, sig, &ints_read, &mprev); consumed += eaten; availablebytes -= eaten; sig >>= eaten; count += ints_read; } prev = _mm_extract_epi32(mprev, 3); for (; count < length; count++) { consumed += read_int_delta(in + consumed, out + count, &prev); } return consumed; } size_t read_ints_delta(const uint8_t* in, uint32_t* out, int length, uint32_t prev) { __m128i mprev = _mm_set1_epi32(prev); size_t consumed = 0; int count; for (count = 0; count + 15 < length;) { int ints_read; consumed += read_int_group_delta(in + consumed, out + count, &ints_read, &mprev); count += ints_read; } prev = _mm_extract_epi32(mprev, 3); for (; count < length; count++) { consumed += read_int_delta(in + consumed, out + count, &prev); } return consumed; } // inputsize : number of input bytes we want to decode // returns the number of written ints size_t masked_vbyte_decode_fromcompressedsize_delta(const uint8_t* in, uint32_t* out, size_t inputsize, uint32_t prev) { size_t consumed = 0; // number of bytes read uint32_t * initout = out; __m128i mprev = _mm_set1_epi32(prev); uint64_t sig = 0; int availablebytes = 0; if (96 < inputsize) { size_t scanned = 0; #ifdef __AVX2__ __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); uint32_t lowSig = _mm256_movemask_epi8(low); #else __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); uint32_t lowSig1 = _mm_movemask_epi8(low1); __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); uint32_t lowSig2 = _mm_movemask_epi8(low2); uint32_t lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif // excess verbosity to avoid problems with sign extension on conversions // better to think about what's happening and make it clearer __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); uint32_t highSig = _mm_movemask_epi8(high); uint64_t nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; scanned += 48; do { uint64_t thisSig = nextSig; #ifdef __AVX2__ low = _mm256_loadu_si256((__m256i *)(in + scanned)); lowSig = _mm256_movemask_epi8(low); #else low1 = _mm_loadu_si128((__m128i *) (in + scanned)); lowSig1 = _mm_movemask_epi8(low1); low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); lowSig2 = _mm_movemask_epi8(low2); lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); highSig = _mm_movemask_epi8(high); nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; uint64_t remaining = scanned - (consumed + 48); sig = (thisSig << remaining) | sig; uint64_t reload = scanned - 16; scanned += 48; // need to reload when less than 16 scanned bytes remain in sig while (consumed < reload) { uint64_t ints_read; uint64_t bytes = masked_vbyte_read_group_delta(in + consumed, out, sig, &ints_read, &mprev); sig >>= bytes; // seems like this might force the compiler to prioritize shifting sig >>= bytes if (sig == 0xFFFFFFFFFFFFFFFF) return 0; // fake check to force earliest evaluation consumed += bytes; out += ints_read; } } while (scanned + 112 < inputsize); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig sig = (nextSig << (scanned - consumed - 48)) | sig; availablebytes = scanned - consumed; } while (1) { if (availablebytes < 16) { if (availablebytes + consumed + 31 < inputsize) { #ifdef __AVX2__ uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); sig |= (newsigavx << availablebytes); #else uint64_t newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); uint64_t newsig2 = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + 16 + consumed))); sig |= (newsig << availablebytes) | (newsig2 << (availablebytes + 16)); #endif availablebytes += 32; } else if(availablebytes + consumed + 15 < inputsize ) { int newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); sig |= newsig << availablebytes; availablebytes += 16; } else { break; } } uint64_t ints_read; uint64_t bytes = masked_vbyte_read_group_delta(in + consumed, out, sig, &ints_read, &mprev); consumed += bytes; availablebytes -= bytes; sig >>= bytes; out += ints_read; } prev = _mm_extract_epi32(mprev, 3); while (consumed < inputsize) { unsigned int shift = 0; for (uint32_t v = 0; consumed < inputsize; shift += 7) { uint8_t c = in[consumed++]; if ((c & 128) == 0) { uint32_t delta = v + (c << shift); prev += delta; *out++ = prev; break; } else { v += (c & 127) << shift; } } } return out - initout; } static const int8_t ALIGNED(16) shuffle_mask_bytes1[16 * 16 ] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 6, 7, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 8, 9, 10, 11, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 6, 7, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, }; static const __m128i *shuffle_mask = (__m128i *) shuffle_mask_bytes1; /* perform a lower-bound search for |key| in |out|; the resulting uint32 * is stored in |*presult|.*/ #define CHECK_AND_INCREMENT(i, out, key, presult) \ do { \ __m128i tmpout = _mm_sub_epi32(out, conversion); \ uint32_t mmask = _mm_movemask_ps(_mm_castsi128_ps(_mm_cmplt_epi32(tmpout, key4))); \ if (mmask != 15) { \ __m128i pp = _mm_shuffle_epi8(out, shuffle_mask[mmask ^ 15]); \ int offset; \ SIMDCOMP_CTZ(offset, mmask ^ 15); \ *presult = _mm_cvtsi128_si32(pp); \ return (i + offset); \ } \ i += 4; \ } while (0) /* perform a lower-bound search for |key| in |out|; the resulting uint32 * is stored in |*presult|.*/ #define CHECK_AND_INCREMENT_2(i, out, key, presult) \ do { \ __m128i tmpout = _mm_sub_epi32(out, conversion); \ uint32_t mmask = 3 & _mm_movemask_ps(_mm_castsi128_ps(_mm_cmplt_epi32(tmpout, key4))); \ if (mmask != 3) { \ __m128i pp = _mm_shuffle_epi8(out, shuffle_mask[mmask ^ 3]); \ int offset; \ SIMDCOMP_CTZ(offset, mmask ^ 3); \ *presult = _mm_cvtsi128_si32(pp); \ return (i + offset); \ } \ i += 2; \ } while (0) static int masked_vbyte_search_group_delta(const uint8_t *in, uint64_t *p, uint64_t mask, uint64_t *ints_read, __m128i *prev, int i, uint32_t key, uint32_t *presult) { __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); __m128i conversion = _mm_set1_epi32(2147483648U); __m128i key4 = _mm_set1_epi32(key - 2147483648U); if (!(mask & 0xFFFF)) { __m128i result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_AND_INCREMENT(i, *prev, key, presult); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_AND_INCREMENT(i, *prev, key, presult); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_AND_INCREMENT(i, *prev, key, presult); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_AND_INCREMENT(i, *prev, key, presult); *ints_read = 16; *p = 16; return (-1); } uint32_t low_12_bits = mask & 0xFFF; // combine index and bytes consumed into a single lookup index_bytes_consumed combined = combined_lookup[low_12_bits]; uint64_t consumed = combined.bytes_consumed; uint8_t index = combined.index; __m128i shuffle_vector = vectors[index]; // __m128i shuffle_vector = {0, 0}; // speed check: 20% faster at large, less at small if (index < 64) { *ints_read = 6; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x007F)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x7F00)); __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); __m128i unpacked_result_a = _mm_and_si128(packed_result, _mm_set1_epi32(0x0000FFFF)); *prev = PrefixSum(unpacked_result_a, *prev); CHECK_AND_INCREMENT(i, *prev, key, presult); __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); *prev = PrefixSum2ints(unpacked_result_b, *prev); //_mm_storel_epi64(&out, *prev); CHECK_AND_INCREMENT_2(i, *prev, key, presult); *p = consumed; return (-1); } if (index < 145) { *ints_read = 4; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x0000007F)); __m128i middle_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x00007F00)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x007F0000)); __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); *prev = PrefixSum(result, *prev); CHECK_AND_INCREMENT(i, *prev, key, presult); *p = consumed; return (-1); } *ints_read = 2; __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); __m128i result_evens = _mm_or_si128(recombined, low_byte); __m128i result = _mm_shuffle_epi8(result_evens, _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1)); *prev = PrefixSum2ints(result, *prev); //_mm_storel_epi64(&out, *prev); CHECK_AND_INCREMENT_2(i, *prev, key, presult); *p = consumed; return (-1); } // returns the index of the matching key int masked_vbyte_search_delta(const uint8_t *in, uint64_t length, uint32_t prev, uint32_t key, uint32_t *presult) { size_t consumed = 0; // number of bytes read __m128i mprev = _mm_set1_epi32(prev); uint64_t count = 0; // how many integers we have read so far uint64_t sig = 0; int availablebytes = 0; if (96 < length) { size_t scanned = 0; #ifdef __AVX2__ __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); uint32_t lowSig = _mm256_movemask_epi8(low); #else __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); uint32_t lowSig1 = _mm_movemask_epi8(low1); __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); uint32_t lowSig2 = _mm_movemask_epi8(low2); uint32_t lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif // excess verbosity to avoid problems with sign extension on conversions // better to think about what's happening and make it clearer __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); uint32_t highSig = _mm_movemask_epi8(high); uint64_t nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; scanned += 48; do { uint64_t thisSig = nextSig; #ifdef __AVX2__ low = _mm256_loadu_si256((__m256i *)(in + scanned)); lowSig = _mm256_movemask_epi8(low); #else low1 = _mm_loadu_si128((__m128i *) (in + scanned)); lowSig1 = _mm_movemask_epi8(low1); low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); lowSig2 = _mm_movemask_epi8(low2); lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); highSig = _mm_movemask_epi8(high); nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; uint64_t remaining = scanned - (consumed + 48); sig = (thisSig << remaining) | sig; uint64_t reload = scanned - 16; scanned += 48; // need to reload when less than 16 scanned bytes remain in sig while (consumed < reload) { uint64_t ints_read = 0, bytes = 0; int ret = masked_vbyte_search_group_delta(in + consumed, &bytes, sig, &ints_read, &mprev, count, key, presult); if (ret >= 0) return (ret); sig >>= bytes; // seems like this might force the compiler to prioritize shifting sig >>= bytes if (sig == 0xFFFFFFFFFFFFFFFF) return 0; // fake check to force earliest evaluation consumed += bytes; count += ints_read; } } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig sig = (nextSig << (scanned - consumed - 48)) | sig; availablebytes = scanned - consumed; } while (availablebytes + count < length) { if (availablebytes < 16) break; uint64_t ints_read = 0, bytes = 0; int ret = masked_vbyte_search_group_delta(in + consumed, &bytes, sig, &ints_read, &mprev, count, key, presult); if (ret >= 0) return (ret); consumed += bytes; availablebytes -= bytes; sig >>= bytes; count += ints_read; } prev = _mm_extract_epi32(mprev, 3); for (; count < length; count++) { uint32_t out; consumed += read_int_delta(in + consumed, &out, &prev); if (key <= prev) { *presult = prev; return (count); } } *presult = key + 1; return length; } static const int8_t ALIGNED(16) shuffle_mask_bytes2[16 * 16 ] = { 0,1,2,3,0,0,0,0,0,0,0,0,0,0,0,0, 4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0, 8,9,10,11,0,0,0,0,0,0,0,0,0,0,0,0, 12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0, }; static const __m128i *shuffle_mask_extract = (__m128i *) shuffle_mask_bytes2; static uint32_t branchlessextract (__m128i out, int i) { return _mm_cvtsi128_si32(_mm_shuffle_epi8(out,shuffle_mask_extract[i])); } #define CHECK_SELECT(i, out, slot, presult) \ i += 4; \ if (i > slot) { \ *presult = branchlessextract (out, slot - (i - 4)); \ return (1); \ } #define CHECK_SELECT_2(i, out, slot, presult) \ i += 2; \ if (i > slot) { \ *presult = branchlessextract (out, slot - (i - 2)); \ return (1); \ } static int masked_vbyte_select_group_delta(const uint8_t *in, uint64_t *p, uint64_t mask, uint64_t *ints_read, __m128i *prev, int slot, uint32_t *presult) { __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); int i = 0; if (!(mask & 0xFFFF)) { __m128i result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_SELECT(i, *prev, slot, presult); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_SELECT(i, *prev, slot, presult); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_SELECT(i, *prev, slot, presult); initial = _mm_srli_si128(initial, 4); result = _mm_cvtepi8_epi32(initial); *prev = PrefixSum(result, *prev); CHECK_SELECT(i, *prev, slot, presult); *ints_read = 16; *p = 16; return (0); } uint32_t low_12_bits = mask & 0xFFF; // combine index and bytes consumed into a single lookup index_bytes_consumed combined = combined_lookup[low_12_bits]; uint64_t consumed = combined.bytes_consumed; uint8_t index = combined.index; __m128i shuffle_vector = vectors[index]; // __m128i shuffle_vector = {0, 0}; // speed check: 20% faster at large, less at small if (index < 64) { *ints_read = 6; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x007F)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi16(0x7F00)); __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); __m128i unpacked_result_a = _mm_and_si128(packed_result, _mm_set1_epi32(0x0000FFFF)); *prev = PrefixSum(unpacked_result_a, *prev); CHECK_SELECT(i, *prev, slot, presult); __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); *prev = PrefixSum2ints(unpacked_result_b, *prev); //_mm_storel_epi64(&out, *prev); CHECK_SELECT_2(i, *prev, slot, presult); *p = consumed; return (0); } if (index < 145) { *ints_read = 4; __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); __m128i low_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x0000007F)); __m128i middle_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x00007F00)); __m128i high_bytes = _mm_and_si128(bytes_to_decode, _mm_set1_epi32(0x007F0000)); __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); *prev = PrefixSum(result, *prev); CHECK_SELECT(i, *prev, slot, presult); *p = consumed; return (0); } *ints_read = 2; __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); __m128i result_evens = _mm_or_si128(recombined, low_byte); __m128i result = _mm_shuffle_epi8(result_evens, _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1)); *prev = PrefixSum2ints(result, *prev); //_mm_storel_epi64(&out, *prev); CHECK_SELECT_2(i, *prev, slot, presult); *p = consumed; return (0); } uint32_t masked_vbyte_select_delta(const uint8_t *in, uint64_t length, uint32_t prev, size_t slot) { size_t consumed = 0; // number of bytes read __m128i mprev = _mm_set1_epi32(prev); uint64_t count = 0; // how many integers we have read so far uint64_t sig = 0; int availablebytes = 0; if (96 < length) { size_t scanned = 0; #ifdef __AVX2__ __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); uint32_t lowSig = _mm256_movemask_epi8(low); #else __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); uint32_t lowSig1 = _mm_movemask_epi8(low1); __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); uint32_t lowSig2 = _mm_movemask_epi8(low2); uint32_t lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif // excess verbosity to avoid problems with sign extension on conversions // better to think about what's happening and make it clearer __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); uint32_t highSig = _mm_movemask_epi8(high); uint64_t nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; scanned += 48; do { uint64_t thisSig = nextSig; #ifdef __AVX2__ low = _mm256_loadu_si256((__m256i *)(in + scanned)); lowSig = _mm256_movemask_epi8(low); #else low1 = _mm_loadu_si128((__m128i *) (in + scanned)); lowSig1 = _mm_movemask_epi8(low1); low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); lowSig2 = _mm_movemask_epi8(low2); lowSig = lowSig2 << 16; lowSig |= lowSig1; #endif high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); highSig = _mm_movemask_epi8(high); nextSig = highSig; nextSig <<= 32; nextSig |= lowSig; uint64_t remaining = scanned - (consumed + 48); sig = (thisSig << remaining) | sig; uint64_t reload = scanned - 16; scanned += 48; // need to reload when less than 16 scanned bytes remain in sig while (consumed < reload) { uint32_t result; uint64_t ints_read, bytes; if (masked_vbyte_select_group_delta(in + consumed, &bytes, sig, &ints_read, &mprev, slot - count, &result)) { return (result); } sig >>= bytes; // seems like this might force the compiler to prioritize shifting sig >>= bytes if (sig == 0xFFFFFFFFFFFFFFFF) return 0; // fake check to force earliest evaluation consumed += bytes; count += ints_read; } } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig sig = (nextSig << (scanned - consumed - 48)) | sig; availablebytes = scanned - consumed; } while (availablebytes + count < length) { if (availablebytes < 16) break; if (availablebytes < 16) { if (availablebytes + count + 31 < length) { #ifdef __AVX2__ uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); sig |= (newsigavx << availablebytes); #else uint64_t newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); uint64_t newsig2 = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + 16 + consumed))); sig |= (newsig << availablebytes) | (newsig2 << (availablebytes + 16)); #endif availablebytes += 32; } else if (availablebytes + count + 15 < length) { int newsig = _mm_movemask_epi8( _mm_lddqu_si128( (const __m128i *) (in + availablebytes + consumed))); sig |= newsig << availablebytes; availablebytes += 16; } else { break; } } uint32_t result; uint64_t ints_read, bytes; if (masked_vbyte_select_group_delta(in + consumed, &bytes, sig, &ints_read, &mprev, slot - count, &result)) { return (result); } consumed += bytes; availablebytes -= bytes; sig >>= bytes; count += ints_read; } prev = _mm_extract_epi32(mprev, 3); for (; count < slot + 1; count++) { uint32_t out; consumed += read_int_delta(in + consumed, &out, &prev); } return prev; }
d032316fef438f16d64eed035d1e1d6190713390
e73547787354afd9b717ea57fe8dd0695d161821
/include/mapfs/pra_02_shape.h
3c370f0c8a3023770e5e384a178a9c499e69c317
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
4,470
h
pra_02_shape.h
#define MODEL_Root 0x75 #define MODEL_g238 0x74 #define MODEL_g234 0x73 #define MODEL_o847 0x72 #define MODEL_g219 0x71 #define MODEL_o846 0x70 #define MODEL_o768 0x6F #define MODEL_g220 0x6E #define MODEL_o844 0x6D #define MODEL_o772 0x6C #define MODEL_g291 0x6B #define MODEL_g306 0x6A #define MODEL_o1215 0x69 #define MODEL_o1214 0x68 #define MODEL_o1213 0x67 #define MODEL_g300 0x66 #define MODEL_o1177 0x65 #define MODEL_o1176 0x64 #define MODEL_g293 0x63 #define MODEL_g297 0x62 #define MODEL_o1162 0x61 #define MODEL_g296 0x60 #define MODEL_o1160 0x5F #define MODEL_g295 0x5E #define MODEL_o1158 0x5D #define MODEL_g294 0x5C #define MODEL_o1156 0x5B #define MODEL_g292 0x5A #define MODEL_o1154 0x59 #define MODEL_o1150 0x58 #define MODEL_o1149 0x57 #define MODEL_o1148 0x56 #define MODEL_o1145 0x55 #define MODEL_o1144 0x54 #define MODEL_g270 0x53 #define MODEL_o974 0x52 #define MODEL_o973 0x51 #define MODEL_g305 0x50 #define MODEL_o1194 0x4F #define MODEL_o1204 0x4E #define MODEL_o1198 0x4D #define MODEL_o1205 0x4C #define MODEL_o1202 0x4B #define MODEL_g259 0x4A #define MODEL_g263 0x49 #define MODEL_o952 0x48 #define MODEL_g262 0x47 #define MODEL_o950 0x46 #define MODEL_g261 0x45 #define MODEL_o948 0x44 #define MODEL_g260 0x43 #define MODEL_o946 0x42 #define MODEL_g258 0x41 #define MODEL_o1080 0x40 #define MODEL_o1076 0x3F #define MODEL_o944 0x3E #define MODEL_o943 0x3D #define MODEL_o942 0x3C #define MODEL_o940 0x3B #define MODEL_o939 0x3A #define MODEL_g144 0x39 #define MODEL_g308 0x38 #define MODEL_o1233 0x37 #define MODEL_o1232 0x36 #define MODEL_o1231 0x35 #define MODEL_o1230 0x34 #define MODEL_o1229 0x33 #define MODEL_o1228 0x32 #define MODEL_g307 0x31 #define MODEL_o1225 0x30 #define MODEL_o1226 0x2F #define MODEL_o1227 0x2E #define MODEL_o1224 0x2D #define MODEL_o1223 0x2C #define MODEL_o1222 0x2B #define MODEL_g323 0x2A #define MODEL_g315 0x29 #define MODEL_o1280 0x28 #define MODEL_o1279 0x27 #define MODEL_o1278 0x26 #define MODEL_g318 0x25 #define MODEL_o1311 0x24 #define MODEL_o1312 0x23 #define MODEL_g253 0x22 #define MODEL_o1290 0x21 #define MODEL_o1289 0x20 #define MODEL_o1288 0x1F #define MODEL_g228 0x1E #define MODEL_o795 0x1D #define MODEL_o794 0x1C #define MODEL_g317 0x1B #define MODEL_g252 0x1A #define MODEL_o1298 0x19 #define MODEL_o1294 0x18 #define MODEL_o1297 0x17 #define MODEL_o1304 0x16 #define MODEL_g218 0x15 #define MODEL_o549 0x14 #define MODEL_g322 0x13 #define MODEL_g221 0x12 #define MODEL_o774 0x11 #define MODEL_g237 0x10 #define MODEL_o861 0xF #define MODEL_g236 0xE #define MODEL_o859 0xD #define MODEL_g324 0xC #define MODEL_o1310 0xB #define MODEL_g320 0xA #define MODEL_o1317 0x9 #define MODEL_o1316 0x8 #define MODEL_o1315 0x7 #define MODEL_g185 0x6 #define MODEL_o1254 0x5 #define MODEL_o1253 0x4 #define MODEL_o1250 0x3 #define MODEL_o636 0x2 #define MODEL_o634 0x1 #define MODEL_o1238 0x0
db9ab6f4e2aef7c424c7e2334dc7d0f9fa83a5d1
7e6afb4986a53c420d40a2039240f8c5ed3f9549
/libs/math/src/CSparse/cs_amd.c
c11b3b7bd6bf9ff70f93f41c3878d3dc7b18fe6d
[ "BSD-3-Clause", "LGPL-2.1-or-later", "LGPL-2.0-or-later", "DOC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
MRPT/mrpt
9ea3c39a76de78eacaca61a10e7e96646647a6da
34077ec74a90b593b587f2057d3280ea520a3609
refs/heads/develop
2023-08-17T23:37:29.722496
2023-08-17T15:39:54
2023-08-17T15:39:54
13,708,826
1,695
646
BSD-3-Clause
2023-09-12T22:02:53
2013-10-19T21:09:23
C++
UTF-8
C
false
false
16,648
c
cs_amd.c
// CSparse/Source/cs_amd: approximate minimum degree // CSparse, Copyright (c) 2006-2023, Timothy A. Davis. All Rights Reserved. // SPDX-License-Identifier: LGPL-2.1+ #include "cs.h" /* clear w */ static int cs_wclear (int mark, int lemax, int *w, int n) { int k ; if (mark < 2 || (mark + lemax < 0)) { for (k = 0 ; k < n ; k++) if (w [k] != 0) w [k] = 1 ; mark = 2 ; } return (mark) ; /* at this point, w [0..n-1] < mark holds */ } /* keep off-diagonal entries; drop diagonal entries */ static int cs_diag (int i, int j, double aij, void *other) { return (i != j) ; } /* p = amd(A+A') if symmetric is true, or amd(A'A) otherwise */ int *cs_amd (int order, const cs *A) /* order 0:natural, 1:Chol, 2:LU, 3:QR */ { cs *C, *A2, *AT ; int *Cp, *Ci, *last, *W, *len, *nv, *next, *P, *head, *elen, *degree, *w, *hhead, *ATp, *ATi, d, dk, dext, lemax = 0, e, elenk, eln, i, j, k, k1, k2, k3, jlast, ln, dense, nzmax, mindeg = 0, nvi, nvj, nvk, mark, wnvi, ok, cnz, nel = 0, p, p1, p2, p3, p4, pj, pk, pk1, pk2, pn, q, n, m, t ; unsigned int h ; /* --- Construct matrix C ----------------------------------------------- */ if (!CS_CSC (A) || order <= 0 || order > 3) return (NULL) ; /* check */ AT = cs_transpose (A, 0) ; /* compute A' */ if (!AT) return (NULL) ; m = A->m ; n = A->n ; dense = (int)CS_MAX (16, 10 * sqrt ((double) n)) ; /* find dense threshold */ dense = CS_MIN (n-2, dense) ; if (order == 1 && n == m) { C = cs_add (A, AT, 0, 0) ; /* C = A+A' */ } else if (order == 2) { ATp = AT->p ; /* drop dense columns from AT */ ATi = AT->i ; for (p2 = 0, j = 0 ; j < m ; j++) { p = ATp [j] ; /* column j of AT starts here */ ATp [j] = p2 ; /* new column j starts here */ if (ATp [j+1] - p > dense) continue ; /* skip dense col j */ for ( ; p < ATp [j+1] ; p++) ATi [p2++] = ATi [p] ; } ATp [m] = p2 ; /* finalize AT */ A2 = cs_transpose (AT, 0) ; /* A2 = AT' */ C = A2 ? cs_multiply (AT, A2) : NULL ; /* C=A'*A with no dense rows */ cs_spfree (A2) ; } else { C = cs_multiply (AT, A) ; /* C=A'*A */ } cs_spfree (AT) ; if (!C) return (NULL) ; cs_fkeep (C, &cs_diag, NULL) ; /* drop diagonal entries */ Cp = C->p ; cnz = Cp [n] ; P = cs_malloc (n+1, sizeof (int)) ; /* allocate result */ W = cs_malloc (8*(n+1), sizeof (int)) ; /* get workspace */ t = cnz + cnz/5 + 2*n ; /* add elbow room to C */ if (!P || !W || !cs_sprealloc (C, t)) return (cs_idone (P, C, W, 0)) ; len = W ; nv = W + (n+1) ; next = W + 2*(n+1) ; head = W + 3*(n+1) ; elen = W + 4*(n+1) ; degree = W + 5*(n+1) ; w = W + 6*(n+1) ; hhead = W + 7*(n+1) ; last = P ; /* use P as workspace for last */ /* --- Initialize quotient graph ---------------------------------------- */ for (k = 0 ; k < n ; k++) len [k] = Cp [k+1] - Cp [k] ; len [n] = 0 ; nzmax = C->nzmax ; Ci = C->i ; for (i = 0 ; i <= n ; i++) { head [i] = -1 ; /* degree list i is empty */ last [i] = -1 ; next [i] = -1 ; hhead [i] = -1 ; /* hash list i is empty */ nv [i] = 1 ; /* node i is just one node */ w [i] = 1 ; /* node i is alive */ elen [i] = 0 ; /* Ek of node i is empty */ degree [i] = len [i] ; /* degree of node i */ } mark = cs_wclear (0, 0, w, n) ; /* clear w */ elen [n] = -2 ; /* n is a dead element */ Cp [n] = -1 ; /* n is a root of assembly tree */ w [n] = 0 ; /* n is a dead element */ /* --- Initialize degree lists ------------------------------------------ */ for (i = 0 ; i < n ; i++) { d = degree [i] ; if (d == 0) /* node i is empty */ { elen [i] = -2 ; /* element i is dead */ nel++ ; Cp [i] = -1 ; /* i is a root of assembly tree */ w [i] = 0 ; } else if (d > dense) /* node i is dense */ { nv [i] = 0 ; /* absorb i into element n */ elen [i] = -1 ; /* node i is dead */ nel++ ; Cp [i] = CS_FLIP (n) ; nv [n]++ ; } else { if (head [d] != -1) last [head [d]] = i ; next [i] = head [d] ; /* put node i in degree list d */ head [d] = i ; } } while (nel < n) /* while (selecting pivots) do */ { /* --- Select node of minimum approximate degree -------------------- */ for (k = -1 ; mindeg < n && (k = head [mindeg]) == -1 ; mindeg++) ; if (next [k] != -1) last [next [k]] = -1 ; head [mindeg] = next [k] ; /* remove k from degree list */ elenk = elen [k] ; /* elenk = |Ek| */ nvk = nv [k] ; /* # of nodes k represents */ nel += nvk ; /* nv[k] nodes of A eliminated */ /* --- Garbage collection ------------------------------------------- */ if (elenk > 0 && cnz + mindeg >= nzmax) { for (j = 0 ; j < n ; j++) { if ((p = Cp [j]) >= 0) /* j is a live node or element */ { Cp [j] = Ci [p] ; /* save first entry of object */ Ci [p] = CS_FLIP (j) ; /* first entry is now CS_FLIP(j) */ } } for (q = 0, p = 0 ; p < cnz ; ) /* scan all of memory */ { if ((j = CS_FLIP (Ci [p++])) >= 0) /* found object j */ { Ci [q] = Cp [j] ; /* restore first entry of object */ Cp [j] = q++ ; /* new pointer to object j */ for (k3 = 0 ; k3 < len [j]-1 ; k3++) Ci [q++] = Ci [p++] ; } } cnz = q ; /* Ci [cnz...nzmax-1] now free */ } /* --- Construct new element ---------------------------------------- */ dk = 0 ; nv [k] = -nvk ; /* flag k as in Lk */ p = Cp [k] ; pk1 = (elenk == 0) ? p : cnz ; /* do in place if elen[k] == 0 */ pk2 = pk1 ; for (k1 = 1 ; k1 <= elenk + 1 ; k1++) { if (k1 > elenk) { e = k ; /* search the nodes in k */ pj = p ; /* list of nodes starts at Ci[pj]*/ ln = len [k] - elenk ; /* length of list of nodes in k */ } else { e = Ci [p++] ; /* search the nodes in e */ pj = Cp [e] ; ln = len [e] ; /* length of list of nodes in e */ } for (k2 = 1 ; k2 <= ln ; k2++) { i = Ci [pj++] ; if ((nvi = nv [i]) <= 0) continue ; /* node i dead, or seen */ dk += nvi ; /* degree[Lk] += size of node i */ nv [i] = -nvi ; /* negate nv[i] to denote i in Lk*/ Ci [pk2++] = i ; /* place i in Lk */ if (next [i] != -1) last [next [i]] = last [i] ; if (last [i] != -1) /* remove i from degree list */ { next [last [i]] = next [i] ; } else { head [degree [i]] = next [i] ; } } if (e != k) { Cp [e] = CS_FLIP (k) ; /* absorb e into k */ w [e] = 0 ; /* e is now a dead element */ } } if (elenk != 0) cnz = pk2 ; /* Ci [cnz...nzmax] is free */ degree [k] = dk ; /* external degree of k - |Lk\i| */ Cp [k] = pk1 ; /* element k is in Ci[pk1..pk2-1] */ len [k] = pk2 - pk1 ; elen [k] = -2 ; /* k is now an element */ /* --- Find set differences ----------------------------------------- */ mark = cs_wclear (mark, lemax, w, n) ; /* clear w if necessary */ for (pk = pk1 ; pk < pk2 ; pk++) /* scan 1: find |Le\Lk| */ { i = Ci [pk] ; if ((eln = elen [i]) <= 0) continue ;/* skip if elen[i] empty */ nvi = -nv [i] ; /* nv [i] was negated */ wnvi = mark - nvi ; for (p = Cp [i] ; p <= Cp [i] + eln - 1 ; p++) /* scan Ei */ { e = Ci [p] ; if (w [e] >= mark) { w [e] -= nvi ; /* decrement |Le\Lk| */ } else if (w [e] != 0) /* ensure e is a live element */ { w [e] = degree [e] + wnvi ; /* 1st time e seen in scan 1 */ } } } /* --- Degree update ------------------------------------------------ */ for (pk = pk1 ; pk < pk2 ; pk++) /* scan2: degree update */ { i = Ci [pk] ; /* consider node i in Lk */ p1 = Cp [i] ; p2 = p1 + elen [i] - 1 ; pn = p1 ; for (h = 0, d = 0, p = p1 ; p <= p2 ; p++) /* scan Ei */ { e = Ci [p] ; if (w [e] != 0) /* e is an unabsorbed element */ { dext = w [e] - mark ; /* dext = |Le\Lk| */ if (dext > 0) { d += dext ; /* sum up the set differences */ Ci [pn++] = e ; /* keep e in Ei */ h += e ; /* compute the hash of node i */ } else { Cp [e] = CS_FLIP (k) ; /* aggressive absorb. e->k */ w [e] = 0 ; /* e is a dead element */ } } } elen [i] = pn - p1 + 1 ; /* elen[i] = |Ei| */ p3 = pn ; p4 = p1 + len [i] ; for (p = p2 + 1 ; p < p4 ; p++) /* prune edges in Ai */ { j = Ci [p] ; if ((nvj = nv [j]) <= 0) continue ; /* node j dead or in Lk */ d += nvj ; /* degree(i) += |j| */ Ci [pn++] = j ; /* place j in node list of i */ h += j ; /* compute hash for node i */ } if (d == 0) /* check for mass elimination */ { Cp [i] = CS_FLIP (k) ; /* absorb i into k */ nvi = -nv [i] ; dk -= nvi ; /* |Lk| -= |i| */ nvk += nvi ; /* |k| += nv[i] */ nel += nvi ; nv [i] = 0 ; elen [i] = -1 ; /* node i is dead */ } else { degree [i] = CS_MIN (degree [i], d) ; /* update degree(i) */ Ci [pn] = Ci [p3] ; /* move first node to end */ Ci [p3] = Ci [p1] ; /* move 1st el. to end of Ei */ Ci [p1] = k ; /* add k as 1st element in of Ei */ len [i] = pn - p1 + 1 ; /* new len of adj. list of node i */ h %= n ; /* finalize hash of i */ next [i] = hhead [h] ; /* place i in hash bucket */ hhead [h] = i ; last [i] = h ; /* save hash of i in last[i] */ } } /* scan2 is done */ degree [k] = dk ; /* finalize |Lk| */ lemax = CS_MAX (lemax, dk) ; mark = cs_wclear (mark+lemax, lemax, w, n) ; /* clear w */ /* --- Supernode detection ------------------------------------------ */ for (pk = pk1 ; pk < pk2 ; pk++) { i = Ci [pk] ; if (nv [i] >= 0) continue ; /* skip if i is dead */ h = last [i] ; /* scan hash bucket of node i */ i = hhead [h] ; hhead [h] = -1 ; /* hash bucket will be empty */ for ( ; i != -1 && next [i] != -1 ; i = next [i], mark++) { ln = len [i] ; eln = elen [i] ; for (p = Cp [i]+1 ; p <= Cp [i] + ln-1 ; p++) w [Ci [p]] = mark; jlast = i ; for (j = next [i] ; j != -1 ; ) /* compare i with all j */ { ok = (len [j] == ln) && (elen [j] == eln) ; for (p = Cp [j] + 1 ; ok && p <= Cp [j] + ln - 1 ; p++) { if (w [Ci [p]] != mark) ok = 0 ; /* compare i and j*/ } if (ok) /* i and j are identical */ { Cp [j] = CS_FLIP (i) ; /* absorb j into i */ nv [i] += nv [j] ; nv [j] = 0 ; elen [j] = -1 ; /* node j is dead */ j = next [j] ; /* delete j from hash bucket */ next [jlast] = j ; } else { jlast = j ; /* j and i are different */ j = next [j] ; } } } } /* --- Finalize new element------------------------------------------ */ for (p = pk1, pk = pk1 ; pk < pk2 ; pk++) /* finalize Lk */ { i = Ci [pk] ; if ((nvi = -nv [i]) <= 0) continue ;/* skip if i is dead */ nv [i] = nvi ; /* restore nv[i] */ d = degree [i] + dk - nvi ; /* compute external degree(i) */ d = CS_MIN (d, n - nel - nvi) ; if (head [d] != -1) last [head [d]] = i ; next [i] = head [d] ; /* put i back in degree list */ last [i] = -1 ; head [d] = i ; mindeg = CS_MIN (mindeg, d) ; /* find new minimum degree */ degree [i] = d ; Ci [p++] = i ; /* place i in Lk */ } nv [k] = nvk ; /* # nodes absorbed into k */ if ((len [k] = p-pk1) == 0) /* length of adj list of element k*/ { Cp [k] = -1 ; /* k is a root of the tree */ w [k] = 0 ; /* k is now a dead element */ } if (elenk != 0) cnz = p ; /* free unused space in Lk */ } /* --- Postordering ----------------------------------------------------- */ for (i = 0 ; i < n ; i++) Cp [i] = CS_FLIP (Cp [i]) ;/* fix assembly tree */ for (j = 0 ; j <= n ; j++) head [j] = -1 ; for (j = n ; j >= 0 ; j--) /* place unordered nodes in lists */ { if (nv [j] > 0) continue ; /* skip if j is an element */ next [j] = head [Cp [j]] ; /* place j in list of its parent */ head [Cp [j]] = j ; } for (e = n ; e >= 0 ; e--) /* place elements in lists */ { if (nv [e] <= 0) continue ; /* skip unless e is an element */ if (Cp [e] != -1) { next [e] = head [Cp [e]] ; /* place e in list of its parent */ head [Cp [e]] = e ; } } for (k = 0, i = 0 ; i <= n ; i++) /* postorder the assembly tree */ { if (Cp [i] == -1) k = cs_tdfs (i, k, head, next, P, w) ; } return (cs_idone (P, C, W, 1)) ; }
4017181fed8f1b06866720dbf1a6b197ca250a3d
9c8044df21f177ad57a6c5235b5187b8a9cca55f
/Estruturas de Dados/Exemplos/Filas/FilaPrioridadeEstatica.c
f138c23b8c21545a18faca5314349bf3f9cdef06
[]
no_license
AlexGalhardo/ICMC-USP
48f268fe60f917d5a24921c103c8a88c790634d7
f43efb6afea7d92b6aaa0b48516fb89705b46f24
refs/heads/master
2018-10-08T15:45:22.434741
2018-10-02T17:49:25
2018-10-02T17:49:25
162,185,299
168
51
null
null
null
null
UTF-8
C
false
false
2,898
c
FilaPrioridadeEstatica.c
#include <stdio.h> #include <stdlib.h> //Arquivo FilaPrioridade.h #define MAX 100 typedef struct fila_prioridade FilaPrio; FilaPrio* cria_FilaPrio(); void libera_FilaPrio(FilaPrio* fp); int consulta_FilaPrio(FilaPrio* fp, char* nome); int insere_FilaPrio(FilaPrio* fp, char *nome, int prioridade); int remove_FilaPrio(FilaPrio* fp); int tamanho_FilaPrio(FilaPrio* fp); int estaCheia_FilaPrio(FilaPrio* fp); int estaVazia_FilaPrio(FilaPrio* fp); void imprime_FilaPrio(FilaPrio* fp); struct paciente{ char nome[30]; int prio; }; struct fila_prioridade{ int qtd; struct paciente dados[MAX]; }; FilaPrio* cria_FilaPrio(){ FilaPrio *fp; fp = (FilaPrio*) malloc(sizeof(struct fila_prioridade)); if(fp != NULL) fp->qtd = 0; return fp; } void libera_FilaPrio(FilaPrio* fp){ free(fp); } int consulta_FilaPrio(FilaPrio* fp, char* nome){ if(fp == NULL || fp->qtd == 0) return 0; strcpy(nome,fp->dados[fp->qtd-1].nome); return 1; } int insere_FilaPrio(FilaPrio* fp, char *nome, int prioridade){ if(fp == NULL) return 0; if(fp->qtd == MAX)//fila cheia return 0; int i = fp->qtd-1; while(i >= 0 && fp->dados[i].prio >= prioridade){ fp->dados[i+1] = fp->dados[i]; i--; } strcpy(fp->dados[i+1].nome,nome); fp->dados[i+1].prio = prioridade; fp->qtd++; return 1; } int remove_FilaPrio(FilaPrio* fp){ if(fp == NULL) return 0; if(fp->qtd == 0) return 0; fp->qtd--; return 1; } int tamanho_FilaPrio(FilaPrio* fp){ if(fp == NULL) return -1; else return fp->qtd; } int estaCheia_FilaPrio(FilaPrio* fp){ if(fp == NULL) return -1; return (fp->qtd == MAX); } int estaVazia_FilaPrio(FilaPrio* fp){ if(fp == NULL) return -1; return (fp->qtd == 0); } void imprime_FilaPrio(FilaPrio* fp){ if(fp == NULL) return; int i; for(i=fp->qtd-1; i >=0 ; i--){ printf("Prio: %d \tNome: %s\n",fp->dados[i].prio,fp->dados[i].nome); } } int main(){ struct paciente itens[6] = {{"Andre",1}, {"Bianca",2}, {"Carlos",5}, {"Nilza",10}, {"Inacio",9}, {"Edu",2}}; FilaPrio* fp; fp = cria_FilaPrio(); int i; for (i=0; i< 6; i++){ printf("%d) %d %s\n",i,itens[i].prio, itens[i].nome); insere_FilaPrio(fp, itens[i].nome,itens[i].prio); } printf("=================================\n"); imprime_FilaPrio(fp); printf("=================================\n"); for (i=0; i< 6; i++){ remove_FilaPrio(fp); imprime_FilaPrio(fp); printf("=================================\n"); } libera_FilaPrio(fp); system("pause"); return 0; }
42218d8efe5daf057924fef3686b48948d169db4
50dd46b8ece33f3cdd174284b15d1d51f89669d4
/third_party/edk2/SecurityPkg/Tcg/PhysicalPresencePei/PhysicalPresencePei.c
5117c7441124d3716e5fa46dd29e8984edc6e2dd
[ "LicenseRef-scancode-generic-cla", "Apache-2.0", "BSD-2-Clause", "OpenSSL" ]
permissive
google/google-ctf
f99da1ee07729bbccb869fff1cbaed6a80e43bcc
df02323eaf945d15e124801c74abaadca2749dc7
refs/heads/master
2023-08-31T14:30:27.548081
2023-08-29T13:04:20
2023-08-29T13:04:20
131,317,137
4,136
607
Apache-2.0
2023-08-30T22:17:02
2018-04-27T15:56:03
Go
UTF-8
C
false
false
4,063
c
PhysicalPresencePei.c
/** @file This driver produces PEI_LOCK_PHYSICAL_PRESENCE_PPI to indicate whether TPM need be locked or not. It can be replaced by a platform specific driver. Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include <PiPei.h> #include <Ppi/LockPhysicalPresence.h> #include <Ppi/ReadOnlyVariable2.h> #include <Guid/PhysicalPresenceData.h> #include <Library/PcdLib.h> #include <Library/PeiServicesLib.h> /** This interface returns whether TPM physical presence needs be locked or not. @param[in] PeiServices The pointer to the PEI Services Table. @retval TRUE The TPM physical presence should be locked. @retval FALSE The TPM physical presence cannot be locked. **/ BOOLEAN EFIAPI LockTpmPhysicalPresence ( IN CONST EFI_PEI_SERVICES **PeiServices ); // // Gobal defintions for lock physical presence PPI and its descriptor. // PEI_LOCK_PHYSICAL_PRESENCE_PPI mLockPhysicalPresencePpi = { LockTpmPhysicalPresence }; EFI_PEI_PPI_DESCRIPTOR mLockPhysicalPresencePpiList = { EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, &gPeiLockPhysicalPresencePpiGuid, &mLockPhysicalPresencePpi }; /** This interface returns whether TPM physical presence needs be locked or not. @param[in] PeiServices The pointer to the PEI Services Table. @retval TRUE The TPM physical presence should be locked. @retval FALSE The TPM physical presence cannot be locked. **/ BOOLEAN EFIAPI LockTpmPhysicalPresence ( IN CONST EFI_PEI_SERVICES **PeiServices ) { EFI_STATUS Status; EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable; UINTN DataSize; EFI_PHYSICAL_PRESENCE TcgPpData; // // The CRTM has sensed the physical presence assertion of the user. For example, // the user has pressed the startup button or inserted a USB dongle. The details // of the implementation are vendor-specific. Here we read a PCD value to indicate // whether operator physical presence. // if (!PcdGetBool (PcdTpmPhysicalPresence)) { return TRUE; } // // Check the pending TPM requests. Lock TPM physical presence if there is no TPM // request. // Status = PeiServicesLocatePpi ( &gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **)&Variable ); if (!EFI_ERROR (Status)) { DataSize = sizeof (EFI_PHYSICAL_PRESENCE); Status = Variable->GetVariable ( Variable, PHYSICAL_PRESENCE_VARIABLE, &gEfiPhysicalPresenceGuid, NULL, &DataSize, &TcgPpData ); if (!EFI_ERROR (Status)) { if (TcgPpData.PPRequest != 0) { return FALSE; } } } // // Lock TPM physical presence by default. // return TRUE; } /** Entry point of this module. It installs lock physical presence PPI. @param[in] FileHandle Handle of the file being invoked. @param[in] PeiServices Describes the list of possible PEI Services. @return Status of install lock physical presence PPI. **/ EFI_STATUS EFIAPI PeimEntry ( IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices ) { return PeiServicesInstallPpi (&mLockPhysicalPresencePpiList); }
69e72162841c5ac0688659f4a3ec5bde5f9ec02d
e73547787354afd9b717ea57fe8dd0695d161821
/src/world/area_mac/mac_01/mac_01_3_entity.c
7e2cacfcd0f4db26bee337092505c0735601b4ea
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
571
c
mac_01_3_entity.c
#include "mac_01.h" #include "entity.h" EvtScript N(EVS_Inspect_StreetSign) = { EVT_CALL(DisablePlayerInput, TRUE) EVT_CALL(ShowMessageAtScreenPos, MSG_Menus_0170, 160, 40) EVT_CALL(DisablePlayerInput, FALSE) EVT_RETURN EVT_END }; EvtScript N(EVS_MakeEntities) = { EVT_IF_LT(GB_StoryProgress, STORY_EPILOGUE) EVT_CALL(MakeEntity, EVT_PTR(Entity_SavePoint), 280, 80, -130, 0, MAKE_ENTITY_END) EVT_END_IF EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Inspect_StreetSign)), TRIGGER_WALL_PRESS_A, COLLIDER_o406, 1, 0) EVT_RETURN EVT_END };
6bbf4e600c2d7fc46951c77d6ff7219099a65c6c
6f247f5400c6a840b6dfcb12388116dc3bb7bd49
/nvbios/bit.c
f883a8e3cf10a1a10fe32a8674d566899f871b9b
[ "MIT" ]
permissive
envytools/envytools
c062fbc3b8af90d3df9c6e0f57e9abbfc5690d01
e11d670a70ae0455261ead53cdd09c321974cc64
refs/heads/master
2023-08-26T23:44:47.131591
2022-04-30T21:15:56
2022-04-30T21:15:56
11,620,001
402
103
MIT
2022-12-07T01:35:18
2013-07-23T21:43:43
C
UTF-8
C
false
false
6,881
c
bit.c
/* * Copyright (C) 2012 Marcelina Kościelnicka <mwk@0x04.net> * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #include "bios.h" int envy_bios_parse_bit_empty (struct envy_bios *bios, struct envy_bios_bit_entry *bit) { if (bit->t_len) { ENVY_BIOS_ERR("BIT table '%c' not empty!\n", bit->type); return -EINVAL; } return 0; } static const struct { uint8_t type; uint8_t version; int (*parse) (struct envy_bios *bios, struct envy_bios_bit_entry *bit); } bit_types[] = { { '2', 1, envy_bios_parse_bit_2 }, /* i2c */ { 'A', 1, envy_bios_parse_bit_A }, /* Analog */ { 'B', 1, envy_bios_parse_bit_empty }, /* BIOSDATA v1 */ { 'B', 2, envy_bios_parse_bit_empty }, /* BIOSDATA v2 */ { 'C', 1, envy_bios_parse_bit_empty }, /* Clock v1 */ { 'C', 2, envy_bios_parse_bit_empty }, /* Clock v2 */ { 'c', 1, envy_bios_parse_bit_empty }, /* 32 Bit */ { 'D', 1, envy_bios_parse_bit_D }, /* DFP/Panel Data */ { 'd', 1, envy_bios_parse_bit_d }, /* DP */ { 'I', 1, envy_bios_parse_bit_empty }, /* NVINIT */ { 'i', 2, envy_bios_parse_bit_i }, /* Info */ { 'L', 1, envy_bios_parse_bit_L }, /* LVDS */ { 'M', 1, envy_bios_parse_bit_M }, /* Mem v1 */ { 'M', 2, envy_bios_parse_bit_M }, /* Mem v2 */ { 'N', 0, envy_bios_parse_bit_empty }, /* NOP */ { 'P', 1, envy_bios_parse_bit_P }, /* Power v1 */ { 'P', 2, envy_bios_parse_bit_P }, /* Power v2 */ { 'p', 1, envy_bios_parse_bit_p }, /* PMU */ { 'p', 2, envy_bios_parse_bit_p }, /* Falcon */ { 'R', 1, envy_bios_parse_bit_empty }, /* Bridge Firmware */ { 'S', 1, envy_bios_parse_bit_empty }, /* String v1 */ { 'S', 2, envy_bios_parse_bit_empty }, /* String v2 */ { 'T', 1, envy_bios_parse_bit_T }, /* TMDS */ { 'U', 1, envy_bios_parse_bit_empty }, /* Display control / programming */ { 'u', 1, envy_bios_parse_bit_empty }, /* UEFI */ { 'V', 1, envy_bios_parse_bit_empty }, /* Virtual Strap */ { 'x', 1, envy_bios_parse_bit_empty }, /* MXM */ { 0 }, }; int envy_bios_parse_bit (struct envy_bios *bios) { struct envy_bios_bit *bit = &bios->bit; if (!bit->offset) return 0; int err = 0; err |= bios_u16(bios, bit->offset+6, &bit->version); err |= bios_u8(bios, bit->offset+8, &bit->hlen); err |= bios_u8(bios, bit->offset+9, &bit->rlen); err |= bios_u8(bios, bit->offset+10, &bit->entriesnum); if (err) return -EFAULT; envy_bios_block(bios, bit->offset, bit->hlen + bit->rlen * bit->entriesnum, "BIT", -1); uint8_t checksum = 0; int i; for (i = 0; i < bit->hlen; i++) { uint8_t byte; err |= bios_u8(bios, bit->offset+i, &byte); if (err) return -EFAULT; checksum += byte; } if (checksum) { ENVY_BIOS_ERR("BIT table checksum mismatch\n"); return -EINVAL; } int wanthlen = 12; int wantrlen = 6; switch (bit->version) { case 0x0100: break; default: ENVY_BIOS_ERR("Unknown BIT table version %d.%d\n", bit->version >> 8, bit->version & 0xff); return -EINVAL; } if (bit->hlen < wanthlen) { ENVY_BIOS_ERR("BIT table header too short [%d < %d]\n", bit->hlen, wanthlen); return -EINVAL; } if (bit->rlen < wantrlen) { ENVY_BIOS_ERR("BIT table record too short [%d < %d]\n", bit->rlen, wantrlen); return -EINVAL; } if (bit->hlen > wanthlen) { ENVY_BIOS_WARN("BIT table header longer than expected [%d > %d]\n", bit->hlen, wanthlen); } if (bit->rlen > wantrlen) { ENVY_BIOS_WARN("BIT table record longer than expected [%d > %d]\n", bit->rlen, wantrlen); } bit->entries = calloc(bit->entriesnum, sizeof *bit->entries); if (!bit->entries) return -ENOMEM; for (i = 0; i < bit->entriesnum; i++) { struct envy_bios_bit_entry *entry = &bit->entries[i]; entry->offset = bit->offset + bit->hlen + bit->rlen * i; err |= bios_u8(bios, entry->offset+0, &entry->type); err |= bios_u8(bios, entry->offset+1, &entry->version); err |= bios_u16(bios, entry->offset+2, &entry->t_len); err |= bios_u16(bios, entry->offset+4, &entry->t_offset); if (err) return -EFAULT; entry->is_unk = 1; if (entry->type != 'b' && entry->t_len) envy_bios_block(bios, entry->t_offset, entry->t_len, "BIT", entry->type); } int j; /* iterate over BIT tables by type first - some types of tables have to be parsed before others, notably 'i'. */ for (j = 0; bit_types[j].parse; j++) { for (i = 0; i < bit->entriesnum; i++) { struct envy_bios_bit_entry *entry = &bit->entries[i]; if (entry->type == bit_types[j].type && entry->version == bit_types[j].version) { if (bit_types[j].parse(bios, entry)) ENVY_BIOS_ERR("Failed to parse BIT table '%c' at 0x%04x version %d\n", entry->type, entry->t_offset, entry->version); else entry->is_unk = 0; } } } bit->valid = 1; return 0; } void envy_bios_print_bit (struct envy_bios *bios, FILE *out, unsigned mask) { struct envy_bios_bit *bit = &bios->bit; if (!bit->offset || !(mask & ENVY_BIOS_PRINT_BMP_BIT)) return; if (!bit->valid) { fprintf(out, "Failed to parse BIT table at 0x%04x version %d.%d\n\n", bit->offset, bit->version >> 8, bit->version & 0xff); return; } fprintf(out, "BIT table at 0x%04x version %d.%d", bit->offset, bit->version >> 8, bit->version & 0xff); fprintf(out, "\n"); envy_bios_dump_hex(bios, out, bit->offset, bit->hlen, mask); int i; for (i = 0; i < bit->entriesnum; i++) { struct envy_bios_bit_entry *entry = &bit->entries[i]; fprintf (out, "BIT table '%c' version %d at 0x%04x length 0x%04x\n", entry->type, entry->version, entry->t_offset, entry->t_len); envy_bios_dump_hex(bios, out, entry->offset, bit->rlen, mask); } fprintf(out, "\n"); for (i = 0; i < bit->entriesnum; i++) { struct envy_bios_bit_entry *entry = &bit->entries[i]; if (entry->is_unk) { fprintf (out, "Unknown BIT table '%c' version %d\n", entry->type, entry->version); envy_bios_dump_hex(bios, out, entry->t_offset, entry->t_len, mask); fprintf(out, "\n"); } } }
98da2a86bcdb5d58c7d692af9a9e2b47fa8a653b
fbe68d84e97262d6d26dd65c704a7b50af2b3943
/third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Include/IndustryStandard/Tpm2Acpi.h
ac3bb1f55e15f8a5c569a172c9d9ae4d2c20aae9
[ "GPL-2.0-only", "LicenseRef-scancode-unknown-license-reference", "CDDL-1.0", "LicenseRef-scancode-warranty-disclaimer", "GPL-1.0-or-later", "LGPL-2.1-or-later", "GPL-2.0-or-later", "MPL-1.0", "LicenseRef-scancode-generic-exception", "Apache-2.0", "OpenSSL", "MIT", "BSD-2-Clause" ]
permissive
thalium/icebox
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
6f78952d58da52ea4f0e55b2ab297f28e80c1160
refs/heads/master
2022-08-14T00:19:36.984579
2022-02-22T13:10:31
2022-02-22T13:10:31
190,019,914
585
109
MIT
2022-01-13T20:58:15
2019-06-03T14:18:12
C++
UTF-8
C
false
false
1,552
h
Tpm2Acpi.h
/** @file TPM2 ACPI table definition. Copyright (c) 2013, Intel Corporation. All rights reserved. <BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #ifndef _TPM2_ACPI_H_ #define _TPM2_ACPI_H_ #include <IndustryStandard/Acpi.h> #pragma pack (1) #define EFI_TPM2_ACPI_TABLE_REVISION 3 typedef struct { EFI_ACPI_DESCRIPTION_HEADER Header; UINT32 Flags; UINT64 AddressOfControlArea; UINT32 StartMethod; //UINT8 PlatformSpecificParameters[]; } EFI_TPM2_ACPI_TABLE; #define EFI_TPM2_ACPI_TABLE_START_METHOD_ACPI 2 #define EFI_TPM2_ACPI_TABLE_START_METHOD_TIS 6 #define EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE 7 #define EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_ACPI 8 typedef struct { UINT32 Reserved; UINT32 Error; UINT32 Cancel; UINT32 Start; UINT64 InterruptControl; UINT32 CommandSize; UINT64 Command; UINT32 ResponseSize; UINT64 Response; } EFI_TPM2_ACPI_CONTROL_AREA; #pragma pack () #endif
0f81fbeb6e4f50620617303447f44a0fcbd9336b
c9bc99866cfab223c777cfb741083be3e9439d81
/product/synquacer/module/synquacer_system/include/internal/synquacer_ppu_driver.h
85033a0fddc483dc240aebb62f3064d9bc381111
[ "BSD-3-Clause" ]
permissive
ARM-software/SCP-firmware
4738ca86ce42d82588ddafc2226a1f353ff2c797
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
refs/heads/master
2023-09-01T16:13:36.962036
2023-08-17T13:00:20
2023-08-31T07:43:37
134,399,880
211
165
NOASSERTION
2023-09-13T14:27:10
2018-05-22T10:35:56
C
UTF-8
C
false
false
907
h
synquacer_ppu_driver.h
/* * Arm SCP/MCP Software * Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef INTERNAL_SYNQUACER_PPU_DRIVER_H #define INTERNAL_SYNQUACER_PPU_DRIVER_H #include <internal/reg_PPU.h> #include <stdint.h> #define PPU_INT_PPU0 20 #define PPU_INT_PPU1 21 #define PPU_INT_PPU2 22 #define PPU_INT_PPU3 23 #define PPU_INT_PPU4 24 #define PPU_INT_PPU5 25 #define PPU_INT_PPU6 26 #define PPU_INT_PPU7 27 #define PPU_INT_PPU8 28 #define PPU_PP_OFF 0x01 #define PPU_PP_MEM_RET 0x02 #define PPU_PP_ON 0x10 #define PPU_STATUS_MASK 0x1F #define PPU_Error 1 #define PPU_NoError 0 uint32_t get_domain_base_address(int domain); int change_power_state( int domain, int next_power_policy, int hwcactiveen, int hwcsysreqen, int reten); int read_power_status(int domain); #endif /* INTERNAL_SYNQUACER_PPU_DRIVER_H */
8b8593d0b961208c721fd07ed6af53340734e027
b1c0a1117a62d5f049e189e041aa19a914be6dbd
/extra/huge.c
e352db51c83d71898d8ca7766dc6932dbbf9c74d
[ "LicenseRef-scancode-public-domain" ]
permissive
lemire/Code-used-on-Daniel-Lemire-s-blog
847451d3acbeb28a6a6d50c6686eb537a6fdff41
c13fe68cdec26d45f688b5c58245fb428dc2ddb9
refs/heads/master
2023-08-31T09:55:12.275811
2023-08-31T00:33:59
2023-08-31T00:33:59
3,945,414
729
194
null
2023-09-04T07:50:21
2012-04-06T00:13:02
C
UTF-8
C
false
false
5,511
c
huge.c
// gcc/icc/clang -O2 -Wall -std=gnu99 huge.c -o huge #include <assert.h> #include <stdio.h> #include <inttypes.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <malloc.h> #ifdef __i386__ # define RDTSC_DIRTY "%eax", "%ebx", "%ecx", "%edx" #elif __x86_64__ # define RDTSC_DIRTY "%rax", "%rbx", "%rcx", "%rdx" #else # error unknown platform #endif #define RDTSC_START(cycles) \ do { \ register unsigned cyc_high, cyc_low; \ __asm volatile("CPUID\n\t" \ "RDTSC\n\t" \ "mov %%edx, %0\n\t" \ "mov %%eax, %1\n\t" \ : "=r" (cyc_high), "=r" (cyc_low) \ :: RDTSC_DIRTY); \ (cycles) = ((uint64_t)cyc_high << 32) | cyc_low; \ } while (0) #define RDTSC_STOP(cycles) \ do { \ register unsigned cyc_high, cyc_low; \ __asm volatile("RDTSCP\n\t" \ "mov %%edx, %0\n\t" \ "mov %%eax, %1\n\t" \ "CPUID\n\t" \ : "=r" (cyc_high), "=r" (cyc_low) \ :: RDTSC_DIRTY); \ (cycles) = ((uint64_t)cyc_high << 32) | cyc_low; \ } while(0) #define NORM_PAGE_SIZE (4096) // 4 KB normal pages #define NORM_PAGE_TLB1_ENTRIES 64 #define NORM_PAGE_TLB2_ENTRIES 512 #define HUGE_PAGE_SIZE (4096 * 512) // 2 MB huge pages #define HUGE_PAGE_TLB1_ENTRIES 32 #define HUGE_PAGE_TLB2_ENTRIES 0 // FUTURE: consider using to avoid TLB collisions #define LARGE_ODD_PAGE_SIZE (HUGE_PAGE_SIZE - NORM_PAGE_SIZE) #define ALLOC_SIZE (NORM_PAGE_TLB2_ENTRIES * HUGE_PAGE_SIZE) #define REPEAT_COUNT 10000000 char random_access(char *desc, char *buf, int gap, int num, int off) { assert(gap * num + off <= ALLOC_SIZE); volatile char dummy = 0; uint64_t tsc_before, tsc_after; RDTSC_START(tsc_before); for (int r = 0; r < REPEAT_COUNT; r++) { int n = rand() % num; int o = rand() % off; dummy = (char) (n * gap + o); } RDTSC_STOP(tsc_after); int avg_baseline_cycles = (tsc_after - tsc_before) / REPEAT_COUNT; RDTSC_START(tsc_before); for (int r = 0; r < REPEAT_COUNT; r++) { int n = rand() % num; int o = rand() % off; dummy |= buf[n * gap + o]; } RDTSC_STOP(tsc_after); int avg_access_cycles = (tsc_after - tsc_before) / REPEAT_COUNT; printf("%s: gap[%d] num[%d] off[%d] %9d cycles\n", desc, gap, num, off, avg_access_cycles - avg_baseline_cycles); return dummy; } int main(int c, char **argv) { // norm uses 4KB standard pages char *norm = mmap(NULL, ALLOC_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE| MAP_ANONYMOUS, -1, 0); // huge uses 2MB huge pages char *huge = mmap(NULL, ALLOC_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE| MAP_ANONYMOUS, -1, 0); madvise(huge, ALLOC_SIZE, MADV_HUGEPAGE); // initialize arrays to something memset(norm, 'n', ALLOC_SIZE); memset(huge, 'h', ALLOC_SIZE); printf("\nRandom with 2MB (should fit in L3):\n"); random_access("norm", norm, NORM_PAGE_SIZE, 512, NORM_PAGE_SIZE); random_access("huge", huge, NORM_PAGE_SIZE, 512, NORM_PAGE_SIZE); printf("\nRandom from 8MB (should fit in L3):\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 4, HUGE_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 4, HUGE_PAGE_SIZE); printf("\nRandom from 64MB (mostly main memory)\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 32, HUGE_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 32, HUGE_PAGE_SIZE); printf("\nRandom from 128MB (mostly main memory)\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 64, HUGE_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 64, HUGE_PAGE_SIZE); printf("\nRandom from 256MB (mostly main memory)\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 128, HUGE_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 128, HUGE_PAGE_SIZE); printf("\nRandom from 512MB (mostly main memory)\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 256, HUGE_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 256, HUGE_PAGE_SIZE); printf("\n64MB but only from first 4K of each 2MB\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 32, NORM_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 32, NORM_PAGE_SIZE); printf("\n128MB but only from first 4K of each 2MB\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 64, NORM_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 64, NORM_PAGE_SIZE); printf("\n256MB but only from first 4K of each 2MB\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 128, NORM_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 128, NORM_PAGE_SIZE); printf("\n512MB but only from first 4K of each 2MB\n"); random_access("norm", norm, HUGE_PAGE_SIZE, 256, NORM_PAGE_SIZE); random_access("huge", huge, HUGE_PAGE_SIZE, 256, NORM_PAGE_SIZE); return 0; }
75b0f055009478767d59e421e76870fb9dcf92d4
131b6d5381fc3bb4403682135b77f9bce91e79f1
/nx/include/switch/services/btdrv_types.h
a5fb58032f00ce2a0e0187123e2a402e2bbe9a8a
[ "ISC" ]
permissive
switchbrew/libnx
53deb695b9ee6f3981c559125e8fce3bce6852b7
4fcdb6eb34b20f1f65eb9791fe513a710a001bea
refs/heads/master
2023-08-28T17:00:22.025929
2023-08-11T04:11:38
2023-08-12T14:51:58
103,794,142
1,286
299
ISC
2023-09-09T12:08:36
2017-09-17T01:12:38
C
UTF-8
C
false
false
16,363
h
btdrv_types.h
/** * @file btdrv_types.h * @brief Bluetooth driver (btdrv) service types (see btdrv.h for the rest). * @author yellows8, ndeadly * @copyright libnx Authors */ #pragma once #include "../types.h" /// BluetoothPropertyType [1.0.0-11.0.1] typedef enum { BtdrvBluetoothPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator. BtdrvBluetoothPropertyType_Address = 2, ///< \ref BtdrvAddress BtdrvBluetoothPropertyType_Unknown3 = 3, ///< Only available with \ref btdrvSetAdapterProperty. Unknown, \ref BtdrvAddress. BtdrvBluetoothPropertyType_ClassOfDevice = 5, ///< 3-bytes, Class of Device. BtdrvBluetoothPropertyType_FeatureSet = 6, ///< 1-byte, FeatureSet. The default is value 0x68. } BtdrvBluetoothPropertyType; /// AdapterPropertyType [12.0.0+] typedef enum { BtdrvAdapterPropertyType_Address = 0, ///< \ref BtdrvAddress BtdrvAdapterPropertyType_Name = 1, ///< Name. String, max length 0xF8 excluding NUL-terminator. BtdrvAdapterPropertyType_ClassOfDevice = 2, ///< 3-bytes, Class of Device. BtdrvAdapterPropertyType_Unknown3 = 3, ///< Only available with \ref btdrvSetAdapterProperty. Unknown, \ref BtdrvAddress. } BtdrvAdapterPropertyType; /// EventType typedef enum { ///< BtdrvEventType_* should be used on [12.0.0+] BtdrvEventType_InquiryDevice = 0, ///< Device found during Inquiry. BtdrvEventType_InquiryStatus = 1, ///< Inquiry status changed. BtdrvEventType_PairingPinCodeRequest = 2, ///< Pairing PIN code request. BtdrvEventType_SspRequest = 3, ///< SSP confirm request / SSP passkey notification. BtdrvEventType_Connection = 4, ///< Connection BtdrvEventType_Tsi = 5, ///< SetTsi (\ref btdrvSetTsi) BtdrvEventType_BurstMode = 6, ///< SetBurstMode (\ref btdrvEnableBurstMode) BtdrvEventType_SetZeroRetransmission = 7, ///< \ref btdrvSetZeroRetransmission BtdrvEventType_PendingConnections = 8, ///< \ref btdrvGetPendingConnections BtdrvEventType_MoveToSecondaryPiconet = 9, ///< \ref btdrvMoveToSecondaryPiconet BtdrvEventType_BluetoothCrash = 10, ///< BluetoothCrash ///< BtdrvEventTypeOld_* should be used on [1.0.0-11.0.1] BtdrvEventTypeOld_Unknown0 = 0, ///< Unused BtdrvEventTypeOld_InquiryDevice = 3, ///< Device found during Inquiry. BtdrvEventTypeOld_InquiryStatus = 4, ///< Inquiry status changed. BtdrvEventTypeOld_PairingPinCodeRequest = 5, ///< Pairing PIN code request. BtdrvEventTypeOld_SspRequest = 6, ///< SSP confirm request / SSP passkey notification. BtdrvEventTypeOld_Connection = 7, ///< Connection BtdrvEventTypeOld_BluetoothCrash = 13, ///< BluetoothCrash } BtdrvEventType; /// BtdrvInquiryStatus typedef enum { BtdrvInquiryStatus_Stopped = 0, ///< Inquiry stopped. BtdrvInquiryStatus_Started = 1, ///< Inquiry started. } BtdrvInquiryStatus; /// ConnectionEventType typedef enum { BtdrvConnectionEventType_Status = 0, ///< BtdrvEventInfo::connection::status BtdrvConnectionEventType_SspConfirmRequest = 1, ///< SSP confirm request. BtdrvConnectionEventType_Suspended = 2, ///< ACL Link is now Suspended. } BtdrvConnectionEventType; /// ExtEventType [1.0.0-11.0.1] typedef enum { BtdrvExtEventType_SetTsi = 0, ///< SetTsi (\ref btdrvSetTsi) BtdrvExtEventType_ExitTsi = 1, ///< ExitTsi (\ref btdrvSetTsi) BtdrvExtEventType_SetBurstMode = 2, ///< SetBurstMode (\ref btdrvEnableBurstMode) BtdrvExtEventType_ExitBurstMode = 3, ///< ExitBurstMode (\ref btdrvEnableBurstMode) BtdrvExtEventType_SetZeroRetransmission = 4, ///< \ref btdrvSetZeroRetransmission BtdrvExtEventType_PendingConnections = 5, ///< \ref btdrvGetPendingConnections BtdrvExtEventType_MoveToSecondaryPiconet = 6, ///< \ref btdrvMoveToSecondaryPiconet } BtdrvExtEventType; /// BluetoothHhReportType /// Bit0-1 directly control the HID bluetooth transaction report-type value. /// Bit2-3: these directly control the Parameter Reserved field for SetReport, for GetReport these control the Parameter Reserved and Size bits. typedef enum { BtdrvBluetoothHhReportType_Other = 0, ///< Other BtdrvBluetoothHhReportType_Input = 1, ///< Input BtdrvBluetoothHhReportType_Output = 2, ///< Output BtdrvBluetoothHhReportType_Feature = 3, ///< Feature } BtdrvBluetoothHhReportType; /// HidEventType typedef enum { ///< BtdrvHidEventType_* should be used on [12.0.0+] BtdrvHidEventType_Connection = 0, ///< Connection. Only used with \ref btdrvGetHidEventInfo. BtdrvHidEventType_Data = 1, ///< DATA report on the Interrupt channel. BtdrvHidEventType_SetReport = 2, ///< Response to SET_REPORT. BtdrvHidEventType_GetReport = 3, ///< Response to GET_REPORT. ///< BtdrvHidEventTypeOld_* should be used on [1.0.0-11.0.1] BtdrvHidEventTypeOld_Connection = 0, ///< Connection. Only used with \ref btdrvGetHidEventInfo. BtdrvHidEventTypeOld_Data = 4, ///< DATA report on the Interrupt channel. BtdrvHidEventTypeOld_Ext = 7, ///< Response for extensions. Only used with \ref btdrvGetHidEventInfo. BtdrvHidEventTypeOld_SetReport = 8, ///< Response to SET_REPORT. BtdrvHidEventTypeOld_GetReport = 9, ///< Response to GET_REPORT. } BtdrvHidEventType; /// HidConnectionStatus [12.0.0+] typedef enum { ///< BtdrvHidConnectionStatus_* should be used on [12.0.0+] BtdrvHidConnectionStatus_Closed = 0, BtdrvHidConnectionStatus_Opened = 1, BtdrvHidConnectionStatus_Failed = 2, ///< BtdrvHidConnectionStatusOld_* should be used on [1.0.0-11.0.1] BtdrvHidConnectionStatusOld_Opened = 0, BtdrvHidConnectionStatusOld_Closed = 2, BtdrvHidConnectionStatusOld_Failed = 8, } BtdrvHidConnectionStatus; /// This determines the u16 data to write into a CircularBuffer. typedef enum { BtdrvFatalReason_Invalid = 0, ///< Only for \ref BtdrvEventInfo: invalid. BtdrvFatalReason_Unknown1 = 1, ///< Can only be triggered by \ref btdrvEmulateBluetoothCrash, not triggered by the sysmodule otherwise. BtdrvFatalReason_CommandTimeout = 2, ///< HCI command timeout. BtdrvFatalReason_HardwareError = 3, ///< HCI event HCI_Hardware_Error occurred. BtdrvFatalReason_Enable = 7, ///< Only for \ref BtdrvEventInfo: triggered after enabling bluetooth, depending on the value of a global state field. BtdrvFatalReason_Audio = 9, ///< [12.0.0+] Only for \ref BtdrvEventInfo: triggered by Audio cmds in some cases. } BtdrvFatalReason; /// BleEventType typedef enum { BtdrvBleEventType_Unknown0 = 0, ///< Unknown. BtdrvBleEventType_Unknown1 = 1, ///< Unknown. BtdrvBleEventType_Unknown2 = 2, ///< Unknown. BtdrvBleEventType_Unknown3 = 3, ///< Unknown. BtdrvBleEventType_Unknown4 = 4, ///< Unknown. BtdrvBleEventType_Unknown5 = 5, ///< Unknown. BtdrvBleEventType_Unknown6 = 6, ///< Unknown. BtdrvBleEventType_Unknown7 = 7, ///< Unknown. BtdrvBleEventType_Unknown8 = 8, ///< Unknown. BtdrvBleEventType_Unknown9 = 9, ///< Unknown. BtdrvBleEventType_Unknown10 = 10, ///< Unknown. BtdrvBleEventType_Unknown11 = 11, ///< Unknown. BtdrvBleEventType_Unknown12 = 12, ///< Unknown. BtdrvBleEventType_Unknown13 = 13, ///< Unknown. } BtdrvBleEventType; /// AudioEventType typedef enum { BtdrvAudioEventType_None = 0, ///< None BtdrvAudioEventType_Connection = 1, ///< Connection } BtdrvAudioEventType; /// AudioOutState typedef enum { BtdrvAudioOutState_Stopped = 0, ///< Stopped BtdrvAudioOutState_Started = 1, ///< Started } BtdrvAudioOutState; /// AudioCodec typedef enum { BtdrvAudioCodec_Pcm = 0, ///< Raw PCM } BtdrvAudioCodec; /// Address typedef struct { u8 address[0x6]; ///< Address } BtdrvAddress; /// ClassOfDevice typedef struct { u8 class_of_device[0x3]; ///< ClassOfDevice } BtdrvClassOfDevice; /// AdapterProperty [1.0.0-11.0.1] typedef struct { BtdrvAddress addr; ///< Same as the data for ::BtdrvBluetoothPropertyType_Address. BtdrvClassOfDevice class_of_device; ///< Same as the data for ::BtdrvBluetoothPropertyType_ClassOfDevice. char name[0xF9]; ///< Same as the data for ::BtdrvBluetoothPropertyType_Name (last byte is not initialized). u8 feature_set; ///< Set to hard-coded value 0x68 (same as the data for ::BtdrvBluetoothPropertyType_FeatureSet). } BtdrvAdapterPropertyOld; /// AdapterProperty [12.0.0+] typedef struct { u8 type; ///< \ref BtdrvAdapterPropertyType u8 size; ///< Data size. u8 data[0x100]; ///< Data (above size), as specified by the type. } BtdrvAdapterProperty; /// AdapterPropertySet [12.0.0+] typedef struct { BtdrvAddress addr; ///< Same as the data for ::BtdrvBluetoothPropertyType_Address. BtdrvClassOfDevice class_of_device; ///< Same as the data for ::BtdrvBluetoothPropertyType_ClassOfDevice. char name[0xF9]; ///< Same as the data for ::BtdrvBluetoothPropertyType_Name. } BtdrvAdapterPropertySet; /// BluetoothPinCode [1.0.0-11.0.1] typedef struct { char code[0x10]; ///< PinCode } BtdrvBluetoothPinCode; /// BtdrvPinCode [12.0.0+] typedef struct { char code[0x10]; ///< PinCode u8 length; ///< Length } BtdrvPinCode; /// HidData [1.0.0-8.1.1] typedef struct { u16 size; ///< Size of data. u8 data[0x280]; ///< Data } BtdrvHidData; /// HidReport [9.0.0+]. typedef struct { u16 size; ///< Size of data. u8 data[0x2BC]; ///< Data } BtdrvHidReport; /// PlrStatistics typedef struct { u8 unk_x0[0x84]; ///< Unknown } BtdrvPlrStatistics; /// PlrList typedef struct { u8 unk_x0[0xA4]; ///< Unknown } BtdrvPlrList; /// ChannelMapList typedef struct { u8 unk_x0[0x88]; ///< Unknown } BtdrvChannelMapList; /// LeConnectionParams typedef struct { u8 unk_x0[0x14]; ///< Unknown } BtdrvLeConnectionParams; /// BleConnectionParameter typedef struct { u8 unk_x0[0xC]; ///< Unknown } BtdrvBleConnectionParameter; /// BtdrvBleAdvertisePacketDataEntry typedef struct { u16 unk_x0; ///< Unknown u8 unused[0x12]; ///< Unused } BtdrvBleAdvertisePacketDataEntry; /// BleAdvertisePacketData typedef struct { u32 unk_x0; ///< Unknown u8 unk_x4; ///< Unknown u8 size0; ///< Size of the data at unk_x6. u8 unk_x6[0x1F]; ///< Unknown, see size0. u8 pad[3]; ///< Padding u8 count; ///< Total array entries, see entries. u8 pad2[7]; ///< Padding BtdrvBleAdvertisePacketDataEntry entries[0x5]; ///< \ref BtdrvBleAdvertisePacketDataEntry u8 pad3[0x10]; ///< Padding u8 size2; ///< Size of the data at unk_xA8. u8 unk_xA5; ///< Unknown u8 pad4[2]; ///< Padding u8 unk_xA8[0x1F]; ///< Unknown, see size2. u8 unk_xC7; ///< Unknown u8 unk_xC8; ///< Unknown u8 pad5[3]; ///< Padding } BtdrvBleAdvertisePacketData; typedef struct { u8 length; u8 type; u8 value[0x1d]; } BtdrvBleAdvertisementData; /// BleAdvertiseFilter typedef struct { u8 unk_x0[0x3E]; ///< Unknown } BtdrvBleAdvertiseFilter; /// BleAdvertisePacketParameter typedef struct { u8 data[0x8]; ///< Unknown } BtdrvBleAdvertisePacketParameter; /// BleScanResult typedef struct { u8 unk_x0; ///< Unknown BtdrvAddress addr; ///< \ref BtdrvAddress u8 unk_x7[0x139]; ///< Unknown s32 unk_x140; ///< Unknown s32 unk_x144; ///< Unknown } BtdrvBleScanResult; /// BleConnectionInfo typedef struct { u32 connection_handle; ///< ConnectionHandle, 0xFFFFFFFF ([5.0.0-5.0.2] 0xFFFF) is invalid. BtdrvAddress addr; ///< \ref BtdrvAddress u8 pad[2]; ///< Padding } BtdrvBleConnectionInfo; /// GattAttributeUuid typedef struct { u32 size; ///< UUID size, must be 0x2, 0x4, or 0x10. u8 uuid[0x10]; ///< UUID with the above size. } BtdrvGattAttributeUuid; /// GattId typedef struct { u8 instance_id; ///< InstanceId u8 pad[3]; ///< Padding BtdrvGattAttributeUuid uuid; ///< \ref BtdrvGattAttributeUuid } BtdrvGattId; /// LeEventInfo typedef struct { u32 unk_x0; ///< Unknown u32 unk_x4; ///< Unknown u8 unk_x8; ///< Unknown u8 pad[3]; ///< Padding BtdrvGattAttributeUuid uuid0; ///< \ref BtdrvGattAttributeUuid BtdrvGattAttributeUuid uuid1; ///< \ref BtdrvGattAttributeUuid BtdrvGattAttributeUuid uuid2; ///< \ref BtdrvGattAttributeUuid u16 size; ///< Size of the below data. u8 data[0x3B6]; ///< Data. } BtdrvLeEventInfo; /// BleClientGattOperationInfo typedef struct { u8 unk_x0; ///< Converted from BtdrvLeEventInfo::unk_x0. u8 pad[3]; ///< Padding u32 unk_x4; ///< BtdrvLeEventInfo::unk_x4 u8 unk_x8; ///< BtdrvLeEventInfo::unk_x8 u8 pad2[3]; ///< Padding BtdrvGattAttributeUuid uuid0; ///< BtdrvLeEventInfo::uuid0 BtdrvGattAttributeUuid uuid1; ///< BtdrvLeEventInfo::uuid1 BtdrvGattAttributeUuid uuid2; ///< BtdrvLeEventInfo::uuid2 u64 size; ///< BtdrvLeEventInfo::size u8 data[0x200]; ///< BtdrvLeEventInfo::data } BtdrvBleClientGattOperationInfo; /// PcmParameter typedef struct { u32 unk_x0; ///< Must be 0-3. Controls number of channels: 0 = mono, non-zero = stereo. s32 sample_rate; ///< Sample rate. Must be one of the following: 16000, 32000, 44100, 48000. u32 bits_per_sample; ///< Bits per sample. Must be 8 or 16. } BtdrvPcmParameter; /// AudioControlButtonState typedef struct { u8 unk_x0[0x10]; ///< Unknown } BtdrvAudioControlButtonState;
04f3871cd2f3e7853a37ce799fde1b7d96afcbfc
d3c83ae2d5a23fadcde502bd9fc9682f054d68c1
/external/hash/ht_hash_function.h
1f65ee563e4a601c2692a63be6dd31099058e7ce
[ "BSD-3-Clause", "Apache-2.0", "MIT", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
dvidelabs/flatcc
44cf9b46341fd49259f8f64ce6cfc7b95fe9da83
eb5228f76d395bffe31a33398ff73e60dfba5914
refs/heads/master
2023-08-25T04:26:36.611078
2023-08-15T15:17:59
2023-08-15T15:17:59
45,867,575
643
204
Apache-2.0
2023-05-30T06:15:06
2015-11-09T21:21:58
C
UTF-8
C
false
false
6,973
h
ht_hash_function.h
#ifndef HT_HASH_FUNCTION_H #define HT_HASH_FUNCTION_H #include <stddef.h> #ifdef _MSC_VER /* `inline` only advisory anyway. */ #pragma warning(disable: 4710) /* function not inlined */ #endif /* Avoid 0 special case in hash functions and allow for configuration with unguessable seed. */ #ifndef HT_HASH_SEED #define HT_HASH_SEED UINT32_C(0x2f693b52) #endif #ifndef HT_HASH_32 #include "cmetrohash.h" static inline size_t ht_default_hash_function(const void *key, size_t len) { uint64_t out; cmetrohash64_1((const uint8_t *)key, len, HT_HASH_SEED, (uint8_t *)&out); return (unsigned int)out; } /* When using the pointer directly as a hash key. */ static inline size_t ht_ptr_hash_function(const void *key, size_t len) { /* MurmurHash3 64-bit finalizer */ uint64_t x; (void)len; x = ((uint64_t)(size_t)key) ^ (HT_HASH_SEED); x ^= x >> 33; x *= 0xff51afd7ed558ccdULL; x ^= x >> 33; x *= 0xc4ceb9fe1a85ec53ULL; x ^= x >> 33; return (size_t)x; } #else #include "PMurHash.h" static inline size_t ht_default_hash_function(const void *key, size_t len) { return (size_t)PMurHash32((HT_HASH_SEED), key, (int)len); } /* When using the pointer directly as a hash key. */ static inline size_t ht_ptr_hash_function(const void *key, size_t len) { /* http://stackoverflow.com/a/12996028 */ size_t x; x = (size_t)key ^ (HT_HASH_SEED); x = ((x >> 16) ^ x) * 0x45d9f3bUL; x = ((x >> 16) ^ x) * 0x45d9f3bUL; x = ((x >> 16) ^ x); return x; } #endif /* HT_HASH_32 */ /* This assumes the key points to a 32-bit aligned random value that is its own hash function. */ static inline size_t ht_uint32_identity_hash_function(const void *key, size_t len) { (void)len; return (size_t)*(uint32_t *)key; } /* This assumes the key points to a 64-bit aligned random value that is its own hash function. */ static inline size_t ht_uint64_identity_hash_function(const void *key, size_t len) { (void)len; return (size_t)*(uint64_t *)key; } /* This assumes the key points to a 32-bit aligned value. */ static inline size_t ht_uint32_hash_function(const void *key, size_t len) { uint32_t x = *(uint32_t *)key + (uint32_t)(HT_HASH_SEED); (void)len; /* http://stackoverflow.com/a/12996028 */ x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b); x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b); x = ((x >> 16) ^ x); return x; } /* This assumes the key points to a 64-bit aligned value. */ static inline size_t ht_uint64_hash_function(const void *key, size_t len) { uint64_t x = *(uint64_t *)key + UINT64_C(0x9e3779b97f4a7c15) + (uint64_t)(HT_HASH_SEED); (void)len; x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb); return (size_t)(x ^ (x >> 31)); } /* * Suited for set operations of low-valued integers where the stored * hash pointer is the key and the value. * * This function is especially useful for small hash tables (<1000) * where collisions are cheap due to caching but also works for integer * sets up to at least 1,000,000. * * NOTE: The multiplicative hash function by Knuth requires the modulo * to table size be done by shifting the upper bits down, since this is * where the quality bits reside. This yields significantly fewer * collisions which is important for e.g. chained hashing. However, our * interface does not provide the required information. * * When used in open hashing with load factors below 0.7 where the * stored pointer is also the key, collision checking is very cheap and * this pays off in a large range of table sizes where a more * complicated hash simply doesn't pay off. * * When used with a pointer set where the pointer is also the key, it is * not likely to work as well because the pointer acts as a large * integer which works against the design of the hash function. Here a * better mix function is probably worthwhile - therefore we also have * ht_ptr_hash_function. */ static inline size_t ht_int_hash_function(const void *key, size_t len) { (void)len; return ((size_t)key ^ (HT_HASH_SEED)) * 2654435761UL; } /* Bernsteins hash function, assumes string is zero terminated, len is ignored. */ static inline size_t ht_str_hash_function(const void *key, size_t len) { const unsigned char *str = key; size_t hash = 5381 ^ (HT_HASH_SEED); size_t c; (void)len; while ((c = (size_t)*str++)) hash = ((hash << 5) + hash) ^ c; /* (hash * 33) xor c */ return hash; } /* Hashes at most len characters or until zero termination. */ static inline size_t ht_strn_hash_function(const void *key, size_t len) { const unsigned char *str = key; size_t hash = 5381 ^ (HT_HASH_SEED); size_t c; while (--len && (c = (size_t)*str++)) hash = ((hash << 5) + hash) ^ c; /* (hash * 33) xor c */ return hash; } static inline uint32_t ht_fnv1a32_hash_function(const void *key, size_t len) { #ifndef FNV1A_NOMUL const uint32_t prime = UINT32_C(0x1000193); #endif uint32_t hash = UINT32_C(0x811c9dc5); const uint8_t *p = key; while (len--) { hash ^= (uint64_t)*p++; #ifndef FNV1A_NOMUL hash *= prime; #else hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24); #endif } return hash; } static inline uint64_t ht_fnv1a64_hash_function(const void *key, size_t len) { #ifndef FNV1A_NOMUL const uint64_t prime = UINT64_C(0x100000001b3); #endif uint64_t hash = UINT64_C(0xcbf29ce484222325); const uint8_t *p = key; while (len--) { hash ^= (uint64_t)*p++; #ifndef FNV1A_NOMUL hash *= prime; #else hash += (hash << 1) + (hash << 4) + (hash << 5) + (hash << 7) + (hash << 8) + (hash << 40); #endif } return hash; } /* Hashes until string termination and ignores length argument. */ static inline uint32_t ht_fnv1a32_str_hash_function(const void *key, size_t len) { #ifndef FNV1A_NOMUL const uint32_t prime = UINT32_C(0x1000193); #endif uint32_t hash = UINT32_C(0x811c9dc5); const uint8_t *p = key; (void)len; while (*p) { hash ^= (uint64_t)*p++; #ifndef FNV1A_NOMUL hash *= prime; #else hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24); #endif } return hash; } /* Hashes until string termination and ignores length argument. */ static inline uint64_t ht_fnv1a64_str_hash_function(const void *key, size_t len) { #ifndef FNV1A_NOMUL const uint64_t prime = UINT64_C(0x100000001b3); #endif uint64_t hash = UINT64_C(0xcbf29ce484222325); const uint8_t *p = key; (void)len; while (*p) { hash ^= (uint64_t)*p++; #ifndef FNV1A_NOMUL hash *= prime; #else hash += (hash << 1) + (hash << 4) + (hash << 5) + (hash << 7) + (hash << 8) + (hash << 40); #endif } return hash; } #endif /* HT_HASH_FUNCTION_H */
1ba841bc898875e251fa308a7f2051687a452d1d
40195e6f86bf8620850f0c56e98eae5693e88277
/deps/protobuf/ruby/ext/google/protobuf_c/message.c
299111404db660eaa878e50aa6feb0b2d961260f
[ "MIT", "BSD-3-Clause", "LicenseRef-scancode-protobuf" ]
permissive
apple/coremltools
009dfa7154d34cab8edcafa618e689e407521f50
feed174188f7773631a3d574e1ff9889a135c986
refs/heads/main
2023-09-01T23:26:13.491955
2023-08-31T18:44:31
2023-08-31T18:44:31
95,862,535
3,742
705
BSD-3-Clause
2023-09-14T17:33:58
2017-06-30T07:39:02
Python
UTF-8
C
false
false
20,202
c
message.c
// Protocol Buffers - Google's data interchange format // Copyright 2014 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "protobuf.h" // ----------------------------------------------------------------------------- // Class/module creation from msgdefs and enumdefs, respectively. // ----------------------------------------------------------------------------- void* Message_data(void* msg) { return ((uint8_t *)msg) + sizeof(MessageHeader); } void Message_mark(void* _self) { MessageHeader* self = (MessageHeader *)_self; layout_mark(self->descriptor->layout, Message_data(self)); } void Message_free(void* self) { xfree(self); } rb_data_type_t Message_type = { "Message", { Message_mark, Message_free, NULL }, }; VALUE Message_alloc(VALUE klass) { VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned); Descriptor* desc = ruby_to_Descriptor(descriptor); MessageHeader* msg = (MessageHeader*)ALLOC_N( uint8_t, sizeof(MessageHeader) + desc->layout->size); VALUE ret; memset(Message_data(msg), 0, desc->layout->size); // We wrap first so that everything in the message object is GC-rooted in case // a collection happens during object creation in layout_init(). ret = TypedData_Wrap_Struct(klass, &Message_type, msg); msg->descriptor = desc; rb_ivar_set(ret, descriptor_instancevar_interned, descriptor); layout_init(desc->layout, Message_data(msg)); return ret; } static VALUE which_oneof_field(MessageHeader* self, const upb_oneofdef* o) { upb_oneof_iter it; size_t case_ofs; uint32_t oneof_case; const upb_fielddef* first_field; const upb_fielddef* f; // If no fields in the oneof, always nil. if (upb_oneofdef_numfields(o) == 0) { return Qnil; } // Grab the first field in the oneof so we can get its layout info to find the // oneof_case field. upb_oneof_begin(&it, o); assert(!upb_oneof_done(&it)); first_field = upb_oneof_iter_field(&it); assert(upb_fielddef_containingoneof(first_field) != NULL); case_ofs = self->descriptor->layout-> fields[upb_fielddef_index(first_field)].case_offset; oneof_case = *((uint32_t*)((char*)Message_data(self) + case_ofs)); if (oneof_case == ONEOF_CASE_NONE) { return Qnil; } // oneof_case is a field index, so find that field. f = upb_oneofdef_itof(o, oneof_case); assert(f != NULL); return ID2SYM(rb_intern(upb_fielddef_name(f))); } /* * call-seq: * Message.method_missing(*args) * * Provides accessors and setters for message fields according to their field * names. For any field whose name does not conflict with a built-in method, an * accessor is provided with the same name as the field, and a setter is * provided with the name of the field plus the '=' suffix. Thus, given a * message instance 'msg' with field 'foo', the following code is valid: * * msg.foo = 42 * puts msg.foo * * This method also provides read-only accessors for oneofs. If a oneof exists * with name 'my_oneof', then msg.my_oneof will return a Ruby symbol equal to * the name of the field in that oneof that is currently set, or nil if none. */ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) { MessageHeader* self; VALUE method_name, method_str; char* name; size_t name_len; bool setter; const upb_oneofdef* o; const upb_fielddef* f; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); if (argc < 1) { rb_raise(rb_eArgError, "Expected method name as first argument."); } method_name = argv[0]; if (!SYMBOL_P(method_name)) { rb_raise(rb_eArgError, "Expected symbol as method name."); } method_str = rb_id2str(SYM2ID(method_name)); name = RSTRING_PTR(method_str); name_len = RSTRING_LEN(method_str); setter = false; // Setters have names that end in '='. if (name[name_len - 1] == '=') { setter = true; name_len--; } // See if this name corresponds to either a oneof or field in this message. if (!upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len, &f, &o)) { return rb_call_super(argc, argv); } if (o != NULL) { // This is a oneof -- return which field inside the oneof is set. if (setter) { rb_raise(rb_eRuntimeError, "Oneof accessors are read-only."); } return which_oneof_field(self, o); } else { // This is a field -- get or set the field's value. assert(f); if (setter) { if (argc < 2) { rb_raise(rb_eArgError, "No value provided to setter."); } layout_set(self->descriptor->layout, Message_data(self), f, argv[1]); return Qnil; } else { return layout_get(self->descriptor->layout, Message_data(self), f); } } } VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) { MessageHeader* self; VALUE method_name, method_str; char* name; size_t name_len; bool setter; const upb_oneofdef* o; const upb_fielddef* f; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); if (argc < 1) { rb_raise(rb_eArgError, "Expected method name as first argument."); } method_name = argv[0]; if (!SYMBOL_P(method_name)) { rb_raise(rb_eArgError, "Expected symbol as method name."); } method_str = rb_id2str(SYM2ID(method_name)); name = RSTRING_PTR(method_str); name_len = RSTRING_LEN(method_str); setter = false; // Setters have names that end in '='. if (name[name_len - 1] == '=') { setter = true; name_len--; } // See if this name corresponds to either a oneof or field in this message. if (!upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len, &f, &o)) { return rb_call_super(argc, argv); } if (o != NULL) { return setter ? Qfalse : Qtrue; } return Qtrue; } int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { MessageHeader* self; VALUE method_str; char* name; const upb_fielddef* f; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); if (!SYMBOL_P(key)) { rb_raise(rb_eArgError, "Expected symbols as hash keys in initialization map."); } method_str = rb_id2str(SYM2ID(key)); name = RSTRING_PTR(method_str); f = upb_msgdef_ntofz(self->descriptor->msgdef, name); if (f == NULL) { rb_raise(rb_eArgError, "Unknown field name '%s' in initialization map entry.", name); } if (is_map_field(f)) { VALUE map; if (TYPE(val) != T_HASH) { rb_raise(rb_eArgError, "Expected Hash object as initializer value for map field '%s'.", name); } map = layout_get(self->descriptor->layout, Message_data(self), f); Map_merge_into_self(map, val); } else if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) { VALUE ary; if (TYPE(val) != T_ARRAY) { rb_raise(rb_eArgError, "Expected array as initializer value for repeated field '%s'.", name); } ary = layout_get(self->descriptor->layout, Message_data(self), f); for (int i = 0; i < RARRAY_LEN(val); i++) { RepeatedField_push(ary, rb_ary_entry(val, i)); } } else { layout_set(self->descriptor->layout, Message_data(self), f, val); } return 0; } /* * call-seq: * Message.new(kwargs) => new_message * * Creates a new instance of the given message class. Keyword arguments may be * provided with keywords corresponding to field names. * * Note that no literal Message class exists. Only concrete classes per message * type exist, as provided by the #msgclass method on Descriptors after they * have been added to a pool. The method definitions described here on the * Message class are provided on each concrete message class. */ VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) { VALUE hash_args; if (argc == 0) { return Qnil; } if (argc != 1) { rb_raise(rb_eArgError, "Expected 0 or 1 arguments."); } hash_args = argv[0]; if (TYPE(hash_args) != T_HASH) { rb_raise(rb_eArgError, "Expected hash arguments."); } rb_hash_foreach(hash_args, Message_initialize_kwarg, _self); return Qnil; } /* * call-seq: * Message.dup => new_message * * Performs a shallow copy of this message and returns the new copy. */ VALUE Message_dup(VALUE _self) { MessageHeader* self; VALUE new_msg; MessageHeader* new_msg_self; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self)); TypedData_Get_Struct(new_msg, MessageHeader, &Message_type, new_msg_self); layout_dup(self->descriptor->layout, Message_data(new_msg_self), Message_data(self)); return new_msg; } // Internal only; used by Google::Protobuf.deep_copy. VALUE Message_deep_copy(VALUE _self) { MessageHeader* self; MessageHeader* new_msg_self; VALUE new_msg; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self)); TypedData_Get_Struct(new_msg, MessageHeader, &Message_type, new_msg_self); layout_deep_copy(self->descriptor->layout, Message_data(new_msg_self), Message_data(self)); return new_msg; } /* * call-seq: * Message.==(other) => boolean * * Performs a deep comparison of this message with another. Messages are equal * if they have the same type and if each field is equal according to the :== * method's semantics (a more efficient comparison may actually be done if the * field is of a primitive type). */ VALUE Message_eq(VALUE _self, VALUE _other) { MessageHeader* self; MessageHeader* other; if (TYPE(_self) != TYPE(_other)) { return Qfalse; } TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); TypedData_Get_Struct(_other, MessageHeader, &Message_type, other); if (self->descriptor != other->descriptor) { return Qfalse; } return layout_eq(self->descriptor->layout, Message_data(self), Message_data(other)); } /* * call-seq: * Message.hash => hash_value * * Returns a hash value that represents this message's field values. */ VALUE Message_hash(VALUE _self) { MessageHeader* self; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); return layout_hash(self->descriptor->layout, Message_data(self)); } /* * call-seq: * Message.inspect => string * * Returns a human-readable string representing this message. It will be * formatted as "<MessageType: field1: value1, field2: value2, ...>". Each * field's value is represented according to its own #inspect method. */ VALUE Message_inspect(VALUE _self) { MessageHeader* self; VALUE str; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); str = rb_str_new2("<"); str = rb_str_append(str, rb_str_new2(rb_class2name(CLASS_OF(_self)))); str = rb_str_cat2(str, ": "); str = rb_str_append(str, layout_inspect( self->descriptor->layout, Message_data(self))); str = rb_str_cat2(str, ">"); return str; } /* * call-seq: * Message.to_h => {} * * Returns the message as a Ruby Hash object, with keys as symbols. */ VALUE Message_to_h(VALUE _self) { MessageHeader* self; VALUE hash; upb_msg_field_iter it; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); hash = rb_hash_new(); for (upb_msg_field_begin(&it, self->descriptor->msgdef); !upb_msg_field_done(&it); upb_msg_field_next(&it)) { const upb_fielddef* field = upb_msg_iter_field(&it); VALUE msg_value = layout_get(self->descriptor->layout, Message_data(self), field); VALUE msg_key = ID2SYM(rb_intern(upb_fielddef_name(field))); if (upb_fielddef_ismap(field)) { msg_value = Map_to_h(msg_value); } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { msg_value = RepeatedField_to_ary(msg_value); } else if (msg_value != Qnil && upb_fielddef_type(field) == UPB_TYPE_MESSAGE) { msg_value = Message_to_h(msg_value); } rb_hash_aset(hash, msg_key, msg_value); } return hash; } /* * call-seq: * Message.[](index) => value * * Accesses a field's value by field name. The provided field name should be a * string. */ VALUE Message_index(VALUE _self, VALUE field_name) { MessageHeader* self; const upb_fielddef* field; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); Check_Type(field_name, T_STRING); field = upb_msgdef_ntofz(self->descriptor->msgdef, RSTRING_PTR(field_name)); if (field == NULL) { return Qnil; } return layout_get(self->descriptor->layout, Message_data(self), field); } /* * call-seq: * Message.[]=(index, value) * * Sets a field's value by field name. The provided field name should be a * string. */ VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) { MessageHeader* self; const upb_fielddef* field; TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); Check_Type(field_name, T_STRING); field = upb_msgdef_ntofz(self->descriptor->msgdef, RSTRING_PTR(field_name)); if (field == NULL) { rb_raise(rb_eArgError, "Unknown field: %s", RSTRING_PTR(field_name)); } layout_set(self->descriptor->layout, Message_data(self), field, value); return Qnil; } /* * call-seq: * Message.descriptor => descriptor * * Class method that returns the Descriptor instance corresponding to this * message class's type. */ VALUE Message_descriptor(VALUE klass) { return rb_ivar_get(klass, descriptor_instancevar_interned); } VALUE build_class_from_descriptor(Descriptor* desc) { const char *name; VALUE klass; if (desc->layout == NULL) { desc->layout = create_layout(desc->msgdef); } if (desc->fill_method == NULL) { desc->fill_method = new_fillmsg_decodermethod(desc, &desc->fill_method); } name = upb_msgdef_fullname(desc->msgdef); if (name == NULL) { rb_raise(rb_eRuntimeError, "Descriptor does not have assigned name."); } klass = rb_define_class_id( // Docs say this parameter is ignored. User will assign return value to // their own toplevel constant class name. rb_intern("Message"), rb_cObject); rb_ivar_set(klass, descriptor_instancevar_interned, get_def_obj(desc->msgdef)); rb_define_alloc_func(klass, Message_alloc); rb_require("google/protobuf/message_exts"); rb_include_module(klass, rb_eval_string("Google::Protobuf::MessageExts")); rb_extend_object( klass, rb_eval_string("Google::Protobuf::MessageExts::ClassMethods")); rb_define_method(klass, "method_missing", Message_method_missing, -1); rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing, -1); rb_define_method(klass, "initialize", Message_initialize, -1); rb_define_method(klass, "dup", Message_dup, 0); // Also define #clone so that we don't inherit Object#clone. rb_define_method(klass, "clone", Message_dup, 0); rb_define_method(klass, "==", Message_eq, 1); rb_define_method(klass, "hash", Message_hash, 0); rb_define_method(klass, "to_h", Message_to_h, 0); rb_define_method(klass, "to_hash", Message_to_h, 0); rb_define_method(klass, "inspect", Message_inspect, 0); rb_define_method(klass, "[]", Message_index, 1); rb_define_method(klass, "[]=", Message_index_set, 2); rb_define_singleton_method(klass, "decode", Message_decode, 1); rb_define_singleton_method(klass, "encode", Message_encode, 1); rb_define_singleton_method(klass, "decode_json", Message_decode_json, 1); rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1); rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0); return klass; } /* * call-seq: * Enum.lookup(number) => name * * This module method, provided on each generated enum module, looks up an enum * value by number and returns its name as a Ruby symbol, or nil if not found. */ VALUE enum_lookup(VALUE self, VALUE number) { int32_t num = NUM2INT(number); VALUE desc = rb_ivar_get(self, descriptor_instancevar_interned); EnumDescriptor* enumdesc = ruby_to_EnumDescriptor(desc); const char* name = upb_enumdef_iton(enumdesc->enumdef, num); if (name == NULL) { return Qnil; } else { return ID2SYM(rb_intern(name)); } } /* * call-seq: * Enum.resolve(name) => number * * This module method, provided on each generated enum module, looks up an enum * value by name (as a Ruby symbol) and returns its name, or nil if not found. */ VALUE enum_resolve(VALUE self, VALUE sym) { const char* name = rb_id2name(SYM2ID(sym)); VALUE desc = rb_ivar_get(self, descriptor_instancevar_interned); EnumDescriptor* enumdesc = ruby_to_EnumDescriptor(desc); int32_t num = 0; bool found = upb_enumdef_ntoiz(enumdesc->enumdef, name, &num); if (!found) { return Qnil; } else { return INT2NUM(num); } } /* * call-seq: * Enum.descriptor * * This module method, provided on each generated enum module, returns the * EnumDescriptor corresponding to this enum type. */ VALUE enum_descriptor(VALUE self) { return rb_ivar_get(self, descriptor_instancevar_interned); } VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) { VALUE mod = rb_define_module_id( rb_intern(upb_enumdef_fullname(enumdesc->enumdef))); upb_enum_iter it; for (upb_enum_begin(&it, enumdesc->enumdef); !upb_enum_done(&it); upb_enum_next(&it)) { const char* name = upb_enum_iter_name(&it); int32_t value = upb_enum_iter_number(&it); if (name[0] < 'A' || name[0] > 'Z') { rb_raise(rb_eTypeError, "Enum value '%s' does not start with an uppercase letter " "as is required for Ruby constants.", name); } rb_define_const(mod, name, INT2NUM(value)); } rb_define_singleton_method(mod, "lookup", enum_lookup, 1); rb_define_singleton_method(mod, "resolve", enum_resolve, 1); rb_define_singleton_method(mod, "descriptor", enum_descriptor, 0); rb_ivar_set(mod, descriptor_instancevar_interned, get_def_obj(enumdesc->enumdef)); return mod; } /* * call-seq: * Google::Protobuf.deep_copy(obj) => copy_of_obj * * Performs a deep copy of a RepeatedField instance, a Map instance, or a * message object, recursively copying its members. */ VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) { VALUE klass = CLASS_OF(obj); if (klass == cRepeatedField) { return RepeatedField_deep_copy(obj); } else if (klass == cMap) { return Map_deep_copy(obj); } else { return Message_deep_copy(obj); } }
af4b41bb38a7ee0c3b216454b1403a71f7da8698
607bb971c8fd33ad3df748c492ba77ec92159c42
/src/projection_family.c
1725fd78f901813ac10149e6541a1540cfafaa92
[ "BSD-2-Clause" ]
permissive
GHamrouni/Recommender
8478c785ad8de16a6e846a334570bd19d6eeac3d
b6cadc8fe611b7dea053568dd131f54c290690f4
refs/heads/master
2022-08-19T14:19:01.840554
2022-07-19T15:21:16
2022-07-19T15:21:16
3,101,244
266
70
BSD-2-Clause
2018-08-28T13:44:06
2012-01-04T10:40:16
C
UTF-8
C
false
false
1,108
c
projection_family.c
#include "projection_family.h" #include <stdlib.h> projection_family_t* init_random_projections(unsigned int dim, unsigned int seed, unsigned int bin_width, size_t projNb) { projection_family_t* pfamily = malloc(sizeof(projection_family_t)); normal_generator_t gen = init_normal_distribution(seed); size_t i; if (!pfamily) return NULL; pfamily->projections = malloc(projNb * sizeof(projection_t*)); pfamily->projection_nb = projNb; if (!pfamily->projections) return pfamily; for (i = 0; i < projNb; i++) pfamily->projections[i] = init_random_projection_rng(dim, seed, bin_width, &gen); return pfamily; } void free_projection_family(projection_family_t* pfamily) { size_t i; for (i = 0; i < pfamily->projection_nb; i++) { free(pfamily->projections[i]->vector); free(pfamily->projections[i]); } free(pfamily); } int lsh_data(projection_family_t* pfamily, double* data) { size_t i; int hash = 1; for (i = 0; i < pfamily->projection_nb; i++) hash = 33 * hash + project_data(pfamily->projections[i], data); return hash; }
e98a2deb8aad122a51d3ec07d6245b72b0b714c5
89db60818afeb3dc7c3b7abe9ceae155f074f7f2
/src/cmd/fossil/9p.c
e15622afae990e93ee8e96563c34a2a3f3afe0a6
[ "bzip2-1.0.6", "LPL-1.02", "MIT" ]
permissive
9fans/plan9port
63c3d01928c6f8a8617d3ea6ecc05bac72391132
65c090346a38a8c30cb242d345aa71060116340c
refs/heads/master
2023-08-25T17:14:26.233105
2023-08-23T13:21:37
2023-08-23T18:47:08
26,095,474
1,645
468
NOASSERTION
2023-09-05T16:55:41
2014-11-02T22:40:13
C
UTF-8
C
false
false
23,094
c
9p.c
#include "stdinc.h" #include "9.h" enum { OMODE = 0x7, /* Topen/Tcreate mode */ }; enum { PermX = 1, PermW = 2, PermR = 4, }; static char EPermission[] = "permission denied"; static int permFile(File* file, Fid* fid, int perm) { char *u; DirEntry de; if(!fileGetDir(file, &de)) return -1; /* * User none only gets other permissions. */ if(strcmp(fid->uname, unamenone) != 0){ /* * There is only one uid<->uname mapping * and it's already cached in the Fid, but * it might have changed during the lifetime * if this Fid. */ if((u = unameByUid(de.uid)) != nil){ if(strcmp(fid->uname, u) == 0 && ((perm<<6) & de.mode)){ vtfree(u); deCleanup(&de); return 1; } vtfree(u); } if(groupMember(de.gid, fid->uname) && ((perm<<3) & de.mode)){ deCleanup(&de); return 1; } } if(perm & de.mode){ if(perm == PermX && (de.mode & ModeDir)){ deCleanup(&de); return 1; } if(!groupMember(uidnoworld, fid->uname)){ deCleanup(&de); return 1; } } if(fsysNoPermCheck(fid->fsys) || (fid->con->flags&ConNoPermCheck)){ deCleanup(&de); return 1; } werrstr(EPermission); deCleanup(&de); return 0; } static int permFid(Fid* fid, int p) { return permFile(fid->file, fid, p); } static int permParent(Fid* fid, int p) { int r; File *parent; parent = fileGetParent(fid->file); r = permFile(parent, fid, p); fileDecRef(parent); return r; } int validFileName(char* name) { char *p; if(name == nil || name[0] == '\0'){ werrstr("no file name"); return 0; } if(name[0] == '.'){ if(name[1] == '\0' || (name[1] == '.' && name[2] == '\0')){ werrstr(". and .. illegal as file name"); return 0; } } for(p = name; *p != '\0'; p++){ if((*p & 0xFF) < 040){ werrstr("bad character in file name"); return 0; } } return 1; } static int rTwstat(Msg* m) { Dir dir; Fid *fid; ulong mode, oldmode; DirEntry de; char *gid, *strs, *uid; int gl, op, retval, tsync, wstatallow; if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil) return 0; gid = uid = nil; retval = 0; if(strcmp(fid->uname, unamenone) == 0 || (fid->qid.type & QTAUTH)){ werrstr(EPermission); goto error0; } if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){ werrstr("read-only filesystem"); goto error0; } if(!fileGetDir(fid->file, &de)) goto error0; strs = vtmalloc(m->t.nstat); if(convM2D(m->t.stat, m->t.nstat, &dir, strs) == 0){ werrstr("wstat -- protocol botch"); goto error; } /* * Run through each of the (sub-)fields in the provided Dir * checking for validity and whether it's a default: * .type, .dev and .atime are completely ignored and not checked; * .qid.path, .qid.vers and .muid are checked for validity but * any attempt to change them is an error. * .qid.type/.mode, .mtime, .name, .length, .uid and .gid can * possibly be changed. * * 'Op' flags there are changed fields, i.e. it's not a no-op. * 'Tsync' flags all fields are defaulted. */ tsync = 1; if(dir.qid.path != ~0){ if(dir.qid.path != de.qid){ werrstr("wstat -- attempt to change qid.path"); goto error; } tsync = 0; } if(dir.qid.vers != (u32int)~0){ if(dir.qid.vers != de.mcount){ werrstr("wstat -- attempt to change qid.vers"); goto error; } tsync = 0; } if(dir.muid != nil && *dir.muid != '\0'){ if((uid = uidByUname(dir.muid)) == nil){ werrstr("wstat -- unknown muid"); goto error; } if(strcmp(uid, de.mid) != 0){ werrstr("wstat -- attempt to change muid"); goto error; } vtfree(uid); uid = nil; tsync = 0; } /* * Check .qid.type and .mode agree if neither is defaulted. */ if(dir.qid.type != (uchar)~0 && dir.mode != (u32int)~0){ if(dir.qid.type != ((dir.mode>>24) & 0xFF)){ werrstr("wstat -- qid.type/mode mismatch"); goto error; } } op = 0; oldmode = de.mode; if(dir.qid.type != (uchar)~0 || dir.mode != (u32int)~0){ /* * .qid.type or .mode isn't defaulted, check for unknown bits. */ if(dir.mode == ~0) dir.mode = (dir.qid.type<<24)|(de.mode & 0777); if(dir.mode & ~(DMDIR|DMAPPEND|DMEXCL|DMTMP|0777)){ werrstr("wstat -- unknown bits in qid.type/mode"); goto error; } /* * Synthesise a mode to check against the current settings. */ mode = dir.mode & 0777; if(dir.mode & DMEXCL) mode |= ModeExclusive; if(dir.mode & DMAPPEND) mode |= ModeAppend; if(dir.mode & DMDIR) mode |= ModeDir; if(dir.mode & DMTMP) mode |= ModeTemporary; if((de.mode^mode) & ModeDir){ werrstr("wstat -- attempt to change directory bit"); goto error; } if((de.mode & (ModeAppend|ModeExclusive|ModeTemporary|0777)) != mode){ de.mode &= ~(ModeAppend|ModeExclusive|ModeTemporary|0777); de.mode |= mode; op = 1; } tsync = 0; } if(dir.mtime != (u32int)~0){ if(dir.mtime != de.mtime){ de.mtime = dir.mtime; op = 1; } tsync = 0; } if(dir.length != ~0){ if(dir.length != de.size){ /* * Cannot change length on append-only files. * If we're changing the append bit, it's okay. */ if(de.mode & oldmode & ModeAppend){ werrstr("wstat -- attempt to change length of append-only file"); goto error; } if(de.mode & ModeDir){ werrstr("wstat -- attempt to change length of directory"); goto error; } de.size = dir.length; op = 1; } tsync = 0; } /* * Check for permission to change .mode, .mtime or .length, * must be owner or leader of either group, for which test gid * is needed; permission checks on gid will be done later. */ if(dir.gid != nil && *dir.gid != '\0'){ if((gid = uidByUname(dir.gid)) == nil){ werrstr("wstat -- unknown gid"); goto error; } tsync = 0; } else gid = vtstrdup(de.gid); wstatallow = (fsysWstatAllow(fid->fsys) || (m->con->flags&ConWstatAllow)); /* * 'Gl' counts whether neither, one or both groups are led. */ gl = groupLeader(gid, fid->uname) != 0; gl += groupLeader(de.gid, fid->uname) != 0; if(op && !wstatallow){ if(strcmp(fid->uid, de.uid) != 0 && !gl){ werrstr("wstat -- not owner or group leader"); goto error; } } /* * Check for permission to change group, must be * either owner and in new group or leader of both groups. * If gid is nil here then */ if(strcmp(gid, de.gid) != 0){ if(!wstatallow && !(strcmp(fid->uid, de.uid) == 0 && groupMember(gid, fid->uname)) && !(gl == 2)){ werrstr("wstat -- not owner and not group leaders"); goto error; } vtfree(de.gid); de.gid = gid; gid = nil; op = 1; tsync = 0; } /* * Rename. * Check .name is valid and different to the current. * If so, check write permission in parent. */ if(dir.name != nil && *dir.name != '\0'){ if(!validFileName(dir.name)) goto error; if(strcmp(dir.name, de.elem) != 0){ if(permParent(fid, PermW) <= 0) goto error; vtfree(de.elem); de.elem = vtstrdup(dir.name); op = 1; } tsync = 0; } /* * Check for permission to change owner - must be god. */ if(dir.uid != nil && *dir.uid != '\0'){ if((uid = uidByUname(dir.uid)) == nil){ werrstr("wstat -- unknown uid"); goto error; } if(strcmp(uid, de.uid) != 0){ if(!wstatallow){ werrstr("wstat -- not owner"); goto error; } if(strcmp(uid, uidnoworld) == 0){ werrstr(EPermission); goto error; } vtfree(de.uid); de.uid = uid; uid = nil; op = 1; } tsync = 0; } if(op) retval = fileSetDir(fid->file, &de, fid->uid); else retval = 1; if(tsync){ /* * All values were defaulted, * make the state of the file exactly what it * claims to be before returning... */ USED(tsync); } error: deCleanup(&de); vtfree(strs); if(gid != nil) vtfree(gid); if(uid != nil) vtfree(uid); error0: fidPut(fid); return retval; }; static int rTstat(Msg* m) { Dir dir; Fid *fid; DirEntry de; if((fid = fidGet(m->con, m->t.fid, 0)) == nil) return 0; if(fid->qid.type & QTAUTH){ memset(&dir, 0, sizeof(Dir)); dir.qid = fid->qid; dir.mode = DMAUTH; dir.atime = time(0L); dir.mtime = dir.atime; dir.length = 0; dir.name = "#¿"; dir.uid = fid->uname; dir.gid = fid->uname; dir.muid = fid->uname; if((m->r.nstat = convD2M(&dir, m->data, m->con->msize)) == 0){ werrstr("stat QTAUTH botch"); fidPut(fid); return 0; } m->r.stat = m->data; fidPut(fid); return 1; } if(!fileGetDir(fid->file, &de)){ fidPut(fid); return 0; } fidPut(fid); /* * TODO: optimise this copy (in convS2M) away somehow. * This pettifoggery with m->data will do for the moment. */ m->r.nstat = dirDe2M(&de, m->data, m->con->msize); m->r.stat = m->data; deCleanup(&de); return 1; } static int _rTclunk(Fid* fid, int remove) { int rok; if(fid->excl) exclFree(fid); rok = 1; if(remove && !(fid->qid.type & QTAUTH)){ if((rok = permParent(fid, PermW)) > 0) rok = fileRemove(fid->file, fid->uid); } fidClunk(fid); return rok; } static int rTremove(Msg* m) { Fid *fid; if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil) return 0; return _rTclunk(fid, 1); } static int rTclunk(Msg* m) { Fid *fid; if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil) return 0; _rTclunk(fid, (fid->open & FidORclose)); return 1; } static int rTwrite(Msg* m) { Fid *fid; int count, n; if((fid = fidGet(m->con, m->t.fid, 0)) == nil) return 0; if(!(fid->open & FidOWrite)){ werrstr("fid not open for write"); goto error; } count = m->t.count; if(count < 0 || count > m->con->msize-IOHDRSZ){ werrstr("write count too big"); goto error; } if(m->t.offset < 0){ werrstr("write offset negative"); goto error; } if(fid->excl != nil && !exclUpdate(fid)) goto error; if(fid->qid.type & QTDIR){ werrstr("is a directory"); goto error; } else if(fid->qid.type & QTAUTH) n = authWrite(fid, m->t.data, count); else n = fileWrite(fid->file, m->t.data, count, m->t.offset, fid->uid); if(n < 0) goto error; m->r.count = n; fidPut(fid); return 1; error: fidPut(fid); return 0; } static int rTread(Msg* m) { Fid *fid; uchar *data; int count, n; if((fid = fidGet(m->con, m->t.fid, 0)) == nil) return 0; if(!(fid->open & FidORead)){ werrstr("fid not open for read"); goto error; } count = m->t.count; if(count < 0 || count > m->con->msize-IOHDRSZ){ werrstr("read count too big"); goto error; } if(m->t.offset < 0){ werrstr("read offset negative"); goto error; } if(fid->excl != nil && !exclUpdate(fid)) goto error; /* * TODO: optimise this copy (in convS2M) away somehow. * This pettifoggery with m->data will do for the moment. */ data = m->data+IOHDRSZ; if(fid->qid.type & QTDIR) n = dirRead(fid, data, count, m->t.offset); else if(fid->qid.type & QTAUTH) n = authRead(fid, data, count); else n = fileRead(fid->file, data, count, m->t.offset); if(n < 0) goto error; m->r.count = n; m->r.data = (char*)data; fidPut(fid); return 1; error: fidPut(fid); return 0; } static int rTcreate(Msg* m) { Fid *fid; File *file; ulong mode; int omode, open, perm; if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil) return 0; if(fid->open){ werrstr("fid open for I/O"); goto error; } if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){ werrstr("read-only filesystem"); goto error; } if(!fileIsDir(fid->file)){ werrstr("not a directory"); goto error; } if(permFid(fid, PermW) <= 0) goto error; if(!validFileName(m->t.name)) goto error; if(strcmp(fid->uid, uidnoworld) == 0){ werrstr(EPermission); goto error; } omode = m->t.mode & OMODE; open = 0; if(omode == OREAD || omode == ORDWR || omode == OEXEC) open |= FidORead; if(omode == OWRITE || omode == ORDWR) open |= FidOWrite; if((open & (FidOWrite|FidORead)) == 0){ werrstr("unknown mode"); goto error; } if(m->t.perm & DMDIR){ if((m->t.mode & (ORCLOSE|OTRUNC)) || (open & FidOWrite)){ werrstr("illegal mode"); goto error; } if(m->t.perm & DMAPPEND){ werrstr("illegal perm"); goto error; } } mode = fileGetMode(fid->file); perm = m->t.perm; if(m->t.perm & DMDIR) perm &= ~0777|(mode & 0777); else perm &= ~0666|(mode & 0666); mode = perm & 0777; if(m->t.perm & DMDIR) mode |= ModeDir; if(m->t.perm & DMAPPEND) mode |= ModeAppend; if(m->t.perm & DMEXCL) mode |= ModeExclusive; if(m->t.perm & DMTMP) mode |= ModeTemporary; if((file = fileCreate(fid->file, m->t.name, mode, fid->uid)) == nil){ fidPut(fid); return 0; } fileDecRef(fid->file); fid->qid.vers = fileGetMcount(file); fid->qid.path = fileGetId(file); fid->file = file; mode = fileGetMode(fid->file); if(mode & ModeDir) fid->qid.type = QTDIR; else fid->qid.type = QTFILE; if(mode & ModeAppend) fid->qid.type |= QTAPPEND; if(mode & ModeExclusive){ fid->qid.type |= QTEXCL; assert(exclAlloc(fid) != 0); } if(m->t.mode & ORCLOSE) open |= FidORclose; fid->open = open; m->r.qid = fid->qid; m->r.iounit = m->con->msize-IOHDRSZ; fidPut(fid); return 1; error: fidPut(fid); return 0; } static int rTopen(Msg* m) { Fid *fid; int isdir, mode, omode, open, rofs; if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil) return 0; if(fid->open){ werrstr("fid open for I/O"); goto error; } isdir = fileIsDir(fid->file); open = 0; rofs = fileIsRoFs(fid->file) || !groupWriteMember(fid->uname); if(m->t.mode & ORCLOSE){ if(isdir){ werrstr("is a directory"); goto error; } if(rofs){ werrstr("read-only filesystem"); goto error; } if(permParent(fid, PermW) <= 0) goto error; open |= FidORclose; } omode = m->t.mode & OMODE; if(omode == OREAD || omode == ORDWR){ if(permFid(fid, PermR) <= 0) goto error; open |= FidORead; } if(omode == OWRITE || omode == ORDWR || (m->t.mode & OTRUNC)){ if(isdir){ werrstr("is a directory"); goto error; } if(rofs){ werrstr("read-only filesystem"); goto error; } if(permFid(fid, PermW) <= 0) goto error; open |= FidOWrite; } if(omode == OEXEC){ if(isdir){ werrstr("is a directory"); goto error; } if(permFid(fid, PermX) <= 0) goto error; open |= FidORead; } if((open & (FidOWrite|FidORead)) == 0){ werrstr("unknown mode"); goto error; } mode = fileGetMode(fid->file); if((mode & ModeExclusive) && exclAlloc(fid) == 0) goto error; /* * Everything checks out, try to commit any changes. */ if((m->t.mode & OTRUNC) && !(mode & ModeAppend)) if(!fileTruncate(fid->file, fid->uid)) goto error; if(isdir && fid->db != nil){ dirBufFree(fid->db); fid->db = nil; } fid->qid.vers = fileGetMcount(fid->file); m->r.qid = fid->qid; m->r.iounit = m->con->msize-IOHDRSZ; fid->open = open; fidPut(fid); return 1; error: if(fid->excl != nil) exclFree(fid); fidPut(fid); return 0; } static int rTwalk(Msg* m) { Qid qid; Fcall *r, *t; int nwname, wlock; File *file, *nfile; Fid *fid, *ofid, *nfid; t = &m->t; if(t->fid == t->newfid) wlock = FidFWlock; else wlock = 0; /* * The file identified by t->fid must be valid in the * current session and must not have been opened for I/O * by an open or create message. */ if((ofid = fidGet(m->con, t->fid, wlock)) == nil) return 0; if(ofid->open){ werrstr("file open for I/O"); fidPut(ofid); return 0; } /* * If newfid is not the same as fid, allocate a new file; * a side effect is checking newfid is not already in use (error); * if there are no names to walk this will be equivalent to a * simple 'clone' operation. * It's a no-op if newfid is the same as fid and t->nwname is 0. */ nfid = nil; if(t->fid != t->newfid){ nfid = fidGet(m->con, t->newfid, FidFWlock|FidFCreate); if(nfid == nil){ werrstr("%s: walk: newfid 0x%ud in use", argv0, t->newfid); fidPut(ofid); return 0; } nfid->open = ofid->open & ~FidORclose; nfid->file = fileIncRef(ofid->file); nfid->qid = ofid->qid; nfid->uid = vtstrdup(ofid->uid); nfid->uname = vtstrdup(ofid->uname); nfid->fsys = fsysIncRef(ofid->fsys); fid = nfid; } else fid = ofid; r = &m->r; r->nwqid = 0; if(t->nwname == 0){ if(nfid != nil) fidPut(nfid); fidPut(ofid); return 1; } file = fid->file; fileIncRef(file); qid = fid->qid; for(nwname = 0; nwname < t->nwname; nwname++){ /* * Walked elements must represent a directory and * the implied user must have permission to search * the directory. Walking .. is always allowed, so that * you can't walk into a directory and then not be able * to walk out of it. */ if(!(qid.type & QTDIR)){ werrstr("not a directory"); break; } switch(permFile(file, fid, PermX)){ case 1: break; case 0: if(strcmp(t->wname[nwname], "..") == 0) break; case -1: goto Out; } if((nfile = fileWalk(file, t->wname[nwname])) == nil) break; fileDecRef(file); file = nfile; qid.type = QTFILE; if(fileIsDir(file)) qid.type = QTDIR; if(fileIsAppend(file)) qid.type |= QTAPPEND; if(fileIsTemporary(file)) qid.type |= QTTMP; if(fileIsExclusive(file)) qid.type |= QTEXCL; qid.vers = fileGetMcount(file); qid.path = fileGetId(file); r->wqid[r->nwqid++] = qid; } if(nwname == t->nwname){ /* * Walked all elements. Update the target fid * from the temporary qid used during the walk, * and tidy up. */ fid->qid = r->wqid[r->nwqid-1]; fileDecRef(fid->file); fid->file = file; if(nfid != nil) fidPut(nfid); fidPut(ofid); return 1; } Out: /* * Didn't walk all elements, 'clunk' nfid if it exists * and leave fid untouched. * It's not an error if some of the elements were walked OK. */ fileDecRef(file); if(nfid != nil) fidClunk(nfid); fidPut(ofid); if(nwname == 0) return 0; return 1; } static int rTflush(Msg* m) { if(m->t.oldtag != NOTAG) msgFlush(m); return 1; } static void parseAname(char *aname, char **fsname, char **path) { char *s; if(aname && aname[0]) s = vtstrdup(aname); else s = vtstrdup("main/active"); *fsname = s; if((*path = strchr(s, '/')) != nil) *(*path)++ = '\0'; else *path = ""; } #ifndef PLAN9PORT /* * Check remote IP address against /mnt/ipok. * Sources.cs.bell-labs.com uses this to disallow * network connections from Sudan, Libya, etc., * following U.S. cryptography export regulations. */ static int conIPCheck(Con* con) { char ok[256], *p; int fd; if(con->flags&ConIPCheck){ if(con->remote[0] == 0){ werrstr("cannot verify unknown remote address"); return 0; } if(access("/mnt/ipok/ok", AEXIST) < 0){ /* mount closes the fd on success */ if((fd = open("/srv/ipok", ORDWR)) >= 0 && mount(fd, -1, "/mnt/ipok", MREPL, "") < 0) close(fd); if(access("/mnt/ipok/ok", AEXIST) < 0){ werrstr("cannot verify remote address"); return 0; } } snprint(ok, sizeof ok, "/mnt/ipok/ok/%s", con->remote); if((p = strchr(ok, '!')) != nil) *p = 0; if(access(ok, AEXIST) < 0){ werrstr("restricted remote address"); return 0; } } return 1; } #endif static int rTattach(Msg* m) { Fid *fid; Fsys *fsys; char *fsname, *path; if((fid = fidGet(m->con, m->t.fid, FidFWlock|FidFCreate)) == nil) return 0; parseAname(m->t.aname, &fsname, &path); if((fsys = fsysGet(fsname)) == nil){ fidClunk(fid); vtfree(fsname); return 0; } fid->fsys = fsys; if(m->t.uname[0] != '\0') fid->uname = vtstrdup(m->t.uname); else fid->uname = vtstrdup(unamenone); #ifndef PLAN9PORT if((fid->con->flags&ConIPCheck) && !conIPCheck(fid->con)){ consPrint("reject %s from %s: %r\n", fid->uname, fid->con->remote); fidClunk(fid); vtfree(fsname); return 0; } #endif if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){ if((fid->uid = uidByUname(fid->uname)) == nil) fid->uid = vtstrdup(unamenone); } else if(!authCheck(&m->t, fid, fsys)){ fidClunk(fid); vtfree(fsname); return 0; } fsysFsRlock(fsys); if((fid->file = fsysGetRoot(fsys, path)) == nil){ fsysFsRUnlock(fsys); fidClunk(fid); vtfree(fsname); return 0; } fsysFsRUnlock(fsys); vtfree(fsname); fid->qid = (Qid){fileGetId(fid->file), 0, QTDIR}; m->r.qid = fid->qid; fidPut(fid); return 1; } static int rTauth(Msg* m) { #ifndef PLAN9PORT int afd; #endif Con *con; Fid *afid; Fsys *fsys; char *fsname, *path; parseAname(m->t.aname, &fsname, &path); if((fsys = fsysGet(fsname)) == nil){ vtfree(fsname); return 0; } vtfree(fsname); if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){ m->con->aok = 1; werrstr("authentication disabled"); fsysPut(fsys); return 0; } if(strcmp(m->t.uname, unamenone) == 0){ werrstr("user 'none' requires no authentication"); fsysPut(fsys); return 0; } con = m->con; if((afid = fidGet(con, m->t.afid, FidFWlock|FidFCreate)) == nil){ fsysPut(fsys); return 0; } afid->fsys = fsys; #ifndef PLAN9PORT if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0){ werrstr("can't open \"/mnt/factotum/rpc\""); fidClunk(afid); return 0; } #endif #ifdef PLAN9PORT if((afid->rpc = auth_allocrpc()) == nil){ #else if((afid->rpc = auth_allocrpc(afd)) == nil){ close(afd); #endif werrstr("can't auth_allocrpc"); fidClunk(afid); return 0; } if(auth_rpc(afid->rpc, "start", "proto=p9any role=server", 23) != ARok){ werrstr("can't auth_rpc"); fidClunk(afid); return 0; } afid->open = FidOWrite|FidORead; afid->qid.type = QTAUTH; afid->qid.path = m->t.afid; afid->uname = vtstrdup(m->t.uname); m->r.qid = afid->qid; fidPut(afid); return 1; } static int rTversion(Msg* m) { int v; Con *con; Fcall *r, *t; t = &m->t; r = &m->r; con = m->con; qlock(&con->lock); if(con->state != ConInit){ qunlock(&con->lock); werrstr("Tversion: down"); return 0; } con->state = ConNew; /* * Release the karma of past lives and suffering. * Should this be done before or after checking the * validity of the Tversion? */ fidClunkAll(con); if(t->tag != NOTAG){ qunlock(&con->lock); werrstr("Tversion: invalid tag"); return 0; } if(t->msize < 256){ qunlock(&con->lock); werrstr("Tversion: message size too small"); return 0; } if(t->msize < con->msize) r->msize = t->msize; else r->msize = con->msize; r->version = "unknown"; if(t->version[0] == '9' && t->version[1] == 'P'){ /* * Currently, the only defined version * is "9P2000"; ignore any later versions. */ v = strtol(&t->version[2], 0, 10); if(v >= 2000){ r->version = VERSION9P; con->msize = r->msize; con->state = ConUp; } else if(strcmp(t->version, "9PEoF") == 0){ r->version = "9PEoF"; con->msize = r->msize; con->state = ConMoribund; /* * Don't want to attempt to write this * message as the connection may be already * closed. */ m->state = MsgF; } } qunlock(&con->lock); return 1; } int (*rFcall[Tmax])(Msg*) = { [Tversion] = rTversion, [Tauth] = rTauth, [Tattach] = rTattach, [Tflush] = rTflush, [Twalk] = rTwalk, [Topen] = rTopen, [Tcreate] = rTcreate, [Tread] = rTread, [Twrite] = rTwrite, [Tclunk] = rTclunk, [Tremove] = rTremove, [Tstat] = rTstat, [Twstat] = rTwstat, };
d063009aeec81269d75b50de658969d4fa17b395
e73547787354afd9b717ea57fe8dd0695d161821
/src/world/area_kzn/kzn_02/kzn_02.h
ebbd5150303d7c50af0b7f9060c80b0166a32e32
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
517
h
kzn_02.h
/// @file kzn_02.h /// @brief Mt Lavalava - First Lava Lake #include "common.h" #include "message_ids.h" #include "map.h" #include "../kzn.h" #include "mapfs/kzn_02_shape.h" #include "mapfs/kzn_02_hit.h" enum { NPC_Kolorado = 0, NPC_LavaBubble = 1, }; #define NAMESPACE kzn_02 extern EvtScript N(EVS_Main); extern EvtScript N(EVS_InitializePlatforms); extern EvtScript N(EVS_PlayDemoScene); extern EvtScript N(EVS_KoloradoSinkingPlatform); extern NpcGroupList N(DefaultNPCs);
773f179e461c69a97c605c827e5568b164aa61c4
c8b39acfd4a857dc15ed3375e0d93e75fa3f1f64
/Engine/Source/Runtime/Core/Public/IOS/IOSPlatformProperties.h
2b93a5b2c30b709e2ab4298f8039af11b25d9e4f
[ "MIT", "LicenseRef-scancode-proprietary-license" ]
permissive
windystrife/UnrealEngine_NVIDIAGameWorks
c3c7863083653caf1bc67d3ef104fb4b9f302e2a
b50e6338a7c5b26374d66306ebc7807541ff815e
refs/heads/4.18-GameWorks
2023-03-11T02:50:08.471040
2022-01-13T20:50:29
2022-01-13T20:50:29
124,100,479
262
179
MIT
2022-12-16T05:36:38
2018-03-06T15:44:09
C++
UTF-8
C
false
false
1,512
h
IOSPlatformProperties.h
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved. /*================================================================================ IOSPlatformProperties.h - Basic static properties of a platform These are shared between: the runtime platform - via FPlatformProperties the target platforms - via ITargetPlatform ==================================================================================*/ #pragma once #include "GenericPlatformProperties.h" /** * Implements iOS platform properties. */ struct FIOSPlatformProperties : public FGenericPlatformProperties { static FORCEINLINE bool HasEditorOnlyData( ) { return false; } static FORCEINLINE const char* PlatformName( ) { return "IOS"; } static FORCEINLINE const char* IniPlatformName( ) { return "IOS"; } static FORCEINLINE bool IsGameOnly() { return true; } static FORCEINLINE bool RequiresCookedData( ) { return true; } static FORCEINLINE bool SupportsBuildTarget( EBuildTargets::Type BuildTarget ) { return (BuildTarget == EBuildTargets::Game); } static FORCEINLINE bool SupportsLowQualityLightmaps() { return true; } static FORCEINLINE bool SupportsHighQualityLightmaps() { return true; } static FORCEINLINE bool SupportsTextureStreaming() { return true; } static FORCEINLINE bool HasFixedResolution() { return true; } static FORCEINLINE bool AllowsFramerateSmoothing() { return true; } static FORCEINLINE bool SupportsAudioStreaming() { return true; } };
dbfab23094a3fa615e1a24aaa2828f0ec7f87248
2898fa4f2ad766afa0495a837f59fe95daa081a7
/tests/unit-pass/effective-malloc-imp-array.c
1210b087a53b5ec0428242059eba001c8a537c8f
[ "NCSA" ]
permissive
kframework/c-semantics
12fcc1b1bf1f7792636d1c37f6f7bb1b89a392b5
e6879d14455771aa0cb3e3d201131d4d763a73a2
refs/heads/master
2023-07-31T23:57:03.316456
2022-02-01T17:50:31
2022-02-01T17:50:31
11,747,541
312
52
NOASSERTION
2022-02-01T17:50:33
2013-07-29T19:13:25
C
UTF-8
C
false
false
534
c
effective-malloc-imp-array.c
#include <stdlib.h> int main(void) { int *a = malloc(sizeof(int [3])); a[1] = 0; a[2] = 0; a[0] = 1; struct s1 {int x; int y; } *b = malloc(sizeof(struct s1)); b->x = 1; struct s2 {int x; int y; } *c = malloc(sizeof(struct s2 [3])); c[0].y = 1; c[1].x = 1; c[2].y = 0; struct s3 {int x; int y; int z[]; } *d = malloc(sizeof(struct s3) + sizeof(int [3])); d->z[1] = 0; d->z[2] = 1; d->z[0] = 0; return *a + b->x + c->y + c[1].x + d->z[2] - 5; }
374700600ff64f4eb0842093fa546dd5abaa69a5
52c8ed39b32ccc7c0673278c1adea3638797c9ff
/src/arch/arm32/mach-v831/driver/audio-v831.c
e0ad3b70355b0f1631f90ee7278732c0511973e6
[ "MIT" ]
permissive
xboot/xboot
0cab7b440b612aa0a4c366025598a53a7ec3adf1
6d6b93947b7fcb8c3924fedb0715c23877eedd5e
refs/heads/master
2023-08-20T05:56:25.149388
2023-07-12T07:38:29
2023-07-12T07:38:29
471,539
765
296
MIT
2023-05-25T09:39:01
2010-01-14T08:25:12
C
UTF-8
C
false
false
7,384
c
audio-v831.c
/* * driver/audio-v831.c * * Copyright(c) 2007-2023 Jianjun Jiang <8192542@qq.com> * Official site: http://xboot.org * Mobile phone: +86-18665388956 * QQ: 8192542 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ #include <xboot.h> #include <clk/clk.h> #include <reset/reset.h> #include <audio/audio.h> enum { AUDIO_DAC_DPC = 0x000, AUDIO_DAC_FIFOC = 0x010, AUDIO_DAC_FIFOS = 0x014, AUDIO_DAC_TXDATA = 0x020, AUDIO_DAC_CNT = 0x024, AUDIO_DAC_DG = 0x028, AUDIO_ADC_FIFOC = 0x030, AUDIO_ADC_FIFOS = 0x038, AUDIO_ADC_RXDATA = 0x040, AUDIO_ADC_CNT = 0x044, AUDIO_ADC_DG = 0x04c, AUDIO_DAC_DAP_CTL = 0x0f0, AUDIO_ADC_DAP_CTL = 0x0f8, AUDIO_DAC_DRC_HHPFC = 0x100, AUDIO_DAC_DRC_LHPFC = 0x104, AUDIO_DAC_DRC_CTRL = 0x108, AUDIO_DAC_DRC_LPFHAT = 0x10c, AUDIO_DAC_DRC_LPFLAT = 0x110, AUDIO_DAC_DRC_RPFHAT = 0x114, AUDIO_DAC_DRC_RPFLAT = 0x118, AUDIO_DAC_DRC_LPFHRT = 0x11c, AUDIO_DAC_DRC_LPFLRT = 0x120, AUDIO_DAC_DRC_RPFHRT = 0x124, AUDIO_DAC_DRC_RPFLRT = 0x128, AUDIO_DAC_DRC_LRMSHAT = 0x12c, AUDIO_DAC_DRC_LRMSLAT = 0x130, AUDIO_DAC_DRC_RRMSHAT = 0x134, AUDIO_DAC_DRC_RRMSLAT = 0x138, AUDIO_DAC_DRC_HCT = 0x13c, AUDIO_DAC_DRC_LCT = 0x140, AUDIO_DAC_DRC_HKC = 0x144, AUDIO_DAC_DRC_LKC = 0x148, AUDIO_DAC_DRC_HOPC = 0x14c, AUDIO_DAC_DRC_LOPC = 0x150, AUDIO_DAC_DRC_HLT = 0x154, AUDIO_DAC_DRC_LLT = 0x158, AUDIO_DAC_DRC_HKI = 0x15c, AUDIO_DAC_DRC_LKI = 0x160, AUDIO_DAC_DRC_HOPL = 0x164, AUDIO_DAC_DRC_LOPL = 0x168, AUDIO_DAC_DRC_HET = 0x16c, AUDIO_DAC_DRC_LET = 0x170, AUDIO_DAC_DRC_HKE = 0x174, AUDIO_DAC_DRC_LKE = 0x178, AUDIO_DAC_DRC_HOPE = 0x17c, AUDIO_DAC_DRC_LOPE = 0x180, AUDIO_DAC_DRC_HKN = 0x184, AUDIO_DAC_DRC_LKN = 0x188, AUDIO_DAC_DRC_SFHAT = 0x18c, AUDIO_DAC_DRC_SFLAT = 0x190, AUDIO_DAC_DRC_SFHRT = 0x194, AUDIO_DAC_DRC_SFLRT = 0x198, AUDIO_DAC_DRC_MXGHS = 0x19c, AUDIO_DAC_DRC_MXGLS = 0x1a0, AUDIO_DAC_DRC_MNGHS = 0x1a4, AUDIO_DAC_DRC_MNGLS = 0x1a8, AUDIO_DAC_DRC_EPSHC = 0x1ac, AUDIO_DAC_DRC_EPSLC = 0x1b0, AUDIO_DAC_DRC_OPT = 0x1b4, AUDIO_DAC_DRC_HPFHGAIN = 0x1b8, AUDIO_DAC_DRC_HPFLGAIN = 0x1bc, AUDIO_ADC_DRC_HHPFC = 0x200, AUDIO_ADC_DRC_LHPFC = 0x204, AUDIO_ADC_DRC_CTRL = 0x208, AUDIO_ADC_DRC_LPFHAT = 0x20c, AUDIO_ADC_DRC_LPFLAT = 0x210, AUDIO_ADC_DRC_RPFHAT = 0x214, AUDIO_ADC_DRC_RPFLAT = 0x218, AUDIO_ADC_DRC_LPFHRT = 0x21c, AUDIO_ADC_DRC_LPFLRT = 0x220, AUDIO_ADC_DRC_RPFHRT = 0x224, AUDIO_ADC_DRC_RPFLRT = 0x228, AUDIO_ADC_DRC_LRMSHAT = 0x22c, AUDIO_ADC_DRC_LRMSLAT = 0x230, AUDIO_ADC_DRC_HCT = 0x23c, AUDIO_ADC_DRC_LCT = 0x240, AUDIO_ADC_DRC_HKC = 0x244, AUDIO_ADC_DRC_LKC = 0x248, AUDIO_ADC_DRC_HOPC = 0x24c, AUDIO_ADC_DRC_LOPC = 0x250, AUDIO_ADC_DRC_HLT = 0x254, AUDIO_ADC_DRC_LLT = 0x258, AUDIO_ADC_DRC_HKI = 0x25c, AUDIO_ADC_DRC_LKI = 0x260, AUDIO_ADC_DRC_HOPL = 0x264, AUDIO_ADC_DRC_LOPL = 0x268, AUDIO_ADC_DRC_HET = 0x26c, AUDIO_ADC_DRC_LET = 0x270, AUDIO_ADC_DRC_HKE = 0x274, AUDIO_ADC_DRC_LKE = 0x278, AUDIO_ADC_DRC_HOPE = 0x27c, AUDIO_ADC_DRC_LOPE = 0x280, AUDIO_ADC_DRC_HKN = 0x284, AUDIO_ADC_DRC_LKN = 0x288, AUDIO_ADC_DRC_SFHAT = 0x28c, AUDIO_ADC_DRC_SFLAT = 0x290, AUDIO_ADC_DRC_SFHRT = 0x294, AUDIO_ADC_DRC_SFLRT = 0x298, AUDIO_ADC_DRC_MXGHS = 0x29c, AUDIO_ADC_DRC_MXGLS = 0x2a0, AUDIO_ADC_DRC_MNGHS = 0x2a4, AUDIO_ADC_DRC_MNGLS = 0x2a8, AUDIO_ADC_DRC_EPSHC = 0x2ac, AUDIO_ADC_DRC_EPSLC = 0x2b0, AUDIO_ADC_DRC_OPT = 0x2b4, AUDIO_ADC_DRC_HPFHGAIN = 0x2b8, AUDIO_ADC_DRC_HPFLGAIN = 0x2bc, AUDIO_ADCL_ANA_CTL = 0x300, AUDIO_DAC_ANA_CTL = 0x310, AUDIO_MICBIAS_ANA_CTL = 0x318, AUDIO_BIAS_ANA_CTL = 0x320, }; struct audio_v831_pdata_t { virtual_addr_t virt; char * clk; int reset; }; static void audio_v831_playback_start(struct audio_t * audio, enum audio_rate_t rate, enum audio_format_t fmt, int ch) { struct audio_v831_pdata_t * pdat = (struct audio_v831_pdata_t *)audio->priv; (void)pdat; } static int audio_v831_playback_write(struct audio_t * audio, void * buf, int len) { return len; } static void audio_v831_playback_stop(struct audio_t * audio) { } static int audio_v831_ioctl(struct audio_t * audio, const char * cmd, void * arg) { return -1; } static struct device_t * audio_v831_probe(struct driver_t * drv, struct dtnode_t * n) { struct audio_v831_pdata_t * pdat; struct audio_t * audio; struct device_t * dev; virtual_addr_t virt = phys_to_virt(dt_read_address(n)); char * clk = dt_read_string(n, "clock-name", NULL); if(!search_clk(clk)) return NULL; pdat = malloc(sizeof(struct audio_v831_pdata_t)); if(!pdat) return NULL; audio = malloc(sizeof(struct audio_t)); if(!audio) { free(pdat); return NULL; } pdat->virt = virt; pdat->clk = strdup(clk); pdat->reset = dt_read_int(n, "reset", -1); audio->name = alloc_device_name(dt_read_name(n), dt_read_id(n)); audio->playback_start = audio_v831_playback_start; audio->playback_write = audio_v831_playback_write; audio->playback_stop = audio_v831_playback_stop; audio->capture_start = NULL; audio->capture_read = NULL; audio->capture_stop = NULL; audio->ioctl = audio_v831_ioctl; audio->priv = pdat; clk_enable(pdat->clk); if(pdat->reset >= 0) reset_deassert(pdat->reset); if(!(dev = register_audio(audio, drv))) { clk_disable(pdat->clk); free(pdat->clk); free_device_name(audio->name); free(audio->priv); free(audio); return NULL; } return dev; } static void audio_v831_remove(struct device_t * dev) { struct audio_t * audio = (struct audio_t *)dev->priv; struct audio_v831_pdata_t * pdat = (struct audio_v831_pdata_t *)audio->priv; if(audio) { unregister_audio(audio); clk_disable(pdat->clk); free(pdat->clk); free_device_name(audio->name); free(audio->priv); free(audio); } } static void audio_v831_suspend(struct device_t * dev) { } static void audio_v831_resume(struct device_t * dev) { } static struct driver_t audio_v831 = { .name = "audio-v831", .probe = audio_v831_probe, .remove = audio_v831_remove, .suspend = audio_v831_suspend, .resume = audio_v831_resume, }; static __init void audio_v831_driver_init(void) { register_driver(&audio_v831); } static __exit void audio_v831_driver_exit(void) { unregister_driver(&audio_v831); } driver_initcall(audio_v831_driver_init); driver_exitcall(audio_v831_driver_exit);
4521bcd511a12c8ddd67adedfca842ea119018e4
d579699e6728aa74084f8cc4dc435007b9f523a8
/data/signatures/stdlib/wctype.h
6ad20b4c0eac9dd3e49e15b11b5a16e1a14dd540
[ "BSD-3-Clause" ]
permissive
BoomerangDecompiler/boomerang
b3c6b4e88c152ac6d437f3dd3640fd9ffa157cb6
411041305f90d1d7c994f67255b5c03ea8666e60
refs/heads/develop
2023-08-31T03:50:56.112711
2020-12-28T12:11:55
2020-12-28T17:38:56
7,819,729
281
41
NOASSERTION
2020-12-27T17:59:52
2013-01-25T12:26:59
C++
UTF-8
C
false
false
611
h
wctype.h
// character classification int iswalnum(wint_t c); int iswalpha(wint_t c); int iswblank(wint_t c); int iswcntrl(wint_t c); int iswdigit(wint_t c); int iswgraph(wint_t c); int iswlower(wint_t c); int iswprint(wint_t c); int iswpunct(wint_t c); int iswspace(wint_t c); int iswupper(wint_t c); int iswxdigit(wint_t c); // character conversion wint_t towlower(wint_t c); wint_t towupper(wint_t c); // Extensible classification/conversion functions int iswctype(wint_t c, wctype_t desc); wint_t towctrans(wint_t c, wctrans_t desc); wctrans_t wctrans(const char *property); wctype_t wctype(const char *property);