1 /*
   2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "struct.h"
  25 #include <stdio.h>
  26 #include <stdlib.h>
  27 
  28 EXPORT char* LastCalledMethod;
  29 
  30 struct UndefinedStruct {
  31     int x;
  32     int y;
  33 };
  34 
  35 struct UndefinedStructForPointer {
  36     UndefinedStruct position;
  37     UndefinedStructPointer parent;
  38     UndefinedStructPointer firstChild;
  39     struct UndefinedStructForPointer *left;
  40     UndefinedStructPointer right;
  41     struct Opaque *data;
  42 };
  43 
  44 struct Opaque {
  45     int size;
  46     char *data;
  47 };
  48 
  49 EXPORT UndefinedStruct* allocateUndefinedStruct() {
  50     UndefinedStruct *p = malloc(sizeof(UndefinedStruct));
  51     p->x = 0x1234;
  52     p->y = 0x3412;
  53     return p;
  54 }
  55 
  56 EXPORT struct Plain fromUndefinedStruct(UndefinedStruct *p) {
  57     return *((struct Plain*) p);
  58 }
  59 
  60 // intentionally mismatch prototype with same type
  61 EXPORT UndefinedStructPointer getParent(struct UndefinedStructForPointer * node) {
  62     return node->parent;
  63 }
  64 
  65 // intentionally mismatch prototype with same type
  66 EXPORT UndefinedStructPointer getSibling(UndefinedStructPointer node) {
  67     return node->right;
  68 }
  69 
  70 EXPORT UndefinedStructPointer getFirstChild(struct UndefinedStructForPointer *node) {
  71     return node->firstChild;
  72 }
  73 
  74 EXPORT struct Opaque* allocate_opaque_struct() {
  75     return (struct Opaque*) malloc(sizeof(struct Opaque));
  76 }
  77 
  78 EXPORT TypedefAnonymous getAnonymous(TypedefNamedDifferent_t fns, int x, int y) {
  79     TypedefAnonymous s;
  80     s.x = x;
  81     s.y = y;
  82     s.l = fns.fn(x, y);
  83 
  84     return s;
  85 }
  86 
  87 EXPORT void emptyArguments() {
  88     LastCalledMethod = "emptyArguments";
  89     printf("%s\n", LastCalledMethod);
  90 }
  91 
  92 EXPORT void voidArguments(void) {
  93     LastCalledMethod = "voidArguments";
  94     printf("%s\n", LastCalledMethod);
  95 }
  96 
  97 EXPORT void* FunctionWithVoidPointer(void *data, void **array_data) {
  98     return NULL;
  99 }