* how to expose a simple const char *array[]?
@ 2015-03-19 14:59 Roman Neuhauser
2015-03-19 21:59 ` Roman Neuhauser
2015-03-19 22:40 ` Bart Schaefer
0 siblings, 2 replies; 3+ messages in thread
From: Roman Neuhauser @ 2015-03-19 14:59 UTC (permalink / raw)
To: zsh-workers
hello,
i need a little help in exposing an array from zsh.
i'm trying to wrap the contents of Src/zshpaths.h in a module, initial
smoke tests look ok except this one thing: FPATH_SUBDIRS as an array.
the other modules that expose arrays use array_gsu structures as the
values need to be generated on the fly. my case should be simpler so i
thought i'd get away without any fanfare, but it segfaults on access.
#define FPATH_SUBDIRS { "Calendar", "Chpwd", "Completion" /* , ... */ }
#ifdef FPATH_SUBDIRS
static const char *fpath_subdirs[] = FPATH_SUBDIRS;
#else
static const char *fpath_subdirs[] = { NULL };
#endif
static struct paramdef patab[] = {
PARAMDEF("module_dir", PM_SCALAR|PM_READONLY, &module_dir, NULL),
PARAMDEF("sitescript_dir", PM_SCALAR|PM_READONLY, &sitescript_dir, NULL),
PARAMDEF("script_dir", PM_SCALAR|PM_READONLY, &script_dir, NULL),
PARAMDEF("sitefpath_dir", PM_SCALAR|PM_READONLY, &sitefpath_dir, NULL),
PARAMDEF("fixed_fpath_dir", PM_SCALAR|PM_READONLY, &fixed_fpath_dir, NULL),
PARAMDEF("fpath_dir", PM_SCALAR|PM_READONLY, &fpath_dir, NULL),
PARAMDEF("fpath_subdirs", PM_ARRAY |PM_READONLY, &fpath_subdirs, NULL)
};
it's surely doing something stupid...
--
roman
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: how to expose a simple const char *array[]?
2015-03-19 14:59 how to expose a simple const char *array[]? Roman Neuhauser
@ 2015-03-19 21:59 ` Roman Neuhauser
2015-03-19 22:40 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Roman Neuhauser @ 2015-03-19 21:59 UTC (permalink / raw)
To: zsh-workers
# neuhauser@sigpipe.cz / 2015-03-19 15:59:47 +0100:
> static const char *fpath_subdirs[] =
> { "Calendar", "Chpwd", "Completion" /* , ... */ };
>
> static struct paramdef patab[] = {
> PARAMDEF("fpath_subdirs", PM_ARRAY |PM_READONLY, &fpath_subdirs, NULL)
> };
>
> it's surely doing something stupid...
it's surely *ME* doing something stupid... and "stupid" as in
"trivially wrong": i'm just a dabbler in C.
--
roman
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: how to expose a simple const char *array[]?
2015-03-19 14:59 how to expose a simple const char *array[]? Roman Neuhauser
2015-03-19 21:59 ` Roman Neuhauser
@ 2015-03-19 22:40 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2015-03-19 22:40 UTC (permalink / raw)
To: Roman Neuhauser, zsh-workers
On Mar 19, 3:59pm, Roman Neuhauser wrote:
}
} i'm trying to wrap the contents of Src/zshpaths.h in a module, initial
} smoke tests look ok except this one thing: FPATH_SUBDIRS as an array.
} the other modules that expose arrays use array_gsu structures as the
} values need to be generated on the fly. my case should be simpler so i
} thought i'd get away without any fanfare, but it segfaults on access.
The only problem you have here is that FPATH_SUBDIRS is not terminated
with a final NULL element, but *fpath_subdirs[] must be so terminated
in order to be treated as an array parameter.
So your module will have to do something in its boot_() function to
copy from FPATH_SUBDIRS into an array one element longer, and poke a
NULL at the end.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-19 22:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-19 14:59 how to expose a simple const char *array[]? Roman Neuhauser
2015-03-19 21:59 ` Roman Neuhauser
2015-03-19 22:40 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).