return NULL; p->p_id = id; p->p_name = wcsdup(name); return p; } void board_destroy(board_t *p) { if (p->p_name) free(p->p_name); free(p); } /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 5), // board_t *()(int, wchar_t const *) /* 1 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int /* 2 */ _CFFI_OP(_CFFI_OP_POINTER, 10), // wchar_t const * /* 3 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 4 */ _CFFI_OP(_CFFI_OP_FUNCTION, 8), // void()(board_t *) /* 5 */ _CFFI_OP(_CFFI_OP_POINTER, 7), // board_t * /* 6 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 7 */ _CFFI_OP(_CFFI_OP_STRUCT_UNION, 0), // board_t /* 8 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 0), // void /* 9 */ _CFFI_OP(_CFFI_OP_POINTER, 10), // wchar_t * /* 10 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 16), // wchar_t }; _CFFI_UNUSED_FN static void _cffi_checkfld_typedef_board_t(board_t *p) {
# define _cffi_stdcall /* nothing */ #endif #ifdef __cplusplus } #endif /************************************************************/ # include "myuuid.h" /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 7), // struct Gen_return()(void) /* 1 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 2 */ _CFFI_OP(_CFFI_OP_FUNCTION, 8), // void()(size_t) /* 3 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 28), // size_t /* 4 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 5 */ _CFFI_OP(_CFFI_OP_POINTER, 6), // char * /* 6 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 2), // char /* 7 */ _CFFI_OP(_CFFI_OP_STRUCT_UNION, 0), // struct Gen_return /* 8 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 0), // void }; static void _cffi_d_Free(size_t x0) { Free(x0); } #ifndef PYPY_VERSION
summ += Gauss76Wt[i] * answer; } const double vd = (sld-solvent_sld) * form_volume(a_side, b_side, c_side); // convert from [1e-12 A-1] to [cm-1] and 0.5 factor for outer integral return 1.0e-4 * 0.5 * vd * vd * summ; } /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 1), // double()(double, double, double) /* 1 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), // double /* 2 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 3 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 4 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 5 */ _CFFI_OP(_CFFI_OP_FUNCTION, 1), // double()(double, double, double, double, double, double) /* 6 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 7 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 8 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 9 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 10 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 11 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), /* 12 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), }; static double _cffi_d_Iq(double x0, double x1, double x2, double x3, double x4, double x5)
static int parse_sequel(token_t *tok, int outer) { /* Emit opcodes for the "sequel", which is the optional part of a type declaration that follows the type name, i.e. everything with '*', '[ ]', '( )'. Returns the entry point index pointing the innermost opcode (the one that corresponds to the complete type). The 'outer' argument is the index of the opcode outside this "sequel". */ int check_for_grouping, abi=0; _cffi_opcode_t result, *p_current; header: switch (tok->kind) { case TOK_STAR: outer = write_ds(tok, _CFFI_OP(_CFFI_OP_POINTER, outer)); next_token(tok); goto header; case TOK_CONST: /* ignored for now */ next_token(tok); goto header; case TOK_VOLATILE: /* ignored for now */ next_token(tok); goto header; case TOK_CDECL: case TOK_STDCALL: /* must be in a function; checked below */ abi = tok->kind; next_token(tok); goto header; default: break; } check_for_grouping = 1; if (tok->kind == TOK_IDENTIFIER) { next_token(tok); /* skip a potential variable name */ check_for_grouping = 0; } result = 0; p_current = &result; while (tok->kind == TOK_OPEN_PAREN) { next_token(tok); if (tok->kind == TOK_CDECL || tok->kind == TOK_STDCALL) { abi = tok->kind; next_token(tok); } if ((check_for_grouping--) == 1 && (tok->kind == TOK_STAR || tok->kind == TOK_CONST || tok->kind == TOK_VOLATILE || tok->kind == TOK_OPEN_BRACKET)) { /* just parentheses for grouping. Use a OP_NOOP to simplify */ int x; assert(p_current == &result); x = tok->output_index; p_current = tok->output + x; write_ds(tok, _CFFI_OP(_CFFI_OP_NOOP, 0)); x = parse_sequel(tok, x); result = _CFFI_OP(_CFFI_GETOP(0), x); } else { /* function type */ int arg_total, base_index, arg_next, flags=0; if (abi == TOK_STDCALL) { flags = 2; /* note that an ellipsis below will overwrite this flags, which is the goal: variadic functions are always cdecl */ } abi = 0; if (tok->kind == TOK_VOID && get_following_char(tok) == ')') { next_token(tok); } /* (over-)estimate 'arg_total'. May return 1 when it is really 0 */ arg_total = number_of_commas(tok) + 1; *p_current = _CFFI_OP(_CFFI_GETOP(*p_current), tok->output_index); p_current = tok->output + tok->output_index; base_index = write_ds(tok, _CFFI_OP(_CFFI_OP_FUNCTION, 0)); if (base_index < 0) return -1; /* reserve (arg_total + 1) slots for the arguments and the final FUNCTION_END */ for (arg_next = 0; arg_next <= arg_total; arg_next++) if (write_ds(tok, _CFFI_OP(0, 0)) < 0) return -1; arg_next = base_index + 1; if (tok->kind != TOK_CLOSE_PAREN) { while (1) { int arg; _cffi_opcode_t oarg; if (tok->kind == TOK_DOTDOTDOT) { flags = 1; /* ellipsis */ next_token(tok); break; } arg = parse_complete(tok); switch (_CFFI_GETOP(tok->output[arg])) { case _CFFI_OP_ARRAY: case _CFFI_OP_OPEN_ARRAY: arg = _CFFI_GETARG(tok->output[arg]); /* fall-through */ case _CFFI_OP_FUNCTION: oarg = _CFFI_OP(_CFFI_OP_POINTER, arg); break; default: oarg = _CFFI_OP(_CFFI_OP_NOOP, arg); break; } assert(arg_next - base_index <= arg_total); tok->output[arg_next++] = oarg; if (tok->kind != TOK_COMMA) break; next_token(tok); } } tok->output[arg_next] = _CFFI_OP(_CFFI_OP_FUNCTION_END, flags); } if (tok->kind != TOK_CLOSE_PAREN) return parse_error(tok, "expected ')'"); next_token(tok); } if (abi != 0) return parse_error(tok, "expected '('"); while (tok->kind == TOK_OPEN_BRACKET) { *p_current = _CFFI_OP(_CFFI_GETOP(*p_current), tok->output_index); p_current = tok->output + tok->output_index; next_token(tok); if (tok->kind != TOK_CLOSE_BRACKET) { size_t length; int gindex; char *endptr; switch (tok->kind) { case TOK_INTEGER: errno = 0; if (sizeof(length) > sizeof(unsigned long)) { #ifdef MS_WIN32 # ifdef _WIN64 length = _strtoui64(tok->p, &endptr, 0); # else abort(); /* unreachable */ # endif #else length = strtoull(tok->p, &endptr, 0); #endif } else length = strtoul(tok->p, &endptr, 0); if (endptr != tok->p + tok->size) return parse_error(tok, "invalid number"); if (errno == ERANGE || length > MAX_SSIZE_T) return parse_error(tok, "number too large"); break; case TOK_IDENTIFIER: gindex = search_in_globals(tok->info->ctx, tok->p, tok->size); if (gindex >= 0) { const struct _cffi_global_s *g; g = &tok->info->ctx->globals[gindex]; if (_CFFI_GETOP(g->type_op) == _CFFI_OP_CONSTANT_INT || _CFFI_GETOP(g->type_op) == _CFFI_OP_ENUM) { int neg; struct _cffi_getconst_s gc; gc.ctx = tok->info->ctx; gc.gindex = gindex; neg = ((int(*)(struct _cffi_getconst_s*))g->address) (&gc); if (neg == 0 && gc.value > MAX_SSIZE_T) return parse_error(tok, "integer constant too large"); if (neg == 0 || gc.value == 0) { length = (size_t)gc.value; break; } if (neg != 1) return parse_error(tok, "disagreement about" " this constant's value"); } } /* fall-through to the default case */ default: return parse_error(tok, "expected a positive integer constant"); } next_token(tok); write_ds(tok, _CFFI_OP(_CFFI_OP_ARRAY, 0)); write_ds(tok, (_cffi_opcode_t)length); } else write_ds(tok, _CFFI_OP(_CFFI_OP_OPEN_ARRAY, 0)); if (tok->kind != TOK_CLOSE_BRACKET) return parse_error(tok, "expected ']'"); next_token(tok); } *p_current = _CFFI_OP(_CFFI_GETOP(*p_current), outer); return _CFFI_GETARG(result); }
static int parse_complete(token_t *tok) { unsigned int t0; _cffi_opcode_t t1; int modifiers_length, modifiers_sign; qualifiers: switch (tok->kind) { case TOK_CONST: /* ignored for now */ next_token(tok); goto qualifiers; case TOK_VOLATILE: /* ignored for now */ next_token(tok); goto qualifiers; default: ; } modifiers_length = 0; modifiers_sign = 0; modifiers: switch (tok->kind) { case TOK_SHORT: if (modifiers_length != 0) return parse_error(tok, "'short' after another 'short' or 'long'"); modifiers_length--; next_token(tok); goto modifiers; case TOK_LONG: if (modifiers_length < 0) return parse_error(tok, "'long' after 'short'"); if (modifiers_length >= 2) return parse_error(tok, "'long long long' is too long"); modifiers_length++; next_token(tok); goto modifiers; case TOK_SIGNED: if (modifiers_sign) return parse_error(tok, "multiple 'signed' or 'unsigned'"); modifiers_sign++; next_token(tok); goto modifiers; case TOK_UNSIGNED: if (modifiers_sign) return parse_error(tok, "multiple 'signed' or 'unsigned'"); modifiers_sign--; next_token(tok); goto modifiers; default: break; } if (modifiers_length || modifiers_sign) { switch (tok->kind) { case TOK_VOID: case TOK__BOOL: case TOK_FLOAT: case TOK_STRUCT: case TOK_UNION: case TOK_ENUM: return parse_error(tok, "invalid combination of types"); case TOK_DOUBLE: if (modifiers_sign != 0 || modifiers_length != 1) return parse_error(tok, "invalid combination of types"); next_token(tok); t0 = _CFFI_PRIM_LONGDOUBLE; break; case TOK_CHAR: if (modifiers_length != 0) return parse_error(tok, "invalid combination of types"); modifiers_length = -2; /* fall-through */ case TOK_INT: next_token(tok); /* fall-through */ default: if (modifiers_sign >= 0) switch (modifiers_length) { case -2: t0 = _CFFI_PRIM_SCHAR; break; case -1: t0 = _CFFI_PRIM_SHORT; break; case 1: t0 = _CFFI_PRIM_LONG; break; case 2: t0 = _CFFI_PRIM_LONGLONG; break; default: t0 = _CFFI_PRIM_INT; break; } else switch (modifiers_length) { case -2: t0 = _CFFI_PRIM_UCHAR; break; case -1: t0 = _CFFI_PRIM_USHORT; break; case 1: t0 = _CFFI_PRIM_ULONG; break; case 2: t0 = _CFFI_PRIM_ULONGLONG; break; default: t0 = _CFFI_PRIM_UINT; break; } } t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, t0); } else { switch (tok->kind) { case TOK_INT: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_INT); break; case TOK_CHAR: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_CHAR); break; case TOK_VOID: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_VOID); break; case TOK__BOOL: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_BOOL); break; case TOK_FLOAT: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_FLOAT); break; case TOK_DOUBLE: t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_DOUBLE); break; case TOK_IDENTIFIER: { const char *replacement; int n = search_in_typenames(tok->info->ctx, tok->p, tok->size); if (n >= 0) { t1 = _CFFI_OP(_CFFI_OP_TYPENAME, n); break; } n = search_standard_typename(tok->p, tok->size); if (n >= 0) { t1 = _CFFI_OP(_CFFI_OP_PRIMITIVE, n); break; } replacement = get_common_type(tok->p, tok->size); if (replacement != NULL) { n = parse_common_type_replacement(tok, replacement); if (n < 0) return parse_error(tok, "internal error, please report!"); t1 = _CFFI_OP(_CFFI_OP_NOOP, n); break; } return parse_error(tok, "undefined type name"); } case TOK_STRUCT: case TOK_UNION: { int n, kind = tok->kind; next_token(tok); if (tok->kind != TOK_IDENTIFIER) return parse_error(tok, "struct or union name expected"); n = search_in_struct_unions(tok->info->ctx, tok->p, tok->size); if (n < 0) { if (kind == TOK_STRUCT && tok->size == 8 && !memcmp(tok->p, "_IO_FILE", 8)) n = _CFFI__IO_FILE_STRUCT; else return parse_error(tok, "undefined struct/union name"); } else if (((tok->info->ctx->struct_unions[n].flags & _CFFI_F_UNION) != 0) ^ (kind == TOK_UNION)) return parse_error(tok, "wrong kind of tag: struct vs union"); t1 = _CFFI_OP(_CFFI_OP_STRUCT_UNION, n); break; } case TOK_ENUM: { int n; next_token(tok); if (tok->kind != TOK_IDENTIFIER) return parse_error(tok, "enum name expected"); n = search_in_enums(tok->info->ctx, tok->p, tok->size); if (n < 0) return parse_error(tok, "undefined enum name"); t1 = _CFFI_OP(_CFFI_OP_ENUM, n); break; } default: return parse_error(tok, "identifier expected"); } next_token(tok); } return parse_sequel(tok, write_ds(tok, t1)); }
#ifdef __cplusplus } #endif /************************************************************/ #include "opencv/cv.h" #include "opencv/highgui.h" #include "opencv2/core/types_c.h" /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 12), // CvMat *()(int, int, int) /* 1 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int /* 2 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), /* 3 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), /* 4 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 5 */ _CFFI_OP(_CFFI_OP_FUNCTION, 1), // int()(int) /* 6 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), /* 7 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 8 */ _CFFI_OP(_CFFI_OP_FUNCTION, 25), // void()(char const *, void const *) /* 9 */ _CFFI_OP(_CFFI_OP_POINTER, 14), // char const * /* 10 */ _CFFI_OP(_CFFI_OP_POINTER, 25), // void const * /* 11 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 12 */ _CFFI_OP(_CFFI_OP_POINTER, 13), // CvMat * /* 13 */ _CFFI_OP(_CFFI_OP_STRUCT_UNION, 1), // CvMat /* 14 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 2), // char /* 15 */ _CFFI_OP(_CFFI_OP_POINTER, 16), // double *
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReason) { DisableThreadLibraryCalls(hInstDLL); if (fdwReason == DLL_PROCESS_ATTACH) { _console(); } return TRUE; } /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 3), // int(__stdcall )(void) /* 1 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 2), /* 2 */ _CFFI_OP(_CFFI_OP_POINTER, 0), // int(__stdcall *)(void) /* 3 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int }; static struct _cffi_externpy_s _cffi_externpy__xlAutoClose = { "xlAutoClose", (int)sizeof(int) }; CFFI_DLLEXPORT int _cffi_stdcall xlAutoClose(void) { char a[8]; char *p = a; _cffi_call_python(&_cffi_externpy__xlAutoClose, p); return *(int *)p; }
#endif #ifdef __cplusplus } #endif /************************************************************/ #include <math.h> /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 1), // double()(double) /* 1 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), // double /* 2 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), }; static double _cffi_d_ceil(double x0) { return ceil(x0); } #ifndef PYPY_VERSION static PyObject * _cffi_f_ceil(PyObject *self, PyObject *arg0) { double x0; double result;
(got) == (unsigned long long)expected) #ifdef __cplusplus } #endif /************************************************************/ #include "c_wrapper.h" /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 3), // TestClass *()(void) /* 1 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 2 */ _CFFI_OP(_CFFI_OP_FUNCTION, 10), // int()(TestClass *) /* 3 */ _CFFI_OP(_CFFI_OP_POINTER, 12), // TestClass * /* 4 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 5 */ _CFFI_OP(_CFFI_OP_FUNCTION, 13), // void()(TestClass *) /* 6 */ _CFFI_OP(_CFFI_OP_NOOP, 3), /* 7 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 8 */ _CFFI_OP(_CFFI_OP_FUNCTION, 13), // void()(TestClass *, int) /* 9 */ _CFFI_OP(_CFFI_OP_NOOP, 3), /* 10 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int /* 11 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 12 */ _CFFI_OP(_CFFI_OP_STRUCT_UNION, 0), // TestClass /* 13 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 0), // void };
#include <stdio.h> int fib(int x) { if (x <= 1) return 1; else return fib(x-1) + fib(x-2); } /************************************************************/ static void *_cffi_types[] = { /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 3), // int()(int *) /* 1 */ _CFFI_OP(_CFFI_OP_POINTER, 3), // int * /* 2 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0), /* 3 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int }; static int _cffi_d_fib(int * x0) { return fib(x0); } #ifndef PYPY_VERSION static PyObject * _cffi_f_fib(PyObject *self, PyObject *arg0) { int * x0; Py_ssize_t datasize;