Skip to content

Instantly share code, notes, and snippets.

@Lovesan
Lovesan / simd-pack-single.lisp
Last active March 15, 2022 05:05
SBCL SSE operations on single-float vectors
(in-package #:sb-vm)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defknown %m128+ ((simd-pack single-float) (simd-pack single-float))
(simd-pack single-float)
(movable foldable flushable always-translatable)
:overwrite-fndb-silently t)
(define-vop (%m128+)
@Lovesan
Lovesan / get-active-object.lisp
Last active March 7, 2020 01:57
usage of bike and cffi libraries for instantiation of active COM objects
(eval-when (:compile-toplevel :load-toplevel :execute)
(cffi:define-foreign-library oleaut32
(t "oleaut32.dll"))
(cffi:use-foreign-library oleaut32))
(cffi:defcfun ("GetActiveObject"
%get-active-object
:library oleaut32
@Lovesan
Lovesan / sb-net-core-crash.lisp
Created July 1, 2019 16:12
A test case for the issue of SBCL crashes should it load .Net Core runtime on Linux
;;; This file reproduces tha fact that SBCL crashes
;;; while .Net runtime is loaded
;;; .Net Core SDK must be installed
;;; run the file like 'sbcl --script sb-net-core-crash.lisp'
(defun version-compare (left right)
(labels ((parse (c)
;; Given .Net version naming convention,
;; 3.0.0 is actually greater then 3.0.0-rc1
@Lovesan
Lovesan / unwind.lisp
Created June 6, 2019 21:45
SBCL code for testing cross-boundary exceptions
(sb-alien:load-shared-object "unwind.dll")
(sb-alien:define-alien-routine
("catches_fn" catches-fn)
sb-alien:void
(fn (* T)))
(defun sap-to-callable (ptr)
(sb-alien:sap-alien
(sb-alien:alien-sap ptr)
@Lovesan
Lovesan / unwind.cxx
Created June 6, 2019 21:45
A library which throws cross-boundary exceptions
// g++ -O0 -shared -o unwind.dll unwind.cxx
// OR
// cl.exe /nologo /Od /MD /EHa /LD /Fe:unwind.dll unwind.cxx
#include <iostream>
#include <exception>
#include <windows.h>
class Foo
{
public:
@Lovesan
Lovesan / sehtest.lisp
Created June 6, 2019 15:39
SBCL test for SEH-utilizing C++ or .NET library
(sb-alien:load-shared-object "sehlib.dll")
(sb-alien:define-alien-routine
("catches_fn" catches-fn)
sb-alien:void)
(defun test-seh ()
(handler-case
(progn (catches-fn)
(format *error-output*
@Lovesan
Lovesan / sehlib_net.cxx
Created June 6, 2019 15:38
Example .NET library which internally throws an exception and catches it
// cl.exe /nologo /clr /Od /MD /EHac /LD /Fe:sehlib.dll sehlib_net.cxx
using namespace System;
#include <iostream>
void throws_fn()
{
std::cerr << ".NET throws exception" << std::endl;
throw gcnew Exception();
}
@Lovesan
Lovesan / sehlib.cxx
Created June 6, 2019 15:37
Example C++ library which internally throws an exception and catches it
// g++ -O0 -shared -o sehlib.dll sehlib.cxx
// OR
// cl.exe /nologo /Od /MD /EHac /LD /Fe:sehlib.dll sehlib.cxx
#include <iostream>
#include <exception>
void throws_fn()
{
std::cerr << "C++ throws exception" << std::endl;
throw std::exception();
@Lovesan
Lovesan / get-commits.sh
Created March 19, 2019 15:12
Get your commits for a repo
#!/bin/bash
set -e
DATE_START=`date +%Y-%m-01`
DATE_END=`date +%Y-%m-%d`
USER_NAME=`git config user.name`
REPO_DIR=`realpath ./`
BRANCH_NAME='origin/master'
if [ -t 0 -a -t 1 ]; then
@Lovesan
Lovesan / ComUtils.hpp
Created April 21, 2017 16:28
COM utils
#ifndef __COM_UTILS_HPP__
#define __COM_UTILS_HPP__
#include <oleidl.h>
template<class T>
class ComPtr
{
public:
ComPtr()