Always use correct header and footer in CFCPerl Also fix CFISH_THROW format strings and args in callbacks.c.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e5c275cd Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e5c275cd Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e5c275cd Branch: refs/heads/master Commit: e5c275cd5abbd51c84ac2980104793178317d8c0 Parents: 8ac8d6b Author: Nick Wellnhofer <[email protected]> Authored: Mon Jan 7 23:23:05 2013 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Mon Jan 7 23:25:34 2013 +0100 ---------------------------------------------------------------------- clownfish/compiler/src/CFCPerl.c | 248 ++++++++++++++------------------ 1 files changed, 109 insertions(+), 139 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/e5c275cd/clownfish/compiler/src/CFCPerl.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/src/CFCPerl.c b/clownfish/compiler/src/CFCPerl.c index 92e4261..43cffe5 100644 --- a/clownfish/compiler/src/CFCPerl.c +++ b/clownfish/compiler/src/CFCPerl.c @@ -319,51 +319,36 @@ CFCPerl_write_boot(CFCPerl *self) { static char* S_xs_file_contents(CFCPerl *self, const char *generated_xs, const char *xs_init, const char *hand_rolled_xs) { - const char pattern[] = - "/* DO NOT EDIT!!!! This is an auto-generated file. */\n" - "\n" - "/* Licensed to the Apache Software Foundation (ASF) under one or more\n" - " * contributor license agreements. See the NOTICE file distributed with\n" - " * this work for additional information regarding copyright ownership.\n" - " * The ASF licenses this file to You under the Apache License, Version 2.0\n" - " * (the \"License\"); you may not use this file except in compliance with\n" - " * the License. You may obtain a copy of the License at\n" - " *\n" - " * http://www.apache.org/licenses/LICENSE-2.0\n" - " *\n" - " * Unless required by applicable law or agreed to in writing, software\n" - " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" - " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - " * See the License for the specific language governing permissions and\n" - " * limitations under the License.\n" - " */\n" - "\n" - "#include \"XSBind.h\"\n" - "#include \"parcel.h\"\n" - "#include \"%s\"\n" - "\n" - "#include \"Clownfish/Util/Memory.h\"\n" - "#include \"Clownfish/Util/StringHelper.h\"\n" - "\n" - "%s\n" - "\n" - "MODULE = %s PACKAGE = %s\n" - "\n" - "void\n" - "_init_autobindings()\n" - "PPCODE:\n" - "{\n" - " const char* file = __FILE__;\n" - " CHY_UNUSED_VAR(cv);\n" - " CHY_UNUSED_VAR(items); %s\n" - "}\n" - "\n" - "%s\n" - "\n"; + const char pattern[] = + "%s" + "\n" + "#include \"XSBind.h\"\n" + "#include \"parcel.h\"\n" + "#include \"%s\"\n" + "\n" + "#include \"Clownfish/Util/Memory.h\"\n" + "#include \"Clownfish/Util/StringHelper.h\"\n" + "\n" + "%s\n" + "\n" + "MODULE = %s PACKAGE = %s\n" + "\n" + "void\n" + "_init_autobindings()\n" + "PPCODE:\n" + "{\n" + " const char* file = __FILE__;\n" + " CHY_UNUSED_VAR(cv);\n" + " CHY_UNUSED_VAR(items); %s\n" + "}\n" + "\n" + "%s\n" + "\n" + "%s"; char *contents - = CFCUtil_sprintf(pattern, self->boot_h_file, generated_xs, - self->boot_class, self->boot_class, xs_init, - hand_rolled_xs); + = CFCUtil_sprintf(pattern, self->header, self->boot_h_file, + generated_xs, self->boot_class, self->boot_class, + xs_init, hand_rolled_xs, self->footer); return contents; } @@ -461,101 +446,84 @@ CFCPerl_write_bindings(CFCPerl *self) { void CFCPerl_write_callbacks(CFCPerl *self) { CFCClass **ordered = CFCHierarchy_ordered_classes(self->hierarchy); - static const char start[] = - "/* DO NOT EDIT!!!! This is an auto-generated file. */\n" - "\n" - "/* Licensed to the Apache Software Foundation (ASF) under one or more\n" - " * contributor license agreements. See the NOTICE file distributed with\n" - " * this work for additional information regarding copyright ownership.\n" - " * The ASF licenses this file to You under the Apache License, Version 2.0\n" - " * (the \"License\"); you may not use this file except in compliance with\n" - " * the License. You may obtain a copy of the License at\n" - " *\n" - " * http://www.apache.org/licenses/LICENSE-2.0\n" - " *\n" - " * Unless required by applicable law or agreed to in writing, software\n" - " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" - " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - " * See the License for the specific language governing permissions and\n" - " * limitations under the License.\n" - " */\n" - "\n" - "#include \"XSBind.h\"\n" - "#include \"parcel.h\"\n" - "\n" - "static void\n" - "S_finish_callback_void(const char *meth_name) {\n" - " int count = call_method(meth_name, G_VOID | G_DISCARD);\n" - " if (count != 0) {\n" - " CFISH_THROW(CFISH_ERR, \"Bad callback to '%%s': %%i32\",\n" - " \"%s\", (int32_t)count);\n" - " }\n" - " FREETMPS;\n" - " LEAVE;\n" - "}\n" - "\n" - "static CHY_INLINE SV*\n" - "SI_do_callback_sv(const char *meth_name) {\n" - " int count = call_method(meth_name, G_SCALAR);\n" - " if (count != 1) {\n" - " CFISH_THROW(CFISH_ERR, \"Bad callback to '%%s': %%i32\",\n" - " \"%s\", (int32_t)count);\n" - " }\n" - " dSP;\n" - " SV *return_sv = POPs;\n" - " PUTBACK;\n" - " return return_sv;\n" - "}\n" - "\n" - "static int64_t\n" - "S_finish_callback_i64(const char *meth_name) {\n" - " SV *return_sv = SI_do_callback_sv(meth_name);\n" - " int64_t retval;\n" - " if (sizeof(IV) == 8) {\n" - " retval = (int64_t)SvIV(return_sv);\n" - " }\n" - " else {\n" - " if (SvIOK(return_sv)) {\n" - " // It's already no more than 32 bits, so don't convert.\n" - " retval = SvIV(return_sv);\n" - " }\n" - " else {\n" - " // Maybe lossy.\n" - " double temp = SvNV(return_sv);\n" - " retval = (int64_t)temp;\n" - " }\n" - " }\n" - " FREETMPS;\n" - " LEAVE;\n" - " return retval;\n" - "}\n" - "\n" - "static double\n" - "S_finish_callback_f64(const char *meth_name) {\n" - " SV *return_sv = SI_do_callback_sv(meth_name);\n" - " double retval = SvNV(return_sv);\n" - " FREETMPS;\n" - " LEAVE;\n" - " return retval;\n" - "}\n" - "\n" - "static cfish_Obj*\n" - "S_finish_callback_obj(void *vself, const char *meth_name,\n" - " int nullable) {\n" - " SV *return_sv = SI_do_callback_sv(meth_name);\n" - " cfish_Obj *retval = XSBind_perl_to_cfish(return_sv);\n" - " FREETMPS;\n" - " LEAVE;\n" - " if (!nullable && !retval) {\n" - " CFISH_THROW(CFISH_ERR, \"%%o#%%s cannot return NULL\",\n" - " Cfish_Obj_Get_Class_Name((cfish_Obj*)vself),\n" - " meth_name);\n" - " }\n" - " return retval;\n" - "}\n" - "\n"; - - char *content = CFCUtil_strdup(start); + static const char pattern[] = + "%s" + "\n" + "#include \"XSBind.h\"\n" + "#include \"parcel.h\"\n" + "\n" + "static void\n" + "S_finish_callback_void(const char *meth_name) {\n" + " int count = call_method(meth_name, G_VOID | G_DISCARD);\n" + " if (count != 0) {\n" + " CFISH_THROW(CFISH_ERR, \"Bad callback to '%%s': %%i32\",\n" + " meth_name, (int32_t)count);\n" + " }\n" + " FREETMPS;\n" + " LEAVE;\n" + "}\n" + "\n" + "static CHY_INLINE SV*\n" + "SI_do_callback_sv(const char *meth_name) {\n" + " int count = call_method(meth_name, G_SCALAR);\n" + " if (count != 1) {\n" + " CFISH_THROW(CFISH_ERR, \"Bad callback to '%%s': %%i32\",\n" + " meth_name, (int32_t)count);\n" + " }\n" + " dSP;\n" + " SV *return_sv = POPs;\n" + " PUTBACK;\n" + " return return_sv;\n" + "}\n" + "\n" + "static int64_t\n" + "S_finish_callback_i64(const char *meth_name) {\n" + " SV *return_sv = SI_do_callback_sv(meth_name);\n" + " int64_t retval;\n" + " if (sizeof(IV) == 8) {\n" + " retval = (int64_t)SvIV(return_sv);\n" + " }\n" + " else {\n" + " if (SvIOK(return_sv)) {\n" + " // It's already no more than 32 bits, so don't convert.\n" + " retval = SvIV(return_sv);\n" + " }\n" + " else {\n" + " // Maybe lossy.\n" + " double temp = SvNV(return_sv);\n" + " retval = (int64_t)temp;\n" + " }\n" + " }\n" + " FREETMPS;\n" + " LEAVE;\n" + " return retval;\n" + "}\n" + "\n" + "static double\n" + "S_finish_callback_f64(const char *meth_name) {\n" + " SV *return_sv = SI_do_callback_sv(meth_name);\n" + " double retval = SvNV(return_sv);\n" + " FREETMPS;\n" + " LEAVE;\n" + " return retval;\n" + "}\n" + "\n" + "static cfish_Obj*\n" + "S_finish_callback_obj(void *vself, const char *meth_name,\n" + " int nullable) {\n" + " SV *return_sv = SI_do_callback_sv(meth_name);\n" + " cfish_Obj *retval = XSBind_perl_to_cfish(return_sv);\n" + " FREETMPS;\n" + " LEAVE;\n" + " if (!nullable && !retval) {\n" + " CFISH_THROW(CFISH_ERR, \"%%o#%%s cannot return NULL\",\n" + " Cfish_Obj_Get_Class_Name((cfish_Obj*)vself),\n" + " meth_name);\n" + " }\n" + " return retval;\n" + "}\n" + "\n"; + char *content = CFCUtil_sprintf(pattern, self->header); for (size_t i = 0; ordered[i] != NULL; i++) { CFCClass *klass = ordered[i]; @@ -575,6 +543,8 @@ CFCPerl_write_callbacks(CFCPerl *self) { FREEMEM(fresh_methods); } + content = CFCUtil_cat(content, self->footer, NULL); + // Write if changed. const char *src_dest = CFCHierarchy_get_source_dest(self->hierarchy); char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "callbacks.c",
