diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 9749afd07..8408d153e 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -1108,7 +1108,8 @@ dict_super_edge_with_tile( const DictionaryCtxt* dict, array_edge* from, void dict_super_init( MPFORMAL DictionaryCtxt* dict ) { - dict->mpool = mpool; + MPASSIGN(dict->mpool, mpool); + /* subclass may change these later.... */ dict->func_edge_for_index = dict_super_edge_for_index; dict->func_dict_getTopEdge = dict_super_getTopEdge; diff --git a/xwords4/common/game.h b/xwords4/common/game.h index 369fe80f0..1d675618b 100644 --- a/xwords4/common/game.h +++ b/xwords4/common/game.h @@ -1,6 +1,6 @@ /* -*- compile-command: "cd ../linux && make -j3 MEMDEBUG=TRUE"; -*- */ /* - * Copyright 2001-2011 by Eric House (xwords@eehouse.org). All rights + * Copyright 2001 - 2021 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or diff --git a/xwords4/wasm/Makefile b/xwords4/wasm/Makefile index dd327cb5e..9bdc40392 100644 --- a/xwords4/wasm/Makefile +++ b/xwords4/wasm/Makefile @@ -1,3 +1,20 @@ +# -*- mode: makefile; compile-command: "make -j3 MEMDEBUG=TRUE install"; -*- +# Copyright 2021 by Eric House (xwords@eehouse.org). All rights +# reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. include ../common/config.mk @@ -5,7 +22,6 @@ DEBS = cmake INPUTS = main.c wasmdict.c wasmutls.c wasmdraw.c wasmutil.c wasmdutil.c ${COMMONSRC} -DEFINES += -DMEM_DEBUG -DDEBUG DEFINES += -DXWFEATURE_CHAT DEFINES += -DXWFEATURE_BONUSALL DEFINES += -DMAX_ROWS=32 @@ -28,6 +44,13 @@ DEFINES += -DPLATFORM_WASM DEFINES += -DXWFEATURE_CROSSHAIRS DEFINES += -DNATIVE_NLI DEFINES += -DDEBUG_REF + +ifeq ($(MEMDEBUG),TRUE) + DEFINES += -DMEM_DEBUG -DDEBUG -O +else + DEFINES += -O3 +endif + OUTPUTS = main.html main.js main.js.mem main.data main.html.mem main.wasm all: main.js diff --git a/xwords4/wasm/main.c b/xwords4/wasm/main.c index 126124145..7012f9ebe 100644 --- a/xwords4/wasm/main.c +++ b/xwords4/wasm/main.c @@ -140,9 +140,11 @@ initDeviceGlobals( Globals* globals ) globals->procs.send = send_msg; globals->procs.closure = globals; +#ifdef MEMDEBUG globals->mpool = mpool_make( "wasm" ); - globals->vtMgr = make_vtablemgr( globals->mpool ); - globals->dutil = wasm_dutil_make( globals->mpool, globals->vtMgr, globals ); +#endif + globals->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(globals->mpool) ); + globals->dutil = wasm_dutil_make( MPPARM(globals->mpool) globals->vtMgr, globals ); globals->dictMgr = dmgr_make( MPPARM_NOCOMMA(globals->mpool) ); globals->dict = wasm_dictionary_make( MPPARM(globals->mpool) NULL, globals, DICTNAME, true ); @@ -218,7 +220,7 @@ gameFromInvite( Globals* globals, const NetLaunchInfo* invite ) gi_disposePlayerInfo( MPPARM(globals->mpool) &globals->gi ); XP_MEMSET( &globals->gi, 0, sizeof(globals->gi) ); - globals->util = wasm_util_make( globals->mpool, &globals->gi, + globals->util = wasm_util_make( MPPARM(globals->mpool) &globals->gi, globals->dutil, globals ); loaded = game_makeFromInvite( MPPARM(globals->mpool) NULL, invite, @@ -243,7 +245,7 @@ loadSavedGame( Globals* globals ) dutil_loadStream( globals->dutil, NULL, KEY_GAME, NULL, stream ); if ( 0 < stream_getSize( stream ) ) { XP_ASSERT( !globals->util ); - globals->util = wasm_util_make( globals->mpool, &globals->gi, + globals->util = wasm_util_make( MPPARM(globals->mpool) &globals->gi, globals->dutil, globals ); XP_LOGFF( "there's a saved game!!" ); @@ -299,7 +301,7 @@ loadAndDraw( Globals* globals, const NetLaunchInfo* invite, globals->gi.players[1].isLocal = XP_TRUE; globals->gi.players[1].robotIQ = p1robot ? 99 : 0; - globals->util = wasm_util_make( globals->mpool, &globals->gi, + globals->util = wasm_util_make( MPPARM(globals->mpool) &globals->gi, globals->dutil, globals ); XP_LOGFF( "calling game_makeNewGame()" ); diff --git a/xwords4/wasm/main.h b/xwords4/wasm/main.h index 5b086982b..0c8045d6e 100644 --- a/xwords4/wasm/main.h +++ b/xwords4/wasm/main.h @@ -1,3 +1,21 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #ifndef _MAIN_H_ #define _MAIN_H_ diff --git a/xwords4/wasm/wasmdict.c b/xwords4/wasm/wasmdict.c index 1ef15a209..b0cfa79f4 100644 --- a/xwords4/wasm/wasmdict.c +++ b/xwords4/wasm/wasmdict.c @@ -1,3 +1,22 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include #include #include diff --git a/xwords4/wasm/wasmdraw.c b/xwords4/wasm/wasmdraw.c index 98da3a2c2..c93138b62 100644 --- a/xwords4/wasm/wasmdraw.c +++ b/xwords4/wasm/wasmdraw.c @@ -1,3 +1,22 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include #include #include diff --git a/xwords4/wasm/wasmdraw.h b/xwords4/wasm/wasmdraw.h index c2eb30b78..d664e5e86 100644 --- a/xwords4/wasm/wasmdraw.h +++ b/xwords4/wasm/wasmdraw.h @@ -1,4 +1,21 @@ - +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #ifndef _WASMDRAW_H_ #define _WASMDRAW_H_ diff --git a/xwords4/wasm/wasmdutil.c b/xwords4/wasm/wasmdutil.c index 94d31b040..de2158ab6 100644 --- a/xwords4/wasm/wasmdutil.c +++ b/xwords4/wasm/wasmdutil.c @@ -1,3 +1,22 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include #include diff --git a/xwords4/wasm/wasmdutil.h b/xwords4/wasm/wasmdutil.h index faf50fa48..92eadcedb 100644 --- a/xwords4/wasm/wasmdutil.h +++ b/xwords4/wasm/wasmdutil.h @@ -1,3 +1,21 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #ifndef _WASMDUTIL_H_ #define _WASMDUTIL_H_ diff --git a/xwords4/wasm/wasmutil.c b/xwords4/wasm/wasmutil.c index 8c4ef74e0..ac50f1ec0 100644 --- a/xwords4/wasm/wasmutil.c +++ b/xwords4/wasm/wasmutil.c @@ -1,3 +1,21 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include "util.h" #include "comtypes.h" @@ -512,7 +530,7 @@ wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dctxt, void* closure ) LOG_FUNC(); WasmUtilCtx* wuctxt = XP_MALLOC( mpool, sizeof(*wuctxt) ); wuctxt->super.vtable = XP_MALLOC( mpool, sizeof(*wuctxt->super.vtable) ); - wuctxt->super.mpool = mpool; + MPASSIGN( wuctxt->super.mpool, mpool ); wuctxt->super.gameInfo = gi; wuctxt->dctxt = dctxt; diff --git a/xwords4/wasm/wasmutil.h b/xwords4/wasm/wasmutil.h index 058cf50ed..33b1e5ab2 100644 --- a/xwords4/wasm/wasmutil.h +++ b/xwords4/wasm/wasmutil.h @@ -1,3 +1,21 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #ifndef _WASMUTIL_H_ #define _WASMUTIL_H_ diff --git a/xwords4/wasm/wasmutls.c b/xwords4/wasm/wasmutls.c index a462f6fe3..1db1d738b 100644 --- a/xwords4/wasm/wasmutls.c +++ b/xwords4/wasm/wasmutls.c @@ -1,3 +1,23 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include #include #include @@ -24,3 +44,14 @@ wasm_debugff( const char* func, const char* file, const char* fmt, ...) va_end( ap ); fprintf( stderr, "\n" ); } + +#ifndef MEM_DEBUG +void +wasm_freep( void** ptrp ) +{ + if ( !!*ptrp ) { + free( *ptrp ); + *ptrp = NULL; + } +} +#endif diff --git a/xwords4/wasm/wasmutls.h b/xwords4/wasm/wasmutls.h index 991c4a55b..744bb0d9c 100644 --- a/xwords4/wasm/wasmutls.h +++ b/xwords4/wasm/wasmutls.h @@ -1,5 +1,29 @@ +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ - +#ifndef _WASMUTLS_H_ +#define _WASMUTLS_H_ void wasm_debugf( const char* format, ... ); void wasm_debugff( const char* func, const char* file, const char* fmt, ...); +# ifndef MEM_DEBUG +void wasm_freep( void** ptrp ); +# endif + +#endif diff --git a/xwords4/wasm/xptypes.h b/xwords4/wasm/xptypes.h index 0289d235a..302808e9a 100644 --- a/xwords4/wasm/xptypes.h +++ b/xwords4/wasm/xptypes.h @@ -1,4 +1,21 @@ - +/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */ +/* + * Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include #include @@ -51,8 +68,7 @@ typedef void* XWEnv; # define XP_CALLOC(pool,nbytes) calloc(1,nbytes) # define XP_REALLOC(pool,p,s) realloc((p),(s)) # define XP_FREE(pool,p) free(p) -void linux_freep( void** ptrp ); -# define XP_FREEP(pool,p) linux_freep((void**)p) +# define XP_FREEP(pool,p) wasm_freep((void**)p) #endif #ifdef DEBUG