Skip to content

Commit

Permalink
#12 Added MWE for simple plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaceresb committed Feb 23, 2023
1 parent 1a1a69d commit fb251a2
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/issues/gh12/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
ifeq ($(OS),Windows_NT)
OSFLAGS = -shared -fPIC
GCC = x86_64-w64-mingw32-gcc.exe
TEST_OUT = src/build/honesttest_windows.plugin
else
ifeq ($(UNAME_S),Linux)
GCC = gcc
OSFLAGS = -shared -fPIC -DSYSTEM=OPUNIX
TEST_OUT = honesttest_unix.plugin
endif
ifeq ($(UNAME_S),Darwin)
GCC = clang
OSFLAGS = -bundle -DSYSTEM=APPLEMAC
ifeq ($(UNAME_M),x86_64)
TEST_OUT = honesttest_macosx86_64.plugin
endif
ifeq ($(UNAME_M),arm64)
TEST_OUT = honesttest_macosxarm64.plugin
endif
endif
endif
CFLAGS = -O3 -Wall $(OSFLAGS)

all: clean honesttest

honesttest: honesttest.c stplugin.c
$(GCC) $(CFLAGS) $^ -o $(TEST_OUT)

.PHONY: clean
clean:
rm -f $(TEST_OUT)
8 changes: 8 additions & 0 deletions src/issues/gh12/honesttest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "stplugin.h"
#include "honesttest.h"

STDLL stata_call(int argc, char *argv[])
{
SF_display("Hello World\n");
return(0);
}
8 changes: 8 additions & 0 deletions src/issues/gh12/honesttest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef HONESTTEST
#define HONESTTEST

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#endif
14 changes: 14 additions & 0 deletions src/issues/gh12/stplugin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
stplugin.c, version 3.0
copyright (c) 2003, 2006, 2015 StataCorp LP
*/

#include "stplugin.h"

ST_plugin *_stata_ ;

STDLL pginit(ST_plugin *p)
{
_stata_ = p ;
return(SD_PLUGINVER) ;
}
246 changes: 246 additions & 0 deletions src/issues/gh12/stplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/*
stplugin.h, version 3.0.0
copyright (c) 2003, 2004, 2006, 2015 StataCorp LP
*/
#if !defined(STPLUGIN_H)
#define STPLUGIN_H

#if !defined(SD_FASTMODE)
#define SD_SAFEMODE
#endif

#define HP9000 1
#define OPUNIX 2
#define APPLEMAC 3
#define STWIN32 4

#ifndef SYSTEM
#define SYSTEM STWIN32
#endif

typedef signed char ST_sbyte ;
typedef unsigned char ST_ubyte ;
typedef int ST_int ;
typedef unsigned ST_unsigned ;
typedef short int ST_int2 ;
typedef int ST_int4 ;
typedef long ST_long ;
typedef unsigned int ST_uint4 ;
typedef float ST_float ;
typedef double ST_double ;
typedef unsigned char ST_boolean ;
typedef int ST_retcode ;
typedef double * ST_dmkey ;

#if !defined(bTrue)
#define bTrue 1
#define bFalse 0
#endif

#define SF_HIWORD(x) ((ST_int2)((ST_int4)(x)>>16))
#define SF_LOWORD(x) ((ST_int2)(x))
#define SF_MAKELONG(x,y) ((ST_int4)(((ST_int2)(x))|((ST_int4)((ST_int2)(y)))<<16))

#if SYSTEM==STWIN32
#if __cplusplus
#define STDLL extern "C" __declspec(dllexport) ST_retcode
#else
#define STDLL extern __declspec(dllexport) ST_retcode
#endif
#endif

#if SYSTEM!=STWIN32
#if SYSTEM==HP9000
#include <dl.h>
#endif

#if SYSTEM==OPUNIX
#include <dlfcn.h>
#endif

#if __cplusplus
#define STDLL extern "C" ST_retcode
#else
#define STDLL ST_retcode
#endif
#define LPSTR char *
#endif

typedef struct {
ST_int type ;
ST_int nel ;
ST_int m ;
ST_int n ;
} ST_matinfo ;

#define SD_PLUGINMAJ 3
#define SD_PLUGINMIN 0
#define SD_PLUGINVER SF_MAKELONG(SD_PLUGINMAJ,SD_PLUGINMIN)

typedef void (* ST_VV) (void) ;
typedef ST_int (* ST_IV) (void) ;
typedef ST_int (* ST_IS) (char *) ;
typedef void (* ST_VU) (ST_ubyte) ;
typedef ST_boolean (* ST_BI) (ST_int) ;
typedef ST_boolean (* ST_BII) (ST_int,ST_int) ;
typedef ST_boolean (* ST_BD) (ST_double) ;
typedef ST_int (* ST_III) (ST_int,ST_int) ;
typedef ST_double (* ST_DII) (ST_int,ST_int) ;
typedef ST_double (* ST_DV) (void) ;
typedef ST_double (* ST_DD) (ST_double) ;
typedef ST_double (* ST_DDD) (ST_double,ST_double) ;
typedef ST_int (* ST_ISS) (char *,char *) ;
typedef ST_int (* ST_ISI) (char *,ST_int) ;
typedef ST_int (* ST_ISSI) (char *,char *,ST_int) ;
typedef void (* ST_VSD) (char *,ST_double) ;
typedef ST_int (* ST_ISD) (char *, ST_double) ;
typedef ST_int (* ST_ISDp) (char *,ST_double *) ;
typedef ST_int (* ST_ISDpIIIII) (char *,ST_int,ST_double *,ST_int,ST_int,ST_int,ST_int,ST_int) ;
typedef ST_int (* ST_ISIID) (char *, ST_int, ST_int, ST_double) ;
typedef ST_int (* ST_ISIIDp) (char *,ST_int,ST_int,ST_double *) ;
typedef ST_int (* ST_ISDpI) (char *,ST_double *,ST_int) ;
typedef void (* ST_VSMip) (char *,ST_matinfo *) ;
typedef ST_int (* ST_IIIDp) (ST_int, ST_int, ST_double *) ;
typedef ST_int (* ST_IIID) (ST_int, ST_int, ST_double) ;
typedef char * (* ST_SSI) (char *,ST_int) ;
typedef char * (* ST_SSSD) (char *,char *,ST_double) ;
typedef char * (* ST_SSSDM) (char *,char *,ST_double, ST_dmkey) ;
typedef ST_int (* ST_IIIS) (ST_int, ST_int, char *) ;
typedef ST_int (* ST_IIISI) (ST_int, ST_int, char *, ST_int) ;

typedef struct {
ST_IS spoutsml ;
ST_IS spoutnosml ;
ST_VV spoutflush ;
ST_VU set_outputlevel ;
ST_ISI get_input ;

ST_IV pollstd ;
ST_IV pollnow ;

ST_SSSD safereforms ;
ST_SSSDM safereforml ;

ST_SSI gettok ;

ST_ISS macresave ;
ST_ISSI macuse ;

ST_ISDp scalaruse ;
ST_ISDp scalarsave ;

ST_ISDpIIIII matrixstore ;
ST_ISDpI matrixload ;
ST_VSMip matrixinfo ;
ST_ISIIDp matrixel ;
ST_int matsize ;

ST_DII data, safedata ;

ST_IV nobs ;
ST_IV nvar ;

ST_double missval ;
ST_BD ismissing ;

ST_ISI stfindvar ;
ST_BI isstr ;
ST_VSD abvarfcn ;

ST_int *stopflag ;

ST_DDD stround ;
ST_DD stsqrt ;
ST_DDD stpow ;
ST_DD stlog ;
ST_DD stexp ;
ST_DV strandom ;

ST_IIID store ;
ST_IIID safestore ;
ST_IIIS sstore ;
ST_BI selobs ;
ST_IV nobs1 ;
ST_IV nobs2 ;
ST_IV nvars ;
ST_IS spouterr ;
ST_ISIIDp safematel ;
ST_ISIID safematstore ;
ST_ISIIDp matel ;
ST_ISIID matstore ;
ST_IIIDp safevdata ;
ST_IIIDp vdata ;
ST_IS colsof ;
ST_IS rowsof ;
ST_ISD scalsave ;

ST_IIIS sdata ;

ST_int2 major ;
ST_int2 minor ;
ST_BI isstrl ;
ST_BII isbinary ;
ST_III sdatalen ;
ST_IIISI strldata ;
} ST_plugin ;


#if __cplusplus
extern "C" ST_plugin *_stata_ ;
#else
extern ST_plugin *_stata_ ;
#endif
STDLL pginit(ST_plugin *p) ;

#define SF_display(a) ((_stata_)->spoutsml((a)))
#define SF_error(a) ((_stata_)->spouterr((a)))

#define SF_poll ((_stata_)->pollstd)
#define SW_stopflag (*((_stata_)->stopflag))

#define SF_macro_save(m,t) ((_stata_)->macresave((m),(t)))
#define SF_macro_use(m,d,l) ((_stata_)->macuse((m),(d),(l)))

#define SF_scal_use(s,d) ((_stata_)->scalaruse((s),(d)))
#define SF_scal_save(s,d) ((_stata_)->scalsave((s),(d)))

#if defined(SD_SAFEMODE)
#define SF_mat_el(s,r,c,d) ((_stata_)->safematel((s),(r),(c),(d)))
#define SF_mat_store(s,r,c,d) ((_stata_)->safematstore((s),(r),(c),(d)))
#else
#define SF_mat_el(s,r,c,d) ((_stata_)->matel((s),(r),(c),(d)))
#define SF_mat_store(s,r,c,d) ((_stata_)->matstore((s),(r),(c),(d)))
#endif
#define SV_matsize ((_stata_)->matsize)
#define SF_col(s) ((_stata_)->colsof((s)))
#define SF_row(s) ((_stata_)->rowsof((s)))

#if defined(SD_SAFEMODE)
#define SF_vdata(i,j,d) ((_stata_)->safevdata((i),(j),(d)))
#define SF_vstore(i,j,v) ((_stata_)->safestore((i),(j),(v)))
#else
#define SF_vdata(i,j,d) ((_stata_)->vdata((i),(j),(d)))
#define SF_vstore(i,j,v) ((_stata_)->store((i),(j),(v)))
#endif

#define SF_nobs ((_stata_)->nobs)
#define SF_in1 ((_stata_)->nobs1)
#define SF_in2 ((_stata_)->nobs2)
#define SF_nvar ((_stata_)->nvar)
#define SF_nvars ((_stata_)->nvars)

#define SF_sstore(i,j,s) ((_stata_)->sstore((i),(j),(s)))
#define SF_sdata(i,j,s) ((_stata_)->sdata((i),(j),(s)))
#define SF_strldata(i,j,s,l) ((_stata_)->strldata((i),(j),(s),(l)))

#define SF_sdatalen(i,j) ((_stata_)->sdatalen((i),(j)))
#define SF_var_is_string(a) ((_stata_)->isstr(a))
#define SF_var_is_strl(a) ((_stata_)->isstrl(a))
#define SF_var_is_binary(i,j) ((_stata_)->isbinary((i),(j)))

#define SV_missval ((_stata_)->missval)

#define SF_is_missing(z) ((_stata_)->ismissing(z))
#define SF_ifobs(z) ((_stata_)->selobs(z))

#endif
12 changes: 12 additions & 0 deletions src/issues/gh12/test.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if ( inlist("`c(os)'", "MacOSX") | strpos("`c(machine_type)'", "Mac") ) {
local c_os_ macosx
}
else {
local c_os_: di lower("`c(os)'")
}

* stata14-mp
cap program drop honesttest
program honesttest, plugin using("honesttest_`c_os_'.plugin")
plugin call honesttest
* exit, clear

0 comments on commit fb251a2

Please sign in to comment.