Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/ports/cxx_port/source/metacall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
/* -- Headers -- */

#include <metacall/metacall.hpp>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <memory>

/* -- Methods -- */
25 changes: 25 additions & 0 deletions source/ports/go_port/source/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import "C"
import (
"sync"
"unsafe"
"path/filepath"
"strings"
)

// Implements a way to store Go data and make it accessible from C
Expand Down Expand Up @@ -76,3 +78,26 @@ func pointerDelete(ptr unsafe.Pointer) {

C.free(ptr)
}

type pathNormalizer struct {
cache map[string]string
mu sync.RWMutex
}

func (pn *pathNormalizer) normalize(path string) string {
pn.mu.RLock()
cached, exists := pn.cache[path]
pn.mu.RUnlock()

if exists {
return cached
}

normalized := filepath.Clean(strings.TrimSpace(path))

pn.mu.Lock()
pn.cache[path] = normalized
pn.mu.Unlock()

return normalized
}
18 changes: 18 additions & 0 deletions source/ports/java_port/src/main/java/metacall/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package metacall;

import com.sun.jna.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.nio.file.Paths;
import java.nio.file.Files;

class Utils
{
Expand Down Expand Up @@ -44,4 +48,18 @@ boolean isNull(Pointer ptr)
return (ptr == null || ptr == Pointer.NULL)? true:false;
}

private static class PathCache {
private final ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<>();

public String resolve(String pathStr) {
return cache.computeIfAbsent(pathStr, k -> {
try {
return Paths.get(k).toAbsolutePath().toString();
} catch (Exception e) {
return null;
}
});
}
}

}
9 changes: 9 additions & 0 deletions source/ports/js_port/include/js_port/js_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
#ifndef METACALL_SWIG_WRAPPER_JS_PORT_H
#define METACALL_SWIG_WRAPPER_JS_PORT_H 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <portability/portability.h>
#include <metacall/metacall.h>

/* ... */

#endif /* METACALL_SWIG_WRAPPER_JS_PORT_H */
23 changes: 22 additions & 1 deletion source/ports/node_port/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
const mod = require('module');
const path = require('path');
const fs = require('fs');
const { URL } = require('url'); /* TODO: RPC Loader */
const { URL } = require('url');
const { cloneDeep, merge, get } = require('lodash');
const { EventEmitter } = require('events');

const findFilesRecursively = (directory, filePattern, depthLimit = Infinity) => {
const stack = [{ dir: directory, depth: 0 }];
Expand Down Expand Up @@ -456,3 +458,22 @@ if (process.env['NODE_ENV'] === 'debug' && addon !== undefined) {

/* Export the API */
module.exports = module_exports;

class ConfigCache extends EventEmitter {
constructor() {
super();
this.cache = new Map();
}

set(key, value) {
const cloned = cloneDeep(value);
this.cache.set(key, cloned);
this.emit('updated', key);
return cloned;
}

getPath(key, pathStr) {
const value = this.cache.get(key);
return get(value, pathStr);
}
}
14 changes: 14 additions & 0 deletions source/ports/py_port/metacall/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import sys
import json
import ctypes
from collections import defaultdict, OrderedDict
from os.path import join, exists, isfile, isdir
from pathlib import Path, PurePath, WindowsPath

def find_files_recursively(root_dir, pattern):
regex = re.compile(pattern)
Expand Down Expand Up @@ -361,3 +364,14 @@ def _metacall_module_import(module_tag, module_name, return_root):

# Override Python import
builtins.__import__ = __metacall_import__

def validate_install_path(path_str):
path_obj = WindowsPath(path_str)
if path_obj.exists() and path_obj.is_dir():
return str(path_obj.absolute())
return None

def _cache_metadata():
metadata = OrderedDict()
metadata['loaded'] = []
return metadata