- if your wrapper calls directly the function, without doing anything else, but dropping "self" you should use DEFINE_, just in case compiler doesn't inline that call. I don't remember if it's in the doc.
re this an SvREFCNT_inc below, I figured it might be best to keep it as a separate function and not use define. in the patch below, the C function digs out the object, while the *.h wrapper calls the C function and increments the refcount before returning to Perl-land. sound ok?
- I don't think modperl_get_config is a good choice for a function name. It must start with modperl_module_ (think of namespaces, ala C++). How about modperl_module_config_get?
ok
Probably need to add comments explaining the difference between this and get_config_obj functions.
as I read things, get_config_obj isn't digging out the object, it's creating it. in fact, if the object already exists it doesn't even return it
if ((*obj = (SV*)modperl_svptr_table_fetch(aTHX_ table, cfg))) {
/* object already exists */
return NULL;
}so, the below patch renames that function to modperl_module_config_create_obj instead, in the hopes of clarifying things a bit more.
- Also I'm not sure about keeping the SvREFCNT_inc(obj) part. It's needed when returning an SV that goes into perl domain, but it's probably not a good choice for C API.
anyway, lemme know if you think this fits.
--Geoff
Index: src/modules/perl/modperl_module.c
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_module.c,v
retrieving revision 1.14
diff -u -r1.14 modperl_module.c
--- src/modules/perl/modperl_module.c 30 May 2003 12:55:14 -0000 1.14
+++ src/modules/perl/modperl_module.c 2 Jun 2003 13:57:07 -0000
@@ -246,7 +246,7 @@
sv_2mortal(modperl_ptr2obj(aTHX_ "Apache::CmdParms", (void *)parms)) static const char *
-modperl_module_config_get_obj(pTHX_
+modperl_module_config_create_obj(pTHX_
apr_pool_t *p,
PTR_TBL_t *table,
modperl_module_cfg_t *cfg,
@@ -385,7 +385,7 @@}
- errmsg = modperl_module_config_get_obj(aTHX_ p, table, cfg, info,
+ errmsg = modperl_module_config_create_obj(aTHX_ p, table, cfg, info,
minfo->dir_create,
parms, &obj);@@ -406,7 +406,7 @@
if (srv_cfg) {
SV *srv_obj;
- errmsg = modperl_module_config_get_obj(aTHX_ p, table, srv_cfg, info,
+ errmsg = modperl_module_config_create_obj(aTHX_ p, table, srv_cfg, info,
minfo->srv_create,
parms, &srv_obj);
if (errmsg) {
@@ -852,4 +852,45 @@
#endif return NULL;
+}
+
+SV *modperl_module_config_get(pTHX_ SV *pmodule, server_rec *s, ap_conf_vector_t *v)
+{
+ MP_dSCFG(s);
+ module *modp;
+ const char *name;
+ void *ptr;
+ PTR_TBL_t *table;
+ SV *obj;
+
+ if (!v) {
+ v = s->module_config;
+ }
+
+ if (SvROK(pmodule)) {
+ name = SvCLASS(pmodule);
+ }
+ else {
+ STRLEN n_a;
+ name = SvPV(pmodule, n_a);
+ }
+
+ if (!(scfg->modules &&
+ (modp = apr_hash_get(scfg->modules, name, APR_HASH_KEY_STRING)))) {
+ return &PL_sv_undef;
+ }
+
+ if (!(ptr = ap_get_module_config(v, modp))) {
+ return &PL_sv_undef;
+ }
+
+ if (!(table = modperl_module_config_table_get(aTHX_ FALSE))) {
+ return &PL_sv_undef;
+ }
+
+ if (!(obj = modperl_svptr_table_fetch(aTHX_ table, ptr))) {
+ return &PL_sv_undef;
+ }
+
+ obj;
}
Index: src/modules/perl/modperl_module.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_module.h,v
retrieving revision 1.1
diff -u -r1.1 modperl_module.h
--- src/modules/perl/modperl_module.h 27 Aug 2002 04:21:20 -0000 1.1
+++ src/modules/perl/modperl_module.h 2 Jun 2003 13:57:07 -0000
@@ -8,4 +8,6 @@
const char *modperl_module_add(apr_pool_t *p, server_rec *s,
const char *name);+SV *modperl_module_config_get(pTHX_ SV *pmodule, server_rec *s, ap_conf_vector_t *v);
+
#endif /* MODPERL_MODULE_H */
Index: xs/Apache/Module/Apache__Module.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/Apache/Module/Apache__Module.h,v
retrieving revision 1.10
diff -u -r1.10 Apache__Module.h
--- xs/Apache/Module/Apache__Module.h 30 May 2003 13:39:44 -0000 1.10
+++ xs/Apache/Module/Apache__Module.h 2 Jun 2003 13:57:09 -0000
@@ -44,41 +44,7 @@
server_rec *s,
ap_conf_vector_t *v)
{
- MP_dSCFG(s);
- module *modp;
- const char *name;
- void *ptr;
- PTR_TBL_t *table;
- SV *obj;
-
- if (!v) {
- v = s->module_config;
- }
-
- if (SvROK(pmodule)) {
- name = SvCLASS(pmodule);
- }
- else {
- STRLEN n_a;
- name = SvPV(pmodule, n_a);
- }
-
- if (!(scfg->modules &&
- (modp = apr_hash_get(scfg->modules, name, APR_HASH_KEY_STRING)))) {
- return &PL_sv_undef;
- }
-
- if (!(ptr = ap_get_module_config(v, modp))) {
- return &PL_sv_undef;
- }
-
- if (!(table = modperl_module_config_table_get(aTHX_ FALSE))) {
- return &PL_sv_undef;
- }
-
- if (!(obj = modperl_svptr_table_fetch(aTHX_ table, ptr))) {
- return &PL_sv_undef;
- }
+ SV *obj = modperl_module_config_get(aTHX_ pmodule, s, v); return SvREFCNT_inc(obj);
}
Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
retrieving revision 1.115
diff -u -r1.115 FunctionTable.pm
--- xs/tables/current/ModPerl/FunctionTable.pm 30 May 2003 12:55:15 -0000 1.115
+++ xs/tables/current/ModPerl/FunctionTable.pm 2 Jun 2003 13:57:10 -0000
@@ -3139,6 +3139,28 @@
]
},
{
+ 'return_type' => 'SV *',
+ 'name' => 'modperl_module_config_get',
+ 'args' => [
+ {
+ 'type' => 'PerlInterpreter *',
+ 'name' => 'my_perl'
+ },
+ {
+ 'type' => 'SV *',
+ 'name' => 'pmodule'
+ },
+ {
+ 'type' => 'server_rec *',
+ 'name' => 's'
+ },
+ {
+ 'type' => 'ap_conf_vector_t *',
+ 'name' => 'v'
+ }
+ ]
+ },
+ {
'return_type' => 'PTR_TBL_t *',
'name' => 'modperl_module_config_table_get',
'args' => [
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
