This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Regexdispatcher #1944
Merged
markus2330
merged 40 commits into
ElektraInitiative:master
from
e1528532:regexdispatcher
Jun 8, 2018
Merged
Regexdispatcher #1944
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
aae608b
haskell-cmake-improvements: add release note
e1528532 78fe8ba
haskell-cmake-improvements: adjust the release notes to expected format
e1528532 91c2807
typechecker-regex-prototype: improve/finish cmake packaging process, …
e1528532 0546bd0
typechecker-regex-prototype: improve build process; avoid artifacts i…
e1528532 2ef3869
typechecker-regex-prototype: require hint 0.7.0 or it fails on stretch
e1528532 d1c8684
typechecker-regex-prototype: fix/unify sandbox handling
e1528532 1657d17
regexdispatcher: add first draft of the plugin
e1528532 3c4f964
regexdispatcher: finish range dispatcher
e1528532 61e7d66
regexdispatcher: adjust typechecker to dispatched regexes
e1528532 26aa49a
regexdispatcher: add dispatcher for enum checks
e1528532 4fb298b
regexdispatcher: add travis test
e1528532 9c1e001
regexdispatcher: fix compilation on linux
e1528532 9e72ede
regexdispatcher: reformat cmake
e1528532 4bf7de5
regexdispatcher: mount along typechecker
e1528532 0583114
regexdispatcher: fix adjusted typechecker example
e1528532 58d972a
regexdispatcher: rebase fixies
e1528532 fccad52
regexdispatcher: adjust cabal file
e1528532 3b241c9
regexdispatcher: prepare for new prelude loading implementation
e1528532 3b48a98
regexdispatcher: add invoke bindings for alternative prelude handling
e1528532 c33660b
regexdispatcher: prepare typechecker for alternate prelude handling
e1528532 1ff9e34
regexdispatcher: use invoke now for prelude loading to avoid kdbOpen …
e1528532 6130545
regexdispatcher: bindings are implicitly included with new cmake system
e1528532 53e1f4a
regexdispatcher: greatly improve plugin data plumbing to avoid messin…
e1528532 0cb37dd
regexdispatcher: invoke in open/close, store plugin data
e1528532 2eac7e4
regexdispatcher: fix type signature in prelude
e1528532 00c6af9
regexdispatcher: update release notes
e1528532 66c6de3
regexdispatcher: adjust ifKey and whenKey syntax to how its normally …
e1528532 4d93782
regexdispatcher: add validation support
e1528532 5e39fda
regexdispatcher: correct order & minimize inversion results
e1528532 2bbf2c2
regexdispatcher: small simplification
e1528532 f9ce3e0
regexdispatcher: adjust rebase issue
e1528532 98b38fd
regexdispatcher: add validation example to typechecker
e1528532 efa7502
regexdispatcher: remove ununsed function
e1528532 0dd7dca
regexdispatcher: use raw pointers directly, figure out segfaults
e1528532 96be930
regexdispatcher: fix plugin data handling in combination with pluginp…
e1528532 176a63a
regexdispatcher: correct case of file
e1528532 9bee5b1
regexdispatcher: fix case #2
e1528532 8c05f4a
regexdispatcher: resolve the review comments
e1528532 0f75668
regexdispatcher: use check/validation metakey for generated regexes
e1528532 e589848
regexdispatcher: add usedby to check/validation metadata
e1528532 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
-- | ||
-- @file | ||
-- | ||
-- @brief Haskell bindings for libelektra-invoke | ||
-- | ||
-- @copyright BSD License (see LICENSE.md or https://www.libelektra.org) | ||
-- | ||
module Elektra.Invoke ( | ||
InvokeFunction, | ||
elektraInvokeOpen, elektraInvokeGetFunction, | ||
elektraInvokeGetPluginConfig, elektraInvokeGetPluginName, elektraInvokeGetPluginData, elektraInvokeGetModules, | ||
elektraInvokeGetExports, elektraInvoke2Args, elektraInvokeClose, | ||
ifHandle | ||
) where | ||
|
||
{#import Elektra.Key #} | ||
{#import Elektra.KeySet #} | ||
{#import Elektra.Plugin #} | ||
|
||
import Data.Maybe (maybe) | ||
import Foreign.Ptr (Ptr, castPtr, nullPtr) | ||
import Foreign.ForeignPtr (withForeignPtr, newForeignPtr_) | ||
|
||
#include <kdbinvoke.h> | ||
|
||
{#pointer *ElektraInvokeHandle newtype #} | ||
type InvokeFunction = Ptr () | ||
|
||
-- Handles are already pointers, so just cast them from/to void pointers | ||
instance PluginData ElektraInvokeHandle where | ||
store a (ElektraInvokeHandle p) = a $ castPtr p | ||
retrieve p = if p == nullPtr then Nothing else (Just . ElektraInvokeHandle $ castPtr p) | ||
|
||
ifHandle :: IO a -> (ElektraInvokeHandle -> IO a) -> ElektraInvokeHandle -> IO a | ||
ifHandle f t h@(ElektraInvokeHandle p) = if p == nullPtr then f else t h | ||
|
||
-- *** | ||
-- Invoke METHODS | ||
-- *** | ||
|
||
elektraInvokeOpen :: String -> Maybe KeySet -> Maybe Key -> IO ElektraInvokeHandle | ||
elektraInvokeOpen elektraPluginName config errorKey = do | ||
c <- maybe (ksNew 0) return config | ||
e <- maybe (keyNew "") return errorKey | ||
elektraInvokeOpenRaw elektraPluginName c e | ||
{#fun unsafe elektraInvokeOpen as elektraInvokeOpenRaw {`String', `KeySet', `Key'} -> `ElektraInvokeHandle' #} | ||
|
||
{#fun unsafe elektraInvokeGetFunction {`ElektraInvokeHandle', `String'} -> `InvokeFunction' return* #} | ||
{#fun unsafe elektraInvokeGetPluginConfig {`ElektraInvokeHandle'} -> `KeySet' #} | ||
{#fun unsafe elektraInvokeGetPluginName {`ElektraInvokeHandle'} -> `String' #} | ||
elektraInvokeGetPluginData :: PluginData d => ElektraInvokeHandle -> IO (Maybe d) | ||
elektraInvokeGetPluginData h = retrieve <$> elektraInvokeGetPluginDataRaw h | ||
{#fun unsafe elektraInvokeGetPluginData as elektraInvokeGetPluginDataRaw {`ElektraInvokeHandle'} -> `Ptr ()' return* #} | ||
{#fun unsafe elektraInvokeGetModules {`ElektraInvokeHandle'} -> `KeySet' #} | ||
{#fun unsafe elektraInvokeGetExports {`ElektraInvokeHandle'} -> `KeySet' #} | ||
{#fun unsafe elektraInvoke2Args {`ElektraInvokeHandle', `String', `KeySet', `Key'} -> `Int' #} | ||
|
||
elektraInvokeClose :: ElektraInvokeHandle -> Maybe Key -> IO () | ||
elektraInvokeClose handle errorKey = do | ||
e <- maybe (keyNew "") return errorKey | ||
elektraInvokeCloseRaw handle e | ||
{#fun unsafe elektraInvokeClose as elektraInvokeCloseRaw {`ElektraInvokeHandle',`Key'} -> `()' #} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- | ||
-- @file | ||
-- | ||
-- @brief PluginProcess Haskell bindings | ||
-- | ||
-- @copyright BSD License (see LICENSE.md or https://www.libelektra.org) | ||
-- | ||
module Elektra.PluginProcess ( | ||
elektraPluginProcessGetData, | ||
elektraPluginProcessSetData | ||
) where | ||
|
||
{#import Elektra.Plugin#} | ||
{#import Elektra.Invoke#} | ||
|
||
import Foreign.Ptr (Ptr) | ||
|
||
#include <kdbpluginprocess.h> | ||
|
||
-- *** | ||
-- PLUGINPROCESS METHODS | ||
-- *** | ||
|
||
elektraPluginProcessSetData :: PluginData d => Plugin -> d -> IO () | ||
elektraPluginProcessSetData p = store (elektraPluginProcessSetDataRaw p) | ||
{#fun unsafe elektraPluginProcessSetData as elektraPluginProcessSetDataRaw {`Plugin', `Ptr ()'} -> `()' #} | ||
|
||
elektraPluginProcessGetData :: PluginData d => Plugin -> IO (Maybe d) | ||
elektraPluginProcessGetData p = retrieve <$> elektraPluginProcessGetDataRaw p | ||
{#fun unsafe elektraPluginProcessGetData as elektraPluginProcessGetDataRaw {`Plugin'} -> `Ptr ()' #} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ struct _ElektraPluginProcess | |
int pid; | ||
int counter; | ||
ElektraInvokeHandle * dump; | ||
void * pluginData; | ||
}; | ||
|
||
static void cleanupPluginData (ElektraPluginProcess * pp, Key * errorKey) | ||
|
@@ -333,6 +334,7 @@ ElektraPluginProcess * elektraPluginProcessInit (Key * errorKey) | |
pp->resultPipe = getPipename (pp->pipeDirectory, "/result"); | ||
pp->dump = elektraInvokeOpen ("dump", 0, errorKey); | ||
pp->counter = 0; | ||
pp->pluginData = NULL; | ||
|
||
if (pp->pipeDirectory && pp->commandPipe && pp->resultPipe && pp->dump) | ||
{ | ||
|
@@ -401,3 +403,34 @@ int elektraPluginProcessClose (ElektraPluginProcess * pp, Key * errorKey) | |
if (done) cleanupPluginData (pp, errorKey); | ||
return done; | ||
} | ||
|
||
/** Store a pointer to any plugin related data that is being executed inside an own process. | ||
* | ||
* @param plugin a pointer to the plugin | ||
* @param data the pointer to the data | ||
*/ | ||
void elektraPluginProcessSetData (Plugin * handle, void * data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this serialized and sent to the other process? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not, the proxied plugins just run in the child process and on linux it seems to share the memory between the parent and the child process. Thus if the child sets any plugin data directly, this would override the plugin data of the parent process, causing the pluginprocess library to fail. |
||
{ | ||
ElektraPluginProcess * pp = elektraPluginGetData (handle); | ||
if (pp) | ||
{ | ||
pp->pluginData = data; | ||
} | ||
} | ||
|
||
/** Get a pointer to any plugin related data stored before. | ||
* | ||
* If elektraPluginProcessSetData was not called earlier, NULL will be returned. | ||
* | ||
* @param plugin a pointer to the plugin | ||
* @retval a pointer to the data | ||
*/ | ||
void * elektraPluginProcessGetData (Plugin * handle) | ||
{ | ||
ElektraPluginProcess * pp = elektraPluginGetData (handle); | ||
if (pp) | ||
{ | ||
return pp->pluginData; | ||
} | ||
return NULL; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts about the metadata name:
And wouldn't it be better that we only have a single metadata and the regex is always merged together? Do you need the information of where the regex comes from?
What was the idea of giving this name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. as the regexdispatcher does all the preprocessing this essentially yields a check/validation keyword in the end all the time, so in that case i don't need further information where it came from i think. i will try that idea out.