Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
fixing getcwd
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Sep 16, 2020
1 parent a76268c commit b2ea1b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
3 changes: 3 additions & 0 deletions c/csound_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern int emugens_init_(CSOUND *csound);
extern int pvsops_init_(CSOUND *csound);
extern int liveconv_init_(CSOUND *csound);
extern int unsupported_opdoces_init_(CSOUND *csound);
extern int dateops_init_(CSOUND *csound);
#endif

// returns the address of a string
Expand Down Expand Up @@ -206,6 +207,7 @@ CSOUND *csoundCreateWasi() {
emugens_init_(csound);
pvsops_init_(csound);
liveconv_init_(csound);
dateops_init_(csound);
unsupported_opdoces_init_(csound);
return csound;
}
Expand All @@ -222,6 +224,7 @@ void csoundResetWasi(CSOUND *csound) {
emugens_init_(csound);
pvsops_init_(csound);
liveconv_init_(csound);
dateops_init_(csound);
unsupported_opdoces_init_(csound);
}

Expand Down
41 changes: 10 additions & 31 deletions nix/native/libcsound_objects.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,6 @@ in pkgs.callPackage
'';
};

patchGetCWD = pkgs.writeTextFile {
name = "patchGetCWD";
executable = true;
destination = "/bin/patchGetCWD";
text = ''
#!${pkgs.nodejs}/bin/node
const myArgs = process.argv.slice(2);
const myFile = myArgs[0];
const fs = require('fs')
fs.readFile(myFile, 'utf8', function (err,data) {
if (err) { return console.log(err); }
const regex = "static int32_t getcurdir.*" +
"#ifndef MAXLINE";
const result = data.replace(new RegExp(regex, 'is'),
`
static int32_t getcurdir(CSOUND *csound, GETCWD *p) {
p->Scd->size = 2;
p->Scd->data = "/";
return OK;
}
#ifndef MAXLINE`);
fs.writeFile(myFile, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
'';
};
libsndfileP = import ./sndfileWasi.nix;

csoundModLoadPatch = pkgs.writeTextFile
Expand Down Expand Up @@ -163,9 +135,6 @@ in pkgs.callPackage
# Patch 64bit integer clock
${patchClock}/bin/patchClock Top/csound.c
# Patch getCWD
${patchGetCWD}/bin/patchGetCWD Opcodes/date.c
touch include/float-version.h
substituteInPlace Top/csmodule.c \
--replace '#include <dlfcn.h>' ""
Expand Down Expand Up @@ -309,6 +278,16 @@ in pkgs.callPackage
return csound->AppendOpcodes(csound,
&(localops[0]), (int32_t) (sizeof(localops) / sizeof(OENTRY))); }'
# date and fs
sed -i '1s|^|char *getcwd(x,y) {return "/";}\n|' Opcodes/date.c
sed -i '1s/^/#include <unistd.h>\n/' Opcodes/date.c
sed -i -e 's/LINUX/1/g' Opcodes/date.c
substituteInPlace Opcodes/date.c \
--replace 'LINKAGE_BUILTIN(date_localops)' \
'int32_t dateops_init_(CSOUND *csound) {
return csound->AppendOpcodes(csound,
&(date_localops[0]), (int32_t) (sizeof(date_localops) / sizeof(OENTRY))); }'
echo 'extern "C" {
extern int pvsops_init_(CSOUND *csound) {
csnd::on_load((csnd::Csound *)csound);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "csound-wasm",
"version": "6.14.0-5",
"version": "6.14.0-6",
"author": "Hlödver Sigurdsson <[email protected]>",
"license": "LGPL-3.0",
"main": "./dist/libcsound.mjs",
Expand Down

0 comments on commit b2ea1b1

Please sign in to comment.